> For the complete documentation index, see [llms.txt](https://notes.programmersecurity.com/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://notes.programmersecurity.com/linux-privilege-escalation/getting-a-fully-interactive-tty-shell.md).

# Getting a Fully Interactive TTY Shell

## Method 1: Python TTY Module

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

//Now press CTRL+Z to send the shell in the background

stty -a // get the rows and columns from the first line
stty raw -echo;fg // get back in the shell, Press enter 2 times to get back in

// run the below commands on the compromised machine

stty rows 26 cols 118 // based on the output of stty -a

export TERM=xterm
export TERM=xterm-256color // for colors
exec /bin/bash //I always do this, that's my methodology

// now you should have a full stable shell

```

<figure><img src="/files/Y5RDwKZg7KVpAUO4raVR" alt=""><figcaption><p>stty -a command</p></figcaption></figure>

## Method 2: Using Script Binary (If it is installed on Target System)

```javascript
which script //confirm if script is installed or not
script /dev/null -c bash 

// Now press CTRL+Z to send the shell in the background

stty raw -echo;fg // get back in the shell, Press enter 2 times to get back in

export TERM=xterm

// Now you have a good TTY shell
```

<figure><img src="/files/QdQwusWnZiCw6grdWi9n" alt=""><figcaption></figcaption></figure>

## pwncat-cs (Automated Way) Best One

We can use pwncat listener to get a fully TTY shell automtically

```python
pwncat-cs --listen -p 4444
```

<figure><img src="/files/hlMSI7flt3dqbUOoxYGt" alt=""><figcaption></figcaption></figure>

it has file upload and download feature as well, you need to Press CTRL+D to go to your Local machine and then upload and download files from the target machine to the local machine.

## Penelope Listener (Automated Way)

We can use penelope instead of netcat to get an interactive reverse shell, this automatically upgrades our shell to fully tty

```python
penelope 443  # Start a listener on port 443
```

<figure><img src="/files/VeWVaVfXYpzT3LM9QuRO" alt=""><figcaption></figcaption></figure>
