From 8b29c19a764fc129dd75e727f60fe6224e224853 Mon Sep 17 00:00:00 2001 From: fyodor Date: Fri, 29 Aug 2008 09:24:24 +0000 Subject: [PATCH] o The NSE http library now supports chunked encoding. [Sven Klemm] --- CHANGELOG | 6 ++++++ nselib/http.lua | 31 ++++++++++++++++++++++++------- 2 files changed, 30 insertions(+), 7 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index b87e18bfd..648fd35de 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,11 @@ # Nmap Changelog ($Id$); -*-text-*- +o The NSE http library now supports chunked encoding. [Sven Klemm] + +o Fix a number of NSE scripts which used print_debug() + incorrectly. See + http://seclists.org/nmap-dev/2008/q3/0470.html. [Sven Klemm]. + o Improve the nebtios-smb-os-discovery NSE script to improve target port selection and to also decode the system's timestamp from an SMB response. [Ron at SkullSecurity] diff --git a/nselib/http.lua b/nselib/http.lua index 9aae4f30f..bf7d56ed4 100644 --- a/nselib/http.lua +++ b/nselib/http.lua @@ -143,7 +143,7 @@ request = function( host, port, data, options ) return result end - local buffer = stdnse.make_buffer( socket, "\r?\n" ) + local buffer = stdnse.make_buffer( socket, "\r\n" ) local line, _ local header, body = {}, {} @@ -184,15 +184,32 @@ request = function( host, port, data, options ) end end - -- body loop - while true do - line = buffer() - if not line then break end - table.insert(body,line) + -- handle body + if result.header['transfer-encoding'] == 'chunked' then + -- if the server used chunked encoding we have to 'dechunk' the answer + local counter, chunk_size + counter = 0; chunk_size = 0 + while true do + if counter >= chunk_size then + counter = 0 + chunk_size = tonumber( buffer(), 16 ) + if chunk_size == 0 or not chunk_size then break end + end + line = buffer() + if not line then break end + counter = counter + #line + 2 + table.insert(body,line) + end + else + while true do + line = buffer() + if not line then break end + table.insert(body,line) + end end socket:close() - result.body = table.concat( body, "\n" ) + result.body = table.concat( body, "\r\n" ) return result