Networking/Computing Tips/Tricks

In this article I wanted to explain some of the basics of a tool called 'netcat'.  Similar to my article of nmap, we will start simple and add some details as we go.

What is Netcat?

From the netcat web site: Netcat is a featured networking utility which reads and writes data across network connections, using the TCP/IP protocol.

It is designed to be a reliable "back-end" tool that can be used directly or easily driven by other programs and scripts. At the same time, it is a feature-rich network debugging and exploration tool, since it can create almost any kind of connection you would need and has several interesting built-in capabilities.

Again from the web site: It provides access to the following main features:

  • Outbound and inbound connections, TCP or UDP, to or from any ports.
  • Featured tunneling mode which allows also special tunneling such as UDP to TCP, with the possibility of specifying all network parameters (source port/interface, listening port/interface, and the remote host allowed to connect to the tunnel.
  • Built-in port-scanning capabilities, with randomizer.
  • Advanced usage options, such as buffered send-mode (one line every N seconds), and hexdump (to stderr or to a specified file) of trasmitted and received data.
  • Optional RFC854 telnet codes parser and responder.

In my words it is a security testing tool that can be used for good or for bad.  We will stick to the good.  Plus it is free!

Let's begin with where is netcat?  Well it depends on your operating system:

  • If you have Linux, it is probably already installed.  You can test this by opening a terminal window and typing 'nc -h' to see if it is installed.  
  • If you have a MAC, it is installed.  You can test it by opening a terminal window and typing 'nc -h' at the prompt.
  • If you have Windows you will have to install the tool.  

While I will not go into the step by step install process, just go to netcat.sourceforge.net and click on the downloads button.  For Windows users, you will have to serach for a compiled version on Google and install it as a .exe file.

Let's have a little fun with netcat right away.  For this first experiment, we will open two Terminal windows on one machine.  

Begin by getting the IP address of your machine using the ifconfig command (ipconfig in Windows).  You can see in mine it is 10.0.2.15:

 

In one terminal window type the following command:

nc -l -p 31337

When you do this, the cursor will be to the leftmost position and it will just sit there.  What you just did was you told your system to execute netcat with the -l meaning go into "listen mode", and the -p 31337 means to listen on port 31337.  We could have used any port here, but this should work. Assuming you did this in the same window that you typed the ifconfig command, it should look like this:

Screen Shot 2014-07-24 at 8.57.59 PM

Note: MAC users, there appear to be two versions of netcat in OSX.  If you try the above command, it will not work properly.  Try this command instead: 'ncat -4 -l -p 31337'

OK, now in the other terminal window, type the following command - make sure you replace the IP addres 10.0.2.15 with whatever the IP address was on your machine, but keep the 31337 port number:

nc 10.0.2.15 31337

What you are doing here is starting another instance of netcat and asking it to connect to the instance that you told to "listen" for connections on port 31337.  The result will be that the cursor will be sitting at the leftmost position:

Screen Shot 2014-07-24 at 9.02.13 PM

 

OK - you now have a "chat session" between the two instances of netcat!  Type "hello" in one and it appears in the other.  Then type "hello back" and the message is sent back:

Screen Shot 2014-07-24 at 9.04.52 PM

Pretty cool.  Of course you can do this between different systems on your network as well.

To end the netcat session, simply het CTRL-C on both windows and you will be back at the prompt.

OK, we are off to a great start with netcat.  I will add some more articles and experiments in the near future.  Meanwhile have fun with netcat!

 

Comments powered by CComment

Find by Tag

4G Networks 5G Networks 6LoWLAN 6LoWPAN 802.11 802.11ah 802.11ax 802.11ay 802.11az Addressing Analysis Ansible Architecture ARP Assessment AToM Baseline BGP Bloom's Taxonomy Broadband Cable cat CellStream Cellular Central Office Cheat Sheet Chrome Cisco Cloud CMD Coloring Rules Computer Consulting Customer Support Data Center Data Networking DHCPv6 DNS Docker Documentation Dublin-Traceroute dumpcap ECMP Ethernet Ethics Evaluation Field Operations Fragmentation G-MPLS GeoIP Git GNS3 Google GQUIC Hands-On History Home Network ICMP ICMPv6 IEEE 802.11p IEEE 802.15.4 India Interface Control Internet IoT IPsec IPv4 IPv6 IRINN IS-IS L2VPN L3VPN LDP Linux LLN LoL M-BGP MAC Macro Microsoft mininet Monitoring MPLS mtr MTU Multicast Name Resolution Netcat Netmiko NetMon netsh Networking Network Science nmap NSE Observations Online School OpenFlow OSPF OSPFv2 OSPFv3 OSX OTT Paris-Traceroute Parrot PIM PMTU Policy POTS POTS to Pipes PPP Profile Programming Project Management PW3E Python QoS QUIC Remote Desktop Requirements Resume Review RIP Routing RPL RSVP Rural SDN Security Service Provider Small Business SONET Speed SS7 SSH SSL Subnetting SYSCTL T-Shark TCP TCP/IP Telco Telecom 101 Telecommunications Telephone termshark Testing TLS Tools Traceroute Traffic Engineering Training Travel Tunnel Ubuntu Utility Video Virtualbox Virtualization VoIP VRF VXLAN Wi-Fi Wi-Fi 4 Wi-Fi 5 Wi-Fi 6 Windows Wireless Wireless 5G Wireshark Wireshark Tip WLAN Writing Zenmap ZigBee

Twitter Feed