> For the complete documentation index, see [llms.txt](https://cajac.gitbook.io/ctf-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://cajac.gitbook.io/ctf-notes/lat-mov/reverse-shells/reverse-shell-cheat-sheets.md).

# Reverse Shell Cheat Sheets

{% hint style="info" %}
HINT

As the listener port, use one of the **open ports on the target machine**.

This maximaizes the chance that **a firewall won't block the connection**.
{% endhint %}

## Upgrade shell to TTY shell

```bash
python3 -c 'import pty;pty.spawn("/bin/bash")'
CTRL + Z                                   # backgrounds session
stty raw -echo ; fg ; reset                # brings session back to the foreground
export SHELL=bash
export TERM=xterm-256color
stty rows 200 columns 200
```

Another solution is to use `script`

```bash
script /dev/null -c /bin/bash
CTRL + Z                                   # backgrounds session
stty raw -echo ; fg ; reset                # brings session back to the foreground
export SHELL=bash
export TERM=xterm-256color
stty rows 200 columns 200
```

This will give us a TTY-session, but it's **not** `CTRL + C` safe!

## Cmd or PowerShell?

Code to figure out if your command shell is running `cmd.exe` or `powershell.exe`

```batch
(dir 2>&1 *`|echo CMD);&<# rem #>echo PowerShell
```

Will output either `CMD` or `PowerShell` depending on your shell.

URL-encoded version of the code snippet

```
(dir%202%3E%261%20*%60%7Cecho%20CMD)%3B%26%3C%23%20rem%20%23%3Eecho%20PowerShell
```

## References

Reverse Shells - HackTricks: <https://hacktricks.wiki/en/generic-hacking/reverse-shells/index.html>

Reverse Shell Cheat Sheet - HighOn.Coffee: <https://highon.coffee/blog/reverse-shell-cheat-sheet/>

Reverse Shell Cheat Sheet - Internal All The Things: <https://swisskyrepo.github.io/InternalAllTheThings/cheatsheets/shell-reverse-cheatsheet/>

Reverse Shell Cheat Sheet - PayloadsAllTheThings: <https://github.com/swisskyrepo/PayloadsAllTheThings/blob/master/Methodology%20and%20Resources/Reverse%20Shell%20Cheatsheet.md>

Reverse Shell Cheat Sheet - Pentestmonkey: <https://pentestmonkey.net/cheat-sheet/shells/reverse-shell-cheat-sheet>

Reverse Shell Generator - revshells.com: <https://www.revshells.com/>

What Happens In a "Shell Upgrade"? - 0xdf: <https://www.youtube.com/watch?v=DqE6DxqJg8Q>
