1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-06 04:31:29 +00:00

Remove unneeded retries around send/receive_buf(numbytes) left from when different behavior was used

This commit is contained in:
dmiller
2018-09-01 18:50:19 +00:00
parent 29d9b81749
commit cc768ddec8
2 changed files with 10 additions and 31 deletions

View File

@@ -807,7 +807,6 @@ function smb_send(smb, header, parameters, data, overrides)
local encoded_parameters = smb_encode_parameters(parameters, overrides) local encoded_parameters = smb_encode_parameters(parameters, overrides)
local encoded_data = smb_encode_data(data, overrides) local encoded_data = smb_encode_data(data, overrides)
local body = header .. encoded_parameters .. encoded_data local body = header .. encoded_parameters .. encoded_data
local attempts = 5
local status, err local status, err
-- Calculate the message signature -- Calculate the message signature
@@ -816,14 +815,11 @@ function smb_send(smb, header, parameters, data, overrides)
local out = string.pack(">s4", body) local out = string.pack(">s4", body)
repeat stdnse.debug3("SMB: Sending SMB packet (len: %d)", #out)
attempts = attempts - 1
stdnse.debug3("SMB: Sending SMB packet (len: %d, attempts remaining: %d)", #out, attempts)
status, err = smb['socket']:send(out) status, err = smb['socket']:send(out)
until(status or (attempts == 0))
if(attempts == 0) then if not status then
stdnse.debug1("SMB: Sending packet failed after 5 tries! Giving up.") stdnse.debug1("SMB: Sending packet failed.")
end end
return status, err return status, err
@@ -841,9 +837,7 @@ end
-- removed). If status is false, header contains an error message and parameters/ -- removed). If status is false, header contains an error message and parameters/
-- data are undefined. -- data are undefined.
function smb_read(smb, read_data) function smb_read(smb, read_data)
local status
local pos, netbios_data, netbios_length, length, header, parameter_length, parameters, data_length, data local pos, netbios_data, netbios_length, length, header, parameter_length, parameters, data_length, data
local attempts = 5
stdnse.debug3("SMB: Receiving SMB packet") stdnse.debug3("SMB: Receiving SMB packet")
@@ -851,20 +845,11 @@ function smb_read(smb, read_data)
smb['socket']:set_timeout(TIMEOUT) smb['socket']:set_timeout(TIMEOUT)
-- perform 5 attempt to read the Netbios header -- perform 5 attempt to read the Netbios header
local netbios local status, netbios_data = smb['socket']:receive_buf(match.numbytes(4), true);
repeat
attempts = attempts - 1
status, netbios_data = smb['socket']:receive_buf(match.numbytes(4), true);
if ( not(status) and netbios_data == "EOF" ) then
stdnse.debug1("SMB: ERROR: Server disconnected the connection")
return false, "SMB: ERROR: Server disconnected the connection"
end
until(status or (attempts == 0))
-- Make sure the connection is still alive -- Make sure the connection is still alive
if(status ~= true) then if not status then
return false, "SMB: Failed to receive bytes after 5 attempts: " .. netbios_data return false, "SMB: Failed to receive bytes: " .. netbios_data
end end
-- The length of the packet is 4 bytes of big endian (for our purposes). -- The length of the packet is 4 bytes of big endian (for our purposes).
@@ -879,16 +864,11 @@ function smb_read(smb, read_data)
-- The total length is the netbios_length, plus 4 (for the length itself) -- The total length is the netbios_length, plus 4 (for the length itself)
length = netbios_length + 4 length = netbios_length + 4
local attempts = 5 local status, smb_data = smb['socket']:receive_buf(match.numbytes(netbios_length), true)
local smb_data
repeat
attempts = attempts - 1
status, smb_data = smb['socket']:receive_buf(match.numbytes(netbios_length), true)
until(status or (attempts == 0))
-- Make sure the connection is still alive -- Make sure the connection is still alive
if(status ~= true) then if not status then
return false, "SMB: Failed to receive bytes after 5 attempts: " .. smb_data return false, "SMB: Failed to receive bytes: " .. smb_data
end end
local result = netbios_data .. smb_data local result = netbios_data .. smb_data

View File

@@ -1,4 +1,3 @@
local bin = require('bin')
local nmap = require('nmap') local nmap = require('nmap')
local shortport = require('shortport') local shortport = require('shortport')
local stdnse = require('stdnse') local stdnse = require('stdnse')