1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-09 14:11:29 +00:00

Revert "Squashed commit of the following:"

This reverts commit 71f5f22e79bdb44fffa14edd5d3ffa570efde8ed.
This commit is contained in:
patrik
2012-10-06 19:25:04 +00:00
parent 85c1ce9ce5
commit 2e5a448aa5
7 changed files with 68 additions and 52 deletions

View File

@@ -264,27 +264,12 @@ function do_nbstat(host)
local socket = nmap.new_socket() local socket = nmap.new_socket()
local encoded_name = name_encode("*") local encoded_name = name_encode("*")
local statistics local statistics
local reg
if type(host) == "string" then --ip
stdnse.print_debug(3, "Performing nbstat on host '%s'", host)
nmap.registry.netbios = nmap.registry.netbios or {}
nmap.registry.netbios[host] = nmap.registry.netbios[host] or {}
reg = nmap.registry.netbios[host]
else
stdnse.print_debug(3, "Performing nbstat on host '%s'", host.ip)
if host.registry.netbios == nil and
nmap.registry.netbios ~= nil and
nmap.registry.netbios[host.ip] ~= nil then
host.registry.netbios = nmap.registry.netbios[host.ip]
end
host.registry.netbios = host.registry.netbios or {}
reg = host.registry.netbios
end
-- Check if it's cached in the registry for this host stdnse.print_debug(3, "Performing nbstat on host '%s'", host)
if(reg["nbstat_names"] ~= nil) then -- Check if it's cased in the registry for this host
if(nmap.registry["nbstat_names_" .. host] ~= nil) then
stdnse.print_debug(3, " |_ [using cached value]") stdnse.print_debug(3, " |_ [using cached value]")
return true, reg["nbstat_names"], reg["nbstat_statistics"] return true, nmap.registry["nbstat_names_" .. host], nmap.registry["nbstat_statistics_" .. host]
end end
-- Create the query header -- Create the query header
@@ -384,8 +369,8 @@ function do_nbstat(host)
pos, statistics = bin.unpack(string.format(">A%d", rrlength), result, pos) pos, statistics = bin.unpack(string.format(">A%d", rrlength), result, pos)
-- Put it in the registry, in case anybody else needs it -- Put it in the registry, in case anybody else needs it
reg["nbstat_names"] = names nmap.registry["nbstat_names_" .. host] = names
reg["nbstat_statistics"] = statistics nmap.registry["nbstat_statistics_" .. host] = statistics
return true, names, statistics return true, names, statistics

View File

@@ -105,11 +105,11 @@ local ACCOUNT_TYPES = {
} }
local function account_exists(host, username, domain) local function account_exists(host, username, domain)
if(host.registry['smbaccounts'] == nil) then if(nmap.registry[host.ip] == nil or nmap.registry[host.ip]['smbaccounts'] == nil) then
return false return false
end end
for i, j in pairs(host.registry['smbaccounts']) do for i, j in pairs(nmap.registry[host.ip]['smbaccounts']) do
if(j['username'] == username and j['domain'] == domain) then if(j['username'] == username and j['domain'] == domain) then
return true return true
end end
@@ -120,13 +120,13 @@ end
function next_account(host, num) function next_account(host, num)
if(num == nil) then if(num == nil) then
if(host.registry['smbindex'] == nil) then if(nmap.registry[host.ip]['smbindex'] == nil) then
host.registry['smbindex'] = 1 nmap.registry[host.ip]['smbindex'] = 1
else else
host.registry['smbindex'] = host.registry['smbindex'] + 1 nmap.registry[host.ip]['smbindex'] = nmap.registry[host.ip]['smbindex'] + 1
end end
else else
host.registry['smbindex'] = num nmap.registry[host.ip]['smbindex'] = num
end end
end end
@@ -165,8 +165,11 @@ function add_account(host, username, domain, password, password_hash, hash_type,
return return
end end
if(host.registry['smbaccounts'] == nil) then if(nmap.registry[host.ip] == nil) then
host.registry['smbaccounts'] = {} nmap.registry[host.ip] = {}
end
if(nmap.registry[host.ip]['smbaccounts'] == nil) then
nmap.registry[host.ip]['smbaccounts'] = {}
end end
-- Determine the type of account, if it wasn't given -- Determine the type of account, if it wasn't given
@@ -201,10 +204,10 @@ function add_account(host, username, domain, password, password_hash, hash_type,
new_entry['account_type'] = account_type new_entry['account_type'] = account_type
-- Insert the new entry into the table -- Insert the new entry into the table
table.insert(host.registry['smbaccounts'], new_entry) table.insert(nmap.registry[host.ip]['smbaccounts'], new_entry)
-- Sort the table based on the account type (we want anonymous at the end, administrator at the front) -- Sort the table based on the account type (we want anonymous at the end, administrator at the front)
table.sort(host.registry['smbaccounts'], function(a,b) return a['account_type'] > b['account_type'] end) table.sort(nmap.registry[host.ip]['smbaccounts'], function(a,b) return a['account_type'] > b['account_type'] end)
-- Print a debug message -- Print a debug message
stdnse.print_debug(1, "SMB: Added account '%s' to account list", username) stdnse.print_debug(1, "SMB: Added account '%s' to account list", username)
@@ -212,7 +215,7 @@ function add_account(host, username, domain, password, password_hash, hash_type,
-- Reset the credentials -- Reset the credentials
next_account(host, 1) next_account(host, 1)
-- io.write("\n\n" .. nsedebug.tostr(host.registry['smbaccounts']) .. "\n\n") -- io.write("\n\n" .. nsedebug.tostr(nmap.registry[host.ip]['smbaccounts']) .. "\n\n")
end end
---Retrieve the current set of credentials set in the registry. If these fail, <code>next_credentials</code> should be ---Retrieve the current set of credentials set in the registry. If these fail, <code>next_credentials</code> should be
@@ -222,12 +225,12 @@ end
--@return (result, username, domain, password, password_hash, hash_type) If result is false, username is an error message. Otherwise, username and password are --@return (result, username, domain, password, password_hash, hash_type) If result is false, username is an error message. Otherwise, username and password are
-- the current username and password that should be used. -- the current username and password that should be used.
function get_account(host) function get_account(host)
if(host.registry['smbindex'] == nil) then if(nmap.registry[host.ip]['smbindex'] == nil) then
host.registry['smbindex'] = 1 nmap.registry[host.ip]['smbindex'] = 1
end end
local index = host.registry['smbindex'] local index = nmap.registry[host.ip]['smbindex']
local account = host.registry['smbaccounts'][index] local account = nmap.registry[host.ip]['smbaccounts'][index]
if(account == nil) then if(account == nil) then
return false, "No accounts left to try" return false, "No accounts left to try"
@@ -241,13 +244,18 @@ end
-- --
--@param host The host object. --@param host The host object.
function init_account(host) function init_account(host)
-- Create the key if it exists
if(nmap.registry[host.ip] == nil) then
nmap.registry[host.ip] = {}
end
-- Don't run this more than once for each host -- Don't run this more than once for each host
if(host.registry['smbaccounts'] ~= nil) then if(nmap.registry[host.ip]['smbaccounts'] ~= nil) then
return return
end end
-- Create the list -- Create the list
host.registry['smbaccounts'] = {} nmap.registry[host.ip]['smbaccounts'] = {}
-- Add the anonymous/guest accounts -- Add the anonymous/guest accounts
add_account(host, '', '', '', nil, 'none') add_account(host, '', '', '', nil, 'none')

View File

@@ -66,8 +66,10 @@ Driver =
if ( not(status) and err:match("I HATE YOU") ) then if ( not(status) and err:match("I HATE YOU") ) then
-- let's store the repositories in the registry so the brute -- let's store the repositories in the registry so the brute
-- script can use them later. -- script can use them later.
self.host.registry.cvs_repos = self.host.registry.cvs_repos or {} nmap.registry.cvs = nmap.registry.cvs or {}
table.insert(self.host.registry.cvs_repos, password) nmap.registry.cvs[self.host.ip] = nmap.registry.cvs[self.host.ip] or {}
nmap.registry.cvs[self.host.ip].repos = nmap.registry.cvs[self.host.ip].repos or {}
table.insert(nmap.registry.cvs[self.host.ip].repos, password)
return true, brute.Account:new(username, password, 0) return true, brute.Account:new(username, password, 0)
end end
return false, brute.Error:new( "Incorrect password" ) return false, brute.Error:new( "Incorrect password" )

View File

@@ -79,11 +79,14 @@ Driver =
local function getDiscoveredRepos(host) local function getDiscoveredRepos(host)
if ( not(host.registry.cvs_repos)) then if ( not(nmap.registry.cvs) or
not(nmap.registry.cvs[host.ip]) or
not(nmap.registry.cvs[host.ip].repos)
) then
return return
end end
return host.registry.cvs_repos return nmap.registry.cvs[host.ip].repos
end end
action = function(host, port) action = function(host, port)

View File

@@ -80,22 +80,22 @@ action = function(host)
-- Get the list of NetBIOS names -- Get the list of NetBIOS names
status, names, statistics = netbios.do_nbstat(host) status, names, statistics = netbios.do_nbstat(host.ip)
status, names, statistics = netbios.do_nbstat(host) status, names, statistics = netbios.do_nbstat(host.ip)
status, names, statistics = netbios.do_nbstat(host) status, names, statistics = netbios.do_nbstat(host.ip)
status, names, statistics = netbios.do_nbstat(host) status, names, statistics = netbios.do_nbstat(host.ip)
if(status == false) then if(status == false) then
return stdnse.format_output(false, names) return stdnse.format_output(false, names)
end end
-- Get the server name -- Get the server name
status, server_name = netbios.get_server_name(host, names) status, server_name = netbios.get_server_name(host.ip, names)
if(status == false) then if(status == false) then
return stdnse.format_output(false, server_name) return stdnse.format_output(false, server_name)
end end
-- Get the logged in user -- Get the logged in user
status, user_name = netbios.get_user_name(host, names) status, user_name = netbios.get_user_name(host.ip, names)
if(status == false) then if(status == false) then
return stdnse.format_output(false, user_name) return stdnse.format_output(false, user_name)
end end

View File

@@ -261,7 +261,10 @@ end
-- Sets necessary probe data in registry -- Sets necessary probe data in registry
local setreg = function(host, proto, port) local setreg = function(host, proto, port)
host.registry['pathmtuprobe'] = { if not nmap.registry[host.ip] then
nmap.registry[host.ip] = {}
end
nmap.registry[host.ip]['pathmtuprobe'] = {
['proto'] = proto, ['proto'] = proto,
['port'] = port ['port'] = port
} }
@@ -298,8 +301,8 @@ action = function(host)
local mtuset local mtuset
local sock = nmap.new_dnet() local sock = nmap.new_dnet()
local pcap = nmap.new_socket() local pcap = nmap.new_socket()
local proto = host.registry['pathmtuprobe']['proto'] local proto = nmap.registry[host.ip]['pathmtuprobe']['proto']
local port = host.registry['pathmtuprobe']['port'] local port = nmap.registry[host.ip]['pathmtuprobe']['port']
local saddr = packet.toip(host.bin_ip_src) local saddr = packet.toip(host.bin_ip_src)
local daddr = packet.toip(host.bin_ip) local daddr = packet.toip(host.bin_ip)
local try = nmap.new_try() local try = nmap.new_try()

View File

@@ -45,7 +45,6 @@ dependencies = {"snmp-brute"}
-- Revised 04/11/2010 - v0.2 - moved snmp_walk to snmp library <patrik@cqure.net> -- Revised 04/11/2010 - v0.2 - moved snmp_walk to snmp library <patrik@cqure.net>
-- Revised 08/10/2010 - v0.3 - prerule; add interface addresses to Nmap's target list (Kris Katterjohn) -- Revised 08/10/2010 - v0.3 - prerule; add interface addresses to Nmap's target list (Kris Katterjohn)
-- Revised 05/27/2011 - v0.4 - action; add MAC addresses to nmap.registry[host.ip]["mac-geolocation"] (Gorjan Petrovski) -- Revised 05/27/2011 - v0.4 - action; add MAC addresses to nmap.registry[host.ip]["mac-geolocation"] (Gorjan Petrovski)
-- Revised 07/31/2012 - v0.5 - action; remove mac-geolocation changes (script removed from trunk)
@@ -420,6 +419,14 @@ action = function(host, port)
srvport = port.number srvport = port.number
end end
-- table for mac-geolocation.nse
if not nmap.registry[srvhost] then
nmap.registry[srvhost] = {}
nmap.registry[srvhost]["mac-geolocation"] = {}
elseif not nmap.registry[srvhost]["mac-geolocation"] then
nmap.registry[srvhost]["mac-geolocation"] = {}
end
socket:set_timeout(5000) socket:set_timeout(5000)
try(socket:connect(srvhost, srvport, "udp")) try(socket:connect(srvhost, srvport, "udp"))
@@ -446,6 +453,14 @@ action = function(host, port)
end end
local output = stdnse.format_output( true, build_results(interfaces) ) local output = stdnse.format_output( true, build_results(interfaces) )
-- insert the MAC addresses into the mac-geolocation table
for _,item in ipairs(interfaces) do
if item.phys_addr then
table.insert(nmap.registry[srvhost]["mac-geolocation"], item.phys_addr:match("^(%x+:%x+:%x+:%x+:%x+:%x+)"))
end
end
-- wtf is this? table.insert(nmap.registry[srvhost]["mac-geolocation"], "00:23:69:2a:b1:27")
if SCRIPT_TYPE == "prerule" and target.ALLOW_NEW_TARGETS then if SCRIPT_TYPE == "prerule" and target.ALLOW_NEW_TARGETS then
local sum = 0 local sum = 0