local nmap = require "nmap" local shortport = require "shortport" local http = require "http" local stdnse = require "stdnse" local string = require "string" local table = require "table" description = [[ Attempts to retrieve the server-status page for Apache webservers that have mod_status enabled. If the server-status page exists and appears to be from mod_status the script will parse useful information such as the system uptime, Apache version and recent HTTP requests. References: * http://httpd.apache.org/docs/2.4/mod/mod_status.html * https://blog.sucuri.net/2012/10/popular-sites-with-apache-server-status-enabled.html * https://www.exploit-db.com/ghdb/1355/ * https://github.com/michenriksen/nmap-scripts ]] --- --@usage nmap -p80 --script http-apache-server-status --@usage nmap -sV --script http-apache-server-status -- --@output -- PORT STATE SERVICE -- 80/tcp open http -- | http-apache-server-status: -- | Heading: Apache Server Status for example.com (via 127.0.1.1) -- | Server Version: Apache/2.4.12 (Ubuntu) -- | Server Built: Jul 24 2015 15:59:00 -- | Server Uptime: 53 minutes 31 seconds -- | Server Load: 0.00 0.01 0.05 -- | VHosts: -- |_ www.example.com:80 GET /server-status HTTP/1.1 -- -- @xmloutput -- Apache Server Status for example.com (via 127.0.1.1) -- Apache/2.4.12 (Ubuntu) -- Jul 24 2015 15:59:00 -- 59 minutes 26 seconds -- 0.01 0.02 0.05 -- -- www.example.com:80 --
author = "Eric Gershman" license = "Same as Nmap--See https://nmap.org/book/man-legal.html" categories = {"discovery", "safe"} portrule = function(host, port) if not shortport.http(host, port) then return false end if port.version and port.version.product then return string.match(port.version.product, "Apache") end return true end action = function(host, port) -- Perform a GET request for /server-status local path = "/server-status" local response = http.get(host,port,path) local result = {} -- Fail if there is no data in the response, the response body or if the HTTP status code is not successful if not response or not response.status or response.status ~= 200 or not response.body then stdnse.debug(1, "Failed to retrieve: %s", path) return end -- Fail if this doesn't appear to be an Apache mod_status page if not string.match(response.body, "Apache%sServer%sStatus") then stdnse.debug(1, "%s does not appear to be a mod_status page", path) return end result = stdnse.output_table() -- Remove line breaks from response.body to handle html tags that span multiple lines response.body = string.gsub(response.body, "\n", "") -- Add useful data to the result table result["Heading"] = string.match(response.body, "

([^<]*)

") result["Server Version"] = string.match(response.body, "Server%sVersion:%s*([^<]*).-") do -- skip line if the request is empty if not string.match(line, "") then local vhost = string.match(line, ">([^<]*)