From 866dc375e42e8edb4257d50388eb7da33aab430a Mon Sep 17 00:00:00 2001 From: dmiller Date: Mon, 30 Dec 2019 00:53:23 +0000 Subject: [PATCH] Correctly print VM socket address. Closes #1868 --- CHANGELOG | 3 +++ ncat/ncat_connect.c | 10 ++++++++++ ncat/ncat_listen.c | 16 ++++++++++++++++ 3 files changed, 29 insertions(+) diff --git a/CHANGELOG b/CHANGELOG index 5d35fed93..1ec607262 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,5 +1,8 @@ #Nmap Changelog ($Id$); -*-text-*- +o [Ncat][GH#1868] Fix a fatal error when connecting to a Linux VM socket with + verbose output enabled. [Stefano Garzarella] + o [NSE][GH#1723] Fixed a crash on Windows when processing a GZIP-encoded HTTP body. [Daniel Miller] diff --git a/ncat/ncat_connect.c b/ncat/ncat_connect.c index 0a8476a20..21b12a59d 100644 --- a/ncat/ncat_connect.c +++ b/ncat/ncat_connect.c @@ -326,6 +326,11 @@ static void connect_report(nsock_iod nsi) if (peer.sockaddr.sa_family == AF_UNIX) loguser("Connected to %s.\n", peer.un.sun_path); else +#endif +#ifdef HAVE_LINUX_VM_SOCKETS_H + if (peer.sockaddr.sa_family == AF_VSOCK) + loguser("Connection to %u.\n", peer.vm.svm_cid); + else #endif loguser("Connected to %s:%d.\n", inet_socktop(&peer), nsock_iod_get_peerport(nsi)); @@ -335,6 +340,11 @@ static void connect_report(nsock_iod nsi) if (peer.sockaddr.sa_family == AF_UNIX) loguser("Connected to %s.\n", peer.un.sun_path); else +#endif +#ifdef HAVE_LINUX_VM_SOCKETS_H + if (peer.sockaddr.sa_family == AF_VSOCK) + loguser("Connection to %u.\n", peer.vm.svm_cid); + else #endif loguser("Connected to %s:%d.\n", inet_socktop(&peer), nsock_iod_get_peerport(nsi)); diff --git a/ncat/ncat_listen.c b/ncat/ncat_listen.c index 46ba6ff06..3c4c07503 100644 --- a/ncat/ncat_listen.c +++ b/ncat/ncat_listen.c @@ -479,6 +479,11 @@ static void handle_connection(int socket_accept) if (remoteaddr.sockaddr.sa_family == AF_UNIX) loguser("Connection from a client on Unix domain socket.\n"); else +#endif +#ifdef HAVE_LINUX_VM_SOCKETS_H + if (remoteaddr.sockaddr.sa_family == AF_VSOCK) + loguser("Connection from a client on vsock socket.\n"); + else #endif if (o.chat) loguser("Connection from %s on file descriptor %d.\n", inet_socktop(&remoteaddr), s.fd); @@ -500,6 +505,12 @@ static void handle_connection(int socket_accept) if (remoteaddr.sockaddr.sa_family == AF_UNIX) loguser("Connection from %s.\n", remoteaddr.un.sun_path); else +#endif +#ifdef HAVE_LINUX_VM_SOCKETS_H + if (remoteaddr.sockaddr.sa_family == AF_VSOCK) + loguser("Connection from %u:%u.\n", + remoteaddr.vm.svm_cid, remoteaddr.vm.svm_port); + else #endif loguser("Connection from %s:%hu.\n", inet_socktop(&remoteaddr), inet_port(&remoteaddr)); } @@ -883,6 +894,11 @@ static int ncat_listen_dgram(int proto) if (remotess.sockaddr.sa_family == AF_UNIX) loguser("Connection from %s.\n", remotess.un.sun_path); else +#endif +#ifdef HAVE_LINUX_VM_SOCKETS_H + if (remotess.sockaddr.sa_family == AF_VSOCK) + loguser("Connection from %u.\n", remotess.vm.svm_cid); + else #endif loguser("Connection from %s.\n", inet_socktop(&remotess)); }