Netcat: Difference between revisions
Initial content |
No edit summary |
||
| Line 3: | Line 3: | ||
netcat can refer to the following projects. Each implementation has similar functionalities, but the command line options may differ. | netcat can refer to the following projects. Each implementation has similar functionalities, but the command line options may differ. | ||
# GNU <code>netcat</code> (which is symlinked to <code>nc</code> on some Linux systems, leading to confusion) | #GNU <code>netcat</code> (which is symlinked to <code>nc</code> on some Linux systems, leading to confusion) | ||
# OpenBSD <code>nc</code> | #OpenBSD <code>nc</code> | ||
# Nmap's <code>ncat</code> (which is also symlinked to nc) with lots of features including SSL support and proxy connections. | #Nmap's <code>ncat</code> (which is also symlinked to nc) with lots of features including SSL support and proxy connections. | ||
== Usage == | ==Usage== | ||
For the most part, netcat and ncat are very similar. The older OpenBSD nc has less features. | For the most part, netcat and ncat are very similar. The older OpenBSD nc has less features. | ||
{| class="wikitable" | {| class="wikitable" | ||
| Line 31: | Line 31: | ||
|} | |} | ||
=== SSL with ncat === | ===SSL with ncat=== | ||
ncat allows for creating SSL server or client. | ncat allows for creating SSL server or client. | ||
{| class="wikitable" | {| class="wikitable" | ||
! | !Description | ||
! | !Command | ||
|- | |- | ||
|Connect to a server using SSL | |Connect to a server using SSL | ||
| Line 51: | Line 51: | ||
<code>ncat --listen 443 --ssl --ssl-key key.pem --ssl-cert cert.pem</code> | <code>ncat --listen 443 --ssl --ssl-key key.pem --ssl-cert cert.pem</code> | ||
|} | |} | ||
< | |||
== Tasks == | |||
=== Create a remote shell === | |||
With ncat, you can use the --exec option to spawn a program on a new connection. | |||
{{Highlight | |||
| code = hostA# ncat --exec /bin/sh -l 8888 | |||
hostB# ncat hostA 8888 | |||
## Any command you type goes to /bin/sh on hostA | |||
| lang = terminal | |||
}} | |||
If you want to do this a bit more securely, you can also: | |||
* Enable SSL with <code>--ssl</code>. | |||
* Restrict access to a specific host with <code>--allow $sourceIP</code>. | |||
Revision as of 21:58, 17 December 2021
netcat/nc/ncat are utilities that sends and receives data using TCP or UDP.
netcat can refer to the following projects. Each implementation has similar functionalities, but the command line options may differ.
- GNU
netcat(which is symlinked toncon some Linux systems, leading to confusion) - OpenBSD
nc - Nmap's
ncat(which is also symlinked to nc) with lots of features including SSL support and proxy connections.
Usage
For the most part, netcat and ncat are very similar. The older OpenBSD nc has less features.
| nc | netcat | ncat | |
|---|---|---|---|
| Listen on a port | nc -l -p $port
|
netcat -l $port
|
ncat -l -p $port
|
| Send to a port | nc $port
|
netcat $port
|
ncat $port
|
| Send to a port, using a specific source port | n/a
|
netcat -p $sport $dest $dport
|
ncat -p $sport $dest $dport
|
SSL with ncat
ncat allows for creating SSL server or client.
| Description | Command |
|---|---|
| Connect to a server using SSL | ncat -C --ssl <server> 443
|
| Verify a server's SSL | ncat -C --ssl-verify <server> 443
|
| Listen using SSL (auto generated) | ncat --listen --ssl
|
| Listen using SSL (manual SSL certs) | openssl req -x509 -newkey rsa:4096 -keyout key.pem -out cert.pem -days 365
|
Tasks
Create a remote shell
With ncat, you can use the --exec option to spawn a program on a new connection.
hostA# ncat --exec /bin/sh -l 8888
hostB# ncat hostA 8888
## Any command you type goes to /bin/sh on hostA
If you want to do this a bit more securely, you can also:
- Enable SSL with
--ssl. - Restrict access to a specific host with
--allow $sourceIP.