1
0
mirror of https://github.com/nmap/nmap.git synced 2025-12-31 11:59:03 +00:00

o The command line in XML output (/nmaprun/@args attribute) now does

quoting of whitespace using double quotes and backslashes. This
  allows recovering the original command line array even when
  arguments contain whitespace. [David]
This commit is contained in:
david
2010-11-14 02:09:58 +00:00
parent 3c2b82100e
commit cec33e3aad
4 changed files with 46 additions and 2 deletions

View File

@@ -1,5 +1,10 @@
# Nmap Changelog ($Id$); -*-text-*-
o The command line in XML output (/nmaprun/@args attribute) now does
quoting of whitespace using double quotes and backslashes. This
allows recovering the original command line array even when
arguments contain whitespace. [David]
o XML output now excludes output for down hosts when doing host
discovery only, except in verbose mode. This is how it already
worked for normal scans, but the ping-only case was overlooked.

View File

@@ -1488,7 +1488,7 @@ int nmap_main(int argc, char *argv[]) {
}
xml_start_comment();
xml_write_escaped(" %s %s scan initiated %s as: %s ", NMAP_NAME, NMAP_VERSION, mytime, command.c_str());
xml_write_escaped(" %s %s scan initiated %s as: %s ", NMAP_NAME, NMAP_VERSION, mytime, join_quoted(fakeargv, argc).c_str());
xml_end_comment();
xml_newline();
@@ -1499,7 +1499,7 @@ int nmap_main(int argc, char *argv[]) {
xml_open_start_tag("nmaprun");
xml_attribute("scanner", "nmap");
xml_attribute("args", "%s", command.c_str());
xml_attribute("args", "%s", join_quoted(fakeargv, argc).c_str());
xml_attribute("start", "%lu", (unsigned long) timep);
xml_attribute("startstr", "%s", mytime);
xml_attribute("version", "%s", NMAP_VERSION);

View File

@@ -1190,6 +1190,41 @@ static void doscaninfo(const char *type, const char *proto,
xml_newline();
}
static std::string quote(const char *s) {
std::string result("");
const char *p;
bool space;
space = false;
for (p = s; *p != '\0'; p++) {
if (isspace(*p))
space = true;
if (*p == '"' || *p == '\\')
result += "\\";
result += *p;
}
if (space)
result = "\"" + result + "\"";
return result;
}
/* Return a std::string containing all n strings separated by whitespace, and
individually quoted if needed. */
std::string join_quoted(const char * const strings[], unsigned int n) {
std::string result("");
unsigned int i;
for (i = 0; i < n; i++) {
if (i > 0)
result += " ";
result += quote(strings[i]);
}
return result;
}
/* Similar to output_ports_to_machine_parseable_output, this function
outputs the XML version, which is scaninfo records of each scan
requested and the ports which it will scan for */

View File

@@ -190,6 +190,10 @@ void output_ports_to_machine_parseable_output(struct scan_lists *ports,
int tcpscan, int udpscan,
int sctpscan, int protscan);
/* Return a std::string containing all n strings separated by whitespace, and
individually quoted if needed. */
std::string join_quoted(const char * const strings[], unsigned int n);
/* Similar to output_ports_to_machine_parseable_output, this function
outputs the XML version, which is scaninfo records of each scan
requested and the ports which it will scan for */