From 57b144447165595cf1d2d55af03ce16aed3aa5ea Mon Sep 17 00:00:00 2001 From: Mrx Date: Mon, 21 Sep 2026 02:22:07 +0530 Subject: [PATCH] Escape XML special characters in OMP2 authenticate() credentials nselib/omp2.lua built the authentication XML by concatenating the raw username and password, so credentials containing &, <, >, " or ' could produce malformed XML or failed logins. Add a local xml_escape() helper and apply it to both credentials (resolving the TODO). Fixes #3311. --- nselib/omp2.lua | 17 ++++++++++++++--- 1 file changed, 14 insertions(+), 3 deletions(-) diff --git a/nselib/omp2.lua b/nselib/omp2.lua index 83c38cdd2..d96d51a86 100644 --- a/nselib/omp2.lua +++ b/nselib/omp2.lua @@ -39,6 +39,18 @@ if pcall(require,'openssl') then HAVE_SSL = true end +--- Escapes XML special characters in a string so it can be safely +-- embedded in XML element content. +-- @param s the string to escape +-- @return the escaped string +local function xml_escape(s) + return (s:gsub("&", "&") + :gsub("<", "<") + :gsub(">", ">") + :gsub('"', """) + :gsub("'", "'")) +end + --- A Session class holds connection and interaction with the server Session = { @@ -74,10 +86,9 @@ Session = { authenticate = function(self, username, password) local status, err, xmldata - -- TODO escape credentials status, err = self.socket:send("" - .. "" .. username .. "" - .. "" .. password .. "" + .. "" .. xml_escape(username) .. "" + .. "" .. xml_escape(password) .. "" .. "") if not status then