Chapter 17. Ncat Reference Guide
Name
ncat — Concatenate and redirect sockets
Synopsis
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
Ncat 7.96SVN ( https://nmap.org/ncat ) Usage: ncat [options] [hostname] [port] Options taking a time assume seconds. Append 'ms' for milliseconds, 's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms). -4 Use IPv4 only -6 Use IPv6 only -U, --unixsock Use Unix domain sockets only --vsock Use vsock sockets only -C, --crlf Use CRLF for EOL sequence -c, --sh-exec <command> Executes the given command via /bin/sh -e, --exec <command> Executes the given command --lua-exec <filename> Executes the given Lua script -g hop1[,hop2,...] Loose source routing hop points (8 max) -G <n> Loose source routing hop pointer (4, 8, 12, ...) -m, --max-conns <n> Maximum <n> simultaneous connections -h, --help Display this help screen -d, --delay <time> Wait between read/writes -o, --output <filename> Dump session data to a file -x, --hex-dump <filename> Dump session data as hex to a file -i, --idle-timeout <time> Idle read/write timeout -p, --source-port port Specify source port to use -s, --source addr Specify source address to use (doesn't affect -l) -l, --listen Bind and listen for incoming connections -k, --keep-open Accept multiple connections in listen mode -n, --nodns Do not resolve hostnames via DNS -t, --telnet Answer Telnet negotiations -u, --udp Use UDP instead of default TCP --sctp Use SCTP instead of default TCP -v, --verbose Set verbosity level (can be used several times) -w, --wait <time> Connect timeout -z Zero-I/O mode, report connection status only --append-output Append rather than clobber specified output files --send-only Only send data, ignoring received; quit on EOF --recv-only Only receive data, never send anything --no-shutdown Continue half-duplex when receiving EOF on stdin -q <time> After EOF on stdin, wait <time> then quit. --allow Allow only given hosts to connect to Ncat --allowfile A file of hosts allowed to connect to Ncat --deny Deny given hosts from connecting to Ncat --denyfile A file of hosts denied from connecting to Ncat --broker Enable Ncat's connection brokering mode --chat Start a simple Ncat chat server --proxy <addr[:port]> Specify address of host to proxy through --proxy-type <type> Specify proxy type ("http", "socks4", "socks5") --proxy-auth <auth> Authenticate with HTTP or SOCKS proxy server --proxy-dns <type> Specify where to resolve proxy destination --ssl Connect or listen with SSL --ssl-cert Specify SSL certificate file (PEM) for listening --ssl-key Specify SSL private key (PEM) for listening --ssl-verify Verify trust and domain name of certificates --ssl-trustfile PEM file containing trusted SSL certificates --ssl-ciphers Cipherlist containing SSL ciphers to use --ssl-servername Request distinct server name (SNI) --ssl-alpn ALPN protocol list to use --version Display Ncat's version information and exit See the ncat(1) manpage for full options, descriptions and usage examples
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 <hostname>
arguments tell
what to connect to.
<port>
is required,
and may be a hostname or IP address. If
<hostname>
is supplied, it
must be a decimal port number. If omitted, it defaults to
31337.
<port>
In listen mode,
and <hostname>
control the
address the server will bind to. Both arguments are optional in
listen mode. If <port>
is omitted, it defaults to listening on all available addresses over
IPv4 and IPv6. If <hostname>
is
omitted, it defaults to 31337.
<port>
Protocol Options
-
-4
(IPv4 only) -
-6
(IPv6 only) -
-U
,--unixsock
(Use Unix domain sockets) Use Unix domain sockets rather than network sockets. This option may be used on its own for stream sockets, or combined with
--udp
for datagram sockets. A description of-U
mode is in the section called “Unix Domain Sockets”.-
-u
,--udp
(Use UDP) -
--sctp
(Use SCTP) -
--vsock
(Use AF_VSOCK sockets) 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
--udp
for datagram sockets. A description of--vsock
mode is in the section called “AF_VSOCK Sockets”.
Connect Mode Options
-
-g
(Loose source routing)<hop1>
[,<hop2>
,...] -
-G
(Set source routing pointer)<ptr>
-
-p
,<port>
--source-port
(Specify source port)<port>
-
-s
,<host>
--source
(Specify source address)<host>
See the section called “Access Control Options” for information on limiting the hosts that may connect to the listening Ncat process.
-
-l
,--listen
(Listen for connections) Listen for connections rather than connecting to a remote machine
-
-m
,<numconns>
--max-conns
(Specify maximum number of connections)<numconns>
-
-k
,--keep-open
(Accept multiple connections, do not quit on socket EOF) -
--broker
(Connection brokering) -
--chat
(Ad-hoc “chat server”)
-
--ssl
(Use SSL) -
--ssl-verify
(Verify server certificates) In client mode,
--ssl-verify
is like--ssl
except that it also requires verification of the server certificate. Ncat comes with a default set of trusted certificates in the fileca-bundle.crt
. Some operating systems provide a default list of trusted certificates; these will also be used if available. Use--ssl-trustfile
to give a custom list. Use-v
one or more times to get details about verification failures.-
--ssl-cert
(Specify SSL certificate)<certfile.pem>
-
--ssl-key
(Specify SSL private key)<keyfile.pem>
-
--ssl-trustfile
(List trusted certificates)<cert.pem>
This option sets a list of certificates that are trusted for purposes of certificate verification. It has no effect unless combined with
--ssl-verify
. The argument to this option is the name of a PEM 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.-
--ssl-ciphers
(Specify SSL ciphersuites)<cipherlist>
-
--ssl-servername
(Request distinct server name)<name>
-
--ssl-alpn
(Specify ALPN protocol list)<ALPN list>
-
--proxy
(Specify proxy address)<host>
[:<port>
] Requests proxying through
<host>
:<port>
, using the protocol specified by--proxy-type
.-
--proxy-type
(Specify proxy protocol)<proto>
-
--proxy-auth
(Specify proxy credentials)<user>
[:<pass>
] These credentials can be alternatively passed onto Ncat by setting environment variable
NCAT_PROXY_AUTH
, which reduces the risk of the credentials being captured in process logs. (Option--proxy-auth
takes precedence.)-
--proxy-dns
(Specify where to resolve proxy destination)<type>
remote
- Hostnames are passed directly onto the remote proxy server. This is the default behavior.
All exec options add the following variables to the child's environment:
-
-C
,--crlf
(Use CRLF as EOL) This option tells Ncat to convert LF line endings to CRLF when taking input from 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.
-
-h
,--help
(Help screen) Displays a short help screen with common options and parameters, and then exits.
-
--recv-only
(Only receive data) If this option is passed, Ncat will only receive data and will not try to send anything.
-
--send-only
(Only send data) -
--no-shutdown
(Do not shutdown into half-duplex mode) -
-n
,--nodns
(Do not resolve hostnames) -
-t
,--telnet
(Answer Telnet negotiations) -
--version
(Display version)
- Connect to example.org on TCP port 8080.
- Listen for connections on TCP port 8080.
- Redirect TCP port 8080 on the local machine to host on port 80.
-
Bind to TCP port 8081 and attach
/bin/bash
for the world to access freely. - 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.
- Send a file over TCP port 9899 from host2 (client) to host1 (server).
- Transfer in the other direction, turning Ncat into a “one file” server.
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 https://nmap.org
. 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 https://seclists.org/
.
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 https://svn.nmap.org/nmap/HACKING
. Patches may
be sent to nmap-dev (recommended) or to Fyodor directly.
Authors
Chris Gibson
<chris@linuxops.net>
Gordon Lyon (Fyodor)
<fyodor@nmap.org>
(http://insecure.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
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 in the section called “Nmap Copyright and Licensing”.
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, 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.
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 https://nmap.org/npsl/
,
or in the LICENSE
file
included with Nmap.
Inappropriate Usage
Ncat should never be installed with special privileges (e.g. suid root). 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 library is distributed along with Ncat. The Windows version of Ncat utilized the Libpcap-derived Npcap library instead. Certain raw networking functions use the Libdnet networking library, which was written by Dug Song. A modified version is distributed with Ncat. Ncat can optionally link with the OpenSSL cryptography toolkit for SSL version detection support. All of the third-party software described in this paragraph is freely redistributable under BSD-style software licenses.