Created
February 4, 2012 10:21
-
-
Save bcoles/1736948 to your computer and use it in GitHub Desktop.
http-server.nse - Retrieves all HTTP "server" headers.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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