1NCAT(1)                      Ncat Reference Guide                      NCAT(1)
2
3
4

NAME

6       ncat - Concatenate and redirect sockets
7

SYNOPSIS

9       ncat [OPTIONS...] [hostname] [port]
10

DESCRIPTION

12       Ncat is a feature-packed networking utility which reads and writes data
13       across networks from the command line. Ncat was written for the Nmap
14       Project and is the culmination of the currently splintered family of
15       Netcat incarnations. It is designed to be a reliable back-end tool to
16       instantly provide network connectivity to other applications and users.
17       Ncat will not only work with IPv4 and IPv6 but provides the user with a
18       virtually limitless number of potential uses.
19
20       Among Ncat's vast number of features there is the ability to chain
21       Ncats together; redirection of TCP, UDP, and SCTP ports to other sites;
22       SSL support; and proxy connections via SOCKS4 or HTTP proxies (with
23       optional proxy authentication as well). Some general principles apply
24       to most applications and thus give you the capability of instantly
25       adding networking support to software that would normally never support
26       it.
27

OPTIONS SUMMARY

29           Ncat 7.50 ( https://nmap.org/ncat )
30           Usage: ncat [options] [hostname] [port]
31
32           Options taking a time assume seconds. Append 'ms' for milliseconds,
33           's' for seconds, 'm' for minutes, or 'h' for hours (e.g. 500ms).
34             -4                         Use IPv4 only
35             -6                         Use IPv6 only
36             -U, --unixsock             Use Unix domain sockets only
37             -C, --crlf                 Use CRLF for EOL sequence
38             -c, --sh-exec <command>    Executes the given command via /bin/sh
39             -e, --exec <command>       Executes the given command
40                 --lua-exec <filename>  Executes the given Lua script
41             -g hop1[,hop2,...]         Loose source routing hop points (8 max)
42             -G <n>                     Loose source routing hop pointer (4, 8, 12, ...)
43             -m, --max-conns <n>        Maximum <n> simultaneous connections
44             -h, --help                 Display this help screen
45             -d, --delay <time>         Wait between read/writes
46             -o, --output <filename>    Dump session data to a file
47             -x, --hex-dump <filename>  Dump session data as hex to a file
48             -i, --idle-timeout <time>  Idle read/write timeout
49             -p, --source-port port     Specify source port to use
50             -s, --source addr          Specify source address to use (doesn't affect -l)
51             -l, --listen               Bind and listen for incoming connections
52             -k, --keep-open            Accept multiple connections in listen mode
53             -n, --nodns                Do not resolve hostnames via DNS
54             -t, --telnet               Answer Telnet negotiations
55             -u, --udp                  Use UDP instead of default TCP
56                 --sctp                 Use SCTP instead of default TCP
57             -v, --verbose              Set verbosity level (can be used several times)
58             -w, --wait <time>          Connect timeout
59             -z                         Zero-I/O mode, report connection status only
60                 --append-output        Append rather than clobber specified output files
61                 --send-only            Only send data, ignoring received; quit on EOF
62                 --recv-only            Only receive data, never send anything
63                 --allow                Allow only given hosts to connect to Ncat
64                 --allowfile            A file of hosts allowed to connect to Ncat
65                 --deny                 Deny given hosts from connecting to Ncat
66                 --denyfile             A file of hosts denied from connecting to Ncat
67                 --broker               Enable Ncat's connection brokering mode
68                 --chat                 Start a simple Ncat chat server
69                 --proxy <addr[:port]>  Specify address of host to proxy through
70                 --proxy-type <type>    Specify proxy type ("http" or "socks4" or "socks5")
71                 --proxy-auth <auth>    Authenticate with HTTP or SOCKS proxy server
72                 --ssl                  Connect or listen with SSL
73                 --ssl-cert             Specify SSL certificate file (PEM) for listening
74                 --ssl-key              Specify SSL private key (PEM) for listening
75                 --ssl-verify           Verify trust and domain name of certificates
76                 --ssl-trustfile        PEM file containing trusted SSL certificates
77                 --ssl-ciphers          Cipherlist containing SSL ciphers to use
78                 --version              Display Ncat's version information and exit
79
80           See the ncat(1) manpage for full options, descriptions and usage examples
81
82

CONNECT MODE AND LISTEN MODE

84       Ncat operates in one of two primary modes: connect mode and listen
85       mode. Other modes, such as the HTTP proxy server, act as special cases
86       of these two. In connect mode, Ncat works as a client. In listen mode
87       it is a server.
88
89       In connect mode, the hostname and port arguments tell what to connect
90       to.  hostname is required, and may be a hostname or IP address. If port
91       is supplied, it must be a decimal port number. If omitted, it defaults
92       to 31337.
93
94       In listen mode, hostname and port control the address the server will
95       bind to. Both arguments are optional in listen mode. If hostname is
96       omitted, it defaults to listening on all available addresses over IPv4
97       and IPv6. If port is omitted, it defaults to 31337.
98

PROTOCOL OPTIONS

100       -4 (IPv4 only)
101           Force the use of IPv4 only.
102
103       -6 (IPv6 only)
104           Force the use of IPv6 only.
105
106       -U, --unixsock (Use Unix domain sockets)
107           Use Unix domain sockets rather than network sockets. This option
108           may be used on its own for stream sockets, or combined with --udp
109           for datagram sockets. A description of -U mode is in the section
110           called “UNIX DOMAIN SOCKETS”.
111
112       -u, --udp (Use UDP)
113           Use UDP for the connection (the default is TCP).
114
115       --sctp (Use SCTP)
116           Use SCTP for the connection (the default is TCP). SCTP support is
117           implemented in TCP-compatible mode.
118

CONNECT MODE OPTIONS

120       -g hop1[,hop2,...] (Loose source routing)
121           Sets hops for IPv4 loose source routing. You can use -g once with a
122           comma-separated list of hops, use -g multiple times with single
123           hops to build the list, or combine the two. Hops can be given as IP
124           addresses or hostnames.
125
126       -G ptr (Set source routing pointer)
127           Sets the IPv4 source route “pointer” for use with -g. The argument
128           must be a multiple of 4 and no more than 28. Not all operating
129           systems support setting this pointer to anything other than four.
130
131       -p port, --source-port port (Specify source port)
132           Set the port number for Ncat to bind to.
133
134       -s host, --source host (Specify source address)
135           Set the address for Ncat to bind to.
136

LISTEN MODE OPTIONS

138       See the section called “ACCESS CONTROL OPTIONS” for information on
139       limiting the hosts that may connect to the listening Ncat process.
140
141       -l, --listen (Listen for connections)
142           Listen for connections rather than connecting to a remote machine
143
144       -m numconns, --max-conns numconns (Specify maximum number of
145       connections)
146           The maximum number of simultaneous connections accepted by an Ncat
147           instance. 100 is the default (60 on Windows).
148
149       -k, --keep-open (Accept multiple connections)
150           Normally a listening server accepts only one connection and then
151           quits when the connection is closed. This option makes it accept
152           multiple simultaneous connections and wait for more connections
153           after they have all been closed. It must be combined with --listen.
154           In this mode there is no way for Ncat to know when its network
155           input is finished, so it will keep running until interrupted. This
156           also means that it will never close its output stream, so any
157           program reading from Ncat and looking for end-of-file will also
158           hang.
159
160       --broker (Connection brokering)
161           Allow multiple parties to connect to a centralised Ncat server and
162           communicate with each other. Ncat can broker communication between
163           systems that are behind a NAT or otherwise unable to directly
164           connect. This option is used in conjunction with --listen, which
165           causes the --listen port to have broker mode enabled.
166
167       --chat (Ad-hoc “chat server”)
168           The --chat option enables chat mode, intended for the exchange of
169           text between several users. In chat mode, connection brokering is
170           turned on. Ncat prefixes each message received with an ID before
171           relaying it to the other connections. The ID is unique for each
172           connected client. This helps distinguish who sent what.
173           Additionally, non-printing characters such as control characters
174           are escaped to keep them from doing damage to a terminal.
175

SSL OPTIONS

177       --ssl (Use SSL)
178           In connect mode, this option transparently negotiates an SSL
179           session with an SSL server to securely encrypt the connection. This
180           is particularly handy for talking to SSL enabled HTTP servers, etc.
181
182           In server mode, this option listens for incoming SSL connections,
183           rather than plain untunneled traffic.
184
185       --ssl-verify (Verify server certificates)
186           In client mode, --ssl-verify is like --ssl except that it also
187           requires verification of the server certificate. Ncat comes with a
188           default set of trusted certificates in the file ca-bundle.crt.
189           Some operating systems provide a default list of trusted
190           certificates; these will also be used if available. Use
191           --ssl-trustfile to give a custom list. Use -v one or more times to
192           get details about verification failures.  Ncat does not check for
193           revoked certificates.
194
195           This option has no effect in server mode.
196
197       --ssl-cert certfile.pem (Specify SSL certificate)
198           This option gives the location of a PEM-encoded certificate files
199           used to authenticate the server (in listen mode) or the client (in
200           connect mode). Use it in combination with --ssl-key.
201
202       --ssl-key keyfile.pem (Specify SSL private key)
203           This option gives the location of the PEM-encoded private key file
204           that goes with the certificate named with --ssl-cert.
205
206       --ssl-trustfile cert.pem (List trusted certificates)
207           This option sets a list of certificates that are trusted for
208           purposes of certificate verification. It has no effect unless
209           combined with --ssl-verify. The argument to this option is the name
210           of a PEM file containing trusted certificates. Typically, the file
211           will contain certificates of certification authorities, though it
212           may also contain server certificates directly. When this option is
213           used, Ncat does not use its default certificates.
214
215       --ssl-ciphers cipherlist (Specify SSL ciphersuites)
216           This option sets the list of ciphersuites that Ncat will use when
217           connecting to servers or when accepting SSL connections from
218           clients. The syntax is described in the OpenSSL ciphers(1) man
219           page, and defaults to ALL:!ADH:!LOW:!EXP:!MD5:@STRENGTH
220

PROXY OPTIONS

222       --proxy host[:port] (Specify proxy address)
223           Requests proxying through host:port, using the protocol specified
224           by --proxy-type.
225
226           If no port is specified, the proxy protocol's well-known port is
227           used (1080 for SOCKS and 3128 for HTTP). However, when specifying
228           an IPv6 HTTP proxy server using the IP address rather than the
229           hostname, the port number MUST be specified as well. If the proxy
230           requires authentication, use --proxy-auth.
231
232       --proxy-type proto (Specify proxy protocol)
233           In connect mode, this option requests the protocol proto to connect
234           through the proxy host specified by --proxy. In listen mode, this
235           option has Ncat act as a proxy server using the specified protocol.
236
237           The currently available protocols in connect mode are http
238           (CONNECT) and socks4 (SOCKSv4). The only server currently supported
239           is http. If this option is not used, the default protocol is http.
240
241       --proxy-auth user[:pass] (Specify proxy credentials)
242           In connect mode, gives the credentials that will be used to connect
243           to the proxy server. In listen mode, gives the credentials that
244           will be required of connecting clients. For use with --proxy-type
245           http, the form should be user:pass. For --proxy-type socks4, it
246           should be a username only.
247

COMMAND EXECUTION OPTIONS

249       -e command, --exec command (Execute command)
250           Execute the specified command after a connection has been
251           established. The command must be specified as a full pathname. All
252           input from the remote client will be sent to the application and
253           responses sent back to the remote client over the socket, thus
254           making your command-line application interactive over a socket.
255           Combined with --keep-open, Ncat will handle multiple simultaneous
256           connections to your specified port/application like inetd. Ncat
257           will only accept a maximum, definable, number of simultaneous
258           connections controlled by the -m option. By default this is set to
259           100 (60 on Windows).
260
261       -c command, --sh-exec command (Execute command via sh)
262           Same as -e, except it tries to execute the command via /bin/sh.
263           This means you don't have to specify the full path for the command,
264           and shell facilities like environment variables are available.
265
266       --lua-exec file (Execute a .lua script)
267           Runs the specified file as a Lua script after a connection has been
268           established, using a built-in interpreter. Both the script's
269           standard input and the standard output are redirected to the
270           connection data streams.
271
272       All exec options add the following variables to the child's
273       environment:
274
275       NCAT_REMOTE_ADDR, NCAT_REMOTE_PORT
276           The IP address and port number of the remote host. In connect mode,
277           it's the target's address; in listen mode, it's the client's
278           address.
279
280       NCAT_LOCAL_ADDR, NCAT_LOCAL_PORT
281           The IP address and port number of the local end of the connection.
282
283       NCAT_PROTO
284           The protocol in use: one of TCP, UDP, and SCTP.
285

ACCESS CONTROL OPTIONS

287       --allow host[,host,...] (Allow connections)
288           The list of hosts specified will be the only hosts allowed to
289           connect to the Ncat process. All other connection attempts will be
290           disconnected. In case of a conflict between --allow and --deny,
291           --allow takes precedence. Host specifications follow the same
292           syntax used by Nmap.
293
294       --allowfile file (Allow connections from file)
295           This has the same functionality as --allow, except that the allowed
296           hosts are provided in a new-line delimited allow file, rather than
297           directly on the command line.
298
299       --deny host[,host,...] (Deny connections)
300           Issue Ncat with a list of hosts that will not be allowed to connect
301           to the listening Ncat process. Specified hosts will have their
302           session silently terminated if they try to connect. In case of a
303           conflict between --allow and --deny, --allow takes precedence. Host
304           specifications follow the same syntax used by Nmap.
305
306       --denyfile file (Deny connections from file)
307           This is the same functionality as --deny, except that excluded
308           hosts are provided in a new-line delimited deny file, rather than
309           directly on the command line.
310

TIMING OPTIONS

312       These options accept a time parameter. This is specified in seconds by
313       default, though you can append ms, s, m, or h to the value to specify
314       milliseconds, seconds, minutes, or hours.
315
316       -d time, --delay time (Specify line delay)
317           Set the delay interval for lines sent. This effectively limits the
318           number of lines that Ncat will send in the specified period. This
319           may be useful for low-bandwidth sites, or have other uses such as
320           coping with annoying iptables --limit options.
321
322       -i time, --idle-timeout time (Specify idle timeout)
323           Set a fixed timeout for idle connections. If the idle timeout is
324           reached, the connection is terminated.
325
326       -w time, --wait time (Specify connect timeout)
327           Set a fixed timeout for connection attempts.
328

OUTPUT OPTIONS

330       -o file, --output file (Save session data)
331           Dump session data to a file
332
333       -x file, --hex-dump file (Save session data in hex)
334           Dump session data in hex to a file.
335
336       --append-output (Append output)
337           Issue Ncat with --append-ouput along with -o and/or -x and it will
338           append the resulted output rather than truncating the specified
339           output files.
340
341       -v, --verbose (Be verbose)
342           Issue Ncat with -v and it will be verbose and display all kinds of
343           useful connection based information. Use more than once (-vv,
344           -vvv...) for greater verbosity.
345

MISC OPTIONS

347       -C, --crlf (Use CRLF as EOL)
348           This option tells Ncat to convert LF line endings to CRLF when
349           taking input from standard input.  This is useful for talking to
350           some stringent servers directly from a terminal in one of the many
351           common plain-text protocols that use CRLF for end-of-line.
352
353       -h, --help (Help screen)
354           Displays a short help screen with common options and parameters,
355           and then exits.
356
357       --recv-only (Only receive data)
358           If this option is passed, Ncat will only receive data and will not
359           try to send anything.
360
361       --send-only (Only send data)
362           If this option is passed, then Ncat will only send data and will
363           ignore anything received. This option also causes Ncat to close the
364           network connection and terminate after EOF is received on standard
365           input.
366
367       --no-shutdown (Do not shutdown into half-duplex mode)
368           If this option is passed, Ncat will not invoke shutdown on a socket
369           aftering seeing EOF on stdin. This is provided for
370           backward-compatibility with OpenBSD netcat, which exhibits this
371           behavior when executed with its '-d' option.
372
373       -t, --telnet (Answer Telnet negotiations)
374           Handle DO/DONT WILL/WONT Telnet negotiations. This makes it
375           possible to script Telnet sessions with Ncat.
376
377       --version (Display version)
378           Displays the Ncat version number and exits.
379

UNIX DOMAIN SOCKETS

381       The -U option (same as --unixsock) causes Ncat to use Unix domain
382       sockets rather than network sockets. Unix domain sockets exist as an
383       entry in the filesystem. You must give the name of a socket to connect
384       to or to listen on. For example, to make a connection,
385
386       ncat -U ~/unixsock
387
388       To listen on a socket:
389
390       ncat -l -U ~/unixsock
391
392       Listen mode will create the socket if it doesn't exist. The socket will
393       continue to exist after the program ends.
394
395       Both stream and datagram domain sockets are supported. Use -U on its
396       own for stream sockets, or combine it with --udp for datagram sockets.
397       Datagram sockets require a source socket to connect from. By default, a
398       source socket with a random filename will be created as needed, and
399       deleted when the program ends. Use the --source with a path to use a
400       source socket with a specific name.
401

EXAMPLES

403       Connect to example.org on TCP port 8080.
404           ncat example.org 8080
405
406       Listen for connections on TCP port 8080.
407           ncat -l 8080
408
409       Redirect TCP port 8080 on the local machine to host on port 80.
410           ncat --sh-exec "ncat example.org 80" -l 8080 --keep-open
411
412       Bind to TCP port 8081 and attach /bin/bash for the world to access
413       freely.
414           ncat --exec "/bin/bash" -l 8081 --keep-open
415
416       Bind a shell to TCP port 8081, limit access to hosts on a local
417       network, and limit the maximum number of simultaneous connections to 3.
418           ncat --exec "/bin/bash" --max-conns 3 --allow 192.168.0.0/24 -l
419           8081 --keep-open
420
421       Connect to smtphost:25 through a SOCKS4 server on port 1080.
422           ncat --proxy socks4host --proxy-type socks4 --proxy-auth user
423           smtphost 25
424
425       Create an HTTP proxy server on localhost port 8888.
426           ncat -l --proxy-type http localhost 8888
427
428       Send a file over TCP port 9899 from host2 (client) to host1 (server).
429           HOST1$ ncat -l 9899 > outputfile
430
431           HOST2$ ncat HOST1 9899 < inputfile
432
433       Transfer in the other direction, turning Ncat into a “one file” server.
434           HOST1$ ncat -l 9899 < inputfile
435
436           HOST2$ ncat HOST1 9899 > outputfile
437

EXIT CODE

439       The exit code reflects whether a connection was made and completed
440       successfully. 0 means there was no error. 1 means there was a network
441       error of some kind, for example “Connection refused” or “Connection
442       reset”. 2 is reserved for all other errors, like an invalid option or a
443       nonexistent file.
444

BUGS

446       Like its authors, Ncat isn't perfect. But you can help make it better
447       by sending bug reports or even writing patches. If Ncat doesn't behave
448       the way you expect, first upgrade to the latest version available from
449       https://nmap.org. If the problem persists, do some research to
450       determine whether it has already been discovered and addressed. Try
451       Googling the error message or browsing the nmap-dev archives at
452       http://seclists.org/.  Read this full manual page as well. If nothing
453       comes of this, mail a bug report to <dev@nmap.org>. Please include
454       everything you have learned about the problem, as well as what version
455       of Ncat you are running and what operating system version it is running
456       on. Problem reports and Ncat usage questions sent to dev@nmap.org are
457       far more likely to be answered than those sent to Fyodor directly.
458
459       Code patches to fix bugs are even better than bug reports. Basic
460       instructions for creating patch files with your changes are available
461       at https://svn.nmap.org/nmap/HACKING. Patches may be sent to nmap-dev
462       (recommended) or to Fyodor directly.
463

AUTHORS

465       ·   Chris Gibson <chris@linuxops.net>
466
467       ·   Kris Katterjohn <katterjohn@gmail.com>
468
469       ·   Mixter <mixter@gmail.com>
470
471       ·   Fyodor <fyodor@nmap.org> (http://insecure.org)
472
473       The original Netcat was written by *Hobbit* <hobbit@avian.org>. While
474       Ncat isn't built on any code from the “traditional” Netcat (or any
475       other implementation), Ncat is most definitely based on Netcat in
476       spirit and functionality.
477
479   Ncat Copyright and Licensing
480       Ncat is (C) 2005–2012 Insecure.Com LLC. It is distributed as free and
481       open source software under the same license terms as our Nmap software.
482       Precise terms and further details are available from
483       https://nmap.org/man/man-legal.html.
484
485   Creative Commons License for this Ncat Guide
486       This Ncat Reference Guide is (C) 2005–2012 Insecure.Com LLC. It is
487       hereby placed under version 3.0 of the Creative Commons Attribution
488       License[1]. This allows you redistribute and modify the work as you
489       desire, as long as you credit the original source. Alternatively, you
490       may choose to treat this document as falling under the same license as
491       Ncap itself (discussed previously).
492
493   Source Code Availability and Community Contributions
494       Source is provided to this software because we believe users have a
495       right to know exactly what a program is going to do before they run it.
496       This also allows you to audit the software for security holes (none
497       have been found so far).
498
499       Source code also allows you to port Nmap (which includes Ncat) to new
500       platforms, fix bugs, and add new features. You are highly encouraged to
501       send your changes to <dev@nmap.org> for possible incorporation into the
502       main distribution. By sending these changes to Fyodor or one of the
503       Insecure.Org development mailing lists, it is assumed that you are
504       offering the Nmap Project (Insecure.Com LLC) the unlimited,
505       non-exclusive right to reuse, modify, and relicense the code. Nmap will
506       always be available open source, but this is important because the
507       inability to relicense code has caused devastating problems for other
508       Free Software projects (such as KDE and NASM). We also occasionally
509       relicense the code to third parties as discussed in the Nmap man page.
510       If you wish to specify special license conditions of your
511       contributions, just say so when you send them.
512
513   No Warranty
514       This program is distributed in the hope that it will be useful, but
515       WITHOUT ANY WARRANTY; without even the implied warranty of
516       MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
517       General Public License v2.0 for more details at
518       http://www.gnu.org/licenses/gpl-2.0.html, or in the COPYING file
519       included with Nmap.
520
521   Inappropriate Usage
522       Ncat should never be installed with special privileges (e.g. suid
523       root).  That would open up a major security vulnerability as other
524       users on the system (or attackers) could use it for privilege
525       escalation.
526
527   Third-Party Software
528       This product includes software developed by the Apache Software
529       Foundation[2]. A modified version of the Libpcap portable packet
530       capture library[3] is distributed along with Ncat. The Windows version
531       of Ncat utilized the Libpcap-derived WinPcap library[4] instead.
532       Certain raw networking functions use the Libdnet[5] networking library,
533       which was written by Dug Song.  A modified version is distributed with
534       Ncat. Ncat can optionally link with the OpenSSL cryptography toolkit[6]
535       for SSL version detection support. All of the third-party software
536       described in this paragraph is freely redistributable under BSD-style
537       software licenses.
538

NOTES

540        1. Creative Commons Attribution License
541           http://creativecommons.org/licenses/by/3.0/
542
543        2. Apache Software Foundation
544           http://www.apache.org
545
546        3. Libpcap portable packet capture library
547           http://www.tcpdump.org
548
549        4. WinPcap library
550           http://www.winpcap.org
551
552        5. Libdnet
553           http://libdnet.sourceforge.net
554
555        6. OpenSSL cryptography toolkit
556           http://www.openssl.org
557
558
559
560Ncat                              06/07/2017                           NCAT(1)
Impressum