Reverse Shell Attack with Netcat

Kawya De Silva
Bug Zero
Published in
4 min readDec 26, 2022

--

Photo by Pascal Debrunner on Unsplash
Image Source: Invicti

Introduction

A reverse shell attack is a type of malicious activity that can lead to the compromise of your computer. The attacker will establish a connection back to their own machine and create a connection with the target system. This allows them to have access to the compromised machine and perform actions on it as if they were actually logged in there.

What are Reverse Shells?

A reverse shell is a shell session that is started on a connection that is made from a distant machine rather than the attacker’s host. If a remote command execution vulnerability is successfully exploited, attackers can use a reverse shell to acquire an interactive shell session on the target computer and carry out their assault. Additionally, reverse shells can operate through a firewall or NAT.

The reverse shell attacker seeks a shell in the compromised target

The reverse shell attacker wants a shell on the compromised target machine. This can be done by sending specially crafted network packets to a port to which you have access and then capturing those packets with an interception tool.

The attacker is in another network, which means he or she will not have direct access to any ports on your machine. To get around this issue, you need some way of getting your program onto the victim machine so that it can communicate with him/her via packet capture tools like Wireshark or tcpdump (or other similar programs). You can do this by using Netcat from Kali Linux as well as any other operating system capable of doing this type of thing if necessary!

The attacker and victim are in separate networks

The victim and attacker are in different networks.

The attacker wants to get a shell on the victim machine and they can use netcat to establish a reverse shell by using the following command:

Option 1: Using netcat to establish a reverse shell

  • Using netcat to establish a reverse shell.

Netcat is a simple utility for reading and writing data across network connections. It’s available on most operating systems, including Linux, Mac OS X, and Windows. Netcat can be used as both client or server depending on what you need it to do; as a client, it connects to another machine (machine A) and then sends some output there; as a server, it listens on port 5555 so that other machines can connect via Telnet or SSH into your computer remotely (machine B).

Netcat isn’t just useful for establishing shell access — it’s also capable of sending data back over the connection!

Option 2: Netcat -e option.

The -e option is used in reverse shells to specify a program to execute. For example:

netcat -l -e bash or netcat -l 2>&1 &

This command will run the shell script named “bash” and pipe its output into the first command line argument. The & operator is used to send data back through the connection, which is useful for running commands on both sides of an SSH connection (as we’ll see later).

Understanding the syntax of netcat.

Netcat is a simple utility for reading from and writing to network connections. It can be used for testing network programs, as well as debugging problems with your own network configuration. Netcat is also useful when you want to create a reverse shell attack (a way of remotely controlling another computer).

Conclusion

We now have a reverse shell on the target machine. To learn more about this exploitation technique, check out the following resources:

References:

Bug Zero is a bug bounty, crowdsourcing platform for security testing. The platform is the intermediatory entity that enables client organizations to publish their service endpoints so that bug hunters (security researchers / ethical hackers) registered in the platform can start testing the endpoints without any upfront charge. Bug hunters can start testing as soon as a client organization publishes a new program. Bug Zero also offers private bug bounty programs for organizations with high-security requirements.

https://bugzero.io/signup

Bug Zero is available for both hackers and organizations.

For organizations and hackers, register with Bug Zero for free, and let’s make cyberspace safe.

--

--