> 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2Fi7zNTjPZRKHhFxRbLvPK%2Fimage.png?alt=media&amp;token=f3bab332-de2f-4890-b676-006bf2bd3f36" 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2F9qtG1w5xUMneTbA7ex57%2Fimage.png?alt=media&amp;token=42a77a11-df44-4237-bdf5-a6f28bb4f08c" 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2FxsfREm4dOx6EUQU8tYtL%2Fimage.png?alt=media&amp;token=5e986bfd-b885-4417-8741-00619e10b992" 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="https://3420091786-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fy1ZUO45eHY8aMCLJ7OiN%2Fuploads%2F7epGeZ57wgOq5c3gS3DA%2Fimage.png?alt=media&amp;token=f51d65dc-139e-4685-a219-7300f1a0eab6" alt=""><figcaption></figcaption></figure>
