Netcat

From Leo's Notes
Revision as of 21:51, 17 December 2021 by Leo (talk | contribs) (Initial content)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
This page was last edited on 17 December 2021, at 21:51.

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.

  1. GNU netcat (which is symlinked to nc on some Linux systems, leading to confusion)
  2. OpenBSD nc
  3. 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.

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

ncat --listen 443 --ssl --ssl-key key.pem --ssl-cert cert.pem