From afc310c0c9651fd2eb7ab3f59773ebd8b854006d Mon Sep 17 00:00:00 2001 From: nnposter Date: Thu, 30 Mar 2017 00:06:03 +0000 Subject: [PATCH] Cleans up XML request build-up by externalizing XML encoding and allowing for white-space indentation --- .../http-default-accounts-fingerprints.lua | 44 ++++++++++++------- 1 file changed, 28 insertions(+), 16 deletions(-) diff --git a/nselib/data/http-default-accounts-fingerprints.lua b/nselib/data/http-default-accounts-fingerprints.lua index 7cc5919b8..90ac96aec 100644 --- a/nselib/data/http-default-accounts-fingerprints.lua +++ b/nselib/data/http-default-accounts-fingerprints.lua @@ -164,6 +164,16 @@ local function url_build_defaults (host, port, parsed) return parts end +--- +-- Encodes a string to make it safe for embedding into XML/HTML. +-- +-- @param s The string to be encoded. +-- @return A string with unsafe characters encoded +--- +local function xmlencode (s) + return s:gsub("%W", function (c) return ("&#x%x;"):format(c:byte()) end) +end + fingerprints = {} --- @@ -1333,24 +1343,26 @@ table.insert(fingerprints, { .. "_" .. stdnse.clock_ms() .. math.random(100000, 999999) - local encpass = stdnse.tohex(pass):gsub("..", "&#x%0;") + local encpass = xmlencode(pass) local header = {["Content-Type"]="text/xml", ["SOAPAction"]='""'} local soapmsg = [[ - - - - -__SESS__ - -0 -__PASS__ -30 - - - - - -]] + + + + + __SESS__ + + 0 + __PASS__ + 30 + + + + + + ]] + -- strip off indentation + soapmsg = soapmsg:gsub("%f[^\0\n]%s+", "") -- username is not injected into the payload because it is implied soapmsg = soapmsg:gsub("__%w+__", {__SESS__=sessionid, __PASS__=encpass}) local req = http_post_simple(host, port, url.absolute(path, "soap"),