Ncat 1 Ncat Ncat Reference Guide ncat Concatenate and redirect sockets ncat OPTIONS hostname port Description Ncat is a feature-packed networking utility which reads and writes data across networks from the command line. Ncat was written for the Nmap Project and is the culmination of the currently splintered family of Netcat incarnations. It is designed to be a reliable back-end tool to instantly provide network connectivity to other applications and users. Ncat will not only work with IPv4 and IPv6 but provides the user with a virtually limitless number of potential uses. Among Ncat's vast number of features there is the ability to chain Ncats together; redirection of TCP, UDP, and SCTP ports to other sites; SSL support; and proxy connections via SOCKS4, SOCKS5 or HTTP proxies (with optional proxy authentication as well). Some general principles apply to most applications and thus give you the capability of instantly adding networking support to software that would normally never support it. Options Summary connect mode (Ncat) client mode (Ncat)connect mode listen mode (Ncat) server mode (Ncat)listen mode Connect Mode and Listen Mode Ncat operates in one of two primary modes: connect mode and listen mode. Other modes, such as the HTTP proxy server, act as special cases of these two. In connect mode, Ncat works as a client. In listen mode it is a server. In connect mode, the and arguments tell what to connect to. is required, and may be a hostname or IP address. If is supplied, it must be a decimal port number. If omitted, it defaults to 31337.default port of Ncat31337default port of Ncat In listen mode, and control the address the server will bind to. Both arguments are optional in listen mode. If is omitted, it defaults to listening on all available addresses over IPv4 and IPv6. If is omitted, it defaults to 31337. Protocol Options (IPv4 only) (Ncat option) Force the use of IPv4 only. (IPv6 only) (Ncat option) Force the use of IPv6 only. , (Use Unix domain sockets) (Ncat option) (Ncat option) Use Unix domain sockets rather than network sockets. This option may be used on its own for stream sockets, or combined with for datagram sockets. A description of mode is in . , (Use UDP) (Ncat option) (Ncat option) Use UDP for the connection (the default is TCP). (Use SCTP) (Ncat option) Use SCTP for the connection (the default is TCP). SCTP support is implemented in TCP-compatible mode. (Use AF_VSOCK sockets) (Ncat option) Use AF_VSOCK sockets rather than the default TCP sockets (Linux only). This option may be used on its own for stream sockets or combined with for datagram sockets. A description of mode is in . Connect Mode Options (Loose source routing) (Ncat option) Sets hops for IPv4 loose source routing. You can use once with a comma-separated list of hops, use multiple times with single hops to build the list, or combine the two. Hops can be given as IP addresses or hostnames. (Set source routing pointer) (Ncat option) Sets the IPv4 source route pointer for use with . The argument must be a multiple of 4 and no more than 28. Not all operating systems support setting this pointer to anything other than four. , (Specify source port) (Ncat option) (Ncat option) Set the port number for Ncat to bind to. , (Specify source address) (Ncat option) (Ncat option) Set the address for Ncat to bind to. Listen Mode Options See for information on limiting the hosts that may connect to the listening Ncat process. , (Listen for connections) (Ncat option) (Ncat option) Listen for connections rather than connecting to a remote machine , (Specify maximum number of connections) (Ncat option) (Ncat option) The maximum number of simultaneous connections accepted by an Ncat instance. 100 is the default (60 on Windows). , (Accept multiple connections) (Ncat option) (Ncat option) Normally a listening server accepts only one connection and then quits when the connection is closed. This option makes it accept multiple simultaneous connections and wait for more connections after they have all been closed. It must be combined with . In this mode there is no way for Ncat to know when its network input is finished, so it will keep running until interrupted. This also means that it will never close its output stream, so any program reading from Ncat and looking for end-of-file will also hang. (Connection brokering) (Ncat option) Allow multiple parties to connect to a centralised Ncat server and communicate with each other. Ncat can broker communication between systems that are behind a NAT or otherwise unable to directly connect. This option is used in conjunction with , which causes the port to have broker mode enabled. (Ad-hoc chat server) (Ncat option) The option enables chat mode, intended for the exchange of text between several users. In chat mode, connection brokering is turned on. Ncat prefixes each message received with an ID before relaying it to the other connections. The ID is unique for each connected client. This helps distinguish who sent what. Additionally, non-printing characters such as control characters are escaped to keep them from doing damage to a terminal. SSL Options (Use SSL) (Ncat option) In connect mode, this option transparently negotiates an SSL session with an SSL server to securely encrypt the connection. This is particularly handy for talking to SSL enabled HTTP servers, etc. In server mode, this option listens for incoming SSL connections, rather than plain untunneled traffic. In UDP mode, this option enables Datagram TLS (DTLS). (Verify server certificates) (Ncat option) In client mode, is like except that it also requires verification of the server certificate. Ncat comes with a default set of trusted certificates in the file ca-bundle.crt.ca-bundle.crt Some operating systems provide a default list of trusted certificates; these will also be used if available. Use to give a custom list. Use one or more times to get details about verification failures. revoked certificatescertificate revocation Ncat does not check for revoked certificates.certification revocation This option has no effect in server mode. (Specify SSL certificate) (Ncat option) This option gives the location of a PEM-encoded certificate files used to authenticate the server (in listen mode) or the client (in connect mode). Use it in combination with . (Specify SSL private key) (Ncat option) This option gives the location of the PEM-encoded private key file that goes with the certificate named with . (List trusted certificates) (Ncat option) This option sets a list of certificates that are trusted for purposes of certificate verification. It has no effect unless combined with . The argument to this option is the name of a PEMPEM (Privacy Enhanced Mail) file containing trusted certificates. Typically, the file will contain certificates of certification authorities, though it may also contain server certificates directly. When this option is used, Ncat does not use its default certificates. (Specify SSL ciphersuites) (Ncat option) This option sets the list of ciphersuites that Ncat will use when connecting to servers or when accepting SSL connections from clients. The syntax is described in the OpenSSL ciphers(1) man page, and defaults to ALL:!aNULL:!eNULL:!LOW:!EXP:!RC4:!MD5:@STRENGTH (Request distinct server name) (Ncat option) In client mode, this option sets the TLS SNI (Server Name Indication) extension, which tells the server the name of the logical server Ncat is contacting. This is important when the target server hosts multiple virtual servers at a single underlying network address. If the option is not provided, the TLS SNI extension will be populated with the target server hostname. (Specify ALPN protocol list) (Ncat option) This option allows you to specify a comma-separated list of protocols to send via the Application-Layer Protocol Negotiation (ALPN) TLS extension. Not supported by all versions of OpenSSL. Proxy Options (Specify proxy address) (Ncat option) Requests proxying through host:port, using the protocol specified by . If no port is specified, the proxy protocol's well-known port is used (1080 for SOCKS and 3128 for HTTP). When specifying an IPv6 HTTP proxy server using the IP address rather than the hostname, the square-bracket notation (for example [2001:db8::1]:8080) MUST be used to separate the port from the IPv6 address. If the proxy requires authentication, use . (Specify proxy protocol) (Ncat option) In connect mode, this option requests the protocol proto to connect through the proxy host specified by . In listen mode, this option has Ncat act as a proxy server using the specified protocol. The currently available protocols in connect mode are http (CONNECT), socks4 (SOCKSv4), and socks5 (SOCKSv5). The only server currently supported is http. If this option is not used, the default protocol is http. (Specify proxy credentials) (Ncat option) In connect mode, gives the credentials that will be used to connect to the proxy server. In listen mode, gives the credentials that will be required of connecting clients. For use with or , the form should be username:password. For , it should be a username only. These credentials can be alternatively passed onto Ncat by setting environment variable NCAT_PROXY_AUTHNCAT_PROXY_AUTH environment variable, which reduces the risk of the credentials being captured in process logs. (Option takes precedence.) (Specify where to resolve proxy destination) (Ncat option) In connect mode, it provides control over whether proxy destination hostnames are resolved by the remote proxy server or locally, by Ncat itself. Possible values for type are: local - Hostnames are resolved locally on the Ncat host. Ncat exits with error if the hostname cannot be resolved. remote - Hostnames are passed directly onto the remote proxy server. This is the default behavior. both - Hostname resolution is first attempted on the Ncat host. Unresolvable hostnames are passed onto the remote proxy server. none - Hostname resolution is completely disabled. Only a literal IPv4 or IPv6 address can be used as the proxy destination. Local hostname resolution generally respects IP version specified with options or , except for SOCKS4, which is incompatible with IPv6. Command Execution Options , (Execute command) (Ncat option) (Ncat option) Execute the specified command after a connection has been established. The command must be specified as a full pathname. All input from the remote client will be sent to the application and responses sent back to the remote client over the socket, thus making your command-line application interactive over a socket. Combined with , Ncat will handle multiple simultaneous connections to your specified port/application like inetd. Ncat will only accept a maximum, definable, number of simultaneous connections controlled by the option. By default this is set to 100 (60 on Windows). , (Execute command via sh) (Ncat option) (Ncat option) Same as , except it tries to execute the command via /bin/sh. This means you don't have to specify the full path for the command, and shell facilities like environment variables are available. (Execute a .lua script) (Ncat option) Runs the specified file as a Lua script after a connection has been established, using a built-in interpreter. Both the script's standard input and the standard output are redirected to the connection data streams. All exec options add the following variables to the child's environment: NCAT_REMOTE_ADDRNCAT_REMOTE_ADDR> environment variable NCAT_REMOTE_PORTNCAT_REMOTE_PORT> environment variable The IP address and port number of the remote host. In connect mode, it's the target's address; in listen mode, it's the client's address. NCAT_LOCAL_ADDRNCAT_LOCAL_ADDR> environment variable NCAT_LOCAL_PORTNCAT_LOCAL_PORT> environment variable The IP address and port number of the local end of the connection. NCAT_PROTONCAT_PROTO> environment variable The protocol in use: one of TCP, UDP, and SCTP. Access Control Options (Allow connections) (Ncat option) The list of hosts specified will be the only hosts allowed to connect to the Ncat process. All other connection attempts will be disconnected. In case of a conflict between and , takes precedence. Host specifications follow the same syntax used by Nmap. (Allow connections from file) (Ncat option) This has the same functionality as , except that the allowed hosts are provided in a new-line delimited allow file, rather than directly on the command line. (Deny connections) (Ncat option) Issue Ncat with a list of hosts that will not be allowed to connect to the listening Ncat process. Specified hosts will have their session silently terminated if they try to connect. In case of a conflict between and , takes precedence. Host specifications follow the same syntax used by Nmap. (Deny connections from file) (Ncat option) This is the same functionality as , except that excluded hosts are provided in a new-line delimited deny file, rather than directly on the command line. Timing Options These options accept a time parameter. This is specified in seconds by default, though you can append ms, s, m, or h to the value to specify milliseconds, seconds, minutes, or hours. , (Specify line delay) (Ncat option) (Ncat option) Set the delay interval for lines sent. This effectively limits the number of lines that Ncat will send in the specified period. This may be useful for low-bandwidth sites, or have other uses such as coping with annoying iptables --limit options. , (Specify idle timeout) (Ncat option) (Ncat option) Set a fixed timeout for idle connections. If the idle timeout is reached, the connection is terminated. , (Specify connect timeout) (Ncat option) (Ncat option) Set a fixed timeout for connection attempts. Output Options , (Save session data) (Ncat option) (Ncat option) Dump session data to a file , (Save session data in hex) (Ncat option) (Ncat option) Dump session data in hex to a file. (Append output) (Ncat option) Issue Ncat with along with and/or and it will append the resulted output rather than truncating the specified output files. , (Be verbose) (Ncat option) (Ncat option) Issue Ncat with and it will be verbose and display all kinds of useful connection based information. Use more than once (, ...) for greater verbosity. Misc Options , (Use CRLF as EOL) (Ncat option) (Ncat option) This option tells Ncat to convert LFLF line ending line endings to CRLFCRLF line ending when taking input from standard input.standard input This is useful for talking to some stringent servers directly from a terminal in one of the many common plain-text protocols that use CRLF for end-of-line. , (Help screen) (Ncat option) (Ncat option) Displays a short help screen with common options and parameters, and then exits. (Only receive data) (Ncat option) If this option is passed, Ncat will only receive data and will not try to send anything. (Only send data) (Ncat option) If this option is passed, then Ncat will only send data and will ignore anything received. This option also causes Ncat to close the network connection and terminate after EOF is received on standard input. (Do not shutdown into half-duplex mode) (Ncat option) If this option is passed, Ncat will not invoke shutdown on a socket after seeing EOF on stdin. This is provided for backward-compatibility with OpenBSD netcat, which exhibits this behavior when executed with its '-d' option. , (Do not resolve hostnames) (Ncat option) (Ncat option) Completely disable hostname resolution across all Ncat options, such as the destination, source address, source routing hops, and the proxy. All addresses must be specified numerically. (Note that resolution of proxy destinations is controlled separately via option .) , (Answer Telnet negotiations) (Ncat option) (Ncat option) Handle DO/DONT WILL/WONT Telnet negotiations. This makes it possible to script Telnet sessions with Ncat. (Display version) (Ncat option) Displays the Ncat version number and exits. Unix Domain Sockets The option (same as ) causes Ncat to use Unix domain sockets rather than network sockets. Unix domain sockets exist as an entry in the filesystem. You must give the name of a socket to connect to or to listen on. For example, to make a connection, ncat -U ~/unixsock To listen on a socket: ncat -l -U ~/unixsock Listen mode will create the socket if it doesn't exist. The socket will continue to exist after the program ends. Both stream and datagram domain sockets are supported. Use on its own for stream sockets, or combine it with for datagram sockets. Datagram sockets require a source socket to connect from. By default, a source socket with a random filename will be created as needed, and deleted when the program ends. Use the with a path to use a source socket with a specific name. AF_VSOCK Sockets The option causes Ncat to use AF_VSOCK sockets rather than network sockets. A CID must be given instead of a hostname or IP address. For example, to make a connection to the host, ncat --vsock 2 1234 To listen on a socket: ncat -l --vsock 1234 Both stream and datagram domain sockets are supported, but socket type availability depends on the hypervisor. Use on its own for stream sockets, or combine it with for datagram sockets. Examples Connect to example.org on TCP port 8080. ncat example.org 8080 Listen for connections on TCP port 8080. ncat -l 8080 Redirect TCP port 8080 on the local machine to host on port 80. ncat --sh-exec "ncat example.org 80" -l 8080 --keep-open Bind to TCP port 8081 and attach /bin/bash for the world to access freely. ncat --exec "/bin/bash" -l 8081 --keep-open Bind a shell to TCP port 8081, limit access to hosts on a local network, and limit the maximum number of simultaneous connections to 3. ncat --exec "/bin/bash" --max-conns 3 --allow 192.168.0.0/24 -l 8081 --keep-open Connect to smtphost:25 through a SOCKS4 server on port 1080. ncat --proxy socks4host --proxy-type socks4 --proxy-auth joe smtphost 25 Connect to smtphost:25 through a SOCKS5 server on port 1080. ncat --proxy socks5host --proxy-type socks5 --proxy-auth joe:secret smtphost 25 Create an HTTP proxy server on localhost port 8888. ncat -l --proxy-type http localhost 8888 Send a file over TCP port 9899 from host2 (client) to host1 (server). HOST1$ ncat -l 9899 > outputfile HOST2$ ncat HOST1 9899 < inputfile Transfer in the other direction, turning Ncat into a one file server. HOST1$ ncat -l 9899 < inputfile HOST2$ ncat HOST1 9899 > outputfile Exit Code The exit code reflects whether a connection was made and completed successfully. 0 means there was no error. 1 means there was a network error of some kind, for example Connection refused or Connection reset. 2 is reserved for all other errors, like an invalid option or a nonexistent file. Bugs Like its authors, Ncat isn't perfect. But you can help make it better by sending bug reports or even writing patches. If Ncat doesn't behave the way you expect, first upgrade to the latest version available from . If the problem persists, do some research to determine whether it has already been discovered and addressed. Try Googling the error message or browsing the nmap-dev archives at . nmap-dev mailing list Read this full manual page as well. If nothing comes of this, mail a bug report to dev@nmap.org. Please include everything you have learned about the problem, as well as what version of Ncat you are running and what operating system version it is running on. Problem reports and Ncat usage questions sent to dev@nmap.org are far more likely to be answered than those sent to Fyodor directly. Code patches to fix bugs are even better than bug reports. Basic instructions for creating patch files with your changes are available at . Patches may be sent to nmap-dev (recommended) or to Fyodor directly. Authors Chris Gibson chris@linuxops.net Gordon Lyon (Fyodor)fyodor@nmap.org () Kris Katterjohn katterjohn@gmail.com Mixter mixter@gmail.com The original Netcat was written by *Hobbit* hobbit@avian.org. While Ncat isn't built on any code from the traditional Netcat (or any other implementation), Ncat is most definitely based on Netcat in spirit and functionality. Legal Notices Ncat Copyright and Licensing copyright Ncat is (C) 2005–2022 Nmap Software LLC. It is distributed as free and open source software under the same license terms as our Nmap software. Precise terms and further details are available from . in . Creative Commons License for this Ncat Guide This Ncat Reference Guide is (C) 2005–2022 Nmap Software LLC. It is hereby placed under version 3.0 of the Creative Commons Attribution License. This allows you redistribute and modify the work as you desire, as long as you credit the original source. Alternatively, you may choose to treat this document as falling under the same license as Ncat itself (discussed previously). Source Code Availability and Community Contributions Source is provided to this software because we believe users have a right to know exactly what a program is going to do before they run it. This also allows you to audit the software for security holes (none have been found so far). Source code also allows you to port Nmap (which includes Ncat) to new platforms, fix bugs, and add new features. You are highly encouraged to send your changes to dev@nmap.org for possible incorporation into the main distribution. By sending these changes to Fyodor or one of the Insecure.Org development mailing lists, it is assumed that you are offering the Nmap Project (Nmap Software LLC) the unlimited, non-exclusive right to reuse, modify, and relicense the code. Nmap will always be available open source,open source but this is important because the inability to relicense code has caused devastating problems for other Free Software projects (such as KDE and NASM). We also occasionally relicense the code to third parties as discussed in the Nmap man page. If you wish to specify special license conditions of your contributions, just say so when you send them. No Warranty<indexterm><primary>warranty (lack of)</primary></indexterm> This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the Nmap Public Source License for more details at , or in the LICENSE file included with Nmap. Inappropriate Usage Ncat should never be installed with special privileges (e.g. suid root).suidsetuid That would open up a major security vulnerability as other users on the system (or attackers) could use it for privilege escalation. Third-Party Software This product includes software developed by the Apache Software Foundation. A modified version of the Libpcap portable packet capture librarylibpcap is distributed along with Ncat. The Windows version of Ncat utilized the Libpcap-derived Npcap libraryNpcap instead. Certain raw networking functions use the Libdnetlibdnet networking library, which was written by Dug Song.Song, Dug A modified version is distributed with Ncat. Ncat can optionally link with the OpenSSL cryptography toolkitOpenSSL for SSL version detection support. All of the third-party software described in this paragraph is freely redistributable under BSD-style software licenses.