diff --git a/core/main/handlers/browserdetails.rb b/core/main/handlers/browserdetails.rb index 2d2fcb8601..ae64c2cc36 100644 --- a/core/main/handlers/browserdetails.rb +++ b/core/main/handlers/browserdetails.rb @@ -261,7 +261,8 @@ def setup proxy_log_string += " [server: #{proxy_server}]" if config.get('beef.extension.network.enable') == true && (proxy_server =~ /^([\d.]+):(\d+)$/) print_debug("Hooked browser [id:#{zombie.id}] is using a proxy [ip: #{Regexp.last_match(1)}]") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: Regexp.last_match(1), type: 'Proxy') + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: Regexp.last_match(1), type: 'Proxy') end end BeEF::Core::Logger.instance.register('Zombie', proxy_log_string.to_s, zombie.id.to_s) @@ -554,7 +555,8 @@ 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') - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: '127.0.0.1', hostname: 'localhost', + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: '127.0.0.1', hostname: 'localhost', os: BeEF::Core::Models::BrowserDetails.get(session_id, 'host.os.name')) end diff --git a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js index 65098f53aa..08912ca9ea 100644 --- a/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js +++ b/extensions/admin_ui/media/javascript/ui/panel/tabs/ZombieTabNetwork.js @@ -1084,7 +1084,7 @@ ZombieTab_Network = function(zombie) { autoDestroy: true, autoLoad: false, root: 'services', - fields: ['id', 'proto', 'ip', 'port', 'type'], + fields: ['id', 'proto', 'ip', 'port', 'ntype'], sortInfo: {field: 'ip', direction: 'ASC'} }); @@ -1118,7 +1118,7 @@ ZombieTab_Network = function(zombie) { {header: 'IP Address', width: 10, sortable: true, dataIndex: 'ip', renderer: function(value){return $jEncoder.encoder.encodeForHTML(value)}}, {header: 'Port', width: 5, sortable: true, dataIndex: 'port', renderer: function(value){return $jEncoder.encoder.encodeForHTML(value)}}, {header: 'Protocol', width: 5, sortable: true, dataIndex: 'proto', renderer: function(value){return $jEncoder.encoder.encodeForHTML(value)}}, - {header: 'Type', width: 20, sortable: true, dataIndex: 'type', renderer: function(value){return $jEncoder.encoder.encodeForHTML(value)}} + {header: 'Type', width: 20, sortable: true, dataIndex: 'ntype', renderer: function(value){return $jEncoder.encoder.encodeForHTML(value)}} ], listeners: { diff --git a/extensions/network/rest/network.rb b/extensions/network/rest/network.rb index 228d595b8f..abcc77b919 100644 --- a/extensions/network/rest/network.rb +++ b/extensions/network/rest/network.rb @@ -65,7 +65,7 @@ class NetworkRest < BeEF::Core::Router::Router get '/hosts/:id' do id = params[:id] - hooked_browser = @hb.where(session: id).distinct + hooked_browser = @hb.where(session: id).first hosts = @nh.where(hooked_browser: hooked_browser).distinct.order(:hooked_browser) count = hosts.length @@ -88,8 +88,8 @@ class NetworkRest < BeEF::Core::Router::Router # Returns all services given a specific hooked browser id get '/services/:id' do id = params[:id] - - services = @ns.where(hooked_browser_id: id).distinct.order(:id) + hooked_browser = @hb.where(session: id).first + services = @ns.where(hooked_browser: hooked_browser).distinct.order(:id) count = services.length result = {} diff --git a/modules/exploits/router/asus_rt_n12e_get_info/module.rb b/modules/exploits/router/asus_rt_n12e_get_info/module.rb index 352a414a3d..51c6f49f1b 100644 --- a/modules/exploits/router/asus_rt_n12e_get_info/module.rb +++ b/modules/exploits/router/asus_rt_n12e_get_info/module.rb @@ -26,11 +26,11 @@ def post_execute gateway = Regexp.last_match(5).to_s dns_servers = Regexp.last_match(6).to_s session_id = @datastore['beefhook'] - + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found Asus RT-N12E router [ip: #{ip}]") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip, type: 'Asus RT-N12E Router') - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: 'http', ip: ip, port: 80, type: 'HTTP Server') + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip, type: 'Asus RT-N12E Router') + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: 'http', ip: ip, port: 80, ntype: 'HTTP Server') end clients.scan(/([\d.]+,[:\dA-F]{17})/).flatten.each do |client| @@ -41,20 +41,20 @@ def post_execute mac = Regexp.last_match(2) if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found router client [ip: #{ip}, mac: #{mac}]") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip, mac: mac) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip, mac: mac) end end if !gateway.nil? && BeEF::Filters.is_valid_ip?(gateway) print_debug("Hooked browser found WAN gateway server [ip: #{gateway}]") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: gateway, type: 'WAN Gateway') + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: gateway, type: 'WAN Gateway') 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}]") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: dns, type: 'DNS Server') + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: dns, type: 'DNS Server') end end end diff --git a/modules/host/detect_airdroid/module.rb b/modules/host/detect_airdroid/module.rb index dd8f05a769..cfaac793f7 100644 --- a/modules/host/detect_airdroid/module.rb +++ b/modules/host/detect_airdroid/module.rb @@ -24,10 +24,10 @@ def post_execute port = Regexp.last_match(3) session_id = @datastore['beefhook'] type = 'Airdroid' - + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found 'Airdroid' [proto: #{proto}, ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: type) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: type) end end end diff --git a/modules/host/detect_cups/module.rb b/modules/host/detect_cups/module.rb index 8bf05ef07e..7122c230c8 100644 --- a/modules/host/detect_cups/module.rb +++ b/modules/host/detect_cups/module.rb @@ -24,9 +24,10 @@ def post_execute port = Regexp.last_match(3) session_id = @datastore['beefhook'] type = 'CUPS' + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found 'CUPS' [proto: #{proto}, ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: type) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: type) end end end diff --git a/modules/host/get_internal_ip_java/module.rb b/modules/host/get_internal_ip_java/module.rb index 9258c8ea8d..70dd73cfc3 100755 --- a/modules/host/get_internal_ip_java/module.rb +++ b/modules/host/get_internal_ip_java/module.rb @@ -24,14 +24,14 @@ def post_execute return unless configuration.get('beef.extension.network.enable') == true session_id = @datastore['beefhook'] - + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first # save the network host return unless @datastore['results'] =~ /^([\d.]+)$/ ip = Regexp.last_match(1) if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser has network interface #{ip}") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip) end end end diff --git a/modules/host/get_internal_ip_webrtc/module.rb b/modules/host/get_internal_ip_webrtc/module.rb index d7f61b8aad..b4c56ac05d 100755 --- a/modules/host/get_internal_ip_webrtc/module.rb +++ b/modules/host/get_internal_ip_webrtc/module.rb @@ -17,6 +17,8 @@ def post_execute # save the network host ips = Regexp.last_match(1).to_s.split(/,/) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + if !ips.nil? && !ips.empty? os = BeEF::Core::Models::BrowserDetails.get(session_id, 'host.os.name') ips.uniq.each do |ip| @@ -25,7 +27,7 @@ def post_execute next unless BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser has network interface #{ip}") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip, os: os) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip, os: os) end end end diff --git a/modules/network/cross_origin_scanner_cors/module.rb b/modules/network/cross_origin_scanner_cors/module.rb index 51f5751ab9..74450b3195 100644 --- a/modules/network/cross_origin_scanner_cors/module.rb +++ b/modules/network/cross_origin_scanner_cors/module.rb @@ -19,9 +19,10 @@ def post_execute port = Regexp.last_match(3) type = 'HTTP Server (CORS)' session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found HTTP server #{ip}:#{port}") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: type) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: type) end end diff --git a/modules/network/cross_origin_scanner_flash/module.rb b/modules/network/cross_origin_scanner_flash/module.rb index a802399e96..1de37ada65 100644 --- a/modules/network/cross_origin_scanner_flash/module.rb +++ b/modules/network/cross_origin_scanner_flash/module.rb @@ -18,6 +18,7 @@ def post_execute return unless configuration.get('beef.extension.network.enable') == true session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first # log discovered hosts case @datastore['results'] @@ -25,7 +26,7 @@ def post_execute ip = Regexp.last_match(1) if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found host #{ip}") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip) end # log discovered network services when /^proto=(.+)&ip=(.+)&port=(\d+)&title/ @@ -35,7 +36,7 @@ def post_execute type = 'HTTP Server (Flash)' if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found HTTP server #{ip}:#{port}") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: type) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: type) end end end diff --git a/modules/network/detect_burp/module.rb b/modules/network/detect_burp/module.rb index 8bb1488074..2a02b377fa 100644 --- a/modules/network/detect_burp/module.rb +++ b/modules/network/detect_burp/module.rb @@ -14,9 +14,11 @@ def post_execute ip = Regexp.last_match(1).split(':')[0] port = Regexp.last_match(1).split(':')[1] session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: 'http', ip: ip, port: port, type: 'Burp Proxy') + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: 'http', ip: ip, port: port, ntype: 'Burp Proxy') end end end diff --git a/modules/network/get_http_servers/module.rb b/modules/network/get_http_servers/module.rb index 99d061e625..c21b9d3d28 100644 --- a/modules/network/get_http_servers/module.rb +++ b/modules/network/get_http_servers/module.rb @@ -30,9 +30,11 @@ def post_execute port = Regexp.last_match(3) url = Regexp.last_match(4) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found HTTP Server [proto: #{proto}, ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: 'HTTP Server') + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: 'HTTP Server') end end end diff --git a/modules/network/get_ntop_network_hosts/module.rb b/modules/network/get_ntop_network_hosts/module.rb index 0c10e5137e..b6faa6dde3 100644 --- a/modules/network/get_ntop_network_hosts/module.rb +++ b/modules/network/get_ntop_network_hosts/module.rb @@ -23,15 +23,16 @@ def post_execute port = Regexp.last_match(3) data = Regexp.last_match(4) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first type = 'ntop' if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found 'ntop' [proto: #{proto}, ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: type) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: type) end data.to_s.scan(/"hostNumIpAddress":"([\d.]+)"/).flatten.each do |ip| if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found host #{ip}") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip, port: port) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip, port: port) end end end diff --git a/modules/network/get_proxy_servers_wpad/module.rb b/modules/network/get_proxy_servers_wpad/module.rb index 405d91c309..17d7b4bd0b 100644 --- a/modules/network/get_proxy_servers_wpad/module.rb +++ b/modules/network/get_proxy_servers_wpad/module.rb @@ -12,6 +12,7 @@ def post_execute return unless @datastore['results'] =~ /^proxies=(.+)$/ session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first proxies = Regexp.last_match(1).to_s proxies.split(',').uniq.each do |proxy| next unless proxy =~ /^(SOCKS|PROXY)\s+([\d.]+:\d{1,5})/ @@ -23,7 +24,7 @@ def post_execute proto = 'SOCKS' if proxy_type =~ /SOCKS/ if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found #{proto} proxy [ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto.downcase, ip: ip, port: port, type: "#{proto} Proxy") + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto.downcase, ip: ip, port: port, ntype: "#{proto} Proxy") end end end diff --git a/modules/network/internal_network_fingerprinting/module.rb b/modules/network/internal_network_fingerprinting/module.rb index de009eb496..80d3753464 100644 --- a/modules/network/internal_network_fingerprinting/module.rb +++ b/modules/network/internal_network_fingerprinting/module.rb @@ -31,9 +31,10 @@ def post_execute discovered = Regexp.last_match(4) url = Regexp.last_match(5) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found '#{discovered}' [ip: #{ip}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: discovered) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: discovered) end end end diff --git a/modules/network/jslanscanner/module.rb b/modules/network/jslanscanner/module.rb index 91056da9a9..a9e329a1c1 100644 --- a/modules/network/jslanscanner/module.rb +++ b/modules/network/jslanscanner/module.rb @@ -17,24 +17,26 @@ def post_execute configuration = BeEF::Core::Configuration.instance return unless configuration.get('beef.extension.network.enable') == true + session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + case @datastore['results'] when /^proto=(.+)&ip=(.+)&port=(\d+)&service=(.+)/ proto = Regexp.last_match(1) ip = Regexp.last_match(2) port = Regexp.last_match(3) service = Regexp.last_match(4) - session_id = @datastore['beefhook'] if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found network service #{service} [proto: #{proto}, ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, type: service) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: service) end when /^ip=(.+)&device=(.+)/ ip = Regexp.last_match(1) device = Regexp.last_match(2) - session_id = @datastore['beefhook'] + if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found network device #{device} [ip: #{ip}]") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip, type: device) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip, type: device) end end end diff --git a/modules/network/ping_sweep/module.rb b/modules/network/ping_sweep/module.rb index 2ad3c38674..9cc4e4333a 100644 --- a/modules/network/ping_sweep/module.rb +++ b/modules/network/ping_sweep/module.rb @@ -18,9 +18,10 @@ def post_execute ip = Regexp.last_match(1) # ping = Regexp.last_match(2) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found host #{ip}") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip) end end diff --git a/modules/network/ping_sweep_ff/module.rb b/modules/network/ping_sweep_ff/module.rb index e2e417b27c..39eab486fb 100644 --- a/modules/network/ping_sweep_ff/module.rb +++ b/modules/network/ping_sweep_ff/module.rb @@ -30,9 +30,11 @@ def post_execute # save the network host ip = Regexp.last_match(1) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first + if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser has network interface #{ip}") - BeEF::Core::Models::NetworkHost.create(hooked_browser_id: session_id, ip: ip) + BeEF::Core::Models::NetworkHost.create(hooked_browser: hooked_browser, ip: ip) end end end diff --git a/modules/network/port_scanner/module.rb b/modules/network/port_scanner/module.rb index a20de1cc85..a076e2a5db 100644 --- a/modules/network/port_scanner/module.rb +++ b/modules/network/port_scanner/module.rb @@ -34,10 +34,11 @@ def post_execute port = Regexp.last_match(3) service = Regexp.last_match(4) session_id = @datastore['beefhook'] + hooked_browser = BeEF::Core::Models::HookedBrowser.where(session: session_id).first proto = 'http' if BeEF::Filters.is_valid_ip?(ip) print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]") - BeEF::Core::Models::NetworkService.create(hooked_browser_id: session_id, proto: proto, ip: ip, port: port, ntype: service) + BeEF::Core::Models::NetworkService.create(hooked_browser: hooked_browser, proto: proto, ip: ip, port: port, ntype: service) end end end