Shells
Last updated
Last updated
There are three different types of shells that can be used for remote code execution
Connects back to our system and gives us control through a reverse connection. A Reverse Shell
is handy when we want to get a quick, reliable connection to our compromised host. However, a Reverse Shell
can be very fragile. Once the reverse shell command is stopped, or if we lose our connection for any reason, we would have to use the initial exploit to execute the reverse shell command again to regain our access.
Waits for us to connect to it and gives us control once we do.
Usually, you leave HOST_IP = 0.0.0.0 which opens it to any IP available and doesn't directly connect back to your host machine.
Once we execute the bind shell command, we should have a shell waiting for us on the specified port. We can now connect to it. We can use netcat
to connect to that port and get a connection to the shell:
As we can see, we are directly dropped into a bash session and can interact with the target system directly. Unlike a Reverse Shell
, if we drop our connection to a bind shell for any reason, we can connect back to it and get another connection immediately. However, if the bind shell command is stopped for any reason, or if the remote host is rebooted, we would still lose our access to the remote host and will have to exploit it again to gain access.
Upgrade TTY to give better versatility with commanding shell through Netcat. In our netcat
shell, we will use the following command to use python to upgrade the type of our shell to a full TTY:
After we run this command, we will hit ctrl+z
to background our shell and get back on our local terminal, and input the following stty
command:
Once we hit fg
, it will bring back our netcat
shell to the foreground. At this point, the terminal will show a blank line. We can hit enter
again to get back to our shell or input reset
and hit enter to bring it back. At this point, we would have a fully working TTY shell with command history and everything else.
Communicates through a web server, accepts our commands through HTTP parameters, executes them, and prints back the output.
First of all, we need to write our web shell that would take our command through a GET
request, execute it, and print its output back. A web shell script is typically a one-liner that is very short and can be memorized easily. The following are some common short web shell scripts for common web languages:
Once we have our web shell, we need to place our web shell script into the remote host's web directory (webroot) to execute the script through the web browser. This can be through a vulnerability in an upload feature, which would allow us to write one of our shells to a file, i.e. shell.php
and upload it, and then access our uploaded file to execute commands.
However, if we only have remote command execution through an exploit, we can write our shell directly to the webroot to access it over the web. So, the first step is to identify where the webroot is. The following are the default webroots for common web servers:
We can check these directories to see which webroot is in use and then use echo
to write out our web shell. For example, if we are attacking a Linux host running Apache, we can write a PHP
shell with the following command:
Once we write our web shell, we can either access it through a browser or by using cURL
. We can visit the shell.php
page on the compromised website, and use ?cmd=id
to execute the id
command:
http://SERVER_IP:PORT/shell.php?cmd=id
Another option is to use cURL
:
Web Server | Default Webroot |
---|---|
Apache
/var/www/html/
Nginx
/usr/local/nginx/html/
IIS
c:\inetpub\wwwroot\
XAMPP
C:\xampp\htdocs\