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

Change calls in these forms:

socket:connect(host.ip, port.number)
socket:connect(host.ip, port.number, port.protocol)

to this:

socket:connect(host, port)

connect can take host and port tables now, and the default protocol is
taken from the port table if possible.
This commit is contained in:
david
2010-08-16 18:59:30 +00:00
parent bfffa53616
commit 3c89e089fc
55 changed files with 63 additions and 63 deletions

View File

@@ -1348,7 +1348,7 @@ Helper = {
self.socket = nmap.new_socket()
self.socket:set_timeout( 5000 )
status = self.socket:connect(host.ip, port.number, port.protocol)
status = self.socket:connect(host, port)
if not status then
return false, "Socket connection failed"
end

View File

@@ -67,7 +67,7 @@
-- end,
-- connect = function( self )
-- self.socket = nmap.new_socket()
-- return self.socket:connect( self.host.ip, self.port.number, "tcp" )
-- return self.socket:connect( self.host, self.port )
-- end,
-- disconnect = function( self )
-- return self.socket:close()

View File

@@ -539,7 +539,7 @@ Helper = {
connect = function( self, host, port )
self.db2socket = DB2Socket:new()
self.comm = Comm:new( self.db2socket )
return self.db2socket:connect(host.ip, port.number, port.protocol)
return self.db2socket:connect(host, port)
end,
--- Closes an open connection.
@@ -736,8 +736,8 @@ DB2Socket = {
--- Establishes a connection.
--
-- @param hostid Hostname or IP address.
-- @param port Port number.
-- @param hostid Host table, hostname, or IP address.
-- @param port Port table or number.
-- @param protocol <code>"tcp"</code>, <code>"udp"</code>, or
-- @return Status (true or false).
-- @return Error code (if status is false).

View File

@@ -21,7 +21,7 @@ function capabilities(host, port)
local capas = {}
socket:set_timeout(10000)
local proto = (port.version and port.version.service_tunnel == "ssl" and "ssl") or "tcp"
if not socket:connect(host.ip, port.number, proto) then return nil, "Could Not Connect" end
if not socket:connect(host, port, proto) then return nil, "Could Not Connect" end
local status, line = socket:receive_lines(1)
if not string.match(line, "^[%*] OK") then return nil, "No Response" end

View File

@@ -654,7 +654,7 @@ TDSStream = {
-- the end of the input buffer. So the only time the timeout is
-- triggered is when waiting for a response to a query.
self.socket:set_timeout( MSSQL_TIMEOUT * 1000 )
status, result = self.socket:connect(host.ip, port.number, port.protocol)
status, result = self.socket:connect(host, port)
status, _, lport, _, _ = self.socket:get_info()
if ( status ) then
math.randomseed(os.time() * lport )

View File

@@ -632,7 +632,7 @@ function pcap_close()
-- @return A table as described above.
-- @usage
-- local s = nmap.new_socket()
-- local status, error = s:connect(host.ip, port.number, "ssl")
-- local status, error = s:connect(host, port, "ssl")
-- if status then
-- local cert = s:get_ssl_certificate()
-- local digest = cert:digest("md5")

View File

@@ -611,7 +611,7 @@ function detectVersion(host, port)
local status, response
local socket = nmap.new_socket()
socket:connect(host.ip, port.number, "tcp")
socket:connect(host, port)
status, response = v3.sendStartup(socket, "versionprobe", "versionprobe")
socket:close()

View File

@@ -174,7 +174,7 @@ function connectProxy(host, port, proxyType, hostname)
local socket = nmap.new_socket()
socket:set_timeout(10000)
local try = nmap.new_try(function() socket:close() return false end)
try(socket:connect(host.ip, port.number))
try(socket:connect(host, port))
if proxyType == "http" then return socket end
if proxyType == "socks4" then return socksHandshake(socket, 4, hostname) end
if proxyType == "socks5" then return socksHandshake(socket, 5, hostname) end

View File

@@ -157,7 +157,7 @@ Comm = {
return status, err
end
socket = nmap.new_socket()
status, err = socket:connect(host.ip, port.number, port.protocol)
status, err = socket:connect(host, port)
if (not(status)) then
return status, string.format("%s connect error: %s", self.program, err)
else

View File

@@ -492,7 +492,7 @@ function start_raw(host, port)
local socket = nmap.new_socket()
socket:set_timeout(TIMEOUT)
status, err = socket:connect(host.ip, port, "tcp")
status, err = socket:connect(host, port, "tcp")
if(status == false) then
return false, "SMB: Failed to connect to host: " .. err
@@ -599,7 +599,7 @@ function start_netbios(host, port, name)
stdnse.print_debug(3, "SMB: Connecting to %s", host.ip)
socket:set_timeout(TIMEOUT)
status, err = socket:connect(host.ip, port, "tcp")
status, err = socket:connect(host, port, "tcp")
if(status == false) then
socket:close()
return false, "SMB: Failed to connect: " .. err

View File

@@ -58,7 +58,7 @@ fetch_host_key = function(host, port)
local socket = nmap.new_socket()
local status, _
status = socket:connect(host.ip, port.number)
status = socket:connect(host, port)
if not status then return end
-- fetch banner
status = socket:receive_lines(1)

View File

@@ -154,7 +154,7 @@ fetch_host_key = function( host, port, key_type )
-- oakley group 2 prime taken from rfc 2409
local prime = "FFFFFFFFFFFFFFFFC90FDAA22168C234C4C6628B80DC1CD129024E088A67CC74020BBEA63B139B22514A08798E3404DDEF9519B3CD3A431B302B0A6DF25F14374FE1356D6D51C245E485B576625E7EC6F44C42E9A637ED6B0BFF5CB6F406B7EDEE386BFB5A899FA5AE9F24117C4B1FE649286651ECE65381FFFFFFFFFFFFFFFF"
status = socket:connect(host.ip, port.number)
status = socket:connect(host, port)
if not status then return end
-- fetch banner
status = socket:receive_lines(1)

View File

@@ -65,7 +65,7 @@ action = function(host, port)
local try = nmap.new_try(catch)
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
-- get our data
afp_proto = afp.Proto:new( { socket=socket } )

View File

@@ -51,8 +51,8 @@ action = function(host, port)
local try = nmap.new_try(catch)
try(client_ident:connect(host.ip, 113))
try(client_service:connect(host.ip, port.number))
try(client_ident:connect(host, 113))
try(client_service:connect(host, port))
local localip, localport, remoteip, remoteport =
try(client_service:get_info())

View File

@@ -118,7 +118,7 @@ action = function(host, port)
try = nmap.new_try(function() socket:close() end)
try( socket:connect(host.ip, port.number, port.protocol) )
try( socket:connect(host, port) )
-- send the two first packets and never look back
repeat

View File

@@ -104,7 +104,7 @@ action = function(host, port)
socket:set_timeout(5000)
try = nmap.new_try(function() socket:close() end)
try(socket:connect(host.ip, port.number, port.protocol))
try(socket:connect(host, port))
-- send the two first packets and never look back
repeat

View File

@@ -294,7 +294,7 @@ action = function(host, port)
local try = nmap.new_try(catch)
try(socket:connect(host.ip, port.number, "tcp"))
try(socket:connect(host, port))
local query

View File

@@ -624,7 +624,7 @@ local function go(host, port)
-- Create the UDP socket
socket = nmap.new_socket()
status, err = socket:connect(host.ip, port.number, "udp")
status, err = socket:connect(host, port)
if(status == false) then
return false, "Couldn't create socket: " .. err
end

View File

@@ -71,7 +71,7 @@ action = function(host, port)
local try = nmap.new_try(err_catch)
try(socket:connect(host.ip, port.number, port.protocol))
try(socket:connect(host, port))
buffer = stdnse.make_buffer(socket, "\r?\n")
-- Read banner.

View File

@@ -109,7 +109,7 @@ action = function(host, port)
local fc
socket:set_timeout(10000)
socket:connect(host.ip, port.number)
socket:connect(host, port)
-- BANNER
fc = get_ftp_code(socket)

View File

@@ -62,7 +62,7 @@ local function login(host, port, user, pass)
-- Create a new socket
local socket = nmap.new_socket()
status, err = socket:connect(host.ip, port.number)
status, err = socket:connect(host, port)
if(not(status)) then
socket:close()
return false, "Couldn't connect to host: " .. err

View File

@@ -36,7 +36,7 @@ action = function(host, port)
local try = nmap.new_try(err_catch)
socket:set_timeout(10000)
try(socket:connect(host.ip, port.number, port.protocol))
try(socket:connect(host, port))
-- First, try a safe User so that we are sure that everything is ok
local payload = "USER opie\r\n"

View File

@@ -113,7 +113,7 @@ action = function( host, port )
socket:close()
-- set a reasonable timeout value
socket:set_timeout(5000)
status = socket:connect(host.ip, port.number, opt)
status = socket:connect(host, port, opt)
if not status then
return
end

View File

@@ -110,7 +110,7 @@ function action(host,port)
-- We close and re-open the socket so that the anonymous bind does not distract us
socket:close()
status = socket:connect(host.ip, port.number, opt)
status = socket:connect(host, port, opt)
socket:set_timeout(10000)
-- Searching for an empty argument list against LDAP on W2K3 returns all attributes
@@ -149,4 +149,4 @@ function action(host,port)
return stdnse.format_output(true, result )
end
end

View File

@@ -98,7 +98,7 @@ function action(host,port)
-- We close and re-open the socket so that the anonymous bind does not distract us
socket:close()
status = socket:connect(host.ip, port.number, opt)
status = socket:connect(host, port, opt)
socket:set_timeout(10000)
local req

View File

@@ -54,7 +54,7 @@ function action(host,port)
local try = nmap.new_try(catch)
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
local req, result, packet, err, status
--Build packet

View File

@@ -66,7 +66,7 @@ function action(host,port)
local try = nmap.new_try(catch)
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
local req, status, statusresponse, buildinfo, packet, err

View File

@@ -137,7 +137,7 @@ action = function(host, port)
end -- get_real_version(dst, dstPort)
-- connect to the potential SQL server
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
-- send a magic packet
-- details here: http://www.codeproject.com/cs/database/locate_sql_servers.asp

View File

@@ -54,7 +54,7 @@ action = function( host, port )
for username in usernames do
for password in passwords do
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
response = try( mysql.receiveGreeting( socket ) )
stdnse.print_debug( "Trying %s/%s ...", username, password )

View File

@@ -82,7 +82,7 @@ action = function( host, port )
--
for username, password in pairs(users) do
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
response = try( mysql.receiveGreeting( socket ) )
status, response = mysql.loginRequest( socket, { authversion = "post41", charset = response.charset }, username, password, response.salt )

View File

@@ -37,7 +37,7 @@ action = function( host, port )
socket:set_timeout(5000)
for _, v in ipairs( users ) do
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
response = try( mysql.receiveGreeting( socket ) )
status, response = mysql.loginRequest( socket, { authversion = "post41", charset = response.charset }, v, nil, response.salt )
if response.errorcode == 0 then

View File

@@ -84,7 +84,7 @@ action = function( host, port )
--
for username, password in pairs(users) do
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
response = try( mysql.receiveGreeting( socket ) )
status, response = mysql.loginRequest( socket, { authversion = "post41", charset = response.charset }, username, password, response.salt )

View File

@@ -93,7 +93,7 @@ action = function( host, port )
--
for username, password in pairs(users) do
try( socket:connect(host.ip, port.number, "tcp") )
try( socket:connect(host, port) )
response = try( mysql.receiveGreeting( socket ) )
status, response = mysql.loginRequest( socket, { authversion = "post41", charset = response.charset }, username, password, response.salt )

View File

@@ -167,7 +167,7 @@ function doquery(sock, host, port, inum, rcode, records)
if not sock then
sock = nmap.new_socket()
sock:set_timeout(TIMEOUT)
local constatus, conerr = sock:connect(host.ip, port.number, port.protocol)
local constatus, conerr = sock:connect(host, port)
if not constatus then
stdnse.print_debug(1,
'Error establishing a UDP connection for %s - %s', target, conerr

View File

@@ -144,7 +144,7 @@ action = function(host, port)
-- check for comments
if not sid:match("#!comment:") then
try(socket:connect(host.ip, port.number))
try(socket:connect(host, port))
request = create_connect_packet( host.ip, port.number, sid )
try(socket:send(request))
response = try(socket:receive_bytes(1))

View File

@@ -61,7 +61,7 @@ local function connectSocket(host, port, ssl)
-- set a reasonable timeout value
socket:set_timeout(5000)
socket:connect(host.ip, port.number, "tcp")
socket:connect(host, port)
-- let's be responsible and avoid sending communication in the clear
if ( ssl ) then

View File

@@ -52,7 +52,7 @@ action = function(host, port)
local socket = nmap.new_socket()
socket:set_timeout(15000)
try = nmap.new_try(function() socket:close() end)
try(socket:connect(host.ip, port.number))
try(socket:connect(host, port))
try(socket:send(statusmsg)) --this block gets the current display status
response,data=socket:receive()
if not response then --send an initial probe. If no response, send nothing further.

View File

@@ -90,7 +90,7 @@ action = function(host, port)
elseif (perror == pop3.err.userError) then
currPw = nil
else
local socstatus = socket:connect(host.ip, port.number, bopt)
local socstatus = socket:connect(host, port, bopt)
if not socstatus
then return
else _, line = socket:receive()

View File

@@ -22,7 +22,7 @@ action = function(host, port)
local result
local status = true
socket:connect(host.ip, port.number, port.protocol)
socket:connect(host, port)
status, result = socket:receive_lines(1)

View File

@@ -368,7 +368,7 @@ local function check_smbv2_dos(host)
return false, "Couldn't create socket"
end
status, result = socket:connect(host.ip, 445)
status, result = socket:connect(host, 445)
if(status == false) then
socket:close()
return false, "Couldn't connect to host: " .. result
@@ -396,7 +396,7 @@ local function check_smbv2_dos(host)
-- Try and do something simple
stdnse.print_debug(1, "smb-check-vulns: Attempting to connect to the host")
socket:set_timeout(5000)
status, result = socket:connect(host.ip, 445)
status, result = socket:connect(host, 445)
-- Check the result
if(status == false or status == nil) then

View File

@@ -42,7 +42,7 @@ action = function(host, port)
local try = nmap.new_try(catch)
-- connect to the potential SNMP system
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
local request = snmp.buildGetRequest({}, "1.3.6.1.2.1.1.3.0")

View File

@@ -355,7 +355,7 @@ action = function(host, port)
local status
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
-- retreive network interface information from IF-MIB
status, interfaces = snmp.snmpWalk( socket, if_oid )
@@ -371,7 +371,7 @@ action = function(host, port)
interfaces = process_interfaces( interfaces )
-- retreive IP address information from IP-MIB
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, ips = snmp.snmpWalk( socket, ip_oid )
-- associate that IP address information with the correct interface

View File

@@ -84,7 +84,7 @@ action = function(host, port)
local status, tcp, udp
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, tcp = snmp.snmpWalk( socket, tcp_oid )
status, udp = snmp.snmpWalk( socket, udp_oid )

View File

@@ -116,7 +116,7 @@ action = function(host, port)
local status
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, shares = snmp.snmpWalk( socket, snmpoid )
socket:close()

View File

@@ -38,7 +38,7 @@ action = function(host, port)
local try = nmap.new_try(catch)
-- connect to the potential SNMP system
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
local payload

View File

@@ -63,7 +63,7 @@ action = function(host, port)
local status
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, services = snmp.snmpWalk( socket, snmpoid )
socket:close()

View File

@@ -81,7 +81,7 @@ action = function(host, port)
local shares = {}
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, shares = snmp.snmpWalk( socket, snmpoid )
socket:close()

View File

@@ -86,7 +86,7 @@ action = function(host, port)
local status
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, sw = snmp.snmpWalk( socket, snmpoid )
socket:close()

View File

@@ -59,7 +59,7 @@ action = function(host, port)
local status
socket:set_timeout(5000)
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
status, users = snmp.snmpWalk( socket, snmpoid )
socket:close()

View File

@@ -20,7 +20,7 @@ action = function(host, port)
local result;
local status = true;
socket:connect(host.ip, port.number, port.protocol)
socket:connect(host, port)
status, result = socket:receive_lines(1);
if (not status) then

View File

@@ -91,7 +91,7 @@ action = function(host, port)
return nil
end
else
local status, error = s:connect(host.ip, port.number, "ssl")
local status, error = s:connect(host, port, "ssl")
if not status then
if nmap.verbosity() > 0 then
@@ -188,7 +188,7 @@ function starttls_negotiate(host, port)
-- Works for SMTP (25) and SMTP Submission (587)
-- Open a standard TCP socket
local status, error = s:connect(host.ip, port.number, "tcp")
local status, error = s:connect(host, port, "tcp")
if not status then
return nil

View File

@@ -156,7 +156,7 @@ action = function(host, port)
table.insert(t, string.char(0x44, 0xc0, 0x3d, 0xc0));
ssl_v2_hello = table.concat(t, "")
socket:connect(host.ip, port.number, "tcp");
socket:connect(host, port, "tcp");
socket:send(ssl_v2_hello);
status, server_hello = socket:receive_bytes(2);

View File

@@ -200,7 +200,7 @@ action = function(host, port)
end
if status == 3 or status == 4 then
try(soc:connect(host.ip, port.number, best_opt))
try(soc:connect(host, port, best_opt))
end
status, pair = brute_cred(user, pass, soc)

View File

@@ -40,7 +40,7 @@ action = function(host, port)
local try = nmap.new_try(catch)
-- connect to the potential UPnP system
try(socket:connect(host.ip, port.number, "udp"))
try(socket:connect(host, port))
local payload = strbuf.new()

View File

@@ -38,7 +38,7 @@ action = function(host, port)
end
try = nmap.new_try(catch)
try(socket:connect(host.ip, port.number))
try(socket:connect(host, port))
-- Sending the network dump of a x11 connection request (captured
-- from the XOpenDisplay() function):