From 811d6096e1e7f2380c7ab3a4ae098a8f997c81b7 Mon Sep 17 00:00:00 2001 From: david Date: Sat, 23 Feb 2013 06:54:29 +0000 Subject: [PATCH] Quit on EOF in non-TCP mode. Apparently SCTP can't have the same kind of half-open sockets that TCP has. When one direction is closed, we can't do anything further with the socket. http://seclists.org/nmap-dev/2013/q1/227 --- ncat/ncat_connect.c | 8 ++++---- ncat/ncat_listen.c | 2 +- 2 files changed, 5 insertions(+), 5 deletions(-) diff --git a/ncat/ncat_connect.c b/ncat/ncat_connect.c index 1277ba278..052b6f191 100644 --- a/ncat/ncat_connect.c +++ b/ncat/ncat_connect.c @@ -786,8 +786,8 @@ static void read_stdin_handler(nsock_pool nsp, nsock_event evt, void *data) if (status == NSE_STATUS_EOF) { shutdown(nsi_getsd(cs.sock_nsi), SHUT_WR); - /* In --send-only mode, exit after EOF on stdin. */ - if (o.sendonly) + /* In --send-only mode or non-TCP mode, exit after EOF on stdin. */ + if (o.proto != IPPROTO_TCP || (o.proto == IPPROTO_TCP && o.sendonly)) nsock_loop_quit(nsp); return; } else if (status == NSE_STATUS_ERROR) { @@ -833,8 +833,8 @@ static void read_socket_handler(nsock_pool nsp, nsock_event evt, void *data) if (status == NSE_STATUS_EOF) { Close(STDOUT_FILENO); - /* In --recv-only mode, exit after EOF on the socket. */ - if (o.recvonly) + /* In --recv-only mode or non-TCP mode, exit after EOF on the socket. */ + if (o.proto != IPPROTO_TCP || (o.proto == IPPROTO_TCP && o.recvonly)) nsock_loop_quit(nsp); return; } else if (status == NSE_STATUS_ERROR) { diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 1631e44ac..ce26587a7 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -331,7 +331,7 @@ static int ncat_listen_stream(int proto) /* Read from stdin and write to all clients. */ rc = read_stdin(); if (rc == 0) { - if (o.sendonly) { + if (o.proto != IPPROTO_TCP || (o.proto == IPPROTO_TCP && o.sendonly)) { /* There will be nothing more to send. If we're not receiving anything, we can quit here. */ return 0;