# TTY Shell

Sometimes when we get a reverse shell, the received shell may not be fully functional.&#x20;

The following commands will allow us to spawn a proper shell.

<pre data-overflow="wrap" data-full-width="true"><code>Python -
    python -c 'import pty; pty.spawn("/bin/sh")'
    python3 -c 'import pty;pty.spawn("/bin/bash")'; export TERM=xterm-256color

Bash -
    echo os.system('/bin/bash')
<strong>    /bin/sh -i
</strong><strong>    /bin/bash -i
</strong>    script -qc /bin/bash /dev/null

Perl -
    perl -e 'exec "/bin/sh";'
    exec "/bin/sh";

<strong>Ruby: exec "/bin/sh"
</strong>
Lua: os.execute('/bin/sh')

IRB: exec "/bin/sh"

vi: :!bash

vi: :set shell=/bin/bash:shell

Nmap: !sh
</code></pre>


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://personal-archive.gitbook.io/oscp-exam-prep/commons/shells/tty-shell.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
