Sunday, June 30, 2019

TCP / UDP connectivity using Netcat

What is Netcat
Netcat (nc) is a computer networking service for reading from and writing to network connections using TCP or UDP.
it is a feature-rich network debugging and investigation tool
  • Its list of features includes
    • port scanning
    • port binding
    • transferring files
    • port listening
    • it can be used as a backdoor
    • Ability to use any local source port
Netcat Command Flags

Command FlagsDescription
-uUDP (User Datagram Protocol)
-zDon't send any Data, just emit a packet without payload(scanning)
-vbe verbose : print out messages on standard information
-ndo not perform DNS lookup on name of system on the other side
-lListen mode
-LListen harder
How To Use Netcat for Port Scanning
Here, we can scan all ports up to 1000 by issuing this command: 
netcat -z -v targetdomain.com 1-1000
Output

Scan will go much faster if you know the IP address that you need.
netcat -z -n -v 127.0.0.1 1-1000
output 

How To Communicate through Netcat
Netcat is not restricted to sending TCP and UDP packets. It also can listen on a port for connections and packets. This gives us the opportunity to connect two instances of netcat in a client-server relationship. 
one system, you can tell netcat to listen to a specific port for connections. 
netcat -l 1234
This will tell netcat to listen for TCP connections on port 1234 
second server, we can connect to the first machine on the port number we choose
netcat targetdomain.com 1234
Type a message and press ENTER. It will appear on both the local and remote screen. This works in the opposite direction as well. When you are finished passing messages, you can press CTRL-D to close the TCP connection

No comments:

Post a Comment