Skip to content

ncat server leaves the socket open in child processes #2843

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
m42a opened this issue May 16, 2024 · 2 comments
Closed

ncat server leaves the socket open in child processes #2843

m42a opened this issue May 16, 2024 · 2 comments
Labels

Comments

@m42a
Copy link

m42a commented May 16, 2024

Describe the bug
In server mode, when running a command with -e or -c, ncat does not close the socket before executing the child process. Since the parent process exits when the client stops sending data, this can incorrectly cause the client to think more data is incoming.

To Reproduce

ncat -l 1234 -c 'sleep 1; echo response'
echo request | ncat 127.0.0.1 1234

When both commands are run in parallel, the server ncat will exit as soon as the client connects, but the client will wait for a second before the socket is closed (with no response data) by sh exiting.

Expected behavior
When a client has stopped sending data, ncat should either:

  1. Exit the server and fully close the connection without waiting for the child to finish.
  2. Wait for the child to finish sending output before exiting.

Option 2 is what I would prefer, but is a bigger change than option 1. In both cases though, there is no reason for the child process to keep the socket open.

Version info (please complete the following information):

  • OS: Linux 6.8.2
  • Output of ncat --version: Ncat: Version 7.94 ( https://nmap.org/ncat )
@m42a m42a added the Ncat label May 16, 2024
@dmiller-nmap
Copy link

I agree this seems like a bug. Traditional (Hobbit's) netcat doesn't behave this way. As a workaround for now, you can tell the client not to shutdown the connection when EOF is seen on STDIN by using the --no-shutdown option. This will prevent the client from closing the socket and triggering the parent process of the server to close. Incidentally, this is the behavior of traditional netcat, though OpenBSD netcat requires the -q-1 option to do the same.

@dmiller-nmap
Copy link

This is now fixed in development, and the fix will be in the next release.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants