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;"):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("..", "%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"),