mirror of
https://github.com/nmap/nmap.git
synced 2025-12-17 21:19:01 +00:00
Add Sven's modifications to http.lua. In his words:
It is unnecessary to prefer targetname over the ip in the request() function since host is only passed to socket:connect() which would have to resolve the targetname back to the ip. I've rewritten the header/body separation to use a single regex which should do the same as your code and since the first match is non-greedy should always prefer the shorter version. I've done something similar for the header splitting. I've removed the type checks for header and body since they are always strings.
This commit is contained in:
@@ -2,7 +2,7 @@
|
|||||||
|
|
||||||
o The http NSE module tries to deal with non-standards-compliant HTTP
|
o The http NSE module tries to deal with non-standards-compliant HTTP
|
||||||
traffic, particularly responses in which the header fields are
|
traffic, particularly responses in which the header fields are
|
||||||
separated by plain LF rather than CRLF. [Jah]
|
separated by plain LF rather than CRLF. [Jah, Sven]
|
||||||
|
|
||||||
o [Zenmap] The help function now properly converts the pathname of the
|
o [Zenmap] The help function now properly converts the pathname of the
|
||||||
local help file to a URL, for better compatibility with different
|
local help file to a URL, for better compatibility with different
|
||||||
|
|||||||
@@ -164,36 +164,14 @@ request = function( host, port, data, options )
|
|||||||
response = table.concat( response )
|
response = table.concat( response )
|
||||||
|
|
||||||
-- try and separate the head from the body
|
-- try and separate the head from the body
|
||||||
local header, body, h1, h2, b1, b2
|
local header, body
|
||||||
if response:match( "\r\n\r\n" ) and response:match( "\n\n" ) then
|
if response:match( "\r?\n\r?\n" ) then
|
||||||
h1, b1 = response:match( "^(.-)\r\n\r\n(.*)$" )
|
header, body = response:match( "^(.-)\r?\n\r?\n(.*)$" )
|
||||||
h2, b2 = response:match( "^(.-)\n\n(.*)$" )
|
|
||||||
if h1 and h2 and h1:len() <= h2:len() then
|
|
||||||
header, body = h1, b1
|
|
||||||
else
|
|
||||||
header, body = h2, b2
|
|
||||||
end
|
|
||||||
elseif response:match( "\r\n\r\n" ) then
|
|
||||||
header, body = response:match( "^(.-)\r\n\r\n(.*)$" )
|
|
||||||
elseif response:match( "\n\r\n" ) then
|
|
||||||
header, body = response:match( "^(.-)\n\r\n(.*)$" )
|
|
||||||
elseif response:match( "\n\n" ) then
|
|
||||||
header, body = response:match( "^(.-)\n\n(.*)$" )
|
|
||||||
else
|
else
|
||||||
body = response
|
header, body = "", response
|
||||||
end
|
end
|
||||||
|
|
||||||
local head_delim, body_delim
|
header = stdnse.strsplit( "\r?\n", header )
|
||||||
if type( header ) == "string" then
|
|
||||||
head_delim = ( header:match( "\r\n" ) and "\r\n" ) or
|
|
||||||
( header:match( "\n" ) and "\n" ) or nil
|
|
||||||
header = ( head_delim and stdnse.strsplit( head_delim, header ) ) or { header }
|
|
||||||
end
|
|
||||||
|
|
||||||
if type( body ) == "string" then
|
|
||||||
body_delim = ( body:match( "\r\n" ) and "\r\n" ) or
|
|
||||||
( body:match( "\n" ) and "\n" ) or nil
|
|
||||||
end
|
|
||||||
|
|
||||||
local line, _
|
local line, _
|
||||||
|
|
||||||
@@ -224,8 +202,11 @@ request = function( host, port, data, options )
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
body_delim = ( body:match( "\r\n" ) and "\r\n" ) or
|
||||||
|
( body:match( "\n" ) and "\n" ) or nil
|
||||||
|
|
||||||
-- handle chunked encoding
|
-- handle chunked encoding
|
||||||
if type( result.header ) == "table" and result.header['transfer-encoding'] == 'chunked' and type( body_delim ) == "string" then
|
if result.header['transfer-encoding'] == 'chunked' and type( body_delim ) == "string" then
|
||||||
body = body_delim .. body
|
body = body_delim .. body
|
||||||
local b = {}
|
local b = {}
|
||||||
local start, ptr = 1, 1
|
local start, ptr = 1, 1
|
||||||
|
|||||||
Reference in New Issue
Block a user