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

more stdnse.print_debug -> stdnse.debug

Manual corrections.
This commit is contained in:
batrick
2014-08-02 03:15:44 +00:00
parent 6e3bde5de5
commit 91a106e7d5
26 changed files with 80 additions and 209 deletions

View File

@@ -1000,24 +1000,18 @@ action = function(host, port)
-- --
local status, err = sock:bind(nil, 47808) local status, err = sock:bind(nil, 47808)
if(status == false) then if(status == false) then
stdnse.print_debug(1, stdnse.debug1("Couldn't bind to 47808/udp. Continuing anyway, results may vary")
"Couldn't bind to 47808/udp. Continuing anyway, results may vary")
end end
-- connect to the remote host -- connect to the remote host
local constatus, conerr = sock:connect(host, port) local constatus, conerr = sock:connect(host, port)
if not constatus then if not constatus then
stdnse.print_debug(1, stdnse.debug1('Error establishing a UDP connection for %s - %s', host, conerr)
'Error establishing a UDP connection for %s - %s', host, conerr
)
return nil return nil
end end
-- send the original query to see if it is a valid BACNet Device -- send the original query to see if it is a valid BACNet Device
local sendstatus, senderr = sock:send(orig_query) local sendstatus, senderr = sock:send(orig_query)
if not sendstatus then if not sendstatus then
stdnse.print_debug(1, stdnse.debug1('Error sending BACNet request to %s:%d - %s', host.ip, port.number, senderr)
'Error sending BACNet request to %s:%d - %s',
host.ip, port.number, senderr
)
return nil return nil
end end

View File

@@ -71,8 +71,7 @@ function grab_banner(host, port)
if not status then if not status then
local errlvl = { ["EOF"]=3,["TIMEOUT"]=3,["ERROR"]=2 } local errlvl = { ["EOF"]=3,["TIMEOUT"]=3,["ERROR"]=2 }
stdnse.print_debug(errlvl[response] or 1, "%s failed for %s on %s port %s. Message: %s", stdnse.debug(errlvl[response] or 1, "failed for %s on %s port %s. Message: %s", host.ip, port.protocol, port.number, response or "No Message.")
SCRIPT_NAME, host.ip, port.protocol, port.number, response or "No Message." )
return nil return nil
end end

View File

@@ -50,9 +50,7 @@ categories = {"discovery","safe"}
prerule = function() prerule = function()
if not stdnse.get_script_args(SCRIPT_NAME..".torrent") and if not stdnse.get_script_args(SCRIPT_NAME..".torrent") and
not stdnse.get_script_args(SCRIPT_NAME..".magnet") then not stdnse.get_script_args(SCRIPT_NAME..".magnet") then
stdnse.print_debug(3, stdnse.debug3("Skipping '%s' %s, No magnet link or torrent file arguments.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, No magnet link or torrent file arguments.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end
return true return true

View File

@@ -68,9 +68,7 @@ categories = {"intrusive", "discovery"}
prerule = function() prerule = function()
if not stdnse.get_script_args("dns-brute.domain") then if not stdnse.get_script_args("dns-brute.domain") then
stdnse.print_debug(1, stdnse.debug1("Skipping '%s' %s, 'dns-brute.domain' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, 'dns-brute.domain' argument is missing.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end
return true return true

View File

@@ -101,16 +101,12 @@ prerule = function()
) )
if not dns_opts.domain then if not dns_opts.domain then
stdnse.print_debug(3, stdnse.debug3("Skipping '%s' %s, 'dnszonetransfer.domain' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, 'dnszonetransfer.domain' argument is missing.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end
if not dns_opts.server then if not dns_opts.server then
stdnse.print_debug(3, stdnse.debug3("Skipping '%s' %s, 'dnszonetransfer.server' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, 'dnszonetransfer.server' argument is missing.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end
@@ -131,9 +127,7 @@ portrule = function(host, port)
dns_opts.domain = host.name dns_opts.domain = host.name
else else
-- can't do anything without a hostname -- can't do anything without a hostname
stdnse.print_debug(3, stdnse.debug3("Skipping '%s' %s, 'dnszonetransfer.domain' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, 'dnszonetransfer.domain' argument is missing.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end
end end
@@ -600,9 +594,7 @@ function add_zone_info(response)
end end
-- parse all available resource records -- parse all available resource records
stdnse.print_debug(3, stdnse.debug3("Script %s: parsing ANCOUNT == %d, NSCOUNT == %d, ARCOUNT == %d", answers, auth_answers, add_answers)
"Script %s: parsing ANCOUNT == %d, NSCOUNT == %d, ARCOUNT == %d",
SCRIPT_NAME, answers, auth_answers, add_answers)
RR['Node Names'] = {} RR['Node Names'] = {}
offset = parse_records(answers, data, RR, offset) offset = parse_records(answers, data, RR, offset)
offset = parse_records(auth_answers, data, RR, offset) offset = parse_records(auth_answers, data, RR, offset)
@@ -638,8 +630,7 @@ function add_zone_info(response)
if dns_opts.addall or not ipOps.isPrivate(rdata) then if dns_opts.addall or not ipOps.isPrivate(rdata) then
status, ret = target.add(rdata) status, ret = target.add(rdata)
if not status then if not status then
stdnse.print_debug(3, stdnse.debug3("Error: failed to add all 'A' records.")
"Error: failed to add all 'A' records.")
break break
end end
newhosts_count = newhosts_count + ret newhosts_count = newhosts_count + ret
@@ -649,8 +640,7 @@ function add_zone_info(response)
for rdata in pairs(RR[rectype]) do for rdata in pairs(RR[rectype]) do
status, ret = target.add(rdata) status, ret = target.add(rdata)
if not status then if not status then
stdnse.print_debug(3, stdnse.debug3("Error: failed to add all '%s' records.", rectype)
"Error: failed to add all '%s' records.", rectype)
break break
end end
newhosts_count = newhosts_count + ret newhosts_count = newhosts_count + ret
@@ -704,9 +694,7 @@ function dump_zone_info(table, response)
end end
-- parse all available resource records -- parse all available resource records
stdnse.print_debug(3, stdnse.debug3("parsing ANCOUNT == %d, NSCOUNT == %d, ARCOUNT == %d", answers, auth_answers, add_answers)
"Script %s: parsing ANCOUNT == %d, NSCOUNT == %d, ARCOUNT == %d",
SCRIPT_NAME, answers, auth_answers, add_answers)
offset = parse_records_table(answers, data, table, offset) offset = parse_records_table(answers, data, table, offset)
offset = parse_records_table(auth_answers, data, table, offset) offset = parse_records_table(auth_answers, data, table, offset)
offset = parse_records_table(add_answers, data, table, offset) offset = parse_records_table(add_answers, data, table, offset)

View File

@@ -81,12 +81,6 @@ local function keys(t)
return ret return ret
end end
if stdnse.debug == nil then
-- Backwards compatibility.
-- TODO: remove this after next release
stdnse.debug = stdnse.print_debug
end
action = function(host) action = function(host)
-- Do reverse-DNS lookup of the IP -- Do reverse-DNS lookup of the IP
-- Can't just use host.name because some IPs have multiple PTR records -- Can't just use host.name because some IPs have multiple PTR records

View File

@@ -113,15 +113,13 @@ end
parse_page = function( host, port, uri, interesting_keys ) parse_page = function( host, port, uri, interesting_keys )
local result = {} local result = {}
local response = http.get( host, port, uri ) local response = http.get( host, port, uri )
stdnse.print_debug(1, "%s: Status %s", stdnse.debug1("Status %s", response['status-line'] or "No Response")
SCRIPT_NAME, response['status-line'] or "No Response")
if response['status-line'] and response['status-line']:match("200%s+OK") if response['status-line'] and response['status-line']:match("200%s+OK")
and response['body'] then and response['body'] then
local body = response['body']:gsub("%%","%%%%") local body = response['body']:gsub("%%","%%%%")
for name,value in string.gmatch(body, for name,value in string.gmatch(body,
"<tr><th>([^][<]+)</th>%s*<td><div%sclass=[^][>]+>([^][<]+)") do "<tr><th>([^][<]+)</th>%s*<td><div%sclass=[^][>]+>([^][<]+)") do
stdnse.print_debug(1, "%s: %s=%s ", stdnse.debug1("%s=%s ", name, value:gsub("^%s*(.-)%s*$", "%1"))
SCRIPT_NAME, name, value:gsub("^%s*(.-)%s*$", "%1"))
if nmap.verbosity() > 1 then if nmap.verbosity() > 1 then
result[#result+1] = ("%s: %s"):format(name,value:gsub("^%s*(.-)%s*$", "%1")) result[#result+1] = ("%s: %s"):format(name,value:gsub("^%s*(.-)%s*$", "%1"))
else else
@@ -173,11 +171,9 @@ action = function( host, port )
local nodes = { } local nodes = { }
local zookeepers = { } local zookeepers = { }
local hbasemasters = { } local hbasemasters = { }
stdnse.print_debug(1, "%s:HTTP GET %s:%s%s", stdnse.debug1("HTTP GET %s:%s%s", host.targetname or host.ip, port.number, uri)
SCRIPT_NAME, host.targetname or host.ip, port.number, uri)
local response = http.get( host, port, uri ) local response = http.get( host, port, uri )
stdnse.print_debug(1, "%s: Status %s", stdnse.debug1("Status %s", response['status-line'] or "No Response")
SCRIPT_NAME, response['status-line'] or "No Response")
if response['status-line'] and response['status-line']:match("200%s+OK") if response['status-line'] and response['status-line']:match("200%s+OK")
and response['body'] then and response['body'] then
local body = response['body']:gsub("%%","%%%%") local body = response['body']:gsub("%%","%%%%")

View File

@@ -84,8 +84,7 @@ local function check_backdoor(host, shell_cmd, vuln)
local status, ret = socket:connect(host, 6200, "tcp") local status, ret = socket:connect(host, 6200, "tcp")
if not status then if not status then
stdnse.print_debug(3, "%s: can't connect to tcp port 6200: NOT VULNERABLE", stdnse.debug3("can't connect to tcp port 6200: NOT VULNERABLE")
SCRIPT_NAME)
vuln.state = vulns.STATE.NOT_VULN vuln.state = vulns.STATE.NOT_VULN
return finish_ftp(socket, true) return finish_ftp(socket, true)
end end
@@ -103,9 +102,7 @@ local function check_backdoor(host, shell_cmd, vuln)
end end
if not ret:match("uid=") then if not ret:match("uid=") then
stdnse.print_debug(3, stdnse.debug3("service on port 6200 is not the vsFTPd backdoor: NOT VULNERABLE")
"%s: service on port 6200 is not the vsFTPd backdoor: NOT VULNERABLE",
SCRIPT_NAME)
vuln.state = vulns.STATE.NOT_VULN vuln.state = vulns.STATE.NOT_VULN
return finish_ftp(socket, true) return finish_ftp(socket, true)
else else
@@ -167,8 +164,7 @@ vsFTPd version 2.3.4 backdoor, this was reported on 2011-07-04.]],
{recv_before = false, {recv_before = false,
timeout = 8000}) timeout = 8000})
if not sock then if not sock then
stdnse.print_debug(1, "%s: can't connect: %s", stdnse.debug1("can't connect: %s", err)
SCRIPT_NAME, err)
return nil return nil
end end
@@ -176,16 +172,14 @@ vsFTPd version 2.3.4 backdoor, this was reported on 2011-07-04.]],
local buffer = stdnse.make_buffer(sock, "\r?\n") local buffer = stdnse.make_buffer(sock, "\r?\n")
local code, message = ftp.read_reply(buffer) local code, message = ftp.read_reply(buffer)
if not code then if not code then
stdnse.print_debug(1, "%s: can't read banner: %s", stdnse.debug1("can't read banner: %s", message)
SCRIPT_NAME, message)
sock:close() sock:close()
return nil return nil
end end
status, ret = sock:send(CMD_FTP .. "\r\n") status, ret = sock:send(CMD_FTP .. "\r\n")
if not status then if not status then
stdnse.print_debug(1, "%s: failed to send privilege escalation command: %s", stdnse.debug1("failed to send privilege escalation command: %s", ret)
SCRIPT_NAME, ret)
return nil return nil
end end

View File

@@ -106,8 +106,7 @@ local function kill_proftpd(socket)
local killed = false local killed = false
local TELNET_KILL = '\000'..'\255' -- TELNET_DUMMY..TELNET_IAC local TELNET_KILL = '\000'..'\255' -- TELNET_DUMMY..TELNET_IAC
stdnse.print_debug(2, "%s: sending evil TELNET_IAC commands.", stdnse.debug2("sending evil TELNET_IAC commands.")
SCRIPT_NAME)
local st, ret = socket:send(string.rep(TELNET_KILL, 4069).. local st, ret = socket:send(string.rep(TELNET_KILL, 4069)..
'\255'..string.rep("Nmap", 256).."\n") '\255'..string.rep("Nmap", 256).."\n")
if not st then if not st then
@@ -118,8 +117,7 @@ local function kill_proftpd(socket)
st, ret = socket:receive_lines(1) st, ret = socket:receive_lines(1)
if not st then if not st then
if ret == "EOF" then -- "connection closed" if ret == "EOF" then -- "connection closed"
stdnse.print_debug(2, "%s: remote proftpd child was killed.", stdnse.debug2("remote proftpd child was killed.")
SCRIPT_NAME)
killed = true killed = true
else else
return st, ret return st, ret

View File

@@ -113,9 +113,7 @@ local function exploit(host, port, basepath)
for i, vector in ipairs(CREDENTIALS_PAYLOADS) do for i, vector in ipairs(CREDENTIALS_PAYLOADS) do
local req = http.get(host, port, basepath..LFI_PAYLOAD_FRAG_1..vector..LFI_PAYLOAD_FRAG_2) local req = http.get(host, port, basepath..LFI_PAYLOAD_FRAG_1..vector..LFI_PAYLOAD_FRAG_2)
if req.body and string.find(req.body, "encrypted=true") then if req.body and string.find(req.body, "encrypted=true") then
stdnse.print_debug(1, stdnse.debug1("String pattern found. Exploitation worked with vector '%s'.", vector)
"%s: String pattern found. Exploitation worked with vector '%s'.",
SCRIPT_NAME, vector)
return true, req.body return true, req.body
end end
end end

View File

@@ -56,8 +56,7 @@ action = function(host, port)
if not response or not response.status or response.status ~= 200 or if not response or not response.status or response.status ~= 200 or
not response.body then not response.body then
stdnse.print_debug(1, "%s: Failed to retrieve file: %s", stdnse.debug1("Failed to retrieve file: %s", path)
SCRIPT_NAME, path)
return return
end end

View File

@@ -111,8 +111,7 @@ overlapping byte ranges are requested.]],
response = http.head(host, port, path, request_opts) response = http.head(host, port, path, request_opts)
if not response.status then if not response.status then
stdnse.print_debug(1, "%s: Invalid response from server to the vulnerability check", stdnse.debug1("Invalid response from server to the vulnerability check")
SCRIPT_NAME)
elseif response.status == 206 then elseif response.status == 206 then
vuln.state = vulns.STATE.VULN vuln.state = vulns.STATE.VULN
else else

View File

@@ -42,7 +42,7 @@ categories={"brute","intrusive"}
portrule = shortport.port_or_service({6666,6667,6697,6679},{"irc","ircs"}) portrule = shortport.port_or_service({6666,6667,6697,6679},{"irc","ircs"})
local dbg = stdnse.print_debug local dbg = stdnse.debug
-- some parts of the following class are taken from irc-brute written by Patrik -- some parts of the following class are taken from irc-brute written by Patrik
Driver = { Driver = {
@@ -65,7 +65,7 @@ Driver = {
end end
if string.find(r:lower(), "throttled") then if string.find(r:lower(), "throttled") then
-- we were reconnecting too fast -- we were reconnecting too fast
dbg(2, "%s, throttled.", SCRIPT_NAME) dbg(2, "throttled.")
return false, "We got throttled." return false, "We got throttled."
end end
local status, _ = s:send("CAP END\r\n") local status, _ = s:send("CAP END\r\n")
@@ -91,7 +91,7 @@ Driver = {
return false, err return false, err
end end
challenge = string.match(response, "AUTHENTICATE (.*)") challenge = string.match(response, "AUTHENTICATE (.*)")
dbg(3, "%s, challenge found: %s", SCRIPT_NAME, tostring(challenge)) dbg(3, "challenge found: %s", tostring(challenge))
if challenge then status = false end if challenge then status = false end
until (not status) until (not status)
local msg = self.saslencoder:encode(username, password, challenge) local msg = self.saslencoder:encode(username, password, challenge)
@@ -150,7 +150,7 @@ local function check_sasl(host, port)
local supported = {} local supported = {}
for _,m in ipairs(to_check) do for _,m in ipairs(to_check) do
s:send("AUTHENTICATE "..m.."\r\n") s:send("AUTHENTICATE "..m.."\r\n")
dbg(3, "%s, checking mechanism %s", SCRIPT_NAME, m) dbg(3, "checking mechanism %s", m)
repeat repeat
local status, lines = s:receive_lines(1) local status, lines = s:receive_lines(1)
if string.find(lines, "AUTHENTICATE") then if string.find(lines, "AUTHENTICATE") then
@@ -185,7 +185,7 @@ action = function(host, port)
for _,m in ipairs(mechs) do for _,m in ipairs(mechs) do
if saslencoder:set_mechanism(m) then if saslencoder:set_mechanism(m) then
sasl_mech = m sasl_mech = m
dbg(2, "%s, supported mechanism found: %s", SCRIPT_NAME, m) dbg(2, "supported mechanism found: %s", m)
break break
end end
end end

View File

@@ -84,8 +84,7 @@ local function test_credentials( instance, helper, username, password )
table.insert( instance.ms_sql_empty, string.format("'sa' account is locked out.", result ) ) table.insert( instance.ms_sql_empty, string.format("'sa' account is locked out.", result ) )
end end
if ( mssql.LoginErrorMessage[ loginErrorCode ] == nil ) then if ( mssql.LoginErrorMessage[ loginErrorCode ] == nil ) then
stdnse.print_debug( 2, "%s: Attemping login to %s: Unknown login error number: %s", stdnse.debug2("Attemping login to %s: Unknown login error number: %s", instance:GetName(), loginErrorCode )
SCRIPT_NAME, instance:GetName(), loginErrorCode )
table.insert( instance.ms_sql_empty, string.format( "Unknown login error number: %s", loginErrorCode ) ) table.insert( instance.ms_sql_empty, string.format( "Unknown login error number: %s", loginErrorCode ) )
end end
else else

View File

@@ -159,10 +159,7 @@ function doquery(sock, host, port, inum, rcode, records)
records.peerlist = records.peerlist or {} records.peerlist = records.peerlist or {}
if #records + #records.peerlist >= MAX_RECORDS then if #records + #records.peerlist >= MAX_RECORDS then
stdnse.print_debug(1, stdnse.debug1('MAX_RECORDS has been reached for target %s - only processing what we have already!', target)
'MAX_RECORDS has been reached for target %s - only processing what we have already!',
target
)
if sock then sock:close() end if sock then sock:close() end
return nil return nil
end end
@@ -173,25 +170,17 @@ function doquery(sock, host, port, inum, rcode, records)
sock:set_timeout(TIMEOUT) sock:set_timeout(TIMEOUT)
local constatus, conerr = sock:connect(host, port) local constatus, conerr = sock:connect(host, port)
if not constatus then if not constatus then
stdnse.print_debug(1, stdnse.debug1('Error establishing a UDP connection for %s - %s', target, conerr)
'Error establishing a UDP connection for %s - %s', target, conerr
)
return nil return nil
end end
end end
-- send -- send
stdnse.print_debug(2, stdnse.debug2('Sending NTPv2 Mode 7 Request %d Implementation %d to %s.', rcode, inum, target)
'Sending NTPv2 Mode 7 Request %d Implementation %d to %s.',
rcode, inum, target
)
local ntpData = getPrivateMode(inum, rcode) local ntpData = getPrivateMode(inum, rcode)
local sendstatus, senderr = sock:send(ntpData) local sendstatus, senderr = sock:send(ntpData)
if not sendstatus then if not sendstatus then
stdnse.print_debug(1, stdnse.debug1('Error sending NTP request to %s:%d - %s', host.ip, port.number, senderr)
'Error sending NTP request to %s:%d - %s',
host.ip, port.number, senderr
)
sock:close() sock:close()
return nil return nil
end end
@@ -219,25 +208,16 @@ function doquery(sock, host, port, inum, rcode, records)
if not track.errcond then if not track.errcond then
local remain = parse_v2m7(packet_to_parse, records) local remain = parse_v2m7(packet_to_parse, records)
if remain > 0 then if remain > 0 then
stdnse.print_debug(1, stdnse.debug1('MAX_RECORDS has been reached while parsing NTPv2 Mode 7 Code %d responses from the target %s.', rcode, target)
'MAX_RECORDS has been reached while parsing NTPv2 Mode 7 Code %d responses from the target %s.',
rcode, target
)
track.rcv_again = false track.rcv_again = false
elseif remain == -1 then elseif remain == -1 then
stdnse.print_debug(1, stdnse.debug1('Parsing of NTPv2 Mode 7 implementation number %d request code %d response from %s has not been implemented.', inum, rcode, target)
'Parsing of NTPv2 Mode 7 implementation number %d request code %d response from %s has not been implemented.',
inum, rcode, target
)
track.rcv_again = false track.rcv_again = false
end end
end end
records.badpkts = records.badpkts + track.evil_pkts records.badpkts = records.badpkts + track.evil_pkts
if records.badpkts >= MAXIMUM_EVIL then if records.badpkts >= MAXIMUM_EVIL then
stdnse.print_debug(1, stdnse.debug1('Had %d bad packets from %s - Not continuing with this host!', target, records.badpkts)
'Had %d bad packets from %s - Not continuing with this host!',
target, records.badpkts
)
sock:close() sock:close()
return nil return nil
end end
@@ -306,9 +286,7 @@ function check(status, response, track)
track.errcond = true track.errcond = true
track.rcv_again = false track.rcv_again = false
if track.rcv_again then -- we were expecting more responses if track.rcv_again then -- we were expecting more responses
stdnse.print_debug(1, stdnse.debug1('Socket error while reading from %s - %s', track.target, response)
'Socket error while reading from %s - %s', track.target, response
)
end end
return nil return nil
end end
@@ -322,9 +300,7 @@ function check(status, response, track)
if pkt == nil then if pkt == nil then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Failed to create a Packet object with response from %s', track.target)
'Failed to create a Packet object with response from %s', track.target
)
return nil return nil
end end
@@ -340,10 +316,7 @@ function check(status, response, track)
if val < 8 then if val < 8 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Expected a response of at least 8 bytes from %s, got %d bytes.', track.target, val)
'Expected a response of at least 8 bytes from %s, got %d bytes.',
track.target, val
)
return nil return nil
end end
@@ -351,9 +324,7 @@ function check(status, response, track)
if bit.rshift(pkt:u8(off), 7) ~= 1 then if bit.rshift(pkt:u8(off), 7) ~= 1 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Bad response from %s - did not have response bit set.', track.target)
'Bad response from %s - did not have response bit set.', track.target
)
return nil return nil
end end
-- version is as expected -- version is as expected
@@ -361,10 +332,7 @@ function check(status, response, track)
if val ~= track.v then if val ~= track.v then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Bad response from %s - expected NTP version %d, got %d', track.target, track.v, val)
'Bad response from %s - expected NTP version %d, got %d', track.target,
track.v, val
)
return nil return nil
end end
-- mode is as expected -- mode is as expected
@@ -372,10 +340,7 @@ function check(status, response, track)
if val ~= track.m then if val ~= track.m then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Bad response from %s - expected NTP mode %d, got %d', track.target, track.m, val)
'Bad response from %s - expected NTP mode %d, got %d', track.target,
track.m, val
)
return nil return nil
end end
-- implementation number is as expected -- implementation number is as expected
@@ -383,10 +348,7 @@ function check(status, response, track)
if val ~= track.i then if val ~= track.i then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Bad response from %s - expected NTP implementation number %d, got %d', track.target, track.i, val)
'Bad response from %s - expected NTP implementation number %d, got %d',
track.target, track.i, val
)
return nil return nil
end end
-- request code is as expected -- request code is as expected
@@ -394,10 +356,7 @@ function check(status, response, track)
if val ~= track.c then if val ~= track.c then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Bad response from %s - expected NTP request code %d got %d.', track.target, track.c, val)
'Bad response from %s - expected NTP request code %d got %d.', track.target,
track.c, val
)
return nil return nil
end end
-- NTP error conditions - defined codes are not evil (bogus codes are). -- NTP error conditions - defined codes are not evil (bogus codes are).
@@ -430,9 +389,7 @@ function check(status, response, track)
end end
if fail then if fail then
track.errcond = true track.errcond = true
stdnse.print_debug(1, stdnse.debug1('Response from %s was NTP Error Code %d - "%s"', track.target, err, msg)
'Response from %s was NTP Error Code %d - "%s"', track.target, err, msg
)
return nil return nil
end end
@@ -447,32 +404,24 @@ function check(status, response, track)
if icount < 1 then if icount < 1 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('Expected at least one record from %s.', track.target)
'Expected at least one record from %s.', track.target
)
return nil return nil
elseif icount*isize + 8 > response:len() then elseif icount*isize + 8 > response:len() then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('NTP Mode 7 response from %s has invalid count (%d) and/or size (%d) values.', track.target, icount, isize)
'NTP Mode 7 response from %s has invalid count (%d) and/or size (%d) values.',
track.target, icount, isize
)
return nil return nil
elseif icount*isize > 500 then elseif icount*isize > 500 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1('NTP Mode 7 data section is larger than 500 bytes (%d) in response from %s.', icount*isize, track.target)
'NTP Mode 7 data section is larger than 500 bytes (%d) in response from %s.',
icount*isize, track.target
)
return nil return nil
end end
if track.c == 42 and track.i == 3 and isize ~= 72 then if track.c == 42 and track.i == 3 and isize ~= 72 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1(
'Expected item size of 72 bytes (got %d) for request code 42 implementation number 3 in response from %s.', 'Expected item size of 72 bytes (got %d) for request code 42 implementation number 3 in response from %s.',
isize, track.target isize, track.target
) )
@@ -480,7 +429,7 @@ function check(status, response, track)
elseif track.c == 0 and track.i == 3 and isize ~= 32 then elseif track.c == 0 and track.i == 3 and isize ~= 32 then
track.errcond = true track.errcond = true
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1(
'Expected item size of 32 bytes (got %d) for request code 0 implementation number 3 in response from %s.', 'Expected item size of 32 bytes (got %d) for request code 0 implementation number 3 in response from %s.',
isize, track.target isize, track.target
) )
@@ -508,7 +457,7 @@ function check(status, response, track)
track.hseq = seq track.hseq = seq
else -- seq <= hseq !duplicate! else -- seq <= hseq !duplicate!
track.evil_pkts = track.evil_pkts+1 track.evil_pkts = track.evil_pkts+1
stdnse.print_debug(1, stdnse.debug1(
'Response from %s had a duplicate sequence number - dropping it.', 'Response from %s had a duplicate sequence number - dropping it.',
track.target track.target
) )
@@ -807,7 +756,7 @@ function interpret(recs, targetip)
elseif r.flags == 4 then elseif r.flags == 4 then
t.casts.m[af][r.daddr] = r.daddr t.casts.m[af][r.daddr] = r.daddr
else -- shouldn't happen else -- shouldn't happen
stdnse.print_debug(1, stdnse.debug1(
'Host associated with %s had transmission flag value %d - Strange!', 'Host associated with %s had transmission flag value %d - Strange!',
targetip, r.flags targetip, r.flags
) )

View File

@@ -36,9 +36,7 @@ categories = {"safe", "discovery"}
prerule = function() prerule = function()
if not stdnse.get_script_args("resolveall.hosts") then if not stdnse.get_script_args("resolveall.hosts") then
stdnse.print_debug(3, stdnse.debug3("Skipping '%s' %s, 'resolveall.hosts' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, 'resolveall.hosts' argument is missing.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end
return true return true

View File

@@ -204,9 +204,7 @@ action = function(host, port)
-- connect to host -- connect to host
local constatus, conerr = sock:connect(host, port) local constatus, conerr = sock:connect(host, port)
if not constatus then if not constatus then
stdnse.print_debug(1, stdnse.debug1('Error establishing connection for %s - %s', host, conerr)
'Error establishing connection for %s - %s', host, conerr
)
return nil return nil
end end
-- send and receive the COTP Packet -- send and receive the COTP Packet
@@ -247,9 +245,7 @@ action = function(host, port)
-- re connect to the device ( a RST packet was sent in the previous attempts) -- re connect to the device ( a RST packet was sent in the previous attempts)
local constatus, conerr = sock:connect(host, port) local constatus, conerr = sock:connect(host, port)
if not constatus then if not constatus then
stdnse.print_debug(1, stdnse.debug1('Error establishing connection for %s - %s', host, conerr)
'Error establishing connection for %s - %s', host, conerr
)
return nil return nil
end end
-- send and receive the alternate COTP Packet, the dst is 200 instead of 102( do nothing with result) -- send and receive the alternate COTP Packet, the dst is 200 instead of 102( do nothing with result)

View File

@@ -481,9 +481,7 @@ function check_ms06_025(host)
msrpc.stop_smb(smbstate) msrpc.stop_smb(smbstate)
--sanity check --sanity check
if(status == false) then if(status == false) then
stdnse.print_debug( stdnse.debug3("check_ms06_025: RRAS_SubmitRequest failed")
3,
"check_ms06_025: RRAS_SubmitRequest failed")
if(sr_result == "NT_STATUS_PIPE_BROKEN") then if(sr_result == "NT_STATUS_PIPE_BROKEN") then
return true, VULNERABLE return true, VULNERABLE
else else
@@ -535,9 +533,7 @@ function check_ms07_029(host)
--sanity check --sanity check
msrpc.stop_smb(smbstate) msrpc.stop_smb(smbstate)
if(status == false) then if(status == false) then
stdnse.print_debug( stdnse.debug3("check_ms07_029: DNSSERVER_Query failed")
3,
"check_ms07_029: DNSSERVER_Query failed")
if(q_result == "NT_STATUS_PIPE_BROKEN") then if(q_result == "NT_STATUS_PIPE_BROKEN") then
return true, VULNERABLE return true, VULNERABLE
else else

View File

@@ -111,8 +111,7 @@ local function escalate_privs(socket, smtp_opts)
local exim_spool = "spool_directory = \\${run{/bin/sh -c 'id > ".. local exim_spool = "spool_directory = \\${run{/bin/sh -c 'id > "..
tmp_file.."' }}" tmp_file.."' }}"
stdnse.print_debug(2, "%s: trying to escalate privileges", stdnse.debug2("trying to escalate privileges")
SCRIPT_NAME)
local status, ret = send_recv(socket, "id\n") local status, ret = send_recv(socket, "id\n")
if not status then if not status then
@@ -145,9 +144,7 @@ local function escalate_privs(socket, smtp_opts)
exploited = true exploited = true
results = results..string.format("\n After 'id': %s", results = results..string.format("\n After 'id': %s",
string.gsub(ret, "^%$*%s*(.-)\n*%$*$", "%1")) string.gsub(ret, "^%$*%s*(.-)\n*%$*$", "%1"))
stdnse.print_debug(2, stdnse.debug2("successfully exploited the Exim privileges escalation.")
"%s: successfully exploited the Exim privileges escalation.",
SCRIPT_NAME)
end end
-- delete tmp file, should we care about this ? -- delete tmp file, should we care about this ?
@@ -163,8 +160,7 @@ end
local function exploit_heap(socket, smtp_opts) local function exploit_heap(socket, smtp_opts)
local exploited, ret = false, "" local exploited, ret = false, ""
stdnse.print_debug(2, "%s: exploiting the heap overflow", stdnse.debug2("exploiting the heap overflow")
SCRIPT_NAME)
local status, response = smtp.mail(socket, smtp_opts.mailfrom) local status, response = smtp.mail(socket, smtp_opts.mailfrom)
if not status then if not status then
@@ -230,8 +226,7 @@ local function exploit_heap(socket, smtp_opts)
return status, msg return status, msg
end end
stdnse.print_debug(1, "%s: sending forged mail, size: %dMB", stdnse.debug1("sending forged mail, size: %dMB", msg_len / (1024*1024))
SCRIPT_NAME, msg_len / (1024*1024))
-- use low socket level functions. -- use low socket level functions.
status, ret = socket:send(hdrs) status, ret = socket:send(hdrs)
@@ -278,8 +273,7 @@ local function exploit_heap(socket, smtp_opts)
end end
end end
stdnse.print_debug(2, "%s: the forged mail was sent successfully.", stdnse.debug2("the forged mail was sent successfully.")
SCRIPT_NAME)
-- second round -- second round
status, response = smtp.query(socket, "MAIL", status, response = smtp.query(socket, "MAIL",
@@ -295,8 +289,7 @@ local function exploit_heap(socket, smtp_opts)
end end
if response:match("sh:%s") or ret:match("sh:%s") then if response:match("sh:%s") or ret:match("sh:%s") then
stdnse.print_debug(2, stdnse.debug2("successfully exploited the Exim heap overflow.")
"%s: successfully exploited the Exim heap overflow.", SCRIPT_NAME)
exploited = "heap-exploited" exploited = "heap-exploited"
end end

View File

@@ -246,8 +246,7 @@ local function check_smtpd(smtp_opts)
auth_tests)) auth_tests))
end end
else else
stdnse.print_debug(2, "%s: Authentication is not available", stdnse.debug2("Authentication is not available")
SCRIPT_NAME)
table.insert(vuln.check_results, "Authentication is not available") table.insert(vuln.check_results, "Authentication is not available")
end end

View File

@@ -84,8 +84,7 @@ end
local function check_dkim(socket, smtp_opts) local function check_dkim(socket, smtp_opts)
local killed = false local killed = false
stdnse.print_debug(2, "%s: checking the Exim DKIM Format String", stdnse.debug2("checking the Exim DKIM Format String")
SCRIPT_NAME)
local status, response = smtp.mail(socket, smtp_opts.mailfrom) local status, response = smtp.mail(socket, smtp_opts.mailfrom)
if not status then if not status then
@@ -123,8 +122,7 @@ local function check_dkim(socket, smtp_opts)
status, response = smtp.query(socket, ".") status, response = smtp.query(socket, ".")
if not status then if not status then
if string.match(response, "connection closed") then if string.match(response, "connection closed") then
stdnse.print_debug(2, stdnse.debug2("Exim server is vulnerable to DKIM Format String")
"%s: Exim server is vulnerable to DKIM Format String", SCRIPT_NAME)
killed = true killed = true
else else
return status, "failed to terminate the message, seems NOT VULNERABLE" return status, "failed to terminate the message, seems NOT VULNERABLE"

View File

@@ -113,8 +113,7 @@ local communities = function()
nmap.fetchfile("nselib/data/snmpcommunities.lst") nmap.fetchfile("nselib/data/snmpcommunities.lst")
if communities_file then if communities_file then
stdnse.print_debug(1, "%s: Using the %s as the communities file", stdnse.debug1("Using the %s as the communities file", communities_file)
SCRIPT_NAME, communities_file)
local status, iterator = communities_raw(communities_file) local status, iterator = communities_raw(communities_file)
@@ -131,8 +130,7 @@ local communities = function()
return true, unpwdb.limited_iterator(iterator, time_limit, count_limit) return true, unpwdb.limited_iterator(iterator, time_limit, count_limit)
else else
stdnse.print_debug(1, "%s: Cannot read the communities file, using the nmap username/password database instead", stdnse.debug1("Cannot read the communities file, using the nmap username/password database instead")
SCRIPT_NAME)
return unpwdb.passwords() return unpwdb.passwords()
end end

View File

@@ -54,9 +54,7 @@ dependencies = {"snmp-brute"}
prerule = function() prerule = function()
if not stdnse.get_script_args({"snmp-interfaces.host", "host"}) then if not stdnse.get_script_args({"snmp-interfaces.host", "host"}) then
stdnse.print_debug(3, stdnse.debug3("Skipping '%s' %s, 'snmp-interfaces.host' argument is missing.", SCRIPT_NAME, SCRIPT_TYPE)
"Skipping '%s' %s, 'snmp-interfaces.host' argument is missing.",
SCRIPT_NAME, SCRIPT_TYPE)
return false return false
end end

View File

@@ -226,20 +226,17 @@ local function test_ccs_injection(host, port, version)
-- Leave the target not vulnerable in case of an error. This could occur -- Leave the target not vulnerable in case of an error. This could occur
-- when running against a different TLS/SSL implementations (e.g., GnuTLS) -- when running against a different TLS/SSL implementations (e.g., GnuTLS)
if not status then if not status then
stdnse.print_debug( stdnse.debug1("Couldn't get reply from the server (probably not OpenSSL)")
1, "Couldn't get reply from the server (probably not OpenSSL)")
s:close() s:close()
return false return false
end end
if not vulnerable then if not vulnerable then
stdnse.print_debug( stdnse.debug1("Server returned UNEXPECTED_MESSAGE alert, not vulnerable")
1, "Server returned UNEXPECTED_MESSAGE alert, not vulnerable")
s:close() s:close()
return false return false
else else
stdnse.print_debug( stdnse.debug1("Vulnerable - alert is not UNEXPECTED_MESSAGE")
1, "Vulnerable - alert is not UNEXPECTED_MESSAGE")
s:close() s:close()
return true return true
end end

View File

@@ -30,15 +30,11 @@ hostrule = function(host)
-- print debug messages because the script relies on -- print debug messages because the script relies on
-- script arguments and traceroute results. -- script arguments and traceroute results.
if not target.ALLOW_NEW_TARGETS then if not target.ALLOW_NEW_TARGETS then
stdnse.print_debug(3, stdnse.debug3("Skipping %s script, 'newtargets' script argument is missing.", SCRIPT_NAME)
"Skipping %s script, 'newtargets' script argument is missing.",
SCRIPT_NAME)
return false return false
end end
if not host.traceroute then if not host.traceroute then
stdnse.print_debug(3, stdnse.debug3("Skipping %s script because traceroute results are missing.", SCRIPT_NAME)
"Skipping %s script because traceroute results are missing.",
SCRIPT_NAME)
return false return false
end end
return true return true
@@ -53,8 +49,7 @@ action = function(host)
local status, ret = target.add(hop.ip) local status, ret = target.add(hop.ip)
if status then if status then
ntargets = ntargets + ret ntargets = ntargets + ret
stdnse.print_debug(3, stdnse.debug3("TRACEROUTE Scan Hops: Added new target "..host.ip.." from traceroute results")
"TRACEROUTE Scan Hops: Added new target "..host.ip.." from traceroute results")
else else
stdnse.debug3("TRACEROUTE Scan Hops: " .. ret) stdnse.debug3("TRACEROUTE Scan Hops: " .. ret)
end end

View File

@@ -600,7 +600,7 @@ action = function(host, port)
if (fulldatalen > totpck) or (curlen > totlen) if (fulldatalen > totpck) or (curlen > totlen)
or (fulldatalen == totpck and curlen ~= totlen) or (fulldatalen == totpck and curlen ~= totlen)
or (curlen == totlen and fulldatalen ~= totpck) then or (curlen == totlen and fulldatalen ~= totpck) then
stdnse.print_debug("Invalid state (fulldatalen = " .. fulldatalen .. stdnse.debug1("Invalid state (fulldatalen = " .. fulldatalen ..
"; totpck = " .. totpck .. "; curlen = " .. curlen .. "; totpck = " .. totpck .. "; curlen = " .. curlen ..
"; totlen = " .. totlen .. "). Aborting script.") "; totlen = " .. totlen .. "). Aborting script.")
cleanup() cleanup()