Home page logo

nmap-dev logo Nmap Development mailing list archives

Re: [nmap-svn] r31481 - nmap-exp/d33tah/lua-exec-examples/ncat
From: David Fifield <david () bamsoftware com>
Date: Tue, 23 Jul 2013 03:27:19 -0700

On Mon, Jul 22, 2013 at 09:10:45PM +0200, Jacek Wielemborek wrote:
2013/7/22  <commit-mailer () nmap org>:
Author: d33tah
Date: Mon Jul 22 16:47:03 2013
New Revision: 31481

set binary mode for stdout for --lua-exec-internal under Windows. that
prevents Windows from messing with line breaks for httpd.lua.


Modified: nmap-exp/d33tah/lua-exec-examples/ncat/ncat_main.c
--- nmap-exp/d33tah/lua-exec-examples/ncat/ncat_main.c  (original)
+++ nmap-exp/d33tah/lua-exec-examples/ncat/ncat_main.c  Mon Jul 22 16:47:03 2013
@@ -500,6 +500,13 @@
                    forking in POSIX builds, Windows does not have the fork() system
                    call and thus requires this workaround. More info here:
                    http://seclists.org/nmap-dev/2013/q2/492 */
+#ifdef WIN32
+                if (o.debug)
+                    logdebug("Enabling binary stdout for the Lua output.\n");
+                int result = _setmode(_fileno(stdout), _O_BINARY);
+                if (result == -1)
+                    perror("Cannot set mode");
                 ncat_assert(argc == 3);
                 o.cmdexec = argv[2];

This needs some discussion.

I'm not sure it's okay to just change the stdout mode for Lua scripts
- it could create a discrepancy between "traditional" Lua behavior on
Windows and one altered by binary mode.

I just did some testing that proves that without the binary mode,
print("a") produces CR LF. With binary mode on, it's just \n.

That change seems right. We already do this _setmode trick for stdout on
Windows through the function set_lf_mode. Please make this change in the

David Fifield
Sent through the dev mailing list
Archived at http://seclists.org/nmap-dev/

  By Date           By Thread  

Current thread:
[ Nmap | Sec Tools | Mailing Lists | Site News | About/Contact | Advertising | Privacy ]