Nmap Development mailing list archives
[PATCH] --log-comment for, um, log comments
From: Kris Katterjohn <katterjohn () gmail com>
Date: Fri, 14 Aug 2009 11:28:55 -0500
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 Hey everybody, I've attached a really simple patch I've just drawn up to add comments to the log output. This is because a lot of times I try to keep up with old log files (at least xml). But I scan a large variety of stuff, so after weeks or months (or some I found from 2+ years ago) it can be hard to remember what some of the individual scans were for... and there's only so much information I want to squeeze into the filename! :) So to add a comment just specify "--log-comment whatever" and voila! For example, using --log-comment 'just testing' and -oA produces the following in the output files: grepable: # Nmap 5.05BETA1 scan initiated Fri Aug 14 10:37:52 2009 as: ./nmap ... # just testing normal: # Nmap 5.05BETA1 scan initiated Fri Aug 14 10:37:52 2009 as: ./nmap ... # just testing xml: <!-- Nmap 5.05BETA1 scan initiated Fri Aug 14 10:37:52 2009 as: ./nmap ... --> <!-- just testing --> It's just my preference to have the comment underneath the scan info comment like above. I guess it could go elsewhere (e.g., above it). One other idea I had was to add some new xml attribute to store a comment so it can be parsed out, but I don't really see the usefulness in this. Plus I want a comment for all formats; and I don't want to parse it, I just want to read it (and its easy to find this way since comments are sparse). So what do you think? Cheers, Kris Katterjohn -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.9 (GNU/Linux) Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org iQIcBAEBAgAGBQJKhZDHAAoJEEQxgFs5kUfubP8QAKsTnRzrr8MaeQNxERPblXyW lmWMxI/ijFzLupPQAHI23gewHqnMQjcqDlX13Nb07B6ASOgalmE0qdCFsljceX+C yrhyypCKrQtQCyWVM8RMVaKuYNoMujeHPaD0ezOFFhILdyjzLVFpo+89GDHI9mtY 9h8n/Mio+zflkdRscr7pTbI4MLZVntSrehrsk9sxoieCjW1PkPbHJOUpg+sx4VKg Tor8eCoQucb38M4IbsvitanP/yFtq01p22EPicRozOHV/VooQ2t1CHV8LSobfvkK Md4DUXEQO/+tFyTv2GbOmZW/hhUzrYKQ+QCLX+zTOjrI3vweaRTYKHG/BKtRxwYk FHTqf8CX06E9k5R2SUKkPkwDmFv7v0borubJBQC1DbtoumFnSpzTlpP9UNGjd+SL LnkDcW9xZCN01NdZ5Wwu2JFh/KqPXbUIw0MtHCO6mlLzacnv/DP9vYzwGyggHpVA rjqB7xQwLnd5KLLo7Tv5LP7kFbeRkrheDkabZXzZo4JOR/Hqp3WqeXHfCnpY7xeI Y/fQwfMxnt8/jQssoLtZDJEKzV5X+fgMTHbSPu4mc1r2u78GbYiHrwloqGHH4HsR R2VUEnDGd0hYISsC7Do1blR74bqsppAwlyC+b0jx6j1cPXgUbNFliRfsnD3csO/w jUMdD/Cv52uMHsQpA/2H =ja7X -----END PGP SIGNATURE-----
Index: nmap.cc
===================================================================
--- nmap.cc (revision 15012)
+++ nmap.cc (working copy)
@@ -295,6 +295,7 @@
" --iflist: Print host interfaces and routes (for debugging)\n"
" --log-errors: Log errors/warnings to the normal-format output file\n"
" --append-output: Append to rather than clobber specified output files\n"
+ " --log-comment: Add a comment to output files\n"
" --resume <filename>: Resume an aborted scan\n"
" --stylesheet <path/URL>: XSL stylesheet to transform XML output to HTML\n"
" --webxml: Reference stylesheet from Nmap.Org for more portable XML\n"
@@ -708,6 +709,8 @@
{"system-dns", no_argument, 0, 0},
{"log_errors", no_argument, 0, 0},
{"log-errors", no_argument, 0, 0},
+ {"log-comment", required_argument, 0, 0},
+ {"log_comment", required_argument, 0, 0},
{"dns_servers", required_argument, 0, 0},
{"dns-servers", required_argument, 0, 0},
{"port-ratio", required_argument, 0, 0},
@@ -918,6 +921,10 @@
o.dns_servers = strdup(optarg);
} else if (optcmp(long_options[option_index].name, "log-errors") == 0) {
o.log_errors = 1;
+ } else if (optcmp(long_options[option_index].name, "log-comment") == 0) {
+ if (o.logcomment)
+ fatal("Only one log comment allowed");
+ o.logcomment = strdup(optarg);
} else if (strcmp(long_options[option_index].name, "webxml") == 0) {
o.setXSLStyleSheet("http://nmap.org/data/nmap.xsl");
} else if (strcmp(long_options[option_index].name, "oN") == 0) {
@@ -1576,6 +1583,11 @@
log_write(LOG_XML, "-->");
log_write(LOG_NORMAL|LOG_MACHINE|LOG_XML,"\n");
+ if (o.logcomment) {
+ log_write(LOG_XML, "<!-- %s -->\n", o.logcomment);
+ log_write(LOG_NORMAL|LOG_MACHINE, "# %s\n", o.logcomment);
+ }
+
log_write(LOG_XML, "<nmaprun scanner=\"nmap\" args=\"");
for(i=0; i < argc; i++) {
char *p = xml_convert(fakeargv[i]);
@@ -2012,6 +2024,7 @@
if (o.dns_servers) free(o.dns_servers);
if (o.extra_payload) free(o.extra_payload);
if (o.ipoptions) free(o.ipoptions);
+ if (o.logcomment) free(o.logcomment);
#ifndef NOLUA
if (o.scriptversion || o.script)
close_nse();
Index: NmapOps.cc
===================================================================
--- NmapOps.cc (revision 15012)
+++ NmapOps.cc (working copy)
@@ -264,6 +264,7 @@
sctpcookieechoscan = 0;
append_output = 0;
memset(logfd, 0, sizeof(FILE *) * LOG_NUM_FILES);
+ logcomment = NULL;
ttl = -1;
badsum = 0;
nmap_stdout = stdout;
Index: docs/refguide.xml
===================================================================
--- docs/refguide.xml (revision 15012)
+++ docs/refguide.xml (working copy)
@@ -3813,6 +3813,18 @@
<varlistentry>
<term>
+ <option>--log-comment</option> (Add comment to output files)
+ <indexterm><primary><option>--log-comment</option></primary></indexterm>
+ </term>
+ <listitem>
+ <para>Adds a user comment to the output file(s). The comment
+ text is a single line which is placed directly in the output
+ in whatever format the output type supports for comments.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
<option>--resume <replaceable>filename</replaceable></option> (Resume aborted scan)
<indexterm><primary><option>--resume</option></primary></indexterm>
<indexterm><primary>resuming scans</primary></indexterm>
Index: NmapOps.h
===================================================================
--- NmapOps.h (revision 15012)
+++ NmapOps.h (working copy)
@@ -302,6 +302,7 @@
int append_output; /* Append to any output files rather than overwrite */
FILE *logfd[LOG_NUM_FILES];
FILE *nmap_stdout; /* Nmap standard output */
+ char *logcomment; /* User comment to add to log files */
int ttl; // Time to live
int badsum;
char *datadir;
_______________________________________________ Sent through the nmap-dev mailing list http://cgi.insecure.org/mailman/listinfo/nmap-dev Archived at http://SecLists.Org
Current thread:
- [PATCH] --log-comment for, um, log comments Kris Katterjohn (Aug 14)
- Re: [PATCH] --log-comment for, um, log comments Fyodor (Aug 15)
- Re: [PATCH] --log-comment for, um, log comments Kris Katterjohn (Aug 15)
- Re: [PATCH] --log-comment for, um, log comments Fyodor (Aug 15)
- Re: [PATCH] --log-comment for, um, log comments David Fifield (Aug 28)
- Re: [PATCH] --log-comment for, um, log comments Kris Katterjohn (Aug 15)
- Re: [PATCH] --log-comment for, um, log comments Fyodor (Aug 15)
