Skip to content

Commit

Permalink
Use NetworkService.add and NetworkHost.add
Browse files Browse the repository at this point in the history
  • Loading branch information
bcoles committed Jun 28, 2015
1 parent d05397e commit 0d3c123
Show file tree
Hide file tree
Showing 13 changed files with 31 additions and 80 deletions.
6 changes: 2 additions & 4 deletions core/main/handlers/browserdetails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -180,8 +180,7 @@ def setup()
if config.get("beef.extension.network.enable") == true
if proxy_server =~ /^([\d\.]+):([\d]+)$/
print_debug("Hooked browser [id:#{zombie.id}] is using a proxy [ip: #{$1}]")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => $1, :type => 'Proxy', :cid => 'init')
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => $1, :type => 'Proxy', :cid => 'init')
end
end
end
Expand Down Expand Up @@ -354,8 +353,7 @@ def setup()
# add localhost as network host
if config.get('beef.extension.network.enable')
print_debug("Hooked browser has network interface 127.0.0.1")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => '127.0.0.1', :hostname => 'localhost', :os => BeEF::Core::Models::BrowserDetails.get(session_id, 'OsName'), :cid => 'init')
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => '127.0.0.1', :hostname => 'localhost', :os => BeEF::Core::Models::BrowserDetails.get(session_id, 'OsName'), :cid => 'init')
end

# Call autorun modules
Expand Down
15 changes: 5 additions & 10 deletions modules/exploits/router/asus_rt_series_get_info/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,8 @@ def post_execute

if !ip.nil? && BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found Asus RT series router [ip: #{ip}]")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :type => 'Asus Router', :cid => cid)
r.save
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => 'http', :ip => ip, :port => 80, :type => 'HTTP Server', :cid => cid)
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :type => 'Asus Router', :cid => cid)
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => 'http', :ip => ip, :port => 80, :type => 'HTTP Server', :cid => cid)
end
clients.scan(/([\d\.]+,[:\dA-F]{17})/).flatten.each do |client|
next if client.nil?
Expand All @@ -43,22 +41,19 @@ def post_execute
mac = $2
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found router client [ip: #{ip}, mac: #{mac}]")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :mac => mac, :cid => cid)
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :mac => mac, :cid => cid)
end
end
end
if !gateway.nil? && BeEF::Filters.is_valid_ip?(gateway)
print_debug("Hooked browser found WAN gateway server [ip: #{gateway}]")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => gateway, :type => 'WAN Gateway', :cid => cid)
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => gateway, :type => 'WAN Gateway', :cid => cid)
end
if !dns_servers.nil? && dns_servers =~ /^([\d\. ]+)$/
dns_servers.split(/ /).uniq.each do |dns|
if BeEF::Filters.is_valid_ip?(dns)
print_debug("Hooked browser found DNS server [ip: #{dns}]")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => dns, :type => 'DNS Server', :cid => cid)
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => dns, :type => 'DNS Server', :cid => cid)
end
end
end
Expand Down
9 changes: 2 additions & 7 deletions modules/host/detect_cups/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,9 @@ def post_execute
session_id = @datastore['beefhook']
type = 'CUPS'
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) && BeEF::Core::Models::NetworkService.all(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type).empty?
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found 'CUPS' [proto: #{proto}, ip: #{ip}, port: #{port}]")
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type, :cid => cid)
r.save
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty?
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type, :cid => cid)
end
end
end
Expand Down
5 changes: 2 additions & 3 deletions modules/host/get_internal_ip/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,9 @@ def post_execute
# save the network host
if @datastore['results'] =~ /^([\d\.]+)$/
ip = $1
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty? # prevent duplicates
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser has network interface #{ip}")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
end
end
end
Expand Down
10 changes: 2 additions & 8 deletions modules/host/get_internal_ip_webrtc/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,8 @@ def post_execute

configuration = BeEF::Core::Configuration.instance
if configuration.get("beef.extension.network.enable") == true

session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i

# save the network host
if @datastore['results'] =~ /IP is ([\d\.,]+)/
ips = $1.to_s.split(/,/)
Expand All @@ -25,16 +23,12 @@ def post_execute
next unless ip =~ /^[\d\.]+$/
next if ip =~ /^0\.0\.0\.0$/
next unless BeEF::Filters.is_valid_ip?(ip)
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty? # prevent duplicates
print_debug("Hooked browser has network interface #{ip}")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :os => os, :cid => cid)
r.save
end
print_debug("Hooked browser has network interface #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :os => os, :cid => cid)
end
end
end
end

end

end
11 changes: 3 additions & 8 deletions modules/network/cross_origin_scanner/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,9 @@ def post_execute
port = $2
proto = 'http'
type = 'HTTP Server (CORS)'
print_debug("Hooked browser found HTTP server #{ip}:#{port}")
if !ip.nil? && !port.nil? && BeEF::Filters.is_valid_ip?(ip) && BeEF::Core::Models::NetworkService.all(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type).empty?
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type, :cid => cid)
r.save
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty?
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found HTTP server #{ip}:#{port}")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type, :cid => cid)
end
end
end
Expand Down
7 changes: 1 addition & 6 deletions modules/network/get_http_servers/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,12 +35,7 @@ def post_execute
cid = @datastore['cid'].to_i
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found HTTP Server [proto: #{proto}, ip: #{ip}, port: #{port}]")
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => "HTTP Server", :cid => cid)
r.save
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty?
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => "HTTP Server", :cid => cid)
end
end

Expand Down
7 changes: 2 additions & 5 deletions modules/network/identify_lan_subnets/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ def post_execute
next if ip.nil?
next unless ip.to_s =~ /^([\d\.]+)$/
next unless BeEF::Filters.is_valid_ip?(ip)
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty? # prevent duplicates
print_debug("Hooked browser found host #{ip}")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
print_debug("Hooked browser found host #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
end
end
end
Expand Down
9 changes: 2 additions & 7 deletions modules/network/internal_network_fingerprinting/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -35,14 +35,9 @@ def post_execute
url = $5
session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip)
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found '#{discovered}' [ip: #{ip}]")
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => discovered, :cid => cid)
r.save
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty?
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => discovered, :cid => cid)
end
end

Expand Down
10 changes: 4 additions & 6 deletions modules/network/jslanscanner/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -25,20 +25,18 @@ def post_execute
service = $4
session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) && BeEF::Core::Models::NetworkService.all(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service).empty?
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found network service " + service + " [proto: #{proto}, ip: #{ip}, port: #{port}]")
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service, :cid => cid)
r.save
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service, :cid => cid)
end
elsif @datastore['results'] =~ /^ip=(.+)&device=(.+)/
ip = $1
device = $2
session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) && BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip, :type => device).empty?
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found network device " + device + " [ip: #{ip}]")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :type => device, :cid => cid)
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :type => device, :cid => cid)
end
end
end
Expand Down
7 changes: 2 additions & 5 deletions modules/network/ping_sweep/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,11 +37,8 @@ def post_execute
if @datastore['results'] =~ /host=([\d\.]+) is alive/
ip = $1
if BeEF::Filters.is_valid_ip?(ip)
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty? # prevent duplicates
print_debug("Hooked browser has network interface #{ip}")
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
print_debug("Hooked browser has network interface #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
end
end
end
Expand Down
9 changes: 2 additions & 7 deletions modules/network/port_scanner/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -39,14 +39,9 @@ def post_execute
session_id = @datastore['beefhook']
proto = 'http'
cid = @datastore['cid'].to_i
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) && BeEF::Core::Models::NetworkService.all(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service).empty?
if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]")
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service, :cid => cid)
r.save
if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => session_id, :ip => ip).empty?
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => session_id, :ip => ip, :cid => cid)
r.save
end
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service, :cid => cid)
end
end

Expand Down
6 changes: 2 additions & 4 deletions test/unit/extensions/tc_network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,17 +28,15 @@ def test_01_database
# Tests procedure for properly adding new host
def test_02_add_host_good
assert_nothing_raised do
r = BeEF::Core::Models::NetworkHost.new(:hooked_browser_id => '1234', :ip => '127.0.0.1')
r.save
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => '1234', :ip => '127.0.0.1')
raise "Adding network host failed" if BeEF::Core::Models::NetworkHost.all(:hooked_browser_id => '1234', :ip => '127.0.0.1').empty?
end
end

# Tests procedure for properly adding new service
def test_03_add_service_good
assert_nothing_raised do
r = BeEF::Core::Models::NetworkService.new(:hooked_browser_id => '1234', :proto => 'http', :ip => '127.0.0.1', :port => 80, :type => 'Apache', :cid => 1)
r.save
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => '1234', :proto => 'http', :ip => '127.0.0.1', :port => 80, :type => 'Apache', :cid => 1)
raise "Adding network service failed" if BeEF::Core::Models::NetworkService.all(:hooked_browser_id => '1234', :ip => '127.0.0.1').empty?
end
end
Expand Down

0 comments on commit 0d3c123

Please sign in to comment.