From d4dd71261d7e8ba861bd9668c2779f2328ce367e Mon Sep 17 00:00:00 2001 From: david Date: Thu, 31 Mar 2011 20:32:55 +0000 Subject: [PATCH] Documentation, whitespace, style in http-affiliate-id. --- scripts/http-affiliate-id.nse | 46 +++++++++++++++++------------------ 1 file changed, 23 insertions(+), 23 deletions(-) diff --git a/scripts/http-affiliate-id.nse b/scripts/http-affiliate-id.nse index 0ff89976f..76e1e4392 100644 --- a/scripts/http-affiliate-id.nse +++ b/scripts/http-affiliate-id.nse @@ -1,9 +1,11 @@ description = [[ +Grabs affiliate network IDs from an HTML page. These can be used to +identify pages with the same owner. -This script grabs Google Analytics and Adsense IDs. -They could be used to further look for related websites (that have -the same owner.) - +Supported IDs: +* Google Analytics +* Google AdSense +* Amazon Associates ]] --- @@ -16,9 +18,10 @@ the same owner.) -- @output -- PORT STATE SERVICE -- 80/tcp open http --- | http-affiliate-id: --- | Google Analytics ID: UA-XXXXXXXX-XX --- |_ Google Adsense ID: pub-YYYYYYYYYYYYYYYY +-- | http-affiliate-id: +-- | Amazon Associates ID: XXXX-XX +-- | Google Adsense ID: pub-YYYY +-- |_ Google Analytics ID: UA-ZZZZ-ZZ author = "Hani Benhabiles, Daniel Miller" @@ -31,34 +34,31 @@ require 'http' require 'pcre' require 'stdnse' -portrule = shortport.port_or_service( {80,443}, {"http","https"} ) - -action = function(host, port) - local url_path, body, analyticsid, adsenseid, result - result = "" - url_path = stdnse.get_script_args("http-affiliate-id.url-path") or "/" - body = http.get( host, port, url_path).body - - -- these are the regular expressions for affiliate IDs - local affiliates = { +-- these are the regular expressions for affiliate IDs +local AFFILIATE_PATTERNS = { ["Google Analytics ID"] = "(?PUA-[0-9]{6,9}-[0-9]{1,2})", ["Google Adsense ID"] = "(?Ppub-[0-9]{16,16})", ["Amazon Associates ID"] = "href=\"http://www.amazon.com/[^\"]*[&;]tag=(?P\\w+-\\d+)", - } +} +portrule = shortport.http + +action = function(host, port) + local url_path, body, result + result = {} + url_path = stdnse.get_script_args("http-affiliate-id.url-path") or "/" + body = http.get(host, port, url_path).body -- Here goes affiliate matching - for name,re in pairs(affiliates) do + for name, re in pairs(AFFILIATE_PATTERNS) do local regex, limit, limit2, matches, affiliateid regex = pcre.new(re, 0, "C") limit, limit2, matches = regex:match(body) if limit ~= nil then affiliateid = matches["id"] - result = result .. "\n " .. name .. ": " .. affiliateid + result[#result + 1] = name .. ": " .. affiliateid end end - if result ~= "" then - return result - end + return stdnse.format_output(true, result) end