mirror of
https://github.com/nmap/nmap.git
synced 2026-11-28 10:30:14 +00:00
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.
This commit is contained in:
parent
e135983b21
commit
57b1444471
1 changed files with 14 additions and 3 deletions
|
|
@ -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("<authenticate><credentials>"
|
||||
.. "<username>" .. username .. "</username>"
|
||||
.. "<password>" .. password .. "</password>"
|
||||
.. "<username>" .. xml_escape(username) .. "</username>"
|
||||
.. "<password>" .. xml_escape(password) .. "</password>"
|
||||
.. "</credentials></authenticate>")
|
||||
|
||||
if not status then
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue