Skip to content

Commit

Permalink
SocEng RESTful API test case fix
Browse files Browse the repository at this point in the history
The test_1_dns_spoof test will now work on OSX/nix by
using dig +short to get the A record instead of using
a large regex. In addition, the test will not iterate
over ALL local non-loopback IPs for a match.

See Issue #1083
  • Loading branch information
xntrik committed Jun 23, 2015
1 parent ba990e2 commit f24dd22
Showing 1 changed file with 17 additions and 13 deletions.
30 changes: 17 additions & 13 deletions test/integration/tc_social_engineering_rest.rb
Original file line number Diff line number Diff line change
Expand Up @@ -50,29 +50,33 @@ def test_1_dns_spoof

json = {:url => url, :mount => mount, :dns_spoof => dns_spoof}.to_json

domain = url.gsub(%r{^http://}, '')

response = RestClient.post("#{RESTAPI_SENG}/clone_page?token=#{@@token}",
json,
@@headers)

check_response(response)

ip = Socket.ip_address_list.detect { |i| !(i.ipv4_loopback? || i.ipv6_loopback?) }
domain = url.gsub(%r{^http://}, '')

regex = %r{
^#{domain}\.\t+
\d+\t+
IN\t+
A\t+
#{ip.ip_address}$
}x

# Send DNS request to server to verify that a new rule was added
dns_address = @@config.get('beef.extension.dns.address')
dns_port = @@config.get('beef.extension.dns.port')
dig_output = IO.popen(["dig", "@#{dns_address}", "-p", "#{dns_port}", "-t",
"A", "+short", "#{domain}"], 'r+').read.strip!

foundmatch = false

# Iterate local IPs (excluding loopbacks) to find a match to the 'dig'
# output
assert_block do
Socket.ip_address_list.each { |i|
if !(i.ipv4_loopback? || i.ipv6_loopback?)
return true if i.ip_address.to_s.eql?(dig_output.to_s)
end
}
end

dig_output = IO.popen(["dig", "@#{dns_address}", "-p", "#{dns_port}", "-t", "A", "#{domain}"], 'r+').read
assert_match(regex, dig_output)
# assert(foundmatch)
end

private
Expand Down

0 comments on commit f24dd22

Please sign in to comment.