Nmap Development mailing list archives

[PATCH] Ncat: match traditional and OpenBSD netcat behaviour of terminating on EOF


From: Tobias Girstmair <t-nmap () girst at>
Date: Sun, 7 Feb 2021 16:47:01 +0100

Hi people and apologies for the unwieldy title!

Right now, Ncat keeps running when the remote end closes the connection. Only when the client pushes more bytes into Ncat, it fails with "Broken pipe." For example, this makes it impossible to wrap Ncat in a while-loop to keep reconnecting.

Here is a simple PoC of the problem:
 - run `ncat -l 1234` in one terminal and `nc ::1 1234` in another.
 - ^C the listen-mode ncat.
 - hit return (possibly twice) in the connect-mode ncat.
With the current version, this prints "Ncat: Broken pipe."; with the patch applied, it works and the connect-mode ncat exits.

This has been requested multiple times [1] [2] [3] [4], and was accepted in 2017 by dmiller [5] and fyodor [6], who for lack of feedback back then didn't go ahead with it.

To get Ncat's previous behaviour, I opted for a new command line switch, --no-terminate, instead of overloading --keep-open (as Daniel suggested), as I felt it is unintuitive to have an option that does two different things depending on the context (-l vs no -l). I was contemplating overloading --no-shutdown, but didn't, as it is already a backwards-compatibility-option for openbsd-nc, so changing it didn't feel right.

For your convenience, I have attached the patch to this email, and opened https://github.com/nmap/nmap/pull/2246 for it as well.

[1]: https://seclists.org/nmap-dev/2017/q2/67
[2]: https://github.com/nmap/nmap/issues/894
[3]: https://github.com/nmap/nmap/issues/1413
[4]: https://github.com/nmap/nmap/issues/1779
[5]: https://seclists.org/nmap-dev/2017/q2/94
[6]: https://seclists.org/nmap-dev/2017/q2/134

Attachment: no-terminate.patch
Description:

_______________________________________________
Sent through the dev mailing list
https://nmap.org/mailman/listinfo/dev
Archived at http://seclists.org/nmap-dev/

Current thread: