Skip to content

Commit

Permalink
Fix issue beefproject#3174
Browse files Browse the repository at this point in the history
  • Loading branch information
Phasip committed Oct 23, 2024
1 parent 4287153 commit 2e985c1
Show file tree
Hide file tree
Showing 19 changed files with 55 additions and 35 deletions.
6 changes: 4 additions & 2 deletions core/main/handlers/browserdetails.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down Expand Up @@ -552,7 +553,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

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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'}
});

Expand Down Expand Up @@ -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: {
Expand Down
6 changes: 3 additions & 3 deletions extensions/network/rest/network.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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 = {}
Expand Down
12 changes: 6 additions & 6 deletions modules/exploits/router/asus_rt_n12e_get_info/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down
4 changes: 2 additions & 2 deletions modules/host/detect_airdroid/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion modules/host/detect_cups/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 2 additions & 2 deletions modules/host/get_internal_ip_java/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion modules/host/get_internal_ip_webrtc/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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|
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/network/cross_origin_scanner_cors/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
5 changes: 3 additions & 2 deletions modules/network/cross_origin_scanner_flash/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -18,14 +18,15 @@ 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']
when /^ip=(.+)&status=alive$/
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/
Expand All @@ -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
Expand Down
4 changes: 3 additions & 1 deletion modules/network/detect_burp/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
4 changes: 3 additions & 1 deletion modules/network/get_http_servers/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
5 changes: 3 additions & 2 deletions modules/network/get_ntop_network_hosts/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/network/get_proxy_servers_wpad/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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})/
Expand All @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/network/internal_network_fingerprinting/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
10 changes: 6 additions & 4 deletions modules/network/jslanscanner/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
3 changes: 2 additions & 1 deletion modules/network/ping_sweep/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
4 changes: 3 additions & 1 deletion modules/network/ping_sweep_ff/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
3 changes: 2 additions & 1 deletion modules/network/port_scanner/module.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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

0 comments on commit 2e985c1

Please sign in to comment.