Remove :cid property from Network extension data models

This commit is contained in:
Brendan Coles
2015-09-30 07:20:29 +00:00
parent cc3b10b889
commit ed321bf5ec
16 changed files with 23 additions and 41 deletions

View File

@@ -180,7 +180,7 @@ module BeEF
if config.get("beef.extension.network.enable") == true if config.get("beef.extension.network.enable") == true
if proxy_server =~ /^([\d\.]+):([\d]+)$/ if proxy_server =~ /^([\d\.]+):([\d]+)$/
print_debug("Hooked browser [id:#{zombie.id}] is using a proxy [ip: #{$1}]") print_debug("Hooked browser [id:#{zombie.id}] is using a proxy [ip: #{$1}]")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => $1, :type => 'Proxy', :cid => 'init') BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => $1, :type => 'Proxy')
end end
end end
end end
@@ -357,7 +357,7 @@ module BeEF
# add localhost as network host # add localhost as network host
if config.get('beef.extension.network.enable') if config.get('beef.extension.network.enable')
print_debug("Hooked browser has network interface 127.0.0.1") print_debug("Hooked browser has network interface 127.0.0.1")
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') 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'))
end end
# Autorun Rule Engine - Check if the hooked browser type/version and OS type/version match any Rule-sets # Autorun Rule Engine - Check if the hooked browser type/version and OS type/version match any Rule-sets

View File

@@ -22,7 +22,6 @@ module BeEF
property :type, String, :lazy => false # proxy, router, gateway, dns, etc property :type, String, :lazy => false # proxy, router, gateway, dns, etc
property :os, String, :lazy => false property :os, String, :lazy => false
property :mac, String, :lazy => false property :mac, String, :lazy => false
property :cid, String, :lazy => false # command id or 'init'
# #
# Stores a network host in the data store # Stores a network host in the data store
@@ -53,8 +52,7 @@ module BeEF
:hostname => host[:hostname], :hostname => host[:hostname],
:type => host[:type], :type => host[:type],
:os => host[:os], :os => host[:os],
:mac => host[:mac], :mac => host[:mac])
:cid => host[:cid])
result = network_host.save result = network_host.save
(print_error "Failed to save network host"; return) if result.nil? (print_error "Failed to save network host"; return) if result.nil?

View File

@@ -21,7 +21,6 @@ module BeEF
property :ip, Text, :lazy => false property :ip, Text, :lazy => false
property :port, String, :lazy => false property :port, String, :lazy => false
property :type, String, :lazy => false property :type, String, :lazy => false
property :cid, String, :lazy => false # command id or 'init'
# #
# Stores a network service in the data store # Stores a network service in the data store
@@ -34,8 +33,7 @@ module BeEF
# store the returned network host details # store the returned network host details
BeEF::Core::Models::NetworkHost.add( BeEF::Core::Models::NetworkHost.add(
:hooked_browser_id => service[:hooked_browser_id], :hooked_browser_id => service[:hooked_browser_id],
:ip => service[:ip], :ip => service[:ip])
:cid => service[:cid])
# prevent duplicates # prevent duplicates
return unless BeEF::Core::Models::NetworkService.all( return unless BeEF::Core::Models::NetworkService.all(
@@ -51,8 +49,7 @@ module BeEF
:proto => service[:proto], :proto => service[:proto],
:ip => service[:ip], :ip => service[:ip],
:port => service[:port], :port => service[:port],
:type => service[:type], :type => service[:type])
:cid => service[:cid])
result = network_service.save result = network_service.save
(print_error "Failed to save network service"; return) if result.nil? (print_error "Failed to save network service"; return) if result.nil?

View File

@@ -18,7 +18,6 @@ class Asus_rt_series_get_info < BeEF::Core::Command
if configuration.get("beef.extension.network.enable") == true if configuration.get("beef.extension.network.enable") == true
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
# log the network hosts # log the network hosts
if @datastore['results'] =~ /ip=(.+)&clients=(.+)&wanip=(.+)&netmask=(.+)&gateway=(.+)&dns=(.+)/ if @datastore['results'] =~ /ip=(.+)&clients=(.+)&wanip=(.+)&netmask=(.+)&gateway=(.+)&dns=(.+)/
@@ -31,8 +30,8 @@ class Asus_rt_series_get_info < BeEF::Core::Command
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) if !ip.nil? && BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found Asus RT series router [ip: #{ip}]") print_debug("Hooked browser found Asus RT series router [ip: #{ip}]")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :type => 'Asus Router', :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :type => 'Asus Router')
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => 'http', :ip => ip, :port => 80, :type => 'HTTP Server', :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => 'http', :ip => ip, :port => 80, :type => 'HTTP Server')
end end
clients.scan(/([\d\.]+,[:\dA-F]{17})/).flatten.each do |client| clients.scan(/([\d\.]+,[:\dA-F]{17})/).flatten.each do |client|
next if client.nil? next if client.nil?
@@ -41,19 +40,19 @@ class Asus_rt_series_get_info < BeEF::Core::Command
mac = $2 mac = $2
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found router client [ip: #{ip}, mac: #{mac}]") print_debug("Hooked browser found router client [ip: #{ip}, mac: #{mac}]")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :mac => mac, :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :mac => mac)
end end
end end
end end
if !gateway.nil? && BeEF::Filters.is_valid_ip?(gateway) if !gateway.nil? && BeEF::Filters.is_valid_ip?(gateway)
print_debug("Hooked browser found WAN gateway server [ip: #{gateway}]") print_debug("Hooked browser found WAN gateway server [ip: #{gateway}]")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => gateway, :type => 'WAN Gateway', :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => gateway, :type => 'WAN Gateway')
end end
if !dns_servers.nil? && dns_servers =~ /^([\d\. ]+)$/ if !dns_servers.nil? && dns_servers =~ /^([\d\. ]+)$/
dns_servers.split(/ /).uniq.each do |dns| dns_servers.split(/ /).uniq.each do |dns|
if BeEF::Filters.is_valid_ip?(dns) if BeEF::Filters.is_valid_ip?(dns)
print_debug("Hooked browser found DNS server [ip: #{dns}]") print_debug("Hooked browser found DNS server [ip: #{dns}]")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => dns, :type => 'DNS Server', :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => dns, :type => 'DNS Server')
end end
end end
end end

View File

@@ -24,10 +24,9 @@ class Detect_airdrone < BeEF::Core::Command
port = $3 port = $3
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
type = 'Airdrone' type = 'Airdrone'
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found 'Airdrone' [proto: #{proto}, ip: #{ip}, port: #{port}]") print_debug("Hooked browser found 'Airdrone' [proto: #{proto}, ip: #{ip}, port: #{port}]")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type, :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type)
end end
end end
end end

View File

@@ -24,10 +24,9 @@ class Detect_cups < BeEF::Core::Command
port = $3 port = $3
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
type = 'CUPS' type = 'CUPS'
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found 'CUPS' [proto: #{proto}, ip: #{ip}, port: #{port}]") print_debug("Hooked browser found 'CUPS' [proto: #{proto}, ip: #{ip}, port: #{port}]")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type, :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type)
end end
end end
end end

View File

@@ -25,14 +25,13 @@ class Get_internal_ip < BeEF::Core::Command
if configuration.get("beef.extension.network.enable") == true if configuration.get("beef.extension.network.enable") == true
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
# save the network host # save the network host
if @datastore['results'] =~ /^([\d\.]+)$/ if @datastore['results'] =~ /^([\d\.]+)$/
ip = $1 ip = $1
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser has network interface #{ip}") print_debug("Hooked browser has network interface #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip)
end end
end end
end end

View File

@@ -13,7 +13,6 @@ class Get_internal_ip_webrtc < BeEF::Core::Command
configuration = BeEF::Core::Configuration.instance configuration = BeEF::Core::Configuration.instance
if configuration.get("beef.extension.network.enable") == true if configuration.get("beef.extension.network.enable") == true
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
# save the network host # save the network host
if @datastore['results'] =~ /IP is ([\d\.,]+)/ if @datastore['results'] =~ /IP is ([\d\.,]+)/
ips = $1.to_s.split(/,/) ips = $1.to_s.split(/,/)
@@ -24,7 +23,7 @@ class Get_internal_ip_webrtc < BeEF::Core::Command
next if ip =~ /^0\.0\.0\.0$/ next if ip =~ /^0\.0\.0\.0$/
next unless BeEF::Filters.is_valid_ip?(ip) next unless BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser has network interface #{ip}") print_debug("Hooked browser has network interface #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :os => os, :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :os => os)
end end
end end
end end

View File

@@ -14,7 +14,6 @@ class Cross_origin_scanner < BeEF::Core::Command
if configuration.get("beef.extension.network.enable") == true if configuration.get("beef.extension.network.enable") == true
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
# log the network service # log the network service
if @datastore['results'] =~ /ip=(.+)&port=([\d]+)&status/ if @datastore['results'] =~ /ip=(.+)&port=([\d]+)&status/
@@ -24,7 +23,7 @@ class Cross_origin_scanner < BeEF::Core::Command
type = 'HTTP Server (CORS)' type = 'HTTP Server (CORS)'
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found HTTP server #{ip}:#{port}") 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) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => type)
end end
end end
end end

View File

@@ -32,10 +32,9 @@ class Get_http_servers < BeEF::Core::Command
port = $3 port = $3
url = $4 url = $4
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if !ip.nil? && BeEF::Filters.is_valid_ip?(ip) if !ip.nil? && BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found HTTP Server [proto: #{proto}, ip: #{ip}, port: #{port}]") print_debug("Hooked browser found HTTP Server [proto: #{proto}, ip: #{ip}, port: #{port}]")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => "HTTP Server", :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => "HTTP Server")
end end
end end

View File

@@ -28,7 +28,6 @@ class Identify_lan_subnets < BeEF::Core::Command
if configuration.get("beef.extension.network.enable") == true if configuration.get("beef.extension.network.enable") == true
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
# log the network hosts # log the network hosts
if @datastore['results'] =~ /^hosts=([\d\.,]+)/ if @datastore['results'] =~ /^hosts=([\d\.,]+)/
@@ -38,7 +37,7 @@ class Identify_lan_subnets < BeEF::Core::Command
next unless ip.to_s =~ /^([\d\.]+)$/ next unless ip.to_s =~ /^([\d\.]+)$/
next unless BeEF::Filters.is_valid_ip?(ip) next unless BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found host #{ip}") print_debug("Hooked browser found host #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip)
end end
end end
end end

View File

@@ -34,10 +34,9 @@ class Internal_network_fingerprinting < BeEF::Core::Command
discovered = $4 discovered = $4
url = $5 url = $5
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found '#{discovered}' [ip: #{ip}]") print_debug("Hooked browser found '#{discovered}' [ip: #{ip}]")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => discovered, :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => discovered)
end end
end end

View File

@@ -24,19 +24,17 @@ class Fingerprint_routers < BeEF::Core::Command
port = $3 port = $3
service = $4 service = $4
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found network service " + service + " [proto: #{proto}, ip: #{ip}, port: #{port}]") print_debug("Hooked browser found network service " + service + " [proto: #{proto}, ip: #{ip}, port: #{port}]")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service, :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service)
end end
elsif @datastore['results'] =~ /^ip=(.+)&device=(.+)/ elsif @datastore['results'] =~ /^ip=(.+)&device=(.+)/
ip = $1 ip = $1
device = $2 device = $2
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found network device " + device + " [ip: #{ip}]") print_debug("Hooked browser found network device " + device + " [ip: #{ip}]")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :type => device, :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :type => device)
end end
end end
end end

View File

@@ -31,14 +31,13 @@ class Ping_sweep < BeEF::Core::Command
if configuration.get("beef.extension.network.enable") == true if configuration.get("beef.extension.network.enable") == true
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
cid = @datastore['cid'].to_i
# save the network host # save the network host
if @datastore['results'] =~ /host=([\d\.]+) is alive/ if @datastore['results'] =~ /host=([\d\.]+) is alive/
ip = $1 ip = $1
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser has network interface #{ip}") print_debug("Hooked browser has network interface #{ip}")
BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip, :cid => cid) BeEF::Core::Models::NetworkHost.add(:hooked_browser_id => session_id, :ip => ip)
end end
end end
end end

View File

@@ -38,10 +38,9 @@ class Port_scanner < BeEF::Core::Command
service = $4 service = $4
session_id = @datastore['beefhook'] session_id = @datastore['beefhook']
proto = 'http' proto = 'http'
cid = @datastore['cid'].to_i
if BeEF::Filters.is_valid_ip?(ip) if BeEF::Filters.is_valid_ip?(ip)
print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]") print_debug("Hooked browser found network service [ip: #{ip}, port: #{port}]")
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service, :cid => cid) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => session_id, :proto => proto, :ip => ip, :port => port, :type => service)
end end
end end

View File

@@ -36,7 +36,7 @@ class TC_Network < Test::Unit::TestCase
# Tests procedure for properly adding new service # Tests procedure for properly adding new service
def test_03_add_service_good def test_03_add_service_good
assert_nothing_raised do assert_nothing_raised do
BeEF::Core::Models::NetworkService.add(:hooked_browser_id => '1234', :proto => 'http', :ip => '127.0.0.1', :port => 80, :type => 'Apache', :cid => 1) BeEF::Core::Models::NetworkService.add(:hooked_browser_id => '1234', :proto => 'http', :ip => '127.0.0.1', :port => 80, :type => 'Apache')
raise "Adding network service failed" if BeEF::Core::Models::NetworkService.all(:hooked_browser_id => '1234', :ip => '127.0.0.1').empty? raise "Adding network service failed" if BeEF::Core::Models::NetworkService.all(:hooked_browser_id => '1234', :ip => '127.0.0.1').empty?
end end
end end