summaryrefslogtreecommitdiffstats
path: root/ncat/docs
diff options
context:
space:
mode:
Diffstat (limited to '')
-rw-r--r--ncat/docs/AUTHORS28
-rw-r--r--ncat/docs/README146
-rw-r--r--ncat/docs/THANKS29
-rw-r--r--ncat/docs/examples/README15
-rw-r--r--ncat/docs/examples/ipaccess23
-rw-r--r--ncat/docs/examples/logs/ascii-output3
-rw-r--r--ncat/docs/examples/logs/hex-output47
-rw-r--r--ncat/docs/examples/scripts/README6
-rwxr-xr-xncat/docs/examples/scripts/http-proxy5
-rw-r--r--ncat/docs/examples/scripts/http-scan/README14
-rw-r--r--ncat/docs/examples/scripts/http-scan/get.request3
-rw-r--r--ncat/docs/examples/scripts/http-scan/iplist5
-rwxr-xr-xncat/docs/examples/scripts/http-scan/scan-example7
-rw-r--r--ncat/docs/examples/scripts/http-scan/scanner-output57
-rw-r--r--ncat/docs/ncat-ascii-art.txt11
-rw-r--r--ncat/docs/ncat.1787
-rw-r--r--ncat/docs/ncat.usage.txt57
-rw-r--r--ncat/docs/ncat.xml1225
-rw-r--r--ncat/docs/ncatguide.xml2008
-rw-r--r--ncat/docs/ncatguidehtml.xml12
-rw-r--r--ncat/docs/ncatmanhtml.xml12
21 files changed, 4500 insertions, 0 deletions
diff --git a/ncat/docs/AUTHORS b/ncat/docs/AUTHORS
new file mode 100644
index 0000000..c0232c8
--- /dev/null
+++ b/ncat/docs/AUTHORS
@@ -0,0 +1,28 @@
+Ncat AUTHORS
+============
+
+Ncat is based in concept (but not code) on the original "Netcat"
+written by Hobbit circa 1994. Ncat combines the original Netcat
+feature set as well as various other ideas from other Netcat-like
+products, such as CryptCat, Socat, GNU Netcat, etc.
+
+Ncat was originally written from the ground up by Chris Gibson
+(chris@linuxops.net) and was funded by the Google Summer of Code Program
+2005.
+
+Development, bug fixes, security auditing, improvements by Sean
+(infamous42md@hotpop.com).
+
+Starting with the Google Summer of Code 2008, Ncat development was
+picked back up by Mixter and Kris Katterjohn. This included many bug
+fixes, new features and code cleanups.
+
+The Ncat requirements, ideas and general support and help were given by
+Fyodor.
+
+Many helpful comments, suggestions and other useful information was
+taken from the nmap-dev list (@insecure.org) as well as other
+contributors via email.
+
+Ncat shares the Nmap infrastructure libraries (Nsock and Nbase) which
+were originally written by Fyodor.
diff --git a/ncat/docs/README b/ncat/docs/README
new file mode 100644
index 0000000..77000fb
--- /dev/null
+++ b/ncat/docs/README
@@ -0,0 +1,146 @@
+ . .
+ \`-"'"-'/
+ } 6 6 {
+ ==. Y ,==
+ /^^^\ .
+ / \ )
+ ( )-( )/ _
+ -""---""--- /
+ / Ncat \_/
+ ( ____
+ \_.=|____E
+
+
+README for Ncat
+---------------
+
+Ncat is a reimplementation of the currently splintered and reasonably
+unmaintained Netcat family. Ncat will do pretty much everything that
+all the other Netcat's do, all in one place. Plus it has the added
+benefit of spanky new features and ongoing development.
+
+Ncat was designed with the original Netcat interface in mind. Rather
+than replacing the old Netcat interface with a brand new (and thus more
+convoluted) set of options, the Ncat interface was intentionally kept
+clean and simple to use, just like the original product.
+
+Ncat provides most of the features present in the original Netcat but with
+a complete overhaul and rewrite, along with completely new features and a
+combination of other well received features of other Netcat products, such
+as IPv6 and SSL support.
+
+The port scanning support has been entirely removed from Ncat. The
+reason for this is fairly obvious: there is a better port scanner out
+there already... :)
+
+Ncat can act as either a client or server, using TCP or UDP over IPv4 or
+IPv6. SSL support is provided for both the client and server mode.
+
+There is also a new "connection brokering" feature which enables two or
+more hosts to connect that previously were unable to directly communicate
+with each other.
+
+For example: "Host A" can connect to "Host B" but not "Host C"
+ "Host C" can connect to "Host B" but not "Host A"
+
+It is clear, then, that if you could connect to "Host B" then "Host A"
+and "Host C" could directly communicate...
+
+[HostA] <------> [HostB-with-Ncat-Broker] <------> [HostC]
+
+Ncat's connection brokering will allow you to connect between Host A and
+Host C via Host B without the trouble of having to have SOCKS support,
+etc. This is still somewhat experimental behaviour.
+
+Ncat has support for HTTP "CONNECT" via an HTTP proxy server such as Squid.
+It can also connect via a SOCKS4 server and is very flexible in terms of
+how it shuffles your data around.
+
+Ncat can also spawn its own HTTP CONNECT proxy server for your
+own relaying requirements.
+
+Ncat has the ability to execute a program and handle the I/O for its data
+over the socket. In other words, Ncat can "add" networking support to
+applications that currently have none.
+
+For example, you could:
+
+ncat --exec "/bin/bash" -l 5000
+
+NOTE: This is exceptionally dangerous behaviour, as it leaves an open shell
+sitting directly accessible to anyone who is able to connect to port 5000.
+See the allow and deny options below for securing your Ncat processes.
+
+Ncat has a TCP and UDP "redir"-style redirection feature to allow the user
+to redirect traffic from one host to another.
+
+For example:
+
+ncat --exec "/usr/local/bin/ncat www.example.com 80" -l 8888
+
+This command binds Ncat to the local machine on port 8888 and redirects
+connections to www.example.com. You may also find uses for this as a "host
+hiding" system. Similar to SOCKS4 but without any of the hassle of having
+to have SOCKS support in the application.
+
+This also begs the question of, "What would happen if you decided you wanted
+to pass the --udp flag in to the above command somewhere?"
+
+In this case, you would have a TCP to UDP "gender changer".
+
+If you have an application that only makes only TCP connections, for example,
+you could spawn a Ncat process to listen on a the applications TCP port and
+then redirect the TCP connection out to the final destination, only over UDP.
+
+The --allow and --deny options are provided to prevent unauthorized access to
+any Ncat process that is listening on a port. These options are also paired
+with the --allowfile and --denyfile options, similar in behaviour to Nmap.
+
+The allow and deny options accept a number of different IP address formats
+for maximum flexibility:
+
+A single IP address, of the format:
+
+ ip.ip.ip.ip
+
+EG: 192.168.10.1
+
+A CIDR-style IP address range, of the format:
+
+ ip.ip.ip.ip/cidr
+
+EG: 192.168.10.0/24
+
+An IP and full netmask, of the format:
+
+ ip.ip.ip.ip:nm.nm.nm.nm
+
+EG: 192.168.10.4:255.255.255.255
+
+An IP address with wildcards:
+
+ ip.ip.ip.*
+ ip.ip.*.*
+ ip.*.*.*
+
+These rules may also be used in a flat file, delimited by newlines. An
+example of a full ACL is included in docs/examples/ labelled 'iplist'. Also
+note that comments start with a # and are perfectly acceptable for use in
+the ACL's.
+
+For example, the file "ipaccess" might look like:
+
+# Abuse from ADSL user.
+88.223.14.1/32
+
+# This guy is scanning us for SOCKS4 servers to abuse, block his /24
+194.213.167.*
+
+To implement this IP address ACL simply run:
+
+ncat --denyfile /path/to/file/ipaccess -l 7000
+
+For further documentation, please see the man page.
+
+--Chris Gibson and Kris Katterjohn
+
diff --git a/ncat/docs/THANKS b/ncat/docs/THANKS
new file mode 100644
index 0000000..d8d1bc0
--- /dev/null
+++ b/ncat/docs/THANKS
@@ -0,0 +1,29 @@
+Ncat Acknowledgements
+=====================
+
+This file is a short rambling of various "thank-you"'s to all
+the very generous support and advice received from various
+parties.
+
+First and foremost: Thanks go out to Fyodor for all the support
+and great ideas throughout the course of development and no doubt
+also in the future.
+
+Thanks to Google and the Summer of Code team. The points of
+contact with Google being Chris DiBona, Natalie and Jude. Thanks to
+you all for making this possible. Without whom I wouldn't even
+be writing this.
+
+Also, thank you to all the folks from #c on Undernet who kicked
+me in the right direction when things were at their most broken.
+
+Thanks to Jan for all her support and, well, general tolerance. :)
+
+Thanks to all the people who've submitted bug reports, given me
+ideas, helped me test Ncat or just given me general encouragement
+over the previous years. It is most appreciated.
+
+Finally, thanks to Hobbit for writing the original Netcat; it still
+rocks.
+
+--Chris Gibson, <chris@linuxops.net>
diff --git a/ncat/docs/examples/README b/ncat/docs/examples/README
new file mode 100644
index 0000000..7e253fc
--- /dev/null
+++ b/ncat/docs/examples/README
@@ -0,0 +1,15 @@
+/examples/scripts
+~~~~~~~~~~~~~~~~~
+These are a set of small scripts to further demonstrate some
+uses for Ncat. You *will* have to change some values yourself,
+such as in "http-proxy", if your proxy server requires authorization,
+you'll have to add your own authorization information.
+
+
+/examples/logs/
+~~~~~~~~~~~~~~~
+These are a set of output logfiles generated by Ncat to briefly
+demonstrate Ncat's logging abilities.
+
+
+--Chris Gibson, <chris@linuxops.net>
diff --git a/ncat/docs/examples/ipaccess b/ncat/docs/examples/ipaccess
new file mode 100644
index 0000000..356bea1
--- /dev/null
+++ b/ncat/docs/examples/ipaccess
@@ -0,0 +1,23 @@
+#
+# This is a sample IP access list that
+# could potentially be used with Ncat
+# to allow or deny specific users from
+# connecting to an Ncat process, such as
+# a standard listen operation to being
+# able to access your newly spawned SOCKS4
+# server.
+#
+# Obviously, these IP addresses are pretty
+# useless to most people. It is an example
+# afterall. :)
+#
+# Chris Gibson, <chris@linuxops.net>
+
+# lo interface.
+127.0.0.1/8
+
+# eth0 internal network.
+192.168.0.0/24
+
+# eth1 to outside world.
+55.20.30.1/32
diff --git a/ncat/docs/examples/logs/ascii-output b/ncat/docs/examples/logs/ascii-output
new file mode 100644
index 0000000..324f2a1
--- /dev/null
+++ b/ncat/docs/examples/logs/ascii-output
@@ -0,0 +1,3 @@
+HELO xxx.xxx.xxx
+220 smtp.google.com ESMTP
+250 smtp.google.com Hello xxx.xxx.xxx [xxx.xxx.xxx.xxx], pleased to meet you
diff --git a/ncat/docs/examples/logs/hex-output b/ncat/docs/examples/logs/hex-output
new file mode 100644
index 0000000..0114db5
--- /dev/null
+++ b/ncat/docs/examples/logs/hex-output
@@ -0,0 +1,47 @@
+[0000] 47 45 54 20 2F 69 6E 64 65 78 2E 68 74 6D 6C 20 GET..ind ex.html.
+[0010] 48 54 54 50 2F 31 2E 30 0A HTTP.1.0 .
+[0000] 55 73 65 72 2D 41 67 65 6E 74 3A 20 4E 63 61 74 User.Age nt..Ncat
+[0010] 0A .
+[0000] 48 6F 73 74 3A 20 77 77 77 2E 67 6F 6F 67 6C 65 Host..ww w.google
+[0010] 2E 63 6F 6D 0A .com.
+[0000] 0A .
+[0000] 48 54 54 50 2F 31 2E 30 20 33 30 32 20 46 6F 75 HTTP.1.0 .302.Fou
+[0010] 6E 64 0D 0A 4C 6F 63 61 74 69 6F 6E 3A 20 68 74 nd..Loca tion..ht
+[0020] 74 70 3A 2F 2F 77 77 77 2E 67 6F 6F 67 6C 65 2E tp...www .google.
+[0030] 63 6F 2E 75 6B 2F 63 78 66 65 72 3F 63 3D 50 52 co.uk.cx fer.c.PR
+[0040] 45 46 25 33 44 3A 54 4D 25 33 44 31 31 32 34 37 EF.3D.TM .3D11247
+[0050] 35 35 38 30 32 3A 53 25 33 44 48 75 52 73 51 62 55802.S. 3DHuRsQb
+[0060] 51 69 43 59 52 71 4A 6E 5A 32 26 70 72 65 76 3D QiCYRqJn Z2.prev.
+[0070] 2F 69 6E 64 65 78 2E 68 74 6D 6C 0D 0A 53 65 74 .index.h tml..Set
+[0080] 2D 43 6F 6F 6B 69 65 3A 20 50 52 45 46 3D 49 44 .Cookie. .PREF.ID
+[0090] 3D 31 63 31 31 36 32 63 66 36 63 63 33 65 35 63 .1c1162c f6cc3e5c
+[00a0] 64 3A 43 52 3D 31 3A 54 4D 3D 31 31 32 34 37 35 d.CR.1.T M.112475
+[00b0] 35 38 30 32 3A 4C 4D 3D 31 31 32 34 37 35 35 38 5802.LM. 11247558
+[00c0] 30 32 3A 53 3D 5F 38 33 69 47 45 53 67 6F 7A 6E 02.S..83 iGESgozn
+[00d0] 33 49 4F 6D 34 3B 20 65 78 70 69 72 65 73 3D 53 3IOm4..e xpires.S
+[00e0] 75 6E 2C 20 31 37 2D 4A 61 6E 2D 32 30 33 38 20 un..17.J an.2038.
+[00f0] 31 39 3A 31 34 3A 30 37 20 47 4D 54 3B 20 70 61 19.14.07 .GMT..pa
+[0100] 74 68 3D 2F 3B 20 64 6F 6D 61 69 6E 3D 2E 67 6F th....do main..go
+[0110] 6F 67 6C 65 2E 63 6F 6D 0D 0A 43 6F 6E 74 65 6E ogle.com ..Conten
+[0120] 74 2D 54 79 70 65 3A 20 74 65 78 74 2F 68 74 6D t.Type.. text.htm
+[0130] 6C 0D 0A 53 65 72 76 65 72 3A 20 47 57 53 2F 32 l..Serve r..GWS.2
+[0140] 2E 31 0D 0A 43 6F 6E 74 65 6E 74 2D 4C 65 6E 67 .1..Cont ent.Leng
+[0150] 74 68 3A 20 32 32 37 0D 0A 44 61 74 65 3A 20 54 th..227. .Date..T
+[0160] 75 65 2C 20 32 33 20 41 75 67 20 32 30 30 35 20 ue..23.A ug.2005.
+[0170] 30 30 3A 31 30 3A 30 32 20 47 4D 54 0D 0A 43 6F 00.10.02 .GMT..Co
+[0180] 6E 6E 65 63 74 69 6F 6E 3A 20 4B 65 65 70 2D 41 nnection ..Keep.A
+[0190] 6C 69 76 65 0D 0A 0D 0A 3C 48 54 4D 4C 3E 3C 48 live.... .HTML..H
+[01a0] 45 41 44 3E 3C 54 49 54 4C 45 3E 33 30 32 20 4D EAD..TIT LE.302.M
+[01b0] 6F 76 65 64 3C 2F 54 49 54 4C 45 3E 3C 2F 48 45 oved..TI TLE...HE
+[01c0] 41 44 3E 3C 42 4F 44 59 3E 0A 3C 48 31 3E 33 30 AD..BODY ...H1.30
+[01d0] 32 20 4D 6F 76 65 64 3C 2F 48 31 3E 0A 54 68 65 2.Moved. .H1..The
+[01e0] 20 64 6F 63 75 6D 65 6E 74 20 68 61 73 20 6D 6F .documen t.has.mo
+[01f0] 76 65 64 0A 3C 41 20 48 52 45 46 3D 22 68 74 74 ved..A.H REF..htt
+[0200] 70 3A 2F 2F 77 77 77 2E 67 6F 6F 67 6C 65 2E 63 p...www. google.c
+[0210] 6F 2E 75 6B 2F 63 78 66 65 72 3F 63 3D 50 52 45 o.uk.cxf er.c.PRE
+[0220] 46 25 33 44 3A 54 4D 25 33 44 31 31 32 34 37 35 F.3D.TM. 3D112475
+[0230] 35 38 30 32 3A 53 25 33 44 48 75 52 73 51 62 51 5802.S.3 DHuRsQbQ
+[0240] 69 43 59 52 71 4A 6E 5A 32 26 61 6D 70 3B 70 72 iCYRqJnZ 2.amp.pr
+[0250] 65 76 3D 2F 69 6E 64 65 78 2E 68 74 6D 6C 22 3E ev..inde x.html..
+[0260] 68 65 72 65 3C 2F 41 3E 2E 0D 0A 3C 2F 42 4F 44 here..A. .....BOD
+[0270] 59 3E 3C 2F 48 54 4D 4C 3E 0D 0A Y...HTML ...
diff --git a/ncat/docs/examples/scripts/README b/ncat/docs/examples/scripts/README
new file mode 100644
index 0000000..e50372f
--- /dev/null
+++ b/ncat/docs/examples/scripts/README
@@ -0,0 +1,6 @@
+These are various scripts that demonstrate some
+potential usage for Ncat.
+
+If you find a neat usage for Ncat and possibly
+write a few lines of code to automate something,
+then please email them over to Chris Gibson (chris@linuxops.net)
diff --git a/ncat/docs/examples/scripts/http-proxy b/ncat/docs/examples/scripts/http-proxy
new file mode 100755
index 0000000..904c20f
--- /dev/null
+++ b/ncat/docs/examples/scripts/http-proxy
@@ -0,0 +1,5 @@
+NCAT_PATH=../../..
+PROXY_HOST=www.cnn.com:80
+PROXY_AUTH=user:pass
+
+$NCAT_PATH/ncat --http-proxy "$PROXY_HOST" --proxy-auth "$PROXY_AUTH" localhost 3128
diff --git a/ncat/docs/examples/scripts/http-scan/README b/ncat/docs/examples/scripts/http-scan/README
new file mode 100644
index 0000000..bb5c8be
--- /dev/null
+++ b/ncat/docs/examples/scripts/http-scan/README
@@ -0,0 +1,14 @@
+HTTP-SCAN with Ncat
+~~~~~~~~~~~~~~~~~~~
+
+This is a simple exercise that uses a small amount of
+scripted automation that will throw out the banner
+information of n number of hosts listed in the file "iplist".
+
+Ncat uses the "get.request" HTTP header to get the newly
+connected webserver to tell you about itself.
+
+Usage: ./scan-example
+
+Variables to change: None, but you may want to change "iplist"
+ to other more informative hosts.
diff --git a/ncat/docs/examples/scripts/http-scan/get.request b/ncat/docs/examples/scripts/http-scan/get.request
new file mode 100644
index 0000000..778a569
--- /dev/null
+++ b/ncat/docs/examples/scripts/http-scan/get.request
@@ -0,0 +1,3 @@
+HEAD / HTTP/1.0
+
+
diff --git a/ncat/docs/examples/scripts/http-scan/iplist b/ncat/docs/examples/scripts/http-scan/iplist
new file mode 100644
index 0000000..f0417e9
--- /dev/null
+++ b/ncat/docs/examples/scripts/http-scan/iplist
@@ -0,0 +1,5 @@
+www.google.com
+www.microsoft.com
+www.apache.org
+www.freebsd.org
+www.apple.com
diff --git a/ncat/docs/examples/scripts/http-scan/scan-example b/ncat/docs/examples/scripts/http-scan/scan-example
new file mode 100755
index 0000000..1fe7f75
--- /dev/null
+++ b/ncat/docs/examples/scripts/http-scan/scan-example
@@ -0,0 +1,7 @@
+NCAT_PATH=../../../..
+if [ -a "$NCAT_PATH/ncat" ]
+ then
+ for addr in `cat iplist`; do $NCAT_PATH/ncat --disable-eof-exit $addr 80 < get.request; done;
+else
+ echo "Ncat is not buit. Please build Ncat before you use these scripts";
+fi
diff --git a/ncat/docs/examples/scripts/http-scan/scanner-output b/ncat/docs/examples/scripts/http-scan/scanner-output
new file mode 100644
index 0000000..5c69d59
--- /dev/null
+++ b/ncat/docs/examples/scripts/http-scan/scanner-output
@@ -0,0 +1,57 @@
+Connected to 66.102.9.147:80
+HTTP/1.0 302 Found
+Location: http://www.google.co.uk/
+Set-Cookie: PREF=ID=b6262fee80b28ffc:TM=1137945347:LM=1137945347:S=s7TLf6mcMNGW-33R; expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com
+Content-Type: text/html
+Server: GWS/2.1
+Content-Length: 224
+Date: Sun, 22 Jan 2006 15:55:47 GMT
+Connection: Keep-Alive
+
+Connected to 207.46.198.30:80
+HTTP/1.1 200 OK
+Connection: close
+Date: Sun, 22 Jan 2006 15:55:48 GMT
+Server: Microsoft-IIS/6.0
+P3P: CP="ALL IND DSP COR ADM CONo CUR CUSo IVAo IVDo PSA PSD TAI TELo OUR SAMo CNT COM INT NAV ONL PHY PRE PUR UNI"
+X-Powered-By: ASP.NET
+X-AspNet-Version: 2.0.50727
+Cache-Control: private
+Content-Type: text/html; charset=utf-8
+Content-Length: 21061
+
+Connected to 209.237.227.195:80
+HTTP/1.1 200 OK
+Date: Sun, 22 Jan 2006 15:55:48 GMT
+Server: Apache/2.2.0 (Unix)
+Last-Modified: Wed, 18 Jan 2006 03:00:54 GMT
+ETag: "997bf1-2d93-419e2580"
+Accept-Ranges: bytes
+Content-Length: 11667
+Cache-Control: max-age=86400
+Expires: Mon, 23 Jan 2006 15:55:48 GMT
+Connection: close
+Content-Type: text/html; charset=ISO-8859-1
+
+Connected to 216.136.204.117:80
+HTTP/1.1 200 OK
+Date: Sun, 22 Jan 2006 15:55:49 GMT
+Server: Apache/1.3.x LaHonda (Unix)
+Last-Modified: Fri, 20 Jan 2006 21:24:33 GMT
+ETag: "26f8f7-9839-43d15511"
+Accept-Ranges: bytes
+Content-Length: 38969
+Connection: close
+Content-Type: text/html
+X-Pad: avoid browser bug
+
+Connected to 17.112.152.32:80
+HTTP/1.0 200 OK
+Age: 328
+Date: Sun, 22 Jan 2006 15:50:20 GMT
+Content-Length: 26131
+Content-Type: text/html
+Expires: Sun, 22 Jan 2006 16:10:20 GMT
+Cache-Control: max-age=1200
+Server: Apache/1.3.29 (Darwin) PHP/4.3.1
+
diff --git a/ncat/docs/ncat-ascii-art.txt b/ncat/docs/ncat-ascii-art.txt
new file mode 100644
index 0000000..1621079
--- /dev/null
+++ b/ncat/docs/ncat-ascii-art.txt
@@ -0,0 +1,11 @@
+ . .
+ \`-"'"-'/
+ } 6 6 {
+ ==. Y ,==
+ /^^^\ .
+ / \ ) Ncat: A modern interpretation of classic Netcat
+ ( )-( )/
+ -""---""--- /
+ / Ncat \_/
+ ( ____
+ \_.=|____E
diff --git a/ncat/docs/ncat.1 b/ncat/docs/ncat.1
new file mode 100644
index 0000000..7fbc5b5
--- /dev/null
+++ b/ncat/docs/ncat.1
@@ -0,0 +1,787 @@
+'\" t
+.\" Title: Ncat
+.\" Author: [see the "Authors" section]
+.\" Generator: DocBook XSL Stylesheets v1.79.1 <http://docbook.sf.net/>
+.\" Date: 05/17/2023
+.\" Manual: Ncat Reference Guide
+.\" Source: Ncat
+.\" Language: English
+.\"
+.TH "NCAT" "1" "05/17/2023" "Ncat" "Ncat Reference Guide"
+.\" -----------------------------------------------------------------
+.\" * Define some portability stuff
+.\" -----------------------------------------------------------------
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.\" http://bugs.debian.org/507673
+.\" http://lists.gnu.org/archive/html/groff/2009-02/msg00013.html
+.\" ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
+.ie \n(.g .ds Aq \(aq
+.el .ds Aq '
+.\" -----------------------------------------------------------------
+.\" * set default formatting
+.\" -----------------------------------------------------------------
+.\" disable hyphenation
+.nh
+.\" disable justification (adjust text to left margin only)
+.ad l
+.\" -----------------------------------------------------------------
+.\" * MAIN CONTENT STARTS HERE *
+.\" -----------------------------------------------------------------
+.SH "NAME"
+ncat \- Concatenate and redirect sockets
+.SH "SYNOPSIS"
+.HP \w'\fBncat\fR\ 'u
+\fBncat\fR [\fIOPTIONS\fR...] [\fIhostname\fR] [\fIport\fR]
+.SH "DESCRIPTION"
+.PP
+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\&.
+.PP
+Among Ncat\*(Aqs 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\&.
+.SH "OPTIONS SUMMARY"
+.PP
+.if n \{\
+.RS 4
+.\}
+.nf
+Ncat 7\&.94 ( https://nmap\&.org/ncat )
+Usage: ncat [options] [hostname] [port]
+
+Options taking a time assume seconds\&. Append \*(Aqms\*(Aq for milliseconds,
+\*(Aqs\*(Aq for seconds, \*(Aqm\*(Aq for minutes, or \*(Aqh\*(Aq 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\*(Aqt 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
+ \-\-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\*(Aqs 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\*(Aqs version information and exit
+
+See the ncat(1) manpage for full options, descriptions and usage examples
+.fi
+.if n \{\
+.RE
+.\}
+.sp
+.SH "CONNECT MODE AND LISTEN MODE"
+.PP
+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\&.
+.PP
+In connect mode, the
+\fB\fIhostname\fR\fR
+and
+\fB\fIport\fR\fR
+arguments tell what to connect to\&.
+\fB\fIhostname\fR\fR
+is required, and may be a hostname or IP address\&. If
+\fB\fIport\fR\fR
+is supplied, it must be a decimal port number\&. If omitted, it defaults to 31337\&.
+.PP
+In listen mode,
+\fB\fIhostname\fR\fR
+and
+\fB\fIport\fR\fR
+control the address the server will bind to\&. Both arguments are optional in listen mode\&. If
+\fB\fIhostname\fR\fR
+is omitted, it defaults to listening on all available addresses over IPv4 and IPv6\&. If
+\fB\fIport\fR\fR
+is omitted, it defaults to 31337\&.
+.SH "PROTOCOL OPTIONS"
+.PP
+\fB\-4\fR (IPv4 only)
+.RS 4
+Force the use of IPv4 only\&.
+.RE
+.PP
+\fB\-6\fR (IPv6 only)
+.RS 4
+Force the use of IPv6 only\&.
+.RE
+.PP
+\fB\-U\fR, \fB\-\-unixsock\fR (Use Unix domain sockets)
+.RS 4
+Use Unix domain sockets rather than network sockets\&. This option may be used on its own for stream sockets, or combined with
+\fB\-\-udp\fR
+for datagram sockets\&. A description of
+\fB\-U\fR
+mode is in
+the section called \(lqUNIX DOMAIN SOCKETS\(rq\&.
+.RE
+.PP
+\fB\-u\fR, \fB\-\-udp\fR (Use UDP)
+.RS 4
+Use UDP for the connection (the default is TCP)\&.
+.RE
+.PP
+\fB\-\-sctp\fR (Use SCTP)
+.RS 4
+Use SCTP for the connection (the default is TCP)\&. SCTP support is implemented in TCP\-compatible mode\&.
+.RE
+.PP
+\fB\-\-vsock\fR (Use AF_VSOCK sockets)
+.RS 4
+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
+\fB\-\-udp\fR
+for datagram sockets\&. A description of
+\fB\-\-vsock\fR
+mode is in
+the section called \(lqAF_VSOCK SOCKETS\(rq\&.
+.RE
+.SH "CONNECT MODE OPTIONS"
+.PP
+\fB\-g \fR\fB\fIhop1\fR\fR\fB[,\fIhop2\fR,\&.\&.\&.]\fR (Loose source routing)
+.RS 4
+Sets hops for IPv4 loose source routing\&. You can use
+\fB\-g\fR
+once with a comma\-separated list of hops, use
+\fB\-g\fR
+multiple times with single hops to build the list, or combine the two\&. Hops can be given as IP addresses or hostnames\&.
+.RE
+.PP
+\fB\-G \fR\fB\fIptr\fR\fR (Set source routing pointer)
+.RS 4
+Sets the IPv4 source route
+\(lqpointer\(rq
+for use with
+\fB\-g\fR\&. 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\&.
+.RE
+.PP
+\fB\-p \fR\fB\fIport\fR\fR, \fB\-\-source\-port \fR\fB\fIport\fR\fR (Specify source port)
+.RS 4
+Set the port number for Ncat to bind to\&.
+.RE
+.PP
+\fB\-s \fR\fB\fIhost\fR\fR, \fB\-\-source \fR\fB\fIhost\fR\fR (Specify source address)
+.RS 4
+Set the address for Ncat to bind to\&.
+.RE
+.SH "LISTEN MODE OPTIONS"
+.PP
+See
+the section called \(lqACCESS CONTROL OPTIONS\(rq
+for information on limiting the hosts that may connect to the listening Ncat process\&.
+.PP
+\fB\-l\fR, \fB\-\-listen\fR (Listen for connections)
+.RS 4
+Listen for connections rather than connecting to a remote machine
+.RE
+.PP
+\fB\-m \fR\fB\fInumconns\fR\fR, \fB\-\-max\-conns \fR\fB\fInumconns\fR\fR (Specify maximum number of connections)
+.RS 4
+The maximum number of simultaneous connections accepted by an Ncat instance\&. 100 is the default (60 on Windows)\&.
+.RE
+.PP
+\fB\-k\fR, \fB\-\-keep\-open\fR (Accept multiple connections)
+.RS 4
+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
+\fB\-\-listen\fR\&. 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\&.
+.RE
+.PP
+\fB\-\-broker\fR (Connection brokering)
+.RS 4
+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
+\fB\-\-listen\fR, which causes the
+\fB\-\-listen\fR
+port to have broker mode enabled\&.
+.RE
+.PP
+\fB\-\-chat\fR (Ad\-hoc \(lqchat server\(rq)
+.RS 4
+The
+\fB\-\-chat\fR
+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\&.
+.RE
+.SH "SSL OPTIONS"
+.PP
+\fB\-\-ssl\fR (Use SSL)
+.RS 4
+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\&.
+.sp
+In server mode, this option listens for incoming SSL connections, rather than plain untunneled traffic\&.
+.sp
+In UDP mode, this option enables Datagram TLS (DTLS)\&.
+.RE
+.PP
+\fB\-\-ssl\-verify\fR (Verify server certificates)
+.RS 4
+In client mode,
+\fB\-\-ssl\-verify\fR
+is like
+\fB\-\-ssl\fR
+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\&.
+Some operating systems provide a default list of trusted certificates; these will also be used if available\&. Use
+\fB\-\-ssl\-trustfile\fR
+to give a custom list\&. Use
+\fB\-v\fR
+one or more times to get details about verification failures\&.
+Ncat does not check for revoked certificates\&.
+.sp
+This option has no effect in server mode\&.
+.RE
+.PP
+\fB\-\-ssl\-cert \fR\fB\fIcertfile\&.pem\fR\fR (Specify SSL certificate)
+.RS 4
+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
+\fB\-\-ssl\-key\fR\&.
+.RE
+.PP
+\fB\-\-ssl\-key \fR\fB\fIkeyfile\&.pem\fR\fR (Specify SSL private key)
+.RS 4
+This option gives the location of the PEM\-encoded private key file that goes with the certificate named with
+\fB\-\-ssl\-cert\fR\&.
+.RE
+.PP
+\fB\-\-ssl\-trustfile \fR\fB\fIcert\&.pem\fR\fR (List trusted certificates)
+.RS 4
+This option sets a list of certificates that are trusted for purposes of certificate verification\&. It has no effect unless combined with
+\fB\-\-ssl\-verify\fR\&. 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\&.
+.RE
+.PP
+\fB\-\-ssl\-ciphers \fR\fB\fIcipherlist\fR\fR (Specify SSL ciphersuites)
+.RS 4
+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
+.RE
+.PP
+\fB\-\-ssl\-servername \fR\fB\fIname\fR\fR (Request distinct server name)
+.RS 4
+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\&.
+.RE
+.PP
+\fB\-\-ssl\-alpn \fR\fB\fIALPN list\fR\fR (Specify ALPN protocol list)
+.RS 4
+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\&.
+.RE
+.SH "PROXY OPTIONS"
+.PP
+\fB\-\-proxy \fR\fB\fIhost\fR\fR\fB[:\fIport\fR]\fR (Specify proxy address)
+.RS 4
+Requests proxying through
+\fIhost\fR:\fIport\fR, using the protocol specified by
+\fB\-\-proxy\-type\fR\&.
+.sp
+If no port is specified, the proxy protocol\*(Aqs 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
+\fB\-\-proxy\-auth\fR\&.
+.RE
+.PP
+\fB\-\-proxy\-type \fR\fB\fIproto\fR\fR (Specify proxy protocol)
+.RS 4
+In connect mode, this option requests the protocol
+\fIproto\fR
+to connect through the proxy host specified by
+\fB\-\-proxy\fR\&. In listen mode, this option has Ncat act as a proxy server using the specified protocol\&.
+.sp
+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\&.
+.RE
+.PP
+\fB\-\-proxy\-auth \fR\fB\fIuser\fR\fR\fB[:\fIpass\fR]\fR (Specify proxy credentials)
+.RS 4
+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
+\fB\-\-proxy\-type http\fR
+or
+\fB\-\-proxy\-type socks5\fR, the form should be username:password\&. For
+\fB\-\-proxy\-type socks4\fR, it should be a username only\&.
+.sp
+These credentials can be alternatively passed onto Ncat by setting environment variable
+\fBNCAT_PROXY_AUTH\fR, which reduces the risk of the credentials being captured in process logs\&. (Option
+\fB\-\-proxy\-auth\fR
+takes precedence\&.)
+.RE
+.PP
+\fB\-\-proxy\-dns \fR\fB\fItype\fR\fR (Specify where to resolve proxy destination)
+.RS 4
+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
+\fItype\fR
+are:
+.sp
+local
+\- Hostnames are resolved locally on the Ncat host\&. Ncat exits with error if the hostname cannot be resolved\&.
+.sp
+remote
+\- Hostnames are passed directly onto the remote proxy server\&. This is the default behavior\&.
+.sp
+both
+\- Hostname resolution is first attempted on the Ncat host\&. Unresolvable hostnames are passed onto the remote proxy server\&.
+.sp
+none
+\- Hostname resolution is completely disabled\&. Only a literal IPv4 or IPv6 address can be used as the proxy destination\&.
+.sp
+Local hostname resolution generally respects IP version specified with options
+\fB\-4\fR
+or
+\fB\-6\fR, except for SOCKS4, which is incompatible with IPv6\&.
+.RE
+.SH "COMMAND EXECUTION OPTIONS"
+.PP
+\fB\-e \fR\fB\fIcommand\fR\fR, \fB\-\-exec \fR\fB\fIcommand\fR\fR (Execute command)
+.RS 4
+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
+\fB\-\-keep\-open\fR, 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
+\fB\-m\fR
+option\&. By default this is set to 100 (60 on Windows)\&.
+.RE
+.PP
+\fB\-c \fR\fB\fIcommand\fR\fR, \fB\-\-sh\-exec \fR\fB\fIcommand\fR\fR (Execute command via sh)
+.RS 4
+Same as
+\fB\-e\fR, except it tries to execute the command via
+/bin/sh\&. This means you don\*(Aqt have to specify the full path for the command, and shell facilities like environment variables are available\&.
+.RE
+.PP
+\fB\-\-lua\-exec \fR\fB\fIfile\fR\fR (Execute a \&.lua script)
+.RS 4
+Runs the specified file as a Lua script after a connection has been established, using a built\-in interpreter\&. Both the script\*(Aqs standard input and the standard output are redirected to the connection data streams\&.
+.RE
+.PP
+All exec options add the following variables to the child\*(Aqs environment:
+.PP
+\fBNCAT_REMOTE_ADDR\fR, \fBNCAT_REMOTE_PORT\fR
+.RS 4
+The IP address and port number of the remote host\&. In connect mode, it\*(Aqs the target\*(Aqs address; in listen mode, it\*(Aqs the client\*(Aqs address\&.
+.RE
+.PP
+\fBNCAT_LOCAL_ADDR\fR, \fBNCAT_LOCAL_PORT\fR
+.RS 4
+The IP address and port number of the local end of the connection\&.
+.RE
+.PP
+\fBNCAT_PROTO\fR
+.RS 4
+The protocol in use: one of
+TCP,
+UDP, and
+SCTP\&.
+.RE
+.SH "ACCESS CONTROL OPTIONS"
+.PP
+\fB\-\-allow \fR\fB\fIhost\fR\fR\fB[,\fIhost\fR,\&.\&.\&.]\fR (Allow connections)
+.RS 4
+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
+\fB\-\-allow\fR
+and
+\fB\-\-deny\fR,
+\fB\-\-allow\fR
+takes precedence\&. Host specifications follow the same syntax used by Nmap\&.
+.RE
+.PP
+\fB\-\-allowfile \fR\fB\fIfile\fR\fR (Allow connections from file)
+.RS 4
+This has the same functionality as
+\fB\-\-allow\fR, except that the allowed hosts are provided in a new\-line delimited allow file, rather than directly on the command line\&.
+.RE
+.PP
+\fB\-\-deny \fR\fB\fIhost\fR\fR\fB[,\fIhost\fR,\&.\&.\&.]\fR (Deny connections)
+.RS 4
+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
+\fB\-\-allow\fR
+and
+\fB\-\-deny\fR,
+\fB\-\-allow\fR
+takes precedence\&. Host specifications follow the same syntax used by Nmap\&.
+.RE
+.PP
+\fB\-\-denyfile \fR\fB\fIfile\fR\fR (Deny connections from file)
+.RS 4
+This is the same functionality as
+\fB\-\-deny\fR, except that excluded hosts are provided in a new\-line delimited deny file, rather than directly on the command line\&.
+.RE
+.SH "TIMING OPTIONS"
+.PP
+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\&.
+.PP
+\fB\-d \fR\fB\fItime\fR\fR, \fB\-\-delay \fR\fB\fItime\fR\fR (Specify line delay)
+.RS 4
+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
+\fBiptables \-\-limit\fR
+options\&.
+.RE
+.PP
+\fB\-i \fR\fB\fItime\fR\fR, \fB\-\-idle\-timeout \fR\fB\fItime\fR\fR (Specify idle timeout)
+.RS 4
+Set a fixed timeout for idle connections\&. If the idle timeout is reached, the connection is terminated\&.
+.RE
+.PP
+\fB\-w \fR\fB\fItime\fR\fR, \fB\-\-wait \fR\fB\fItime\fR\fR (Specify connect timeout)
+.RS 4
+Set a fixed timeout for connection attempts\&.
+.RE
+.SH "OUTPUT OPTIONS"
+.PP
+\fB\-o \fR\fB\fIfile\fR\fR, \fB\-\-output \fR\fB\fIfile\fR\fR (Save session data)
+.RS 4
+Dump session data to a file
+.RE
+.PP
+\fB\-x \fR\fB\fIfile\fR\fR, \fB\-\-hex\-dump \fR\fB\fIfile\fR\fR (Save session data in hex)
+.RS 4
+Dump session data in hex to a file\&.
+.RE
+.PP
+\fB\-\-append\-output\fR (Append output)
+.RS 4
+Issue Ncat with
+\fB\-\-append\-ouput\fR
+along with
+\fB\-o\fR
+and/or
+\fB\-x\fR
+and it will append the resulted output rather than truncating the specified output files\&.
+.RE
+.PP
+\fB\-v\fR, \fB\-\-verbose\fR (Be verbose)
+.RS 4
+Issue Ncat with
+\fB\-v\fR
+and it will be verbose and display all kinds of useful connection based information\&. Use more than once (\fB\-vv\fR,
+\fB\-vvv\fR\&.\&.\&.) for greater verbosity\&.
+.RE
+.SH "MISC OPTIONS"
+.PP
+\fB\-C\fR, \fB\-\-crlf\fR (Use CRLF as EOL)
+.RS 4
+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\&.
+.RE
+.PP
+\fB\-h\fR, \fB\-\-help\fR (Help screen)
+.RS 4
+Displays a short help screen with common options and parameters, and then exits\&.
+.RE
+.PP
+\fB\-\-recv\-only\fR (Only receive data)
+.RS 4
+If this option is passed, Ncat will only receive data and will not try to send anything\&.
+.RE
+.PP
+\fB\-\-send\-only\fR (Only send data)
+.RS 4
+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\&.
+.RE
+.PP
+\fB\-\-no\-shutdown\fR (Do not shutdown into half\-duplex mode)
+.RS 4
+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 \*(Aq\-d\*(Aq option\&.
+.RE
+.PP
+\fB\-n\fR, \fB\-\-nodns\fR (Do not resolve hostnames)
+.RS 4
+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
+\fB\-\-proxy\-dns\fR\&.)
+.RE
+.PP
+\fB\-t\fR, \fB\-\-telnet\fR (Answer Telnet negotiations)
+.RS 4
+Handle DO/DONT WILL/WONT Telnet negotiations\&. This makes it possible to script Telnet sessions with Ncat\&.
+.RE
+.PP
+\fB\-\-version\fR (Display version)
+.RS 4
+Displays the Ncat version number and exits\&.
+.RE
+.SH "UNIX DOMAIN SOCKETS"
+.PP
+The
+\fB\-U\fR
+option (same as
+\fB\-\-unixsock\fR) 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,
+.PP
+\fBncat \-U ~/unixsock\fR
+.PP
+To listen on a socket:
+.PP
+\fBncat \-l \-U ~/unixsock\fR
+.PP
+Listen mode will create the socket if it doesn\*(Aqt exist\&. The socket will continue to exist after the program ends\&.
+.PP
+Both stream and datagram domain sockets are supported\&. Use
+\fB\-U\fR
+on its own for stream sockets, or combine it with
+\fB\-\-udp\fR
+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
+\fB\-\-source\fR
+with a path to use a source socket with a specific name\&.
+.SH "AF_VSOCK SOCKETS"
+.PP
+The
+\fB\-\-vsock\fR
+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,
+.PP
+\fBncat \-\-vsock 2 1234\fR
+.PP
+To listen on a socket:
+.PP
+\fBncat \-l \-\-vsock 1234\fR
+.PP
+Both stream and datagram domain sockets are supported, but socket type availability depends on the hypervisor\&. Use
+\fB\-\-vsock\fR
+on its own for stream sockets, or combine it with
+\fB\-\-udp\fR
+for datagram sockets\&.
+.SH "EXAMPLES"
+.PP
+Connect to example\&.org on TCP port 8080\&.
+.RS 4
+\fBncat example\&.org 8080\fR
+.RE
+.PP
+Listen for connections on TCP port 8080\&.
+.RS 4
+\fBncat \-l 8080\fR
+.RE
+.PP
+Redirect TCP port 8080 on the local machine to host on port 80\&.
+.RS 4
+\fBncat \-\-sh\-exec "ncat example\&.org 80" \-l 8080 \-\-keep\-open\fR
+.RE
+.PP
+Bind to TCP port 8081 and attach /bin/bash for the world to access freely\&.
+.RS 4
+\fBncat \-\-exec "/bin/bash" \-l 8081 \-\-keep\-open\fR
+.RE
+.PP
+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\&.
+.RS 4
+\fBncat \-\-exec "/bin/bash" \-\-max\-conns 3 \-\-allow 192\&.168\&.0\&.0/24 \-l 8081 \-\-keep\-open\fR
+.RE
+.PP
+Connect to smtphost:25 through a SOCKS4 server on port 1080\&.
+.RS 4
+\fBncat \-\-proxy socks4host \-\-proxy\-type socks4 \-\-proxy\-auth joe smtphost 25\fR
+.RE
+.PP
+Connect to smtphost:25 through a SOCKS5 server on port 1080\&.
+.RS 4
+\fBncat \-\-proxy socks5host \-\-proxy\-type socks5 \-\-proxy\-auth joe:secret smtphost 25\fR
+.RE
+.PP
+Create an HTTP proxy server on localhost port 8888\&.
+.RS 4
+\fBncat \-l \-\-proxy\-type http localhost 8888\fR
+.RE
+.PP
+Send a file over TCP port 9899 from host2 (client) to host1 (server)\&.
+.RS 4
+HOST1$
+\fBncat \-l 9899 > outputfile\fR
+.sp
+HOST2$
+\fBncat HOST1 9899 < inputfile\fR
+.RE
+.PP
+Transfer in the other direction, turning Ncat into a \(lqone file\(rq server\&.
+.RS 4
+HOST1$
+\fBncat \-l 9899 < inputfile\fR
+.sp
+HOST2$
+\fBncat HOST1 9899 > outputfile\fR
+.RE
+.SH "EXIT CODE"
+.PP
+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
+\(lqConnection refused\(rq
+or
+\(lqConnection reset\(rq\&. 2 is reserved for all other errors, like an invalid option or a nonexistent file\&.
+.SH "BUGS"
+.PP
+Like its authors, Ncat isn\*(Aqt perfect\&. But you can help make it better by sending bug reports or even writing patches\&. If Ncat doesn\*(Aqt behave the way you expect, first upgrade to the latest version available from
+\m[blue]\fB\%https://nmap.org\fR\m[]\&. 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
+\m[blue]\fB\%https://seclists.org/\fR\m[]\&.
+
+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\&.
+.PP
+Code patches to fix bugs are even better than bug reports\&. Basic instructions for creating patch files with your changes are available at
+\m[blue]\fB\%https://svn.nmap.org/nmap/HACKING\fR\m[]\&. Patches may be sent to
+nmap\-dev
+(recommended) or to Fyodor directly\&.
+.SH "AUTHORS"
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Chris Gibson
+<chris@linuxops\&.net>
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Gordon Lyon (Fyodor)<fyodor@nmap\&.org>
+(\m[blue]\fB\%http://insecure.org\fR\m[])
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Kris Katterjohn
+<katterjohn@gmail\&.com>
+.RE
+.sp
+.RS 4
+.ie n \{\
+\h'-04'\(bu\h'+03'\c
+.\}
+.el \{\
+.sp -1
+.IP \(bu 2.3
+.\}
+Mixter
+<mixter@gmail\&.com>
+.RE
+.PP
+The original Netcat was written by *Hobbit*
+<hobbit@avian\&.org>\&. While Ncat isn\*(Aqt built on any code from the
+\(lqtraditional\(rq
+Netcat (or any other implementation), Ncat is most definitely based on Netcat in spirit and functionality\&.
+.SH "LEGAL NOTICES"
+.SS "Ncat Copyright and Licensing"
+.PP
+Ncat is (C) 2005\(en2022 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 \m[blue]\fB\%https://nmap.org/man/man-legal.html\fR\m[]\&.
+.SS "Creative Commons License for this Ncat Guide"
+.PP
+This
+Ncat Reference Guide
+is (C) 2005\(en2022 Nmap Software LLC\&. It is hereby placed under version 3\&.0 of the
+\m[blue]\fBCreative Commons Attribution License\fR\m[]\&\s-2\u[1]\d\s+2\&. 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)\&.
+.SS "Source Code Availability and Community Contributions"
+.PP
+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)\&.
+.PP
+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\&.
+.SS "No Warranty"
+.PP
+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
+\m[blue]\fB\%https://nmap.org/npsl/\fR\m[], or in the
+LICENSE
+file included with Nmap\&.
+.SS "Inappropriate Usage"
+.PP
+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\&.
+.SS "Third\-Party Software"
+.PP
+This product includes software developed by the
+\m[blue]\fBApache Software Foundation\fR\m[]\&\s-2\u[2]\d\s+2\&. A modified version of the
+\m[blue]\fBLibpcap portable packet capture library\fR\m[]\&\s-2\u[3]\d\s+2
+is distributed along with Ncat\&. The Windows version of Ncat utilized the Libpcap\-derived
+\m[blue]\fBNpcap library\fR\m[]\&\s-2\u[4]\d\s+2
+instead\&. Certain raw networking functions use the
+\m[blue]\fBLibdnet\fR\m[]\&\s-2\u[5]\d\s+2
+networking library, which was written by Dug Song\&.
+A modified version is distributed with Ncat\&. Ncat can optionally link with the
+\m[blue]\fBOpenSSL cryptography toolkit\fR\m[]\&\s-2\u[6]\d\s+2
+for SSL version detection support\&. All of the third\-party software described in this paragraph is freely redistributable under BSD\-style software licenses\&.
+.SH "NOTES"
+.IP " 1." 4
+Creative Commons Attribution License
+.RS 4
+\%http://creativecommons.org/licenses/by/3.0/
+.RE
+.IP " 2." 4
+Apache Software Foundation
+.RS 4
+\%http://www.apache.org
+.RE
+.IP " 3." 4
+Libpcap portable packet capture library
+.RS 4
+\%http://www.tcpdump.org
+.RE
+.IP " 4." 4
+Npcap library
+.RS 4
+\%https://npcap.com
+.RE
+.IP " 5." 4
+Libdnet
+.RS 4
+\%http://libdnet.sourceforge.net
+.RE
+.IP " 6." 4
+OpenSSL cryptography toolkit
+.RS 4
+\%http://www.openssl.org
+.RE
diff --git a/ncat/docs/ncat.usage.txt b/ncat/docs/ncat.usage.txt
new file mode 100644
index 0000000..d965963
--- /dev/null
+++ b/ncat/docs/ncat.usage.txt
@@ -0,0 +1,57 @@
+Ncat 7.94SVN ( 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
+ --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
diff --git a/ncat/docs/ncat.xml b/ncat/docs/ncat.xml
new file mode 100644
index 0000000..d202843
--- /dev/null
+++ b/ncat/docs/ncat.xml
@@ -0,0 +1,1225 @@
+<refentry id="ncatman">
+ <refmeta>
+ <refentrytitle>Ncat</refentrytitle>
+ <manvolnum>1</manvolnum>
+ <refmiscinfo class="source">Ncat</refmiscinfo>
+ <refmiscinfo class="manual">Ncat Reference Guide</refmiscinfo>
+ </refmeta>
+
+ <refnamediv id="ncat-man-name">
+ <refname>ncat</refname>
+ <refpurpose>Concatenate and redirect sockets</refpurpose>
+ </refnamediv>
+
+ <refsynopsisdiv id="ncat-man-synopsis">
+ <cmdsynopsis>
+ <command>ncat</command>
+ <arg choice="opt" rep="repeat">
+ <replaceable>OPTIONS</replaceable>
+ </arg>
+ <arg choice="opt">
+ <replaceable>hostname</replaceable>
+ </arg>
+ <arg choice="opt">
+ <replaceable>port</replaceable>
+ </arg>
+ </cmdsynopsis>
+ </refsynopsisdiv>
+
+ <refsect1 id="ncat-man-description">
+ <title>Description</title>
+
+ <para>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.</para>
+
+ <para>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.</para>
+ </refsect1>
+
+ <refsect1 id="ncat-man-options-summary">
+ <title>Options Summary</title>
+
+ <para>
+<screen><xi:include href="ncat.usage.txt" parse="text" xmlns:xi="http://www.w3.org/2001/XInclude" /></screen>
+ </para>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-modes">
+ <indexterm><primary>connect mode (Ncat)</primary></indexterm>
+ <indexterm><primary>client mode (Ncat)</primary><see>connect mode</see></indexterm>
+ <indexterm><primary>listen mode (Ncat)</primary></indexterm>
+ <indexterm><primary>server mode (Ncat)</primary><see>listen mode</see></indexterm>
+ <title>Connect Mode and Listen Mode</title>
+
+ <para>
+ 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.
+ </para>
+
+ <para>
+ In connect mode, the <option><replaceable>hostname</replaceable></option>
+ and <option><replaceable>port</replaceable></option> arguments tell
+ what to connect to.
+ <option><replaceable>hostname</replaceable></option> is required,
+ and may be a hostname or IP address. If
+ <option><replaceable>port</replaceable></option> is supplied, it
+ must be a decimal port number. If omitted, it defaults to
+ 31337.<indexterm><primary>default port of Ncat</primary></indexterm><indexterm><primary>31337</primary><see>default port of Ncat</see></indexterm>
+ </para>
+
+ <para>
+ In listen mode, <option><replaceable>hostname</replaceable></option>
+ and <option><replaceable>port</replaceable></option> control the
+ address the server will bind to. Both arguments are optional in
+ listen mode. If <option><replaceable>hostname</replaceable></option>
+ is omitted, it defaults to listening on all available addresses over
+ IPv4 and IPv6. If <option><replaceable>port</replaceable></option> is
+ omitted, it defaults to 31337.
+ </para>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-proto-options">
+ <title>Protocol Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-4</option> (IPv4 only)
+ <indexterm><primary><option>-4</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Force the use of IPv4 only.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-6</option> (IPv6 only)
+ <indexterm><primary><option>-6</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Force the use of IPv6 only.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-U</option>,
+ <option>--unixsock</option> (Use Unix domain sockets)
+ <indexterm><primary><option>--unixsock</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-U</option> (Ncat option)</primary><see><option>--unixsock</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Use Unix domain sockets rather than network sockets.
+ This option may be used on its own for stream sockets, or
+ combined with <option>--udp</option> for datagram sockets.
+ A description of <option>-U</option> mode is in
+ <xref linkend="ncat-man-unixsock"/>.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-u</option>,
+ <option>--udp</option> (Use UDP)
+ <indexterm><primary><option>--udp</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-u</option> (Ncat option)</primary><see><option>--udp</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Use UDP for the connection (the default is TCP).</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--sctp</option> (Use SCTP)
+ <indexterm><primary><option>--sctp</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Use SCTP for the connection (the default is TCP).
+ SCTP support is implemented in TCP-compatible mode.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--vsock</option> (Use AF_VSOCK sockets)
+ <indexterm><primary><option>--vsock</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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 <option>--udp</option> for datagram sockets.
+ A description of <option>--vsock</option> mode is in
+ <xref linkend="ncat-man-vsock"/>.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-connect-options">
+ <title>Connect Mode Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-g <replaceable>hop1</replaceable><optional>,<replaceable>hop2</replaceable>,...</optional></option> (Loose source routing)
+ <indexterm><primary><option>-g</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Sets hops for IPv4 loose source routing. You can use <option>-g</option>
+ once with a comma-separated list of hops, use <option>-g</option> multiple
+ times with single hops to build the list, or combine the two. Hops can be
+ given as IP addresses or hostnames.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-G <replaceable>ptr</replaceable></option> (Set source routing pointer)
+ <indexterm><primary><option>-G</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Sets the IPv4 source route <quote>pointer</quote> for use with <option>-g</option>.
+ 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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-p <replaceable>port</replaceable></option>,
+ <option>--source-port <replaceable>port</replaceable></option> (Specify source port)
+ <indexterm><primary><option>--source-port</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-p</option> (Ncat option)</primary><see><option>--source-port</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Set the port number for Ncat to bind to.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-s <replaceable>host</replaceable></option>,
+ <option>--source <replaceable>host</replaceable></option> (Specify source address)
+ <indexterm><primary><option>--source</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-s</option> (Ncat option)</primary><see><option>--source</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Set the address for Ncat to bind to.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-listen-options">
+ <title>Listen Mode Options</title>
+
+ <para>See <xref linkend="ncat-man-access-options"/> for information on limiting the
+ hosts that may connect to the listening Ncat process.</para>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-l</option>,
+ <option>--listen</option> (Listen for connections)
+ <indexterm><primary><option>--listen</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-l</option> (Ncat option)</primary><see><option>--listen</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Listen for connections rather than connecting to a remote
+ machine</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-m <replaceable>numconns</replaceable></option>,
+ <option>--max-conns <replaceable>numconns</replaceable></option> (Specify maximum number of connections)
+ <indexterm><primary><option>--max-conns</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-m</option> (Ncat option)</primary><see><option>--max-conns</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>The maximum number of simultaneous connections accepted by an Ncat
+ instance. 100 is the default (60 on Windows).</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-k</option>,
+ <option>--keep-open</option> (Accept multiple connections)
+ <indexterm><primary><option>--keep-open</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-k</option> (Ncat option)</primary><see><option>--keep-open</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>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
+ <option>--listen</option>. 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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--broker</option> (Connection brokering)
+ <indexterm><primary><option>--broker</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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 <option>--listen</option>, which
+ causes the <option>--listen</option> port to have broker mode enabled.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--chat</option> (Ad-hoc <quote>chat server</quote>)
+ <indexterm><primary><option>--chat</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>The <option>--chat</option> 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.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-ssl-options">
+ <title>SSL Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>--ssl</option> (Use SSL)
+ <indexterm><primary><option>--ssl</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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.</para>
+ <para>In server mode, this option listens for incoming SSL connections,
+ rather than plain untunneled traffic.</para>
+ <para>In UDP mode, this option enables Datagram TLS (DTLS).
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-verify</option> (Verify server certificates)
+ <indexterm><primary><option>--ssl-verify</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>In client mode, <option>--ssl-verify</option> is like
+ <option>--ssl</option> except that it also requires verification of
+ the server certificate. Ncat comes with a default set of trusted
+ certificates in the file
+ <filename>ca-bundle.crt</filename>.<indexterm><primary><filename>ca-bundle.crt</filename></primary></indexterm>
+ Some operating systems provide a default list of
+ trusted certificates; these will also be used if available. Use
+ <option>--ssl-trustfile</option> to give a custom list. Use
+ <option>-v</option> one or more times to get details about
+ verification failures.</para>
+ <indexterm><primary>revoked certificates</primary><see>certificate revocation</see></indexterm>
+ <para>Ncat does not check for revoked
+ certificates.<indexterm><primary>certification revocation</primary></indexterm></para>
+ <para>This option has no effect in server mode.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-cert <replaceable>certfile.pem</replaceable></option> (Specify SSL certificate)
+ <indexterm><primary><option>--ssl-cert</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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 <option>--ssl-key</option>.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-key <replaceable>keyfile.pem</replaceable></option> (Specify SSL private key)
+ <indexterm><primary><option>--ssl-key</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>This option gives the location of the PEM-encoded
+ private key file that goes with the certificate named with
+ <option>--ssl-cert</option>.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-trustfile <replaceable>cert.pem</replaceable></option> (List trusted certificates)
+ <indexterm><primary><option>--ssl-trustfile</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>This option sets a list of certificates that are trusted for
+ purposes of certificate verification. It has no effect unless combined
+ with <option>--ssl-verify</option>. The argument to this option is the
+ name of a PEM<indexterm><primary>PEM (Privacy Enhanced Mail)</primary></indexterm>
+ 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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-ciphers <replaceable>cipherlist</replaceable></option> (Specify SSL ciphersuites)
+ <indexterm><primary><option>--ssl-ciphers</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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
+ <literal>ALL:!aNULL:!eNULL:!LOW:!EXP:!RC4:!MD5:@STRENGTH</literal></para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-servername <replaceable>name</replaceable></option> (Request distinct server name)
+ <indexterm><primary><option>--ssl-servername</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--ssl-alpn <replaceable>ALPN list</replaceable></option> (Specify ALPN protocol list)
+ <indexterm><primary><option>--ssl-alpn</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-proxy-options">
+ <title>Proxy Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>--proxy <replaceable>host</replaceable><optional>:<replaceable>port</replaceable></optional></option> (Specify proxy address)
+ <indexterm><primary><option>--proxy</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Requests proxying through <replaceable>host</replaceable>:<replaceable>port</replaceable>,
+ using the protocol specified by <option>--proxy-type</option>.</para>
+
+ <para>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 <option>--proxy-auth</option>.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--proxy-type <replaceable>proto</replaceable></option> (Specify proxy protocol)
+ <indexterm><primary><option>--proxy-type</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>In connect mode, this option requests the protocol <replaceable>proto</replaceable>
+ to connect through the proxy host specified by <option>--proxy</option>. In listen mode,
+ this option has Ncat act as a proxy server using the specified protocol.</para>
+
+ <para>The currently available protocols in connect mode are <literal>http</literal>
+ (CONNECT), <literal>socks4</literal> (SOCKSv4), and
+ <literal>socks5</literal> (SOCKSv5).
+ The only server currently supported is <literal>http</literal>.
+ If this option is not used, the default protocol is <literal>http</literal>.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--proxy-auth <replaceable>user</replaceable><optional>:<replaceable>pass</replaceable></optional></option> (Specify proxy credentials)
+ <indexterm><primary><option>--proxy-auth</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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
+ <option>--proxy-type http</option> or
+ <option>--proxy-type socks5</option>, the form should be
+ username:password. For
+ <option>--proxy-type socks4</option>, it should be a username only.</para>
+ <para>These credentials can be alternatively passed onto Ncat by
+ setting environment variable
+ <envar>NCAT_PROXY_AUTH</envar><indexterm><primary><envar>NCAT_PROXY_AUTH</envar> environment variable</primary></indexterm>,
+ which reduces the risk of the credentials being captured in process
+ logs. (Option <option>--proxy-auth</option> takes precedence.)</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--proxy-dns <replaceable>type</replaceable></option> (Specify where to resolve proxy destination)
+ <indexterm><primary><option>--proxy-dns</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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 <replaceable>type</replaceable> are:</para>
+
+ <para><literal>local</literal> - Hostnames are resolved locally on
+ the Ncat host. Ncat exits with error if the hostname cannot be
+ resolved.</para>
+
+ <para><literal>remote</literal> - Hostnames are passed directly onto
+ the remote proxy server. This is the default behavior.</para>
+
+ <para><literal>both</literal> - Hostname resolution is first
+ attempted on the Ncat host. Unresolvable hostnames are passed onto
+ the remote proxy server.</para>
+
+ <para><literal>none</literal> - Hostname resolution is completely
+ disabled. Only a literal IPv4 or IPv6 address can be used as
+ the proxy destination.</para>
+
+ <para>Local hostname resolution generally respects IP version
+ specified with options <option>-4</option> or <option>-6</option>,
+ except for SOCKS4, which is incompatible with IPv6.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-command-options">
+ <title>Command Execution Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-e <replaceable>command</replaceable></option>,
+ <option>--exec <replaceable>command</replaceable></option> (Execute command)
+ <indexterm><primary><option>--exec</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-e</option> (Ncat option)</primary><see><option>--exec</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>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 <option>--keep-open</option>,
+ 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>-m</option> option. By default this is set
+ to 100 (60 on Windows).</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-c <replaceable>command</replaceable></option>,
+ <option>--sh-exec <replaceable>command</replaceable></option> (Execute command via sh)
+ <indexterm><primary><option>--sh-exec</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-c</option> (Ncat option)</primary><see><option>--sh-exec</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Same as <option>-e</option>, except it tries to execute
+ the command via <filename>/bin/sh</filename>. This means you don't
+ have to specify the full path for the command, and shell facilities
+ like environment variables are available.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--lua-exec <replaceable>file</replaceable></option> (Execute a .lua script)
+ <indexterm><primary><option>--lua-exec</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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.</para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+
+ <para>All exec options add the following variables to the child's environment:</para>
+ <variablelist>
+ <varlistentry>
+ <term><envar>NCAT_REMOTE_ADDR</envar></term><indexterm><primary><envar>NCAT_REMOTE_ADDR></envar> environment variable</primary></indexterm>
+ <term><envar>NCAT_REMOTE_PORT</envar></term><indexterm><primary><envar>NCAT_REMOTE_PORT></envar> environment variable</primary></indexterm>
+ <listitem>
+ <para>
+ 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.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>NCAT_LOCAL_ADDR</envar></term><indexterm><primary><envar>NCAT_LOCAL_ADDR></envar> environment variable</primary></indexterm>
+ <term><envar>NCAT_LOCAL_PORT</envar></term><indexterm><primary><envar>NCAT_LOCAL_PORT></envar> environment variable</primary></indexterm>
+ <listitem>
+ <para>
+ The IP address and port number of the local end of the connection.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>NCAT_PROTO</envar></term><indexterm><primary><envar>NCAT_PROTO></envar> environment variable</primary></indexterm>
+ <listitem>
+ <para>
+ The protocol in use: one of <code>TCP</code>, <code>UDP</code>, and <code>SCTP</code>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 id="ncat-man-access-options">
+ <title>Access Control Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>--allow <replaceable>host</replaceable><optional>,<replaceable>host</replaceable>,...</optional></option> (Allow connections)
+ <indexterm><primary><option>--allow</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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
+ <option>--allow</option> and <option>--deny</option>,
+ <option>--allow</option> takes precedence. Host
+ specifications follow the same syntax used
+ by Nmap.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--allowfile <replaceable>file</replaceable></option> (Allow connections from file)
+ <indexterm><primary><option>--allowfile</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>This has the same functionality as <option>--allow</option>,
+ except that the allowed hosts are provided in a new-line delimited allow
+ file, rather than directly on the command line.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--deny <replaceable>host</replaceable><optional>,<replaceable>host</replaceable>,...</optional></option> (Deny connections)
+ <indexterm><primary><option>--deny</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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
+ <option>--allow</option> and <option>--deny</option>,
+ <option>--allow</option> takes precedence. Host
+ specifications follow the same syntax used by Nmap.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--denyfile <replaceable>file</replaceable></option> (Deny connections from file)
+ <indexterm><primary><option>--denyfile</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>This is the same functionality as <option>--deny</option>,
+ except that excluded hosts are provided in a new-line delimited deny
+ file, rather than directly on the command line.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-timing-options">
+ <title>Timing Options</title>
+
+ <para>These options accept a <literal>time</literal> parameter. This is specified
+ in seconds by default, though you can append <literal>ms</literal>, <literal>s</literal>, <literal>m</literal>,
+ or <literal>h</literal> to the value to specify milliseconds, seconds, minutes, or hours.</para>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-d <replaceable>time</replaceable></option>,
+ <option>--delay <replaceable>time</replaceable></option> (Specify line delay)
+ <indexterm><primary><option>--delay</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-d</option> (Ncat option)</primary><see><option>--delay</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>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 <command>iptables --limit</command> options.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-i <replaceable>time</replaceable></option>,
+ <option>--idle-timeout <replaceable>time</replaceable></option> (Specify idle timeout)
+ <indexterm><primary><option>--idle-timeout</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-i</option> (Ncat option)</primary><see><option>--idle-timeout</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Set a fixed timeout for idle connections. If the idle timeout
+ is reached, the connection is terminated.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-w <replaceable>time</replaceable></option>,
+ <option>--wait <replaceable>time</replaceable></option> (Specify connect timeout)
+ <indexterm><primary><option>--wait</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-w</option> (Ncat option)</primary><see><option>--wait</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Set a fixed timeout for connection attempts.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-output-options">
+ <title>Output Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-o <replaceable>file</replaceable></option>,
+ <option>--output <replaceable>file</replaceable></option> (Save session data)
+ <indexterm><primary><option>--output</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-o</option> (Ncat option)</primary><see><option>--output</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Dump session data to a file</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-x <replaceable>file</replaceable></option>,
+ <option>--hex-dump <replaceable>file</replaceable></option> (Save session data in hex)
+ <indexterm><primary><option>--hex-dump</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-x</option> (Ncat option)</primary><see><option>--hex-dump</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Dump session data in hex to a file.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--append-output</option> (Append output)
+ <indexterm><primary><option>--append-output</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Issue Ncat with <option>--append-ouput</option> along with
+ <option>-o</option> and/or <option>-x</option> and it will append
+ the resulted output rather than truncating the specified output files.
+ </para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-v</option>,
+ <option>--verbose</option> (Be verbose)
+ <indexterm><primary><option>--verbose</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-v</option> (Ncat option)</primary><see><option>--verbose</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Issue Ncat with <option>-v</option> and it will be verbose and
+ display all kinds of useful connection based information. Use more
+ than once (<option>-vv</option>, <option>-vvv</option>...) for greater
+ verbosity.</para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-misc-options">
+ <title>Misc Options</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ <option>-C</option>,
+ <option>--crlf</option> (Use CRLF as EOL)
+ <indexterm><primary><option>--crlf</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-C</option> (Ncat option)</primary><see><option>--crlf</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>This option tells Ncat to convert
+ LF<indexterm><primary>LF line ending</primary></indexterm>
+ line endings to
+ CRLF<indexterm><primary>CRLF line ending</primary></indexterm>
+ when taking input from
+ standard input.<indexterm><primary>standard input</primary></indexterm>
+ 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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-h</option>,
+ <option>--help</option> (Help screen)
+ <indexterm><primary><option>--help</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-h</option> (Ncat option)</primary><see><option>--help</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Displays a short help screen with common options and parameters,
+ and then exits.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--recv-only</option> (Only receive data)
+ <indexterm><primary><option>--recv-only</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>If this option is passed, Ncat will only receive data and will
+ not try to send anything.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--send-only</option> (Only send data)
+ <indexterm><primary><option>--send-only</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--no-shutdown</option> (Do not shutdown into half-duplex mode)
+ <indexterm><primary><option>--no-shutdown</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>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.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-n</option>,
+ <option>--nodns</option> (Do not resolve hostnames)
+ <indexterm><primary><option>--nodns</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-n</option> (Ncat option)</primary><see><option>--nodns</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>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 <option>--proxy-dns</option>.)</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>-t</option>,
+ <option>--telnet</option> (Answer Telnet negotiations)
+ <indexterm><primary><option>--telnet</option> (Ncat option)</primary></indexterm>
+ <indexterm><primary><option>-t</option> (Ncat option)</primary><see><option>--telnet</option></see></indexterm>
+ </term>
+ <listitem>
+ <para>Handle DO/DONT WILL/WONT Telnet negotiations. This makes it
+ possible to script Telnet sessions with Ncat.</para>
+ </listitem>
+ </varlistentry>
+
+ <varlistentry>
+ <term>
+ <option>--version</option> (Display version)
+ <indexterm><primary><option>--version</option> (Ncat option)</primary></indexterm>
+ </term>
+ <listitem>
+ <para>Displays the Ncat version number and exits.</para>
+ </listitem>
+ </varlistentry>
+
+ </variablelist>
+ </refsect1>
+
+ <refsect1 id="ncat-man-unixsock">
+ <title>Unix Domain Sockets</title>
+
+ <para>
+ The <option>-U</option> option (same as <option>--unixsock</option>)
+ 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,
+ </para>
+ <para><command>ncat -U ~/unixsock</command></para>
+ <para>
+ To listen on a socket:
+ </para>
+ <para><command>ncat -l -U ~/unixsock</command></para>
+ <para>
+ Listen mode will create the socket if it doesn't exist. The socket
+ will continue to exist after the program ends.
+ </para>
+
+ <para>
+ Both stream and datagram domain sockets are supported. Use
+ <option>-U</option> on its own for stream sockets, or
+ combine it with <option>--udp</option> 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
+ <option>--source</option> with a path to use a source socket with a
+ specific name.
+ </para>
+
+ </refsect1>
+
+ <refsect1 id="ncat-man-vsock">
+ <title>AF_VSOCK Sockets</title>
+
+ <para>
+ The <option>--vsock</option> 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,
+ </para>
+ <para><command>ncat --vsock 2 1234</command></para>
+ <para>
+ To listen on a socket:
+ </para>
+ <para><command>ncat -l --vsock 1234</command></para>
+ <para>
+ Both stream and datagram domain sockets are supported, but socket type
+ availability depends on the hypervisor. Use
+ <option>--vsock</option> on its own for stream sockets, or
+ combine it with <option>--udp</option> for datagram sockets.
+ </para>
+ </refsect1>
+ <refsect1 id="ncat-man-examples">
+ <title>Examples</title>
+
+ <variablelist>
+ <varlistentry>
+ <term>
+ Connect to example.org on TCP port 8080.
+ </term>
+ <listitem>
+ <para><command>ncat example.org 8080</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Listen for connections on TCP port 8080.
+ </term>
+ <listitem>
+ <para><command>ncat -l 8080</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Redirect TCP port 8080 on the local machine to host on port 80.
+ </term>
+ <listitem>
+ <para><command>ncat --sh-exec "ncat example.org 80" -l 8080 --keep-open</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Bind to TCP port 8081 and attach <filename>/bin/bash</filename>
+ for the world to access freely.
+ </term>
+ <listitem>
+ <para><command>ncat --exec "/bin/bash" -l 8081 --keep-open</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ 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.
+ </term>
+ <listitem>
+ <para><command>ncat --exec "/bin/bash" --max-conns 3 --allow 192.168.0.0/24 -l 8081 --keep-open</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Connect to smtphost:25 through a SOCKS4 server on port 1080.
+ </term>
+ <listitem>
+ <para><command>ncat --proxy socks4host --proxy-type socks4 --proxy-auth joe smtphost 25</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Connect to smtphost:25 through a SOCKS5 server on port 1080.
+ </term>
+ <listitem>
+ <para><command>ncat --proxy socks5host --proxy-type socks5 --proxy-auth joe:secret smtphost 25</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Create an HTTP proxy server on localhost port 8888.
+ </term>
+ <listitem>
+ <para><command>ncat -l --proxy-type http localhost 8888</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Send a file over TCP port 9899 from host2 (client) to host1
+ (server).
+ </term>
+ <listitem>
+<para>HOST1$ <command>ncat -l 9899 &gt; outputfile</command></para>
+<para>HOST2$ <command>ncat HOST1 9899 &lt; inputfile</command></para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>
+ Transfer in the other direction, turning Ncat into a <quote>one
+ file</quote> server.
+ </term>
+ <listitem>
+<para>HOST1$ <command>ncat -l 9899 &lt; inputfile</command></para>
+<para>HOST2$ <command>ncat HOST1 9899 &gt; outputfile</command></para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+ </refsect1>
+
+ <refsect1 id="ncat-man-exit-code">
+ <title>Exit Code</title>
+
+ <para>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 <quote>Connection
+ refused</quote> or <quote>Connection reset</quote>. 2 is reserved
+ for all other errors, like an invalid option or a nonexistent
+ file.</para>
+ </refsect1>
+
+ <refsect1 id="ncat-man-bugs">
+ <title>Bugs</title>
+
+ <para>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 <ulink
+ url="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 <citetitle>nmap-dev</citetitle> archives at <ulink
+ url="https://seclists.org/" />.
+ <indexterm><primary><citetitle>nmap-dev</citetitle> mailing list</primary></indexterm>
+ Read this full manual page as
+ well. If nothing comes of this, mail a bug report to
+ <email>dev@nmap.org</email>. 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.</para>
+
+ <para>Code patches to fix bugs are even better than bug reports.
+ Basic instructions for creating patch files with your changes are
+ available at <ulink
+ url="https://svn.nmap.org/nmap/HACKING" />. Patches may
+ be sent to <citetitle>nmap-dev</citetitle> (recommended) or to Fyodor directly.</para>
+ </refsect1>
+
+ <refsect1 id="ncat-man-author">
+ <title>Authors</title>
+
+ <itemizedlist>
+ <listitem>
+ <para>Chris Gibson <email>chris@linuxops.net</email></para>
+ </listitem>
+ <listitem>
+ <para>Gordon Lyon (Fyodor)<email>fyodor@nmap.org</email>
+ (<ulink url="http://insecure.org" />)</para>
+ </listitem>
+ <listitem>
+ <para>Kris Katterjohn <email>katterjohn@gmail.com</email></para>
+ </listitem>
+ <listitem>
+ <para>Mixter <email>mixter@gmail.com</email></para>
+ </listitem>
+ </itemizedlist>
+
+ <para>The original Netcat was written by *Hobbit* <email>hobbit@avian.org</email>.
+ While Ncat isn't built on any code from the <quote>traditional</quote> Netcat (or any
+ other implementation), Ncat is most definitely based on Netcat in spirit
+ and functionality.</para>
+ </refsect1>
+
+ <refsect1 id='ncat-man-legal'>
+ <title>Legal Notices</title>
+
+<refsect2 id="ncat-copyright">
+ <title>Ncat Copyright and Licensing</title>
+ <indexterm><primary>copyright</primary></indexterm>
+
+ <para>Ncat is (C) 2005&ndash;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
+ <man>from <ulink url="https://nmap.org/man/man-legal.html"/>.</man>
+ <notman>in <xref linkend="nmap-copyright"/>.</notman></para>
+</refsect2>
+
+<refsect2 id="ncat-man-copyright">
+ <title>Creative Commons License for this Ncat Guide</title>
+ <para>This <citetitle>Ncat Reference Guide</citetitle> is (C)
+ 2005&ndash;2022 Nmap Software LLC. It is
+ hereby placed under version 3.0 of the <ulink
+ url="http://creativecommons.org/licenses/by/3.0/">Creative Commons
+ Attribution License</ulink>. 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).</para>
+</refsect2>
+
+<refsect2 id="ncat-source-contrib">
+ <title>Source Code Availability and Community Contributions</title>
+
+<para>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).</para>
+
+<para>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
+<email>dev@nmap.org</email> 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,<indexterm><primary>open
+source</primary></indexterm> 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.</para>
+
+</refsect2>
+
+<refsect2 id="ncat-no-warranty"><title>No Warranty<indexterm><primary>warranty (lack of)</primary></indexterm></title>
+
+<para>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 <ulink url="https://nmap.org/npsl/" />,
+or in the <filename>LICENSE</filename> file
+included with Nmap.</para>
+</refsect2>
+
+<refsect2 id="ncat-inappropriate-usage"><title>Inappropriate Usage</title>
+<para>Ncat should never be installed with special privileges
+(e.g. suid root).<indexterm><primary>suid</primary><see>setuid</see></indexterm>
+That would open up a major security vulnerability as other users on the
+system (or attackers) could use it for privilege escalation.
+</para>
+</refsect2>
+
+<refsect2 id="ncat-third-party-soft"><title>Third-Party Software</title>
+
+<para>This product includes software developed by
+the <ulink role="hidepdf" url="http://www.apache.org">Apache Software
+Foundation</ulink>. A modified version of the <ulink role="hidepdf"
+url="http://www.tcpdump.org">Libpcap portable packet capture
+library</ulink><indexterm><primary>libpcap</primary></indexterm>
+is distributed along with Ncat.
+The Windows version of Ncat utilized the Libpcap-derived
+<ulink role="hidepdf" url="https://npcap.com">Npcap library</ulink><indexterm><primary>Npcap</primary></indexterm>
+instead.
+Certain raw networking functions use the
+<ulink role="hidepdf" url="http://libdnet.sourceforge.net">Libdnet</ulink><indexterm><primary>libdnet</primary></indexterm>
+networking library, which was written by Dug Song.<indexterm><primary>Song, Dug</primary></indexterm>
+A modified version is distributed with Ncat.
+Ncat can optionally link with the
+<ulink role="hidepdf" url="http://www.openssl.org">OpenSSL
+cryptography toolkit</ulink><indexterm><primary>OpenSSL</primary></indexterm>
+for SSL version detection support.
+All of the third-party software described in this paragraph is freely
+redistributable under BSD-style software licenses.</para>
+</refsect2>
+</refsect1>
+
+</refentry>
+
diff --git a/ncat/docs/ncatguide.xml b/ncat/docs/ncatguide.xml
new file mode 100644
index 0000000..a1010d4
--- /dev/null
+++ b/ncat/docs/ncatguide.xml
@@ -0,0 +1,2008 @@
+<indexterm significance="preferred" class="startofrange" id="ncat-indexterm"><primary>Ncat</primary></indexterm>
+
+<sect1 id="ncat-overview">
+ <title>Ncat: Your General-Purpose Network Connector</title>
+
+ <para>
+ Ncat is a general-purpose command-line tool for reading, writing,
+ redirecting, and encrypting data across a network. It aims to be
+ your network <ulink role="hidepdf"
+ url="http://en.wikipedia.org/wiki/Swiss_Army_knife">Swiss Army
+ knife</ulink>, handling a wide variety of security testing and
+ administration tasks. Ncat is suitable for interactive use or as a
+ network-connected back end for other tools. Ncat can:
+ </para>
+
+ <itemizedlist>
+
+ <listitem><para>Act as a simple TCP/UDP/SCTP/SSL client for interacting
+ with web servers, telnet servers, mail servers, and other TCP/IP
+ network services. Often the best way to understand a service (for
+ fixing problems, finding security flaws, or testing custom commands)
+ is to interact with it using Ncat. This lets you you control every character
+ sent and view the raw, unfiltered responses.</para></listitem>
+
+ <listitem><para>Act as a simple TCP/UDP/SCTP/SSL server for offering
+ services to clients, or simply to understand what existing clients
+ are up to by capturing every byte they send.</para></listitem>
+
+ <listitem><para>Redirect or proxy TCP/UDP/SCTP traffic to other ports or
+ hosts. This can be done using simple redirection (everything sent
+ to a port is automatically relayed somewhere else you specify in
+ advance) or by acting as a SOCKS or HTTP proxy so clients
+ specify their own destinations. In client mode, Ncat can
+ connect to destinations through a chain of anonymous or
+ authenticated proxies.</para></listitem>
+
+ <listitem><para>Run on all major operating systems. We distribute
+ Linux, Windows, and Mac OS X binaries, and Ncat compiles on most
+ other systems. A trusted tool must be available
+ whenever you need it, no matter what computer you're
+ using.</para></listitem>
+
+ <listitem><para>Encrypt communication with SSL, and transport it over IPv4 or IPv6.</para></listitem>
+
+ <listitem><para>Act as a network gateway for execution of system
+ commands, with I/O redirected to the network. It was designed to work
+ like the Unix utility <command>cat</command>, but for the
+ network.</para></listitem>
+
+ <listitem><para>Act as a connection broker, allowing two (or far
+ more) clients to connect to each other through a third (brokering)
+ server. This enables multiple machines hidden behind NAT gateways
+ to communicate with each other, and also enables the simple Ncat
+ chat mode.</para></listitem>
+ </itemizedlist>
+
+ <para>These capabilities become even more powerful and versatile
+ when combined.</para>
+
+ <para>
+ Ncat is our modern reinvention of the venerable Netcat (nc) tool released by Hobbit in 1996. While Ncat is similar to Netcat in spirit, they don't share any source code. Instead, Ncat makes use of Nmap's well optimized and tested networking
+ libraries. Compatibility with the original Netcat and some well known variants is maintained
+ where it doesn't conflict with Ncat's enhancements or cause
+ usability problems. Ncat adds many capabilities not found in
+ Hobbit's original nc, including SSL support, proxy connections,
+ IPv6, and connection brokering.
+ The original nc contained a simple port
+ scanner, but we omitted that from Ncat because we have a preferred
+ tool for that function.
+ </para>
+
+ <para>
+ This guide starts with examples of basic Ncat usage, then moves on to more advanced features. Those are followed by practical sections which use examples to demonstrate how Ncat can solve common real-world problems. A few neat Ncat tricks are covered as well.
+ </para>
+</sect1>
+
+<!-- Need a discussion of shell syntax, as it's such a big part of using
+the tool? Many of these examples suppose a Unix environment. -->
+
+<sect1 id="ncat-usage">
+ <title>Basic usage</title>
+
+ <para>
+ Ncat always operates in one of two basic modes:
+ <firstterm>connect mode</firstterm><indexterm><primary>connect mode</primary></indexterm> and
+ <firstterm>listen mode</firstterm>.<indexterm><primary>listen mode</primary></indexterm>
+ In connect mode, Ncat initiates a connection (or sends UDP data) to a service that is
+ listening somewhere. For those familiar with socket programming,
+ connect mode is like using the <function>connect</function> function.
+ In listen mode, Ncat waits for an incoming connection (or data receipt), like using the
+ <function>bind</function> and <function>listen</function> functions.
+ You can think of connect mode as <quote>client</quote> mode and listen
+ mode as <quote>server</quote> mode.
+ </para>
+
+ <para>
+ To use Ncat in connect mode, run
+ <informalexample>
+<literallayout>
+<command>ncat <replaceable>host</replaceable> <optional><replaceable>port</replaceable></optional></command>
+</literallayout>
+ </informalexample>
+ <replaceable>host</replaceable> may be a hostname or IP
+ address, and
+ <replaceable>port</replaceable> is a port number. Listen mode is the
+ same, with the addition of the
+ <option>--listen</option><indexterm><primary><option>--listen</option>
+ (Ncat option></primary></indexterm> option (or
+ its <option>-l</option><indexterm><primary><option>-l</option> (Ncat
+ option)</primary><see><option>--listen</option></see></indexterm>
+ alias):
+ <informalexample>
+
+<literallayout>
+<command>ncat --listen <optional><replaceable>host</replaceable></optional> <optional><replaceable>port</replaceable></optional></command>
+<command>ncat -l <optional><replaceable>host</replaceable></optional> <optional><replaceable>port</replaceable></optional></command>
+</literallayout>
+ </informalexample>
+ In listen mode, <replaceable>host</replaceable> controls the address
+ on which Ncat listens; if you omit it, Ncat will bind to all local interfaces (INADDR_ANY). If the port number is omitted, Ncat uses its
+ default port
+ 31337.<indexterm><primary>default port of Ncat</primary></indexterm>
+ Typically only privileged
+ (root)<indexterm><primary>privileged users</primary></indexterm>
+ users may bind to a port number lower than
+ 1024.<indexterm><primary>ports</primary><secondary>reserved</secondary></indexterm><indexterm><primary>reserved ports</primary></indexterm>
+ A listening TCP server normally accepts only one connection and will
+ exit after the client disconnects. Combined with the
+ <option>--keep-open</option><indexterm><primary><option>--keep-open</option> (Ncat option)</primary></indexterm>
+ option, Ncat accepts multiple concurrent connections up
+ to the connection limit. With <option>--keep-open</option> (or
+ <option>-k</option> for short), the server receives everything sent by
+ any of its clients, and anything the server sends is sent to all of
+ them.
+ </para>
+
+ <para>
+ By default, Ncat uses TCP. The option
+ <option>--udp</option><indexterm><primary><option>--udp</option> (Ncat option)</primary></indexterm>
+ or
+ <option>-u</option><indexterm><primary><option>-u</option> (Ncat option)</primary><see><option>--udp</option></see></indexterm>
+ enables UDP instead,
+ and
+ <option>--sctp</option><indexterm><primary><option>--sctp</option> (Ncat option)</primary></indexterm>
+ enables SCTP.<indexterm><primary>SCTP</primary><secondary>in Ncat</secondary></indexterm>
+ Ncat listens on both IPv4 and IPv6, and connects to either address family as well. The
+ <option>-6</option><indexterm><primary><option>-6</option> (Ncat option)</primary></indexterm>
+ option forces IPv6-only, and
+ <option>-4</option><indexterm><primary><option>-4</option> (Ncat option)</primary></indexterm>
+ forces IPv4-only. See <xref linkend="ncat-protocols"/> for more details.
+ The rest of this guide documents all the Ncat options through
+ descriptions and examples. For a quick summary of options at any time,
+ run
+ <command>ncat --help</command><indexterm><primary><option>--help</option> (Ncat option)</primary></indexterm>
+ or <command>man ncat</command>.
+ </para>
+
+ <sect2 id="ncat-connect">
+ <title>A Connect Mode Example</title>
+
+ <para>
+
+ A good way to start learning about Ncat (and network protocols in
+ general) is to connect to a network service and talk with it. In
+ this case we use Ncat to manually retrieve a web page from an HTTP
+ server, just as web browsers do in the background when you visit a
+ web site.
+ <xref linkend="ncat-ex-http" xrefstyle="select: label nopage"/>
+ shows a (truncated) sample session. Try it yourself!
+ Text in bold is what you type; everything else is what comes
+ back. The blank line after the <userinput>GET</userinput> line is
+ required&mdash;just hit <keycap>enter</keycap> twice.
+ </para>
+
+ <example id="ncat-ex-http">
+ <title>Ncat as a web browser</title>
+ <indexterm><primary>GET HTTP method</primary></indexterm>
+ <indexterm><primary><option>-C</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<screen>
+$ <userinput>ncat -C scanme.nmap.org 80</userinput>
+<userinput>GET / HTTP/1.0
+
+</userinput>HTTP/1.1 200 OK
+Date: Thu, 05 Feb 2009 15:31:40 GMT
+Server: Apache/2.2.2 (Fedora)
+Last-Modified: Mon, 19 May 2008 04:49:49 GMT
+ETag: "fc8c91-2e3-44d8e17edd540"
+Accept-Ranges: bytes
+Content-Length: 739
+Connection: close
+Content-Type: text/html; charset=UTF-8
+
+&lt;html&gt;
+&lt;head&gt;
+&lt;title&gt;Go ahead and ScanMe!&lt;/title&gt;
+&lt;/head&gt;
+</screen>
+ </example>
+
+ <para>
+ Here we have instructed Ncat to connect to the host
+ scanme.nmap.org<indexterm><primary>scanme.nmap.org</primary></indexterm>
+ on port 80, the port for HTTP. The <option>-C</option> option turns
+ on CRLF<indexterm><primary>CRLF</primary></indexterm> replacement,
+ which replaces any line endings you type with CRLF. CRLF line
+ endings are required by many protocols, including HTTP, though many servers will accept a plain newline (LF) character.
+ </para>
+
+ <para>
+ <userinput>GET / HTTP/1.0</userinput> requests the root document of
+ the server; we are retrieving the same document named by the URL
+ http://scanme.nmap.org:80/. The web server responds with a status code
+ (<computeroutput>HTTP/1.1 200 OK</computeroutput>), followed by the
+ HTTP header and the text of the web page. If you try this with other
+ web servers, note that many of them are actually virtual hosts and you
+ will need to send the <literal>Host</literal> header field. See
+ RFC&nbsp;2616<indexterm><primary>RFC 2616</primary></indexterm> for
+ more information about HTTP.
+ </para>
+ </sect2>
+
+ <sect2 id="ncat-listen">
+ <title>A Listen Mode Example</title>
+
+ <para>
+ So much for using Ncat as a web browser. What about a web server?
+ That's possible too; it just takes a bit of preparation. The first
+ step is to create the document to serve. Create a text file called
+ <filename>hello.http</filename> with these contents:
+<screen>
+<![CDATA[HTTP/1.0 200 OK
+
+<html>
+ <body>
+ <h1>Hello, world!</h1>
+ </body>
+</html>]]>
+</screen>
+ Now run the command
+ <command>ncat -l localhost 8080 &lt; hello.http</command>. This
+ instructs Ncat to listen on the local port 8080 and read
+ <filename>hello.http</filename> on its input. Ncat is now primed to
+ send the contents of the file as soon as it receives a connection.
+ Now open a web browser and type in the address
+ <userinput>http://localhost:8080/</userinput>.
+ <xref linkend="ncat-fig-hello" xrefstyle="select: label nopage"/>
+ shows a sample of what will appear.
+ </para>
+
+ <figure id="ncat-fig-hello">
+ <title>Web page served by Ncat</title>
+ <screenshot>
+ <mediaobject>
+ <imageobject>
+ <imagedata fileref="../../book/images/ncat-fig-hello.png"/>
+ </imageobject>
+ </mediaobject>
+ </screenshot>
+ </figure>
+
+ <para>
+ In the terminal where you ran Ncat, you will see everything the web
+ browser sent to request the page. You should see a
+ <computeroutput>GET</computeroutput><indexterm><primary>GET HTTP method</primary></indexterm>
+ line like the one you sent in
+ the connect mode example. This shows that Ncat by default both sends
+ and receives.
+ </para>
+
+ <para>
+ If you try to refresh the page, it won't work. That's because Ncat
+ ran out of input; it won't re-send what has already been sent. For
+ more information on making a server that continually responds to
+ requests, see the examples in
+ <xref linkend="ncat-simple-services"/>. More HTTP server tricks can
+ be found here in <xref linkend="ncat-httpserv"/>.
+ </para>
+
+ </sect2>
+</sect1>
+
+<sect1 id="ncat-protocols">
+ <title>Protocols</title>
+
+ <indexterm><primary>TLS</primary><see>SSL</see></indexterm>
+ <indexterm><primary>Transport Layer Security (TLS)</primary><see>SSL</see></indexterm>
+
+ <para>
+ Ncat can use TCP, UDP, SCTP, SSL, IPv4, IPv6, and various combinations
+ of these. TCP over IPv4 is the default.
+ </para>
+
+ <para>
+ TCP,<indexterm significance="preferred"><primary>TCP</primary><secondary>in Ncat</secondary></indexterm>
+ the Transmission Control Protocol, is the reliable protocol that
+ underlies a great deal of Internet traffic. Ncat makes TCP connections
+ by default. TCP may be combined with SSL.
+ </para>
+
+ <para>
+ UDP,<indexterm significance="preferred"><primary>UDP</primary><secondary>in Ncat</secondary></indexterm>
+ the User Datagram Protocol, is an unreliable protocol often used by
+ applications that can't afford the overhead of TCP. Use the
+ <option>--udp</option><indexterm><primary><option>--udp</option> (Ncat option)</primary></indexterm>
+ option to make Ncat use UDP.
+ UDP may be secured using the <option>--ssl</option> option, which enables
+ Datagram TLS (DTLS)<indexterm><primary>DTLS</primary><secondary>Datagram TLS</secondary></indexterm>.
+ </para>
+
+ <para>
+ SCTP,<indexterm significance="preferred"><primary>SCTP</primary><secondary>in Ncat</secondary></indexterm>
+ the Stream Control Transmission Protocol, is a newer reliable
+ protocol. It is selected with the
+ <option>--sctp</option><indexterm><primary><option>--sctp</option> (Ncat option)</primary></indexterm>
+ option. Ncat uses a TCP-compatible subset of SCTP features, not
+ including multiple streams per connection or message boundaries. SCTP
+ may be combined with SSL.
+ </para>
+
+ <para>
+ SSL<indexterm significance="preferred"><primary>SSL</primary><secondary>in Ncat</secondary></indexterm>
+ (Secure Sockets Layer) or
+ TLS (Transport Layer Security) provides security to network traffic
+ when used properly. Use the
+ <option>--ssl</option><indexterm><primary><option>--ssl</option> (Ncat option)</primary></indexterm>
+ to turn SSL on; it works with TCP or SCTP. See <xref
+ linkend="ncat-ssl"/> for instructions and caveats.
+ </para>
+
+ <para>
+ IPv4,<indexterm significance="preferred"><primary>IPv4</primary><secondary>in Ncat</secondary></indexterm>
+ the Internet Protocol version 4, is the most popular version of the
+ Internet Protocol in use. Using the
+ <option>-4</option><indexterm><primary><option>-4 (Ncat option)</option></primary></indexterm>
+ puts Ncat into IPv4-only mode; only IPv4 addresses will be used even
+ if, for example, as hostname resolves to IPv6 addresses as well.
+ </para>
+
+ <para>
+ IPv6<indexterm significance="preferred"><primary>IPv6</primary><secondary>in Ncat</secondary></indexterm>
+ is the lesser-used successor to IPv4. Use
+ <option>-6</option><indexterm><primary><option>-6</option> (Ncat option)</primary></indexterm>
+ to put Ncat into IPv6-only mode.
+ By default, Ncat will listen on both IPv4 and IPv6, and will connect to
+ resolved addresses in the order they are returned by the operating system.
+ </para>
+</sect1>
+
+<sect1 id="ncat-broker">
+ <title>Connection Brokering</title>
+
+ <para>
+ One of Ncat's most useful and unique abilities is called
+ connection brokering. A listening Ncat in broker mode accepts
+ connections from multiple clients. Anything received from one of
+ the clients is sent back out to all the others. In this way an
+ Ncat broker acts like a network hub, broadcasting all traffic to
+ everyone connected.
+ </para>
+
+ <para>
+ Activate broker mode with the <option>--broker</option> option, which
+ must be combined with
+ <option>--listen</option>. It wouldn't make sense for a client to be
+ a broker. See <xref linkend="ncat-file-transfer"/> for details on using brokering to transfer files through restrictive firewalls,
+ and <xref linkend="ncat-chat"/> for using brokering to set up multi-user chat rooms.
+ </para>
+</sect1>
+
+<sect1 id="ncat-ssl">
+ <title>SSL</title>
+
+ <para>
+ Ncat can encrypt its traffic using SSL. In connect mode, simply add the
+ <option>--ssl</option><indexterm><primary><option>--ssl</option> (Ncat option)</primary></indexterm>
+ option. <option>--ssl</option> works with TCP (the default) and
+ SCTP<indexterm><primary>SCTP</primary><secondary>in Ncat</secondary></indexterm>
+ (<option>--sctp</option><indexterm><primary><option>--sctp</option> (Ncat option)</primary></indexterm>
+ option). Here is the syntax for connecting to
+ an HTTPS server:
+ <informalexample>
+<literallayout>
+<command>ncat -C --ssl <replaceable>server</replaceable> 443</command>
+</literallayout>
+ </informalexample>
+ </para>
+
+ <para>
+ Sometimes an SSL server will require a client certificate for
+ authentication. When this is the case, use the
+ <option>--ssl-cert</option><indexterm><primary><option>--ssl-cert</option> (Ncat option)</primary></indexterm>
+ and
+ <option>--ssl-key</option><indexterm><primary><option>--ssl-key</option> (Ncat option)</primary></indexterm>
+ options to give the locations of PEM-encoded files containing the
+ certificate and private key, respectively. The certificate and key may
+ be in the same file.
+ </para>
+
+ <para>
+ <indexterm><primary>certificate verification</primary></indexterm>
+ <indexterm><primary>trust</primary><see>certificate verification</see></indexterm>
+ By default the client will not do any server certificate verification, so it
+ will not be detected if the server has the wrong certificate or no
+ certificate at all. Use the <option>--ssl-verify</option> option to
+ require verification of the certificate and matching of the domain
+ name.
+ <indexterm><primary><option>--ssl-verify</option> (Ncat option)</primary></indexterm>
+<literallayout>
+<command>ncat -C --ssl-verify <replaceable>server</replaceable> 443</command>
+</literallayout>
+ Verification is done using the
+ <filename>ca-bundle.crt</filename><indexterm><primary><filename>ca-bundle.crt</filename></primary></indexterm>
+ certificate bundle shipped with Ncat, plus whatever trusted
+ certificates the operating system may provide. If you want to verify a
+ connection to a server whose certificate isn't signed by one of the
+ default certification authorities, use the
+ <option>--ssl-trustfile</option> to name a file containing
+ certificates you trust. The file must be in PEM format.
+ <indexterm><primary><option>--ssl-trustfile</option> (Ncat option)</primary></indexterm>
+<literallayout>
+<command>ncat -C --ssl-verify --ssl-trustfile <replaceable><filename>custom-certs.pem</filename></replaceable> <replaceable>server</replaceable> 443</command>
+</literallayout>
+ Verification should be done whenever it is feasible. Even with
+ encryption, an unverified connection is vulnerable to a
+ man-in-the-middle attack. Ncat does not do certificate
+ revocation<indexterm><primary>certificate revocation</primary></indexterm><indexterm><primary>CRL</primary><see>certificate revocation</see></indexterm>
+ checking.
+ </para>
+
+ <para>
+ <indexterm><primary>SSL ciphers</primary><secondary>in Ncat</secondary></indexterm>
+ SSL connections depend on the client and server agreeing on a common
+ ciphersuite: a combination of key exchange, symmetric cipher, and message
+ integrity mechanism. The choice of which ciphersuites to offer (as a
+ client) or accept (as a server) is a matter of choice between the greatest
+ compatibility and the greatest security. The default set, expressed as an
+ OpenSSL cipherlist, is
+ <literal>ALL:!aNULL:!eNULL:!LOW:!EXP:!RC4:!MD5:@STRENGTH</literal>, a reasonable balance
+ between the two ends of the spectrum. To set a different priority or
+ initial choice, use the <option>--ssl-ciphers</option> option.
+ <indexterm><primary><option>--ssl-ciphers</option> (Ncat option)</primary></indexterm>
+ <literallayout>
+ <command>ncat --ssl-ciphers <replaceable>HIGH:!aNULL:!eNULL</replaceable> <replaceable>server</replaceable> 443</command>
+ </literallayout>
+ </para>
+ <indexterm><primary><option>--ssl-ciphers</option> (Ncat option)</primary></indexterm>
+
+ <indexterm><primary>SSL</primary><secondary>in Ncat</secondary></indexterm>
+ <indexterm><primary>certificate</primary><secondary>automatic generation of</secondary></indexterm>
+ <indexterm><primary>certificate</primary><seealso><option>--ssl-cert</option></seealso></indexterm>
+ <indexterm><primary>keys, cryptographic</primary><seealso><option>--ssl-key</option></seealso></indexterm>
+ <para>
+ Ncat can act as an SSL server as well. The server must provide a
+ certificate that clients can verify if they choose. If you start an
+ SSL server without using the <option>--ssl-cert</option> and
+ <option>--ssl-key</option> options, Ncat will automatically generate a
+ certificate and 2,048-bit RSA key. The certificate will of course not
+ be trusted by any application doing certificate verification. In
+ verbose mode, the key's fingerprint will be printed so you can do
+ manual verification if desired.
+ <xref linkend="ncat-ex-ssl-gen" xrefstyle="select: label nopage"/>
+ shows sample output.
+ </para>
+
+ <example id="ncat-ex-ssl-gen">
+ <title>Automatic certificate generation</title>
+ <indexterm><primary><option>--ssl</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<screen>
+$ <userinput>ncat -v --listen --ssl</userinput>
+Ncat ( https://nmap.org/ncat )
+Generating a temporary 2048-bit RSA key. Use --ssl-key and --ssl-cert to use a <continuation/>permanent one.
+SHA-1 fingerprint: F0:13:BF:FB:2D:AA:76:88:22:60:3E:17:93:29:3E:0E:6B:92:C0:2F
+</screen>
+ </example>
+
+ <para>
+ Using an existing certificate and key is recommended whenever possible
+ because it allows for robust server authentication. Use the
+ <option>--ssl-cert</option> and <option>--ssl-key</option> options to
+ pass in PEM-encoded files.
+ For testing purposes you can generate a self-signed certificate and
+ private key. If you have OpenSSL<indexterm><primary>OpenSSL</primary></indexterm>
+ installed, use this command:
+ <informalexample>
+<literallayout>
+<command>openssl req -new -x509 -keyout test-key.pem -out test-cert.pem</command>.
+</literallayout>
+ </informalexample>
+ For purposes of certificate verification, the
+ <varname>commonName</varname><indexterm><primary><varname>commonName</varname></primary></indexterm>
+ in the certificate should match the fully qualified domain
+ name<indexterm><primary>fully qualified domain name</primary></indexterm>
+ of the host that will run the server. After generating the files,
+ start the server:
+ <informalexample>
+<literallayout>
+<command>ncat --listen --ssl --ssl-cert test-cert.pem --ssl-key test-key.pem</command>.
+</literallayout>
+ </informalexample>
+ To make a verified client connection, copy the
+ <filename>test-cert.pem</filename> file somewhere where the client can
+ access it, then run
+ <informalexample>
+<literallayout>
+<command>ncat --ssl-verify --ssl-trustfile test-cert.pem</command>.
+</literallayout>
+ </informalexample>
+ </para>
+</sect1>
+
+<sect1 id="ncat-exec">
+ <title>Command Execution</title>
+
+ <para>
+ Ncat can execute an external command after establishing a
+ connection. The command's standard input and output<indexterm><primary>standard input</primary></indexterm><indexterm><primary>standard output</primary></indexterm>
+ streams are redirected to use Ncat's network connection. Anything received over
+ the connection is given to the command's stdin, and anything the
+ command writes to stdout is sent back out over the connection. This feature makes
+ almost any terminal application accessible over a network (with some
+ caveats).
+ </para>
+
+ <para>
+ There are three ways of running a command:
+ <itemizedlist spacing="compact">
+ <listitem>
+ <option>--exec</option><indexterm><primary><option>--exec</option> (Ncat option)</primary></indexterm>
+ runs a command without shell interpretation.
+ </listitem>
+ <listitem>
+ <option>--sh-exec</option><indexterm><primary><option>--sh-exec</option> (Ncat option)</primary></indexterm>
+ runs a command by passing a string to a system shell.
+ </listitem>
+ <listitem>
+ <option>--lua-exec</option><indexterm><primary><option>--lua-exec</option> (Ncat option)</primary></indexterm>
+ runs a Lua program using Ncat's built-in Lua interpreter.<indexterm><primary>Lua</primary><secondary>in Ncat</secondary></indexterm>
+ </listitem>
+ </itemizedlist>
+ </para>
+
+ <para>
+ The
+ <option>--exec</option><indexterm><primary><option>--exec</option> (Ncat option)</primary></indexterm>
+ option (alias
+ <option>-e</option>)<indexterm><primary><option>-e</option> (Ncat option)</primary><see><option>--exec</option></see></indexterm>
+ takes the full pathname of a command to execute, along with its
+ arguments. The command is executed directly; Ncat does not interpret
+ the given string beyond splitting the command and its arguments.
+ <xref linkend="ncat-ex-exec" xrefstyle="select: label nopage"/>
+ shows an example of usage.
+ </para>
+
+ <example id="ncat-ex-exec">
+ <title>Running a command with <option>--exec</option></title>
+<literallayout><command>ncat -l --exec "/bin/echo Hello."</command></literallayout>
+ </example>
+
+ <para>
+ The
+ <option>--sh-exec</option><indexterm><primary><option>--sh-exec</option> (Ncat option)</primary></indexterm>
+ option
+ (<option>-c</option>)<indexterm><primary><option>-c</option> (Ncat option)</primary><see><option>--sh-exec</option></see></indexterm>
+ works the same as <option>--exec</option>, except that it
+ executes the command by passing it to <command>/bin/sh -c</command>
+ on Unix or <command>cmd.exe /C</command> on Windows.
+ You don't have to use the full pathname of the command if the
+ command is in the
+ <envar>PATH</envar>.<indexterm><primary><envar>PATH</envar></primary></indexterm>
+ Additionally you have access to shell facilities such as pipelines
+ and environment variable expansion.
+ <xref linkend="ncat-ex-sh-exec" xrefstyle="select: label nopage"/>
+ shows a command run with <option>--sh-exec</option>. This server,
+ when connected to, sends back the name of its working directory.
+ </para>
+
+ <example id="ncat-ex-sh-exec">
+ <title>Running a command with <option>--sh-exec</option></title>
+<literallayout><command>ncat -l --sh-exec "echo `pwd`"</command></literallayout>
+ </example>
+
+ <para>
+ The
+ <option>--lua-exec</option><indexterm significance="preferred"><primary><option>--lua-exec</option> (Ncat option)</primary></indexterm>
+ option takes the filename of a Lua program to run. Ncat runs the
+ program using its built-in interpreter and redirects its input and
+ output streams. Anything the program writes to standard output (for
+ example with <code>print</code> or <code>io.write</code>) is written
+ to the connection, and any reads from standard input come from the
+ connection. A nice thing about running programs written in Lua is that
+ the same interpreter is used on all platforms, in comparison with
+ shells that operate differently.
+ </para>
+
+ <para>
+ That means that the default Ncat build
+ is all you need to run a simple network service. To write a program, the
+ standard text editor (even a Windows "notepad") is enough; to learn how
+ to create programs in Lua, have a look at "Programming in Lua" book
+ available for free at
+ <ulink role="hidepdf" url="http://www.lua.org/pil/contents.html">Lua.org</ulink>
+ website.
+ <xref linkend="ncat-ex-lua-exec" xrefstyle="select: label nopage"/>
+ shows how to run a program stored in a file called
+ <filename>hello-luaexec.lua</filename>. You can find this script - and
+ some other ones - in Nmap's source code package, in
+ <literal>ncat/scripts</literal> directory - the latest versions of the
+ scripts can be found in the
+ <ulink role="hidepdf" url="https://svn.nmap.org/nmap/ncat/scripts/">Nmap project public SVN repository</ulink>.
+ Here are the contents of the hello-luaexec.lua file, if you would prefer
+ to create the file yourself:
+ </para>
+
+<programlisting>
+--This is a --lua-exec "Hello world" example. In order to send to a client,
+--all you need to do is output it to the standard output.
+
+print("Hello, world!")
+</programlisting>
+
+ <example id="ncat-ex-lua-exec">
+ <title>Running a command with <option>--lua-exec</option></title>
+<literallayout><command>ncat -l --lua-exec hello-luaexec.lua</command></literallayout>
+ </example>
+
+ <para>
+ Now, anyone that connects to our server will see the "Hello, world"
+ message. For a script with a bit more capabilities, have a look at
+<ulink role="hidepdf" url="https://svn.nmap.org/nmap/ncat/scripts/conditional.lua">conditional.lua</ulink>.
+ It shows how to create a simple menu, receive some data from the user
+ repeatedly and react according to her decisions. You might want to start
+ off your experiments with Lua by making changes to this script. Also see
+ <xref linkend="ncat-httpserv"/> for information on how to run a simple
+ HTTP server in Lua.
+ </para>
+
+ <para>
+ The exec options can be used in connect mode and listen mode. In
+ listen mode, Ncat accepts one connection, runs the command, and then
+ quits, just like listen mode without exec. But when listen mode is
+ combined with
+ <option>--keep-open</option>,<indexterm><primary><option>--keep-open (Ncat option)</option></primary><secondary>with <option>--exec</option></secondary></indexterm>
+ Ncat will accept multiple connections, forking off a new handler for
+ each.
+ The server will keep running until you press
+ <keycombo><keycap>ctrl</keycap><keycap>C</keycap></keycombo> or
+ otherwise terminate it externally. In this way Ncat can work much like
+ inetd.<indexterm><primary>inetd</primary></indexterm>
+ Many examples of the use of <option>--exec</option> and
+ <option>--sh-exec</option> in listen mode are found in
+ <xref linkend="ncat-simple-services"/>.
+ </para>
+
+ <example id="ncat-ex-sh-exec-persistent">
+ <title>Running an inetd-like server</title>
+<literallayout><command>ncat -l --keep-open --exec "/bin/echo Hello."</command></literallayout>
+ </example>
+
+ <para>
+ Whatever the exec mode, Ncat sets environment variables in the spawned
+ program's environment that describe the connection.
+
+ <variablelist>
+ <varlistentry>
+ <term><envar>NCAT_REMOTE_ADDR</envar></term><indexterm><primary><envar>NCAT_REMOTE_ADDR></envar> environment variable</primary></indexterm>
+ <term><envar>NCAT_REMOTE_PORT</envar></term><indexterm><primary><envar>NCAT_REMOTE_PORT></envar> environment variable</primary></indexterm>
+ <listitem>
+ <para>
+ 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.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>NCAT_LOCAL_ADDR</envar></term><indexterm><primary><envar>NCAT_LOCAL_ADDR></envar> environment variable</primary></indexterm>
+ <term><envar>NCAT_LOCAL_PORT</envar></term><indexterm><primary><envar>NCAT_LOCAL_PORT></envar> environment variable</primary></indexterm>
+ <listitem>
+ <para>
+ The IP address and port number of the local end of the connection.
+ </para>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term><envar>NCAT_PROTO</envar></term><indexterm><primary><envar>NCAT_PROTO></envar> environment variable</primary></indexterm>
+ <listitem>
+ <para>
+ The protocol in use: one of <code>TCP</code>, <code>UDP</code>, and <code>SCTP</code>.
+ </para>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <xref linkend="ncat-ex-exec-env" xrefstyle="select: label nopage"/>
+ shows the output of a Lua program that reads these variables.
+ You can see these environment variables in action by running this
+
+ </para>
+
+ <example id="ncat-ex-exec-env">
+ <title>Exec environment variables</title>
+ <para>The contents of the program <filename>env.lua</filename>:
+<programlisting>function env(v)
+ print(string.format("%s %q", v, os.getenv(v)))
+end
+env("NCAT_REMOTE_ADDR")
+env("NCAT_REMOTE_PORT")
+env("NCAT_LOCAL_ADDR")
+env("NCAT_LOCAL_PORT")
+env("NCAT_PROTO")</programlisting>
+ </para>
+ <para>The output of running the program:
+<screen>
+$ <userinput>ncat -l --lua-exec env.lua &amp;</userinput>
+$ <userinput>ncat localhost</userinput>
+NCAT_REMOTE_ADDR "127.0.0.1"
+NCAT_REMOTE_PORT "60179"
+NCAT_LOCAL_ADDR "127.0.0.1"
+NCAT_LOCAL_PORT "31337"
+NCAT_PROTO "TCP"
+</screen>
+ </para>
+ </example>
+
+ <indexterm><primary>--lua-exec portability</primary></indexterm>
+ <warning><para>
+ When writing your own --lua-exec script, keep in mind that while Lua is
+ very portable, there is a caveat related to running your Lua scripts
+ written on Windows to Unix systems. For technical reasons, --lua-exec
+ on Windows reloads the script every time it is run. Do not rely on this
+ behavior on other systems though - on POSIX-compatible systems, the
+ script is only loaded once and any modifications to its code will not
+ be visible until you restart Ncat.
+ </para></warning>
+
+ <para>
+ Any program that takes input and produces output can be executed by
+ Ncat, but not all programs are suited to this kind of interaction.
+ Many programs buffer their input and output,<indexterm><primary>buffering</primary><secondary>effect on Ncat of</secondary></indexterm>
+ so if they receive some bytes, they many not process those bytes and
+ write output until their input buffer is full, or the output may be
+ deferred until the output buffer is full. If another program sends a
+ few bytes and then waits for a response, it may hang indefinitely.
+ Buffers are flushed when input or output ends, so even those
+ programs that don't work interactively will work when run on an
+ entire file at a time.
+ </para>
+
+ <para>
+ Be careful when using the various exec
+ options. It can be dangerous to connect a
+ new application to a network, especially one that wasn't written
+ with potentially hostile input in mind. Any local vulnerabilities in
+ an application may become remote vulnerabilities when you execute
+ it through Ncat.
+ </para>
+</sect1>
+
+<sect1 id="ncat-output">
+ <title>Output Options</title>
+
+ <indexterm><primary>verbosity</primary><secondary>of Ncat</secondary></indexterm>
+ <para>
+ Like any proper pipeline utility, Ncat reads from
+ standard input<indexterm><primary>standard input</primary></indexterm>
+ and writes to
+ standard output<indexterm><primary>standard output</primary></indexterm>
+ so you can redirect I/O to or from any program or file. The only
+ exception is when Ncat is run with the <option>--exec</option> or
+ <option>--sh-exec</option> options, in which case it communicates with
+ the subprocess instead. Nothing in the streams is added, removed, or
+ altered, unless you specifically ask for it with an option such as
+ <option>-C</option><indexterm><primary><option>-C</option> (Ncat option)</primary></indexterm>
+ (CRLF processing) or
+ <option>--telnet</option><indexterm><primary><option>-telnet</option> (Ncat option)</primary></indexterm>
+ (Telnet negotiation). If Ncat prints any diagnostic messages, they are
+ sent to
+ standard error<indexterm><primary>standard error</primary></indexterm>
+ so as not to interfere with the data stream. By default Ncat does not
+ print any such messages, but you can enable them with the
+ <option>--verbose</option><indexterm><primary><option>--verbose</option> (Ncat option)</primary></indexterm>
+ (<option>-v</option>)<indexterm><primary><option>-v</option> (Ncat option)</primary><see><option>--verbose</option></see></indexterm>
+ option. Use <option>-v</option> more than once for even more output.
+ </para>
+
+ <indexterm><primary>hex dump</primary></indexterm>
+ <indexterm><primary>transcript</primary></indexterm>
+ <indexterm><primary>log file</primary><secondary>of Ncat</secondary></indexterm>
+ <para>
+ Use the
+ <option>--output</option><indexterm><primary><option>--output</option> (Ncat option)</primary></indexterm>
+ option or its alias
+ <option>-o</option><indexterm><primary><option>-o</option> (Ncat option)</primary><see><option>--output</option></see></indexterm>
+ to record a transcript of everything sent and received to a file:
+ <informalexample>
+<literallayout>
+<command>ncat -C --output smtp-debug.log mail.example.com 25</command>
+</literallayout>
+ </informalexample>
+ The log contains everything sent and received without differentiation.
+ Sometimes a hex dump is more useful than a plain text log; for that
+ use
+ <option>--hex-dump</option><indexterm><primary><option>--hex-dump</option> (Ncat option)</primary></indexterm>
+ or
+ <option>-x</option>.<indexterm><primary><option>-x</option> (Ncat option)</primary><see><option>--hex-dump</option></see></indexterm>
+ Let's see what happens if we accidentally speak SMTP to an SSH server:
+<screen>
+$ <userinput>ncat -C --hex-dump ssh-hex.log scanme.nmap.org 22</userinput>
+SSH-2.0-OpenSSH_4.3
+<userinput>HELO example.com</userinput>
+Protocol mismatch.
+</screen>
+ The <option>--hex-dump</option> log file for this session:
+<screen>
+[0000] 53 53 48 2D 32 2E 30 2D 4F 70 65 6E 53 53 48 5F SSH-2.0- OpenSSH_
+[0010] 34 2E 33 0A 4.3.
+[0000] 48 45 4C 4F 20 65 78 61 6D 70 6C 65 2E 63 6F 6D HELO exa mple.com
+[0010] 0D 0A ..
+[0000] 50 72 6F 74 6F 63 6F 6C 20 6D 69 73 6D 61 74 63 Protocol mismatc
+[0010] 68 2E 0A h..
+</screen>
+ Each transmission is dumped separately. There is a break and the
+ counter at the left starts over each time there is a new send.
+ </para>
+</sect1>
+
+<sect1 id="ncat-access">
+ <indexterm><primary>access control</primary></indexterm>
+ <title>Access Control</title>
+
+ <para>
+ A listening Ncat may control which hosts connect to it with the
+ <option>--allow</option><indexterm><primary><option>--allow</option> (Ncat option)</primary></indexterm>
+ and
+ <option>--deny</option><indexterm><primary><option>--deny</option> (Ncat option)</primary></indexterm>
+ options. Each of these takes a comma-separated list of host
+ specifications. The syntax is almost identical to that recognized by Nmap for
+ targets
+ (see <ulink url="https://nmap.org/book/man-target-specification.html">the section called <quote>Target Specification</quote></ulink>).
+ <!-- (see <xref linkend="host-discovery-specify-targets"/>). -->
+ This includes IPv4 and IPv6 addresses, hostnames, IPv4 octet ranges,
+ and CIDR netmasks. In Ncat (unlike Nmap), CIDR netmasks are supported for IPv6
+ addresses.
+ </para>
+
+ <para>
+ With <option>--allow</option>, any hosts matching one of the listed specifiers
+ are allowed and all others are denied. With <option>--deny</option>,
+ those hosts matching the list are denied and all others are accepted.
+ If a host matches both the <option>--allow</option> and
+ <option>--deny</option> lists, it is denied.
+ </para>
+
+ <para>
+ Use
+ <option>--allowfile</option><indexterm><primary><option>--allowfile</option> (Ncat option)</primary></indexterm>
+ and
+ <option>--denyfile</option><indexterm><primary><option>--denyfile</option> (Ncat option)</primary></indexterm>
+ to allow or deny a list of host/network specifiers stored in a file. Each line of the
+ file contains a specification in one of the forms listed above. Any
+ file acceptable to Nmap's
+ <option>-iL</option><indexterm><primary><option>-iL</option></primary></indexterm>
+ and
+ <option>--excludefile</option><indexterm><primary><option>--excludefile</option></primary></indexterm>
+ options is suitable for <option>--allowfile</option> and
+ <option>--denyfile</option>.
+ </para>
+
+ <para>
+ The following example commands demonstrate various kinds of access control.
+ </para>
+
+ <!-- 2001:db8::/32 is an IPv6 prefix reserved for documentation, RFC 3849. -->
+ <variablelist>
+ <varlistentry>
+ <term>Allow one host, deny all others</term>
+ <listitem>
+<literallayout>
+<command>ncat -l --allow 192.168.0.125</command>
+<command>ncat -l --allow 2001:db8::7d</command>
+<command>ncat -l --allow trusted.example.com</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>Deny one host, allow all others</term>
+ <listitem>
+<literallayout>
+<command>ncat -l --deny 192.168.0.200</command>
+<command>ncat -l --deny 2001:db8::c8</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>Allow hosts on a local network, deny all others</term>
+ <listitem>
+<literallayout>
+<command>ncat -l --allow 192.168.0.0/24</command>
+<command>ncat -l --allow 192.168.0.0-255</command>
+<command>ncat -l --allow 2001:db8::/32</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>Allow or deny hosts from a file</term>
+ <listitem>
+<literallayout>
+<command>ncat -l --allowfile trusted-hosts.txt</command>
+<command>ncat -l --denyfile external-hosts.txt</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Be aware that host-based access control is susceptible to spoofing attacks and various other possible failures. These mechanisms should not be relied on for complete security.
+ </para>
+
+ <para>
+ Another kind of access control is simply limiting the maximum number
+ of connections a listening Ncat will accept. Use the
+ <option>--max-conns</option><indexterm><primary><option>--max-conns</option> (Ncat option)</primary></indexterm>
+ option or its
+ <option>-m</option><indexterm><primary><option>-m</option></primary><see><option>--max-conns</option></see></indexterm>
+ alias to do that. The default maximum number of connections is 100, or 60 on Windows.
+ <informalexample>
+<literallayout>
+<command>ncat -l --max-conns 5</command>
+</literallayout>
+ </informalexample>
+ </para>
+</sect1>
+
+<sect1 id="ncat-proxy">
+ <title>Proxying</title>
+
+ <indexterm><primary>HTTP proxy</primary><see>proxy</see></indexterm>
+ <indexterm><primary>proxy</primary><secondary>Ncat as</secondary></indexterm>
+ <para>
+ Ncat can route its connections through a
+ SOCKS&nbsp;4<indexterm><primary>SOCKS proxy</primary></indexterm>, SOCKS&nbsp;5
+ or HTTP<indexterm><primary>HTTP proxy</primary></indexterm> proxy. A basic
+ connection looks like
+ <informalexample>
+<indexterm><primary><option>--proxy</option> (Ncat option)</primary></indexterm>
+<indexterm><primary><option>--proxy-type</option> (Ncat option)</primary></indexterm>
+<literallayout>
+<command>ncat --proxy <replaceable>proxyhost</replaceable><optional>:<replaceable>proxyport</replaceable></optional> --proxy-type <group choice="req"><arg choice="plain">http</arg><arg choice="plain">socks4</arg><arg choice="plain">socks5</arg></group> <replaceable>host</replaceable> <optional><replaceable>port</replaceable></optional></command>
+</literallayout>
+ </informalexample>
+ <option>--proxy-type</option> may be omitted; it defaults to
+ <literal>http</literal>. If <replaceable>proxyport</replaceable> is
+ omitted, it defaults to the well-known port for the chosen proxy type:
+ 1080 for SOCKS and 3128 for HTTP. An exception to this rule is when
+ the proxy host is given by a IPv6 address; in this case the port is
+ required because otherwise it would be ambiguous whether the digits
+ after the last colon are the port number or part of the address.
+ </para>
+
+ <para>
+ If the proxy server requires authentication, use the
+ <option>--proxy-auth</option><indexterm><primary><option>--proxy-auth</option> (Ncat option)</primary></indexterm>
+ option. Use
+ <command>--proxy-auth <replaceable>username</replaceable>:<replaceable>password</replaceable></command>
+ for HTTP and SOCKS5 proxies and
+ <command>--proxy-auth <replaceable>username</replaceable></command>
+ for SOCKS4 proxies.
+ </para>
+
+ <para>
+ Ncat can act as a proxy server itself in listen mode. The only proxy
+ type supported in this case is <literal>http</literal>.
+ <informalexample>
+<literallayout>
+<command>ncat -l 3128 --proxy-type http</command>
+<command>ncat -l 3128 --proxy-type http --proxy-auth <replaceable>user</replaceable>:<replaceable>pass</replaceable></command>
+</literallayout>
+ </informalexample>
+ In listen mode the proxy port number is not automatically set and will
+ be the default of 31337 unless specified. The proxy supports the
+ GET,<indexterm><primary>GET HTTP method</primary></indexterm>
+ HEAD,<indexterm><primary>HEAD HTTP method</primary></indexterm>
+ and POST<indexterm><primary>POST HTTP method</primary></indexterm>
+ methods used in web browsing, as well as the
+ CONNECT<indexterm><primary>CONNECT HTTP method</primary></indexterm>
+ method that allows tunneling arbitrary TCP connections. (When Ncat
+ connects as a client, it uses CONNECT.) Use
+ <option>--proxy-auth</option> to make the server require
+ authentication with a specific username and password.
+ </para>
+
+ <para>
+ For HTTP, both the Basic<indexterm><primary>Basic authentication (HTTP)</primary></indexterm>
+ and Digest<indexterm><primary>Digest authentication (HTTP)</primary></indexterm>
+ authentication schemes are supported, as both a client and a server.
+ Digest is more secure, so the Ncat client will use that in preference
+ to Basic when it is available. The server offers both schemes to its
+ clients. See
+ RFC&nbsp;2617,<indexterm><primary>RFC 2617</primary></indexterm>
+ section 4 for security considerations of HTTP authentication. Basic
+ sends credentials in the clear and Digest does not. Ncat's
+ implementation of Digest authentication allows replay attacks for up
+ to 10 seconds (replay and other attacks are always possible with
+ Basic).
+ </para>
+
+ <indexterm><primary>open proxy</primary></indexterm>
+ <warning><para>
+ Ncat's HTTP proxy is designed to stay out of your way and help you
+ make temporary network connections. It shouldn't be used as an
+ everyday proxy exposed to the Internet. You can limit who connects
+ using <option>--allow</option>,<indexterm><primary><option>--allow</option></primary></indexterm>
+ <option>--deny</option>,<indexterm><primary><option>--deny</option></primary></indexterm> and
+ <option>--proxy-auth</option>, but these are not strong forms of
+ authentication. An unauthenticated proxy is dangerous because it may
+ enable others to perform attacks or help them evade detection. The
+ CONNECT<indexterm><primary>CONNECT HTTP method</primary><secondary>danger of</secondary></indexterm>
+ capability is especially dangerous because it enables any kind
+ of traffic, not just HTTP.
+ </para></warning>
+</sect1>
+
+<sect1 id="ncat-other-options">
+ <title>Other Options</title>
+
+ <para>
+ This section contains descriptions of all options that haven't been
+ discussed so far.
+ </para>
+
+ <para>
+ The
+ <option>--nodns</option><indexterm><primary><option>--nodns</option> (Ncat option)</primary></indexterm>
+ option (and its short form
+ <option>-n</option>)<indexterm><primary><option>-n</option> (Ncat option)</primary><see><option>--nodns</option></see></indexterm>
+ instructs Ncat never to resolve names into addresses. All hosts must
+ appear as IPv4 or IPv6 addresses.
+ </para>
+
+ <para>
+ Ncat can be used as a Telnet client or server with the
+ <option>--telnet</option><indexterm><primary><option>--telnet</option> (Ncat option)</primary></indexterm>
+ option
+ (<option>-t</option>).<indexterm><primary><option>-t</option> (Ncat option)</primary><see><option>--telnet</option></see></indexterm>
+ This simply causes Ncat to respond negatively to any questions asked
+ by the other host in the binary Telnet protocol, removing such
+ negotiations from the stream seen by the user. The primary use of this
+ option is to allow running canned Telnet scripts.
+ </para>
+
+ <para>
+ The
+ <option>--send-only</option><indexterm><primary><option>--send-only</option> (Ncat option)</primary></indexterm>
+ and
+ <option>--recv-only</option><indexterm><primary><option>--send-only</option> (Ncat option)</primary></indexterm>
+ options do what their names imply, turning Ncat into a one-way
+ communications channel instead of its default two-way channel. A usage example is gathering data from a server
+ without the possibility of accidentally sending something typed at the
+ keyboard. <option>--send-only</option> in both connect and listen
+ modes causes Ncat to quit when its input runs out. Normally it will
+ not quit until the network connection is closed because the remote
+ side may still send something, but in the case of
+ <option>--send-only</option> there's no reason to receive anything
+ more.
+ </para>
+
+ <sect2 id="ncat-source">
+ <title>Source Options</title>
+
+ <para>
+ In connect mode, you may set the source address and port used for
+ the connection with the
+ <option>--source</option><indexterm><primary><option>--source</option> (Ncat option)</primary></indexterm>
+ (<option>-s</option>)<indexterm><primary><option>-s</option> (Ncat option)</primary><see><option>--source</option></see></indexterm>
+ and
+ <option>--source-port</option><indexterm><primary><option>--source-port</option> (Ncat option)</primary></indexterm>
+ (<option>-p</option>).<indexterm><primary><option>-p</option> (Ncat option)</primary><see><option>--source-port</option></see></indexterm>
+ The <option>-s</option> option only works for locally configured
+ addresses; it doesn't work like Nmap's
+ <option>-S</option><indexterm><primary><option>-S</option></primary></indexterm>
+ option. The value of <option>-p</option> is that sometimes firewalls
+ will allow traffic that comes from certain source ports (such as 20 or 53).
+ <!-- See <xref linkend="defeating-firewalls-source-port"/>. -->
+ </para>
+
+ <indexterm><primary>source routing</primary><secondary>in Ncat</secondary></indexterm>
+ <para>
+ The
+ <option>-g</option><indexterm><primary><option>-g</option> (Ncat option)</primary></indexterm>
+ option allows hops selection for IPv4 loose source routing. List the
+ hops in order by giving <option>-g</option> multiple times or by
+ separating the hops with commas. By default the source routing
+ pointer is 4 in the packets sent, indicating the first hop in the
+ list. You may set the pointer to another value with the
+ <option>-G</option><indexterm><primary><option>-G</option> (Ncat option)</primary></indexterm>
+ option. The pointer value must be a multiple of 4 between 4 and 28,
+ but some operating systems only support 4.
+ </para>
+ </sect2>
+
+ <sect2 id="ncat-timing">
+ <title>Timing</title>
+
+ <para>
+ Ncat offers various options to control timing. Each of them take an
+ argument that is assumed to be in seconds, unless followed by
+ <quote>ms</quote> for milliseconds,
+ <quote>s</quote> for seconds, <quote>m</quote> for minutes, or
+ <quote>h</quote> for hours. <quote>30s</quote> means 30 seconds. This format should already be familiar to Nmap users.
+ </para>
+
+ <para>
+ The
+ <option>--delay</option><indexterm><primary><option>--delay</option> (Ncat option)</primary></indexterm>
+ option and its short form
+ <option>-d</option><indexterm><primary><option>-d</option> (Ncat option)</primary><see><option>--delay</option></see></indexterm>
+ make Ncat wait the given amount of time between each discrete read
+ or write operation. For example, <command>--delay 500ms</command>
+ enforces a delay of half a second.
+ </para>
+
+ <para>
+ The
+ <option>--idle-timeout</option><indexterm><primary><option>--idle-timeout</option> (Ncat option)</primary></indexterm>
+ option and it synonym
+ <option>-i</option><indexterm><primary><option>-i</option> (Ncat option)</primary><see><option>--idle-timeout</option></see></indexterm>
+ allow setting a timeout for reads and writes in connect mode. If the
+ client fails to read or write for the given time period, the
+ connection is dropped. These options do not work in listen mode.
+ </para>
+
+ <para>The
+ <option>--wait</option><indexterm><primary><option>--wait</option></primary></indexterm> (or <option>-w</option> for short)<indexterm><primary><option>-w</option> (Ncat option)</primary><see><option>--wait</option></see></indexterm>
+ option sets how long Ncat will wait for a connection to be established in
+ connect mode. The default is 10 seconds.
+ </para>
+ </sect2>
+</sect1>
+
+<sect1 id="ncat-file-transfer">
+ <title>File Transfer</title>
+ <indexterm><primary>file transfer with Ncat</primary></indexterm>
+
+ <para>
+ There is no shortage of ways to transfer a file over a network. Most
+ file transfers are ably handled by email, network file systems, HTTP,
+ SFTP, or other protocols. What do you do, though, when that file is
+ too big to email, the transfer is between two machines not connected
+ to the Internet, or you just need to do one quick file transfer
+ without having to set up and tear down a file server? In these and
+ other situations Ncat can be the right tool for the job. Some tricky
+ file transfer scenarios can really make you appreciate the flexibility
+ of a raw network pipe.
+ </para>
+
+ <para>
+ As you know, Ncat by default sends all its traffic without encryption,
+ so it is possible for someone to intercept files in transit. See
+ <xref linkend="ncat-ssl"/> for one method of encrypting traffic.
+ </para>
+
+ <para>
+ By default, Ncat doesn't close its connection until it is closed by
+ the remote end, even after it has exhausted its input. That is because
+ (as far as Ncat knows) the remote server may still have data to send
+ back. The
+ <option>--send-only</option><indexterm><primary><option>--send-only</option> (Ncat option)</primary></indexterm>
+ option, when applicable, changes this behavior to close the connection
+ and quit at the end of input. This is normally what you want when
+ doing a one-way file transfer.
+ </para>
+
+ <para>
+ A basic file transfer is very simple: Start Ncat in listen mode on one
+ end, start Ncat in connect mode on the other end, and pipe the file
+ over the connection. There are two ways to do this that differ only in
+ which end listens, the sender or the receiver. Sometimes you can't
+ create a listening socket on one end of the transfer because of a lack
+ or permissions, NAT, or filtering. As long as you can listen on at
+ least one end, though, you can use this technique.
+ </para>
+
+ <para>
+ These examples show how to transfer <filename>inputfile</filename> on
+ host1 to <filename>outputfile</filename> on host2. Here no port number
+ was specified so Ncat will use its default
+ port<indexterm><primary>default port of Ncat</primary></indexterm> of
+ 31337. To use a different port just list it on the command line.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>Transfer a file, receiver listens</term>
+ <listitem>
+<indexterm><primary><option>--listen</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<indexterm><primary><option>-l</option> (Ncat option)</primary><see><option>--listen</option></see></indexterm>
+<literallayout>
+host2$ <userinput>ncat -l &gt; outputfile</userinput>
+host1$ <userinput>ncat --send-only host2 &lt; inputfile</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>Transfer a file, sender listens</term>
+ <listitem>
+<literallayout>
+host1$ <userinput>ncat -l --send-only &lt; inputfile</userinput>
+host2$ <userinput>ncat host1 &gt; outputfile</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Note the order of the commands. The listener must be started first,
+ regardless of the direction of transfer, or else the client will not
+ have anything to connect to.
+ </para>
+
+ <para>
+ The above technique works fine for sending a single file. One way to
+ send multiple files is to bundle them up with <command>tar</command>
+ or <command>zip</command> and send the archive file. But there's an
+ even easier way. Just pipe the output of <command>tar</command>
+ directly into Ncat on the sending side, and pipe Ncat's output into
+ <command>tar</command> on the receiving side. This is especially
+ useful when the sending computer doesn't have enough free disk space
+ to hold the archive file. Here's how to transfer
+ <replaceable>files</replaceable> using the <quote>receiver
+ listens</quote> method, though of course the <quote>sender
+ listens</quote> method works just as well.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>Transfer a bundle of files</term>
+ <listitem>
+<literallayout>
+host2$ <userinput>ncat -l | tar xzv</userinput>
+host1$ <userinput>tar czv <replaceable>files</replaceable> | ncat --send-only host2</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Not only tar files but any stream of bytes can be transferred in this
+ way. Here is an example of transferring an entire disk image from host1
+ to host2. Naturally, the disk should be unmounted or mounted
+ read-only.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>Transfer a disk image</term>
+ <listitem>
+<literallayout>
+host2$ <userinput>ncat -l &gt; host1-hda.image</userinput>
+host1$ <userinput>ncat --send-only host2 &lt; /dev/hda</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Disk images are typically large files that take a long time to
+ transfer. You can compress the image on the fly while sending and
+ decompress it on the other end. Whether this makes an improvement
+ depends on the speed of the network and the compression program.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>Transfer a disk image with compression</term>
+ <listitem>
+<literallayout>
+host2$ <userinput>ncat -l | bzip2 -d &gt; host1-hda.image</userinput>
+host1$ <userinput>cat /dev/hda | bzip2 | ncat --send-only host2</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ The basic file transmission technique described at the beginning of
+ this section fails if neither participating host is capable of
+ listening, or the two hosts can't communicate directly. This situation
+ has become common with the prevalence of network address translation.
+ A way to work around it is to use a third host as an intermediary. The
+ intermediate host listens in connection brokering mode and the other
+ two hosts connect to it. Recall from <xref linkend="ncat-broker"/>
+ that in connection brokering mode any input received on one socket is
+ copied and sent out to all other sockets. With just two hosts
+ connected this is especially simple: anything coming from one host
+ gets forwarded to the other. This example shows host1 sending
+ <filename>inputfile</filename> to <filename>outputfile</filename> on
+ host2, using host3 as an intermediary.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>Transfer a file through an intermediary</term>
+ <listitem>
+<indexterm><primary><option>--broker</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+host3$ <userinput>ncat -l --broker</userinput>
+host2$ <userinput>ncat host3 &gt; outputfile</userinput>
+host1$ <userinput>ncat --send-only host3 &lt; inputfile</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Note that it's important for host2 (the receiving host) to connect to
+ the broker before host1 (the sending host) does. The broker does not
+ buffer received data to send to hosts that connect later. After the
+ file is transferred, it is necessary to forcibly disconnect the Ncat
+ on host2 with
+ <keycombo><keycap>ctrl</keycap><keycap>C</keycap></keycombo>. The
+ broker never disconnects any of its clients.
+ </para>
+</sect1>
+
+<sect1 id="ncat-chat">
+ <title>Chatting</title>
+
+ <para>
+ In its most basic form, Ncat simply moves bits from one place to
+ another. This is all that is needed to set up a simple chat system. By
+ default, Ncat reads from
+ standard input<indexterm><primary>standard input</primary></indexterm>
+ and writes to
+ standard output,<indexterm><primary>standard output</primary></indexterm>
+ meaning that it will send whatever is typed at the keyboard and will
+ show on the screen whatever is received.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>Two-user chat</term>
+ <listitem>
+<literallayout>
+host1$ <userinput>ncat -l</userinput>
+host2$ <userinput>ncat host1</userinput>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ With this setup, two users can communicate with each other. Whatever
+ one types will appear on the screen of the other. Be aware that
+ standard input is probably line-buffered so it may be necessary to press
+ <keycap>enter</keycap> before a line is sent. Which side listens
+ and which side connects is not important in this situation, except that the listener must start ncat first.
+ </para>
+
+ <para>
+ The above technique is limited to one-on-one conversations. If more
+ users connect to the server, each one will effectively create a new
+ chat channel with the server; none of the connecting users will hear
+ each other. Multi-user chatting is easily supported using connection
+ brokering with the <option>--broker</option> option (see
+ <xref linkend="ncat-broker"/>). In broker mode, anything received on
+ one connection is sent out to all other connections, so everyone can
+ talk with everyone else.
+ </para>
+
+ <indexterm><primary>chat mode (Ncat)</primary></indexterm>
+ <para>
+ When many users are chatting through a connection broker, it can be
+ hard to know who is saying what. For these cases Ncat provides a simple
+ hack to tell users apart. When the
+ <option>--chat</option><indexterm><primary><option>--chat</option> (Ncat option)</primary></indexterm>
+ option is given, connection brokering is automatically enabled. Each
+ message received is prefixed with an ID before being relayed to all
+ other clients. The ID is unique for each client connection, and
+ therefore functions something like a username. Also, in chat mode any
+ control characters are escaped so they won't mess up your terminal.
+ The server is started with
+<literallayout>
+server$ <userinput>ncat -l --chat</userinput>
+</literallayout>
+ </para>
+
+ <para>
+ Once the server is started, this is how the chat appears to one of the
+ connected users. The lines that begin with
+ <literal>&lt;user<replaceable>n</replaceable>&gt;</literal> are from
+ other connected users. The line beginning with
+ <literal>&lt;user0&gt;</literal> was sent by the listening broker.
+ </para>
+
+<screen>
+client$ <userinput>ncat server</userinput>
+&lt;user6&gt; Is anyone there?
+<userinput>I'm here.</userinput>
+&lt;user5&gt; Me too.
+&lt;user0&gt; Go away, all of you.
+</screen>
+
+ <para>
+ The user IDs generated by Ncat are based on the file descriptor for
+ each connection, and must be considered arbitrary. There is no way to
+ choose a particular ID or make one persist across sessions.
+ Nevertheless, <option>--chat</option> can come in handy for those
+ quick multi-user conversations.
+ </para>
+</sect1>
+
+<sect1 id="ncat-tricks">
+ <title>Neat Tricks</title>
+
+ <sect2 id="ncat-smtp">
+ <title>Send Mail</title>
+
+ <para>
+ It is great fun to interact with text-based network protocols with
+ nothing more than Ncat and a keyboard. Here's a short example
+ showing how to send email by talking to an SMTP server. SMTP is
+ described in
+ RFC&nbsp;5321,<indexterm><primary>RFC 5321</primary></indexterm>
+ but you don't need to know much about the protocol to send a simple
+ message. The service's assigned port number is 25, and we use
+ <option>-C</option> because it requires CRLF line endings.
+ <xref linkend="ncat-ex-smtp" xrefstyle="select: label nopage"/>
+ contains a transcript of a session.
+ </para>
+
+ <example id="ncat-ex-smtp">
+ <title>Ncat as mail client</title>
+<indexterm><primary><option>--crlf</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<screen>
+$ <userinput>ncat -C mail.example.com 25</userinput>
+220 mail.example.com ESMTP
+<userinput>HELO client.example.com</userinput>
+250 mail.example.com Hello client.example.com
+<userinput>MAIL FROM:a@example.com</userinput>
+250 OK
+<userinput>RCPT TO:b@example.com</userinput>
+250 Accepted
+<userinput>DATA</userinput>
+354 Enter message, ending with "." on a line by itself
+<userinput>From: a@example.com
+To: b@example.com
+Subject: Greetings from Ncat
+
+Hello. This short message is being sent by Ncat.
+.</userinput>
+250 OK
+<userinput>QUIT</userinput>
+221 mail.example.com closing connection
+</screen>
+ </example>
+
+ <para>
+ To make this example work for you, change
+ <literal>mail.example.com</literal> to your SMTP server and
+ <literal>client.example.com</literal> to your domain
+ name. Naturally you'll want to change the email addresses and
+ message too. It will likely only work when using your normal mail
+ server with your real email address, or when using the recipient's
+ mail server (look up the MX record for the domain name in their
+ email address).
+ </para>
+
+ <para>
+ Obviously this technique can be used for more than just sending
+ mail. Ncat is a great interactive debugging tool for any text-based
+ protocol. Such debugging is sometimes done with the
+ <command>telnet</command> command, because it provides something
+ like a raw text stream. Ncat offers a few advantages over
+ <command>telnet</command>, though. Ncat doesn't print anything
+ except what is sent by the remote host. Telnet isn't suitable for
+ arbitrary binary data because it reserves some bytes as control
+ characters. The <command>telnet</command> command quits when its
+ input runs out, so you may not see what the other end sends. And
+ finally, <command>telnet</command> doesn't do UDP.
+ </para>
+ </sect2>
+
+ <sect2 id="ncat-httpserv">
+ <title>Turn Ncat into a simple web server</title>
+
+ <para>
+ Continuing the example from <xref linkend="ncat-listen"/>, we can
+ create a simple HTTP server that serves the
+ <literal>index.html</literal> file using the following command:
+ </para>
+
+<literallayout>
+<command>ncat -lk -p 8080 --sh-exec "echo -e 'HTTP/1.1 200 OK\r\n'; cat index.html"</command>
+</literallayout>
+
+ <para>
+ Or, if you're a Windows user:
+ </para>
+
+<literallayout>
+<command>ncat -lk -p 8080 --sh-exec "echo HTTP/1.1 200 OK&amp; echo(&amp;type index.html"</command>
+</literallayout>
+
+ <para>
+ This will start the HTTP server, serving the <literal>index.html</literal>
+ file from your current working directory. To try it out, visit
+ <userinput>http://localhost:8080/</userinput> using
+ your web browser. You can also skip <literal>:8080</literal> from the
+ URL if you specified <literal>-p 80</literal> instead of
+ <literal>-p 8080</literal> in the command above. Note that it will send
+ this file regardless of the entered URL - to change the file being sent,
+ you need to change the Ncat command or use the httpd.lua script (see
+ below).
+ </para>
+
+ <para>
+ Since Ncat v6.40, it is possible to use --lua-exec feature to run a Lua
+ script turning Ncat into a web server. In order to do that, need the
+ httpd.lua script which is bundled with the Ncat source in the
+ <literal>ncat/scripts/</literal> directory. With the httpd.lua script in
+ your working directory, run Ncat in listening mode:</para>
+
+<literallayout>
+<command>ncat --lua-exec httpd.lua --listen 8080 --keep-open</command>
+</literallayout>
+
+ <para>
+ This will spawn a HTTP server on TCP port 8080. Unlike the previous
+ example though, the httpd.lua script works without modification on all
+ POSIX-compatible systems and also on Windows. Moreover, you can specify
+ in the URL any other file from the current directory or one of its
+ subdirectories and it will be sent to the user, unlike the
+ <literal>--sh-exec</literal> example.
+ </para>
+
+ <indexterm><primary>Ncat HTTP server on production</primary></indexterm>
+ <warning><para>
+ The Ncat HTTP server examples shown above are very simple and may be not
+ as powerful as complete HTTP servers, such as Apache HTTPD. It is not
+ advised to use them in production environments (such as public website
+ hosting). It might be useful, though, if you need to quickly spawn a HTTP
+ server to copy some files or for educational purposes.
+ </para></warning>
+
+ </sect2>
+
+ <sect2 id="ncat-chain">
+ <title>Chain Ncats Together</title>
+
+ <para>
+ Ncat is designed to work within a pipeline, so naturally the output
+ of one instance of Ncat can be fed into the input of another. Here
+ is one way to send a log file from host1 to host3 by way of host2:
+<screen>
+host3$ <userinput>ncat -l &gt; log.txt</userinput>
+host2$ <userinput>ncat -l | ncat host3</userinput>
+host1$ <userinput>ncat --send-only host2 &lt; log.txt</userinput>
+</screen>
+ </para>
+
+ <para>
+ A possible problem with this technique is that it is one-way: host1 can
+ send to host3 but there is no way for host3 to send anything back to
+ host1. In this case it doesn't matter, but it can be done with a
+ small change. Consider this:
+<screen>
+host3$ <userinput>ncat -l &gt; log.txt</userinput>
+host2$ <userinput>ncat -l --sh-exec "ncat host3"</userinput>
+host1$ <userinput>ncat --send-only host2 &lt; log.txt</userinput>
+</screen>
+ The Ncat listening on host2, upon receiving a connection, creates a
+ new Ncat to speak to host3 and connects the inputs and outputs of
+ the programs running on host1 and host3 together. The same trick can
+ be used on the local host too. This example forwards the local port
+ 8080 to the web server on example.org:
+ <informalexample>
+<literallayout>
+<command>ncat -l localhost 8080 --sh-exec "ncat example.org 80"</command>
+</literallayout>
+ </informalexample>
+ </para>
+ </sect2>
+
+ <sect2 id="ncat-unwrap-ssl">
+ <title>Unwrap SSL</title>
+
+ <!-- This trick was suggested by Brandon Enright.
+ https://seclists.org/nmap-dev/2009/q1/379 -->
+ <para>
+ Suppose you need to connect to an
+ IMAP<indexterm><primary>IMAP</primary></indexterm> server that
+ requires SSL, but your mail reader doesn't support SSL. Ncat can act
+ as the encrypted bridge to connect the client and server. You will
+ connect the mail client to a local port and Ncat will forward the
+ traffic, encrypted, to the server. Here's how to connect IMAP (port
+ 143) on the local host to
+ IMAP over SSL (port 993)<indexterm><primary>IMAPS</primary></indexterm>
+ on <literal>imap.example.com</literal>.
+<literallayout>
+<command>ncat -l localhost 143 --sh-exec "ncat --ssl imap.example.com 993"</command>
+</literallayout>
+ Once this is in place, instruct the mail client to connect to the
+ IMAP server on localhost.
+ </para>
+
+ <para>
+ This trick works for protocols that pass traffic strictly between
+ two hosts. It doesn't work well for
+ HTTP<indexterm><primary>HTTP</primary></indexterm>
+ because HTTP is usually aware of hostnames and often involves
+ multiple hosts.
+ </para>
+ </sect2>
+
+ <sect2 id="ncat-ssh-tunnel">
+ <title>Use SSH Through an Ncat Tunnel</title>
+
+ <!-- This trick was suggested by Greg Darke.
+ https://seclists.org/nmap-dev/2009/q1/403 -->
+ <para>
+ With Ncat and OpenSSH<indexterm><primary>OpenSSH</primary></indexterm>
+ you can SSH to a host behind a NAT<indexterm><primary>network address translation</primary></indexterm>
+ router without having to forward ports on the router. The router
+ must have Ncat installed. Here is how to SSH to
+ <filename><replaceable>host</replaceable></filename> through
+ <filename><replaceable>router</replaceable></filename>:
+<literallayout>
+<command>ssh -o ProxyCommand="ssh -q <replaceable>router</replaceable> ncat %h %p" <replaceable>host</replaceable></command>
+</literallayout>
+ </para>
+ <para>
+ The <varname>ProxyCommand</varname> option of <command>ssh</command>
+ tells how to open the SSH connection to
+ <filename><replaceable>host</replaceable></filename>. It does this
+ by opening another SSH session to
+ <filename><replaceable>router</replaceable></filename> and
+ connecting it to
+ <filename><replaceable>host</replaceable></filename> with Ncat.
+ </para>
+
+ <para>
+ If your SSH server administrator did not disable tunneling (which is
+ enabled in most default configurations), you can use the proxy server
+ built into SSH. Use the following command to spawn a proxy server on
+ TCP port 8080 of your local machine that tunnels the traffic through
+ the SSH connection:
+ </para>
+
+<literallayout>
+<command>ssh router -D 8080</command>
+</literallayout>
+
+ <para>
+ Now you can make connections inside the network using Ncat's proxy client
+ capabilities. For example, to connect to host with IP address
+ 192.168.1.123 that is behind the router, you can use the following
+ command if you spawned the tunnel:
+ </para>
+
+<literallayout>
+<command>ncat --proxy localhost:8080 --proxy-type socks4 192.168.1.123</command>
+</literallayout>
+
+ </sect2>
+
+ <sect2 id="ncat-nmap-version">
+ <title>Watch What Nmap's Version Detection is Doing</title>
+
+ <para>
+ <!-- <xref linkend="vscan"/> tells all about Nmap's version detection
+ system. --> Ncat can show you at a low level what's going on when Nmap
+ version-scans a service. We'll make a service that only listens and
+ instruct Nmap to use every version probe in the book. Set up Ncat to
+ listen and record a hex dump log. The
+ <option>--keep-open</option><indexterm><primary><option>--keep-open</option> (Ncat option)</primary></indexterm>
+ option will make Ncat keep listening and accepting more connections
+ after the first one is finished, contrary to the normal listen mode
+ behavior of quitting when the first connection ends. Some version
+ probes are binary so redirect standard output to
+ <filename>/dev/null</filename><indexterm><primary><filename>/dev/null</filename></primary></indexterm>
+ to avoid writing them to the screen.
+ <informalexample>
+<indexterm><primary><option>--hex-dump</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<indexterm><primary><option>--keep-open</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<command>ncat -l --keep-open 5200 --hex-dump vscan.log &gt; /dev/null</command>
+</literallayout>
+ </informalexample>
+ Now scan the open port you made:
+ <informalexample>
+<indexterm><primary><option>--version-all</option></primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>nmap -d -sV --version-all localhost -p 5200</command>
+</literallayout>
+ </informalexample>
+ An except of the hex dump is shown in
+ <xref linkend="ncat-ex-nmap-version" xrefstyle="select: label nopage"/>.
+ </para>
+
+ <example id="ncat-ex-nmap-version">
+ <title>Hex dump of Nmap version detection</title>
+<screen><![CDATA[[0000] 0D 0A 0D 0A ....
+[0000] 47 45 54 20 2F 20 48 54 54 50 2F 31 2E 30 0D 0A GET / HT TP/1.0..
+[0010] 0D 0A ..
+[0000] 4F 50 54 49 4F 4E 53 20 2F 20 48 54 54 50 2F 31 OPTIONS / HTTP/1
+[0010] 2E 30 0D 0A 0D 0A .0....
+[0000] 4F 50 54 49 4F 4E 53 20 2F 20 52 54 53 50 2F 31 OPTIONS / RTSP/1
+[0010] 2E 30 0D 0A 0D 0A .0....
+[0000] 80 00 00 28 72 FE 1D 13 00 00 00 00 00 00 00 02 ...(r... ........
+[0010] 00 01 86 A0 00 01 97 7C 00 00 00 00 00 00 00 00 .......| ........
+[0020] 00 00 00 00 00 00 00 00 00 00 00 00 ........ ....
+[0000] 00 1E 00 06 01 00 00 01 00 00 00 00 00 00 07 76 ........ .......v
+[0010] 65 72 73 69 6F 6E 04 62 69 6E 64 00 00 10 00 03 ersion.b ind.....
+[0000] 00 0C 00 00 10 00 00 00 00 00 00 00 00 00 ........ ......
+[0000] 45 48 4C 4F 0D 0A EHLO..
+[0000] 48 45 4C 50 0D 0A HELP..]]></screen>
+ </example>
+
+ <para>
+ At the beginning, Nmap would have sent its
+ NULL probe<indexterm><primary>NULL probe</primary></indexterm>,
+ which isn't shown in the log file because the NULL probe doesn't
+ send anything<!-- (see <xref linkend="vscan-technique"/>)-->. At the top of
+ the log is the GenericLines probe
+ (<computeroutput>0D&nbsp;0A&nbsp;0D&nbsp;0A</computeroutput>, or
+ <computeroutput>\r\n\r\n</computeroutput>). After that is our old
+ friend the HTTP GET<indexterm><primary>GET HTTP method</primary></indexterm>
+ request. Then come all the other probes in the
+ <filename>nmap-service-probes</filename><indexterm><primary><filename>nmap-service-probes</filename></primary></indexterm>
+ file. In this excerpt are shown probes designed to get a response
+ from RPC, DNS, and SMTP.
+ </para>
+
+ </sect2>
+</sect1>
+
+<sect1 id="ncat-simple-services">
+ <title>Emulating Diagnostic Services</title>
+
+ <para>
+ There are a number of simple Internet protocols intended for testing
+ and measurement purposes. Because they deal with simple, fundamental
+ network operations they are a good match for Ncat's capabilities. This
+ section shows how to to emulate services of increasing complexity:
+ discard, echo, daytime, qotd, and chargen. These particular commands assume you are on a UNIX system such as Linux or Mac OS X, and using a <filename>/bin/sh</filename> compatible shell, such as Bash.
+ </para>
+
+ <para>
+ The discard service,<indexterm><primary>discard service</primary></indexterm>
+ defined in
+ RFC&nbsp;863,<indexterm><primary>RFC 863</primary></indexterm> simply
+ ignores anything sent to it. It runs on TCP or UDP port&nbsp;9. By
+ default, Ncat doesn't send any information unless instructed to, so
+ nothing special is needed to emulate discard. Send Ncat's output to
+ <filename>/dev/null</filename><indexterm><primary><filename>/dev/null</filename></primary></indexterm>
+ to avoid filling the screen with characters received, or just let it
+ write to the terminal if you're curious to see what's there. Use the
+ <option>--recv-only</option><indexterm><primary><option>--recv-only</option> (Ncat)</primary></indexterm>
+ option to prohibit sending any characters that might be entered at the
+ terminal.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>TCP discard server</term>
+ <listitem>
+<indexterm><primary><option>--recv-only</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<indexterm><primary><option>--keep-open</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>ncat -l --keep-open 9 --recv-only > /dev/null</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>UDP discard server</term>
+ <listitem>
+<literallayout>
+<command>ncat --udp -l --keep-open 9 --recv-only > /dev/null</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Ncat in UDP mode uses all the same options as TCP. The caveat here is that
+ connections can't be closed, only timed out, so you will eventually run out
+ of sockets if you do not use a timeout. Currently, none of the timeout
+ options do the appropriate thing in this instance.
+ </para>
+
+ <para>
+ The echo service<indexterm><primary>echo service</primary></indexterm>
+ is defined in
+ RFC&nbsp;862.<indexterm><primary>RFC 862</primary></indexterm> It runs
+ on TCP or UDP port&nbsp;7. One step more advanced than discard, it
+ sends back any data received until the connection is closed. How do
+ you instruct Ncat to return what it receives? One easy way is to run
+ everything through <filename>/bin/cat</filename>.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>TCP echo server</term>
+ <listitem>
+<indexterm><primary><option>--exec</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>ncat -l 7 --keep-open --exec "/bin/cat"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>UDP echo server</term>
+ <listitem>
+<indexterm><primary><option>--udp</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>ncat -l 7 --keep-open --udp --exec "/bin/cat"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ The daytime service,<indexterm><primary>daytime service</primary></indexterm>
+ defined in
+ RFC&nbsp;867,<indexterm><primary>RFC 867</primary></indexterm>
+ sends a human-readable date and time string over TCP or UDP
+ port&nbsp;13. It ignores any input. The format of the date and time
+ string is left unspecified, so we are free to use the output of
+ <filename>/bin/date</filename>. Because we are not interested in
+ anything sent by the client we use the
+ <option>--send-only</option><indexterm><primary><option>--send-only</option> (Ncat option)</primary></indexterm>
+ option.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>TCP daytime server</term>
+ <listitem>
+<indexterm><primary><option>--send-only</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<indexterm><primary><option>--exec</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>ncat -l 13 --keep-open --send-only --exec "/bin/date"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>UDP daytime server</term>
+ <listitem>
+<indexterm><primary><option>--udp</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>ncat -l 13 --keep-open --udp --send-only --exec "/bin/date"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Nmap comes with a
+ <filename>daytime.nse</filename><indexterm><primary><filename>daytime.nse</filename> script</primary></indexterm>
+ script that works with the daytime service. Here is its output running
+ against Ncat daytime servers on TCP and UDP.
+ </para>
+
+ <example id="ncat-ex-daytime">
+ <title><filename>daytime.nse</filename> against an Ncat daytime server</title>
+ <indexterm><primary><option>--script</option></primary><secondary>example of</secondary></indexterm>
+<screen>
+# <userinput>nmap -sSU -p 13 --script=daytime localhost</userinput>
+Starting Nmap ( https://nmap.org )
+
+Nmap scan report for localhost (127.0.0.1)
+PORT STATE SERVICE
+13/tcp open daytime
+|_daytime: Mon Jan 19 17:43:18 MST 2009
+13/udp open daytime
+|_daytime: Mon Jan 19 17:43:18 MST 2009
+
+Nmap done: 1 IP address (1 host up) scanned in 0.31 seconds
+</screen>
+ </example>
+
+ <para>
+ The qotd<indexterm><primary>qotd service</primary></indexterm>
+ (quote of the day) service is defined in
+ RFC&nbsp;865.<indexterm><primary>RFC 865</primary></indexterm> When a
+ connection is made to TCP or UDP port 17, it sends back a short
+ message, ignoring any input. Ncat can do this by invoking a program
+ that generates messages. A traditional choice is
+ <filename>/usr/games/fortune</filename>, though there are many
+ possibilities. <filename>/usr/bin/uptime</filename>, for example,
+ could be useful.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>TCP qotd server</term>
+ <listitem>
+<indexterm><primary><option>--exec</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>ncat -l 17 --keep-open --send-only --exec "/usr/games/fortune"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ <varlistentry>
+ <term>UDP qotd server</term>
+ <listitem>
+<indexterm><primary><option>--udp</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<literallayout>
+<command>do ncat -l 17 --keep-open --udp --send-only --exec "/usr/games/fortune"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ In this example it's instructive to consider the difference between
+ <command>ncat -l 17 --exec "/usr/games/fortune"</command> and
+ <command>/usr/games/fortune | ncat -l 17</command>. Think about why the
+ second command stops working after the first connection.
+ </para>
+
+ <para>
+ The chargen service<indexterm><primary>chargen service</primary></indexterm>
+ from
+ RFC&nbsp;864<indexterm><primary>RFC 864</primary></indexterm> rounds
+ out our tour of diagnostic services. It runs on TCP and UDP port 19.
+ With TCP, chargen ignores any input and sends a never-ending stream of
+ data. Never-ending, that is, until the connection is closed by the
+ user, who the RFC suggests may have <quote>had enough</quote>. There
+ are many ways of generating the characters; reading from
+ <filename>/dev/zero</filename><indexterm><primary><filename>/dev/zero</filename></primary></indexterm>
+ and running <command>yes</command> come to mind.
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>TCP chargen server</term>
+ <listitem>
+<literallayout>
+<command>yes "chargenchargenchargen" | ncat -l --keep-open 19 --send-only</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Notice that in this case the program pipes its output into
+ <command>ncat</command> rather than being invoked with
+ <option>--exec</option>. For chargen either method would work,
+ because the output of <command>yes</command> never changes.
+ Using a pipe requires only one process other than
+ <command>ncat</command>, but all users connected simultaneously will
+ see the same output stream in synchrony. If the contents must be
+ independent for each stream, then use the <option>--exec</option>
+ method, with the understanding that a new process will be started for
+ each connection.
+ </para>
+
+ <para>
+ The UDP chargen protocol is a little different. When a datagram is
+ received, it sends back one datagram containing a random number of
+ characters. Implementing this is starting to get away from Ncat, but
+ one way it could be done with the
+ Bash shell<indexterm><primary>Bash shell</primary></indexterm>
+ is this:
+ </para>
+
+ <variablelist>
+ <varlistentry>
+ <term>UDP chargen server</term>
+ <listitem>
+<indexterm><primary><option>--udp</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<indexterm><primary><option>--sh-exec</option> (Ncat option)</primary><secondary>example of</secondary></indexterm>
+<indexterm><primary><option>-c</option> (Ncat option)</primary><see><option>--sh-exec</option></see></indexterm>
+<literallayout>
+<command>ncat -l 19 --keep-open --udp --send-only --sh-exec \
+ "yes chargenchargenchargen | dd count=1 bs=$(($RANDOM % 512)) 2> /dev/null"</command>
+</literallayout>
+ </listitem>
+ </varlistentry>
+ </variablelist>
+
+ <para>
+ Notice the use of
+ <option>--sh-exec</option><indexterm><primary><option>--sh-exec</option> (Ncat option)</primary></indexterm>
+ rather than
+ <option>--exec</option><indexterm><primary><option>--exec</option> (Ncat option)</primary></indexterm>
+ to allow the use of the shell's environment variables and arithmetic
+ evaluation. Standard
+ error<indexterm><primary>standard error</primary><secondary>in Ncat subprocesses</secondary></indexterm>
+ is redirected to
+ <filename>/dev/null</filename><indexterm><primary><filename>/dev/null</filename></primary></indexterm>
+ to avoid including <command>dd</command>'s summary lines
+ (<computeroutput>1+0 records out</computeroutput>), which would
+ otherwise be included by Ncat.
+ </para>
+
+ <para>
+ This completes the tour of simple diagnostic services. These have been
+ easy to implement with Ncat because (with the exception of UDP
+ chargen) they all map directly onto a familiar command-line program.
+ As services become more complex it gets harder to do everything in the
+ shell. For complicated services it's better to write a separate
+ program and have Ncat exec it directly.
+ </para>
+
+</sect1>
+
+<indexterm class="endofrange" startref="ncat-indexterm"/>
diff --git a/ncat/docs/ncatguidehtml.xml b/ncat/docs/ncatguidehtml.xml
new file mode 100644
index 0000000..f761d0e
--- /dev/null
+++ b/ncat/docs/ncatguidehtml.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0"?>
+<!DOCTYPE article PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN" "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
+[
+<!ENTITY ncat SYSTEM "ncatguide.xml">
+]>
+
+<article id="ncat">
+<artheader>
+ <title>Ncat Users' Guide</title>
+</artheader>
+&ncat;
+</article>
diff --git a/ncat/docs/ncatmanhtml.xml b/ncat/docs/ncatmanhtml.xml
new file mode 100644
index 0000000..260b030
--- /dev/null
+++ b/ncat/docs/ncatmanhtml.xml
@@ -0,0 +1,12 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE refentry PUBLIC "-//OASIS//DTD DocBook XML V4.4//EN"
+ "http://www.oasis-open.org/docbook/xml/4.4/docbookx.dtd"
+[
+<!ENTITY refguide SYSTEM "ncat.xml">
+]>
+<article id="ncatman">
+<artheader>
+<title>Ncat Reference Guide (Man Page)</title>
+</artheader>
+&refguide;
+</article>