Nmap Development mailing list archives
Re: Lua issues
From: Brendan Coles <bcoles () gmail com>
Date: Mon, 6 Feb 2012 22:40:51 +1100
Hi Peak, I'm not sure about the differences between the latest lua and the lua used in nmap NSE, if any. However, if you want to access the HTTP headers you can use the table req["rawheader"] rather than req["header"] Here's an example which loops through all HTTP headers and returns all matches for "server" : local result = {} local path = "/" -- Retrieve headers stdnse.print_debug(1, ("%s: Connecting to %s:%s"):format(SCRIPT_NAME, host.targetname or host.ip, port.number)) data = http.get(host, port, path) if not data then stdnse.print_debug(1, "%s: Failed to retrieve HTTP headers.", SCRIPT_NAME) return end -- Extract server headers stdnse.print_debug(2, "%s: HTTP %s: %s", SCRIPT_NAME, data.status, path) for line, header in ipairs(data["rawheader"]) do local server_match = string.match(header, '[Ss]erver: (.+)') if server_match then table.insert(result, string.format("%s", server_match)) end end -- Return results stdnse.print_debug(1, ("%s: %s:%s returned %s server headers."):format(SCRIPT_NAME, host.targetname or host.ip, port.number, #result)) return stdnse.format_output(true, result) Here's the full script the example was taken from: https://gist.github.com/1736948 Hope this helps. On Mon, Feb 6, 2012 at 10:14 PM, CheesStick peak <crnxyrnx () gmail com> wrote:
Hello Im currently working with the nmap script engine and with lua. Im more into perl but i wanted to give lua a try so I started scripting a bit. Now it looks for me that the nse is not working like normal lua. I have an example according my work with tables: local table= { 123, 231 , "aaa" , xxx = { "x1", "x2"} , 666 , test="showme" , 777 } now when I do: for i,v in ipairs(table) do print(i,v) end it gives me: 1 123 2 231 3 aaa 4 666 5 777 (the same does table.concat(table,"\n") btw.) BUT, according to different lua sites it should be: 1 123 2 231 3 aaa 4 table: 0035xxxx 5 666 test showme 7 777 ... ? So i hope you can help me, because all I want is to know what http header http.get gives me back: local req = http.get ( "example.com" , 80, "/index.php") print req.status -- 200 print (req['header']) --table: 0x97874a0 print (table.getn(req['header'])) --- erm... what??wtf? sincerely peak _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://seclists.org/nmap-dev/
-- Brendan Coles http://itsecuritysolutions.org/ _______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://seclists.org/nmap-dev/
Current thread:
- Lua issues CheesStick peak (Feb 06)
- Re: Lua issues Brendan Coles (Feb 06)
- Re: Lua issues Patrik Karlsson (Feb 06)