Skip to content

Instantly share code, notes, and snippets.

@bcoles
Created February 4, 2012 10:21
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save bcoles/1736948 to your computer and use it in GitHub Desktop.
Save bcoles/1736948 to your computer and use it in GitHub Desktop.
http-server.nse - Retrieves all HTTP "server" headers.
description = [[
Retrieves all HTTP "server" headers.
]]
---
-- @usage
-- nmap --script http-server -p <port> <host>
--
-- @output
-- PORT STATE SERVICE REASON
-- 80/tcp open http syn-ack
-- | http-server:
-- |_ Apache/2.2.14 (Ubuntu)
--
-- @changelog
-- 2012-02-02 - created by Brendan Coles - itsecuritysolutions.org
--
author = "Brendan Coles [itsecuritysolutions.org]"
license = "Same as Nmap--See http://nmap.org/book/man-legal.html"
categories = {"default", "safe"}
require("url")
require("http")
require("stdnse")
require("shortport")
portrule = shortport.service ({"http","https"})
action = function(host, port)
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)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment