hacktricks/network-services-pentesting/pentesting-web/php-tricks-esp/php-ssrf.md

92 lines
4.6 KiB
Markdown
Raw Normal View History

2023-01-22 18:27:01 +00:00
# PHP SSRF
{% 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)
2023-01-22 18:27:01 +00:00
<details>
2023-01-22 18:27:01 +00:00
<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.
2023-01-22 18:27:01 +00:00
</details>
{% endhint %}
2023-01-22 18:27:01 +00:00
### Funções SSRF PHP
2023-01-22 18:27:01 +00:00
Algumas funções como **file\_get\_contents(), fopen(), file(), md5\_file()** aceitam URLs como entrada que elas seguirão, tornando **possíveis vulnerabilidades SSRF** se o usuário puder controlar os dados:
2023-01-22 18:27:01 +00:00
```php
file_get_contents("http://127.0.0.1:8081");
fopen("http://127.0.0.1:8081", "r");
file("http://127.0.0.1:8081");
md5_file("http://127.0.0.1:8081");
```
### Wordpress SSRF via DNS Rebinding
Como [**explicado neste post do blog**](https://patchstack.com/articles/exploring-the-unpatched-wordpress-ssrf), até mesmo a função do Wordpress **`wp_safe_remote_get`** é vulnerável a DNS rebinding, tornando-a potencialmente vulnerável a ataques SSRF. A principal validação que ela chama é **wp\_http\_validate\_url**, que verifica se o protocolo é `http://` ou `https://` e se a porta é uma das **80**, **443** ou **8080**, mas é **vulnerável a DNS rebinding**.
Outras funções vulneráveis de acordo com o post são:
* `wp_safe_remote_request()`
* `wp_safe_remote_post()`
* `wp_safe_remote_head()`
* `WP_REST_URL_Details_Controller::get_remote_url()`
* `download_url()`
* `wp_remote_fopen()`
* `WP_oEmbed::discover()`
2023-01-22 18:27:01 +00:00
### CRLF
Além disso, em alguns casos, pode ser até possível enviar cabeçalhos arbitrários via "vulnerabilidades" CRLF nas funções anteriores:
2023-01-22 18:27:01 +00:00
```php
# The following will create a header called from with value Hi and
2023-01-22 18:27:01 +00:00
# an extra header "Injected: I HAVE IT"
ini_set("from", "Hi\r\nInjected: I HAVE IT");
file_get_contents("http://127.0.0.1:8081");
GET / HTTP/1.1
From: Hi
Injected: I HAVE IT
Host: 127.0.0.1:8081
Connection: close
# Any of the previously mentioned functions will send those headers
```
{% hint style="warning" %}
Para mais informações sobre essa vulnerabilidade CRLF, verifique este bug [https://bugs.php.net/bug.php?id=81680\&edit=1](https://bugs.php.net/bug.php?id=81680\&edit=1)
2023-01-22 18:27:01 +00:00
{% endhint %}
Observe que essas funções podem ter outros métodos para definir cabeçalhos arbitrários em solicitações, como:
2023-01-22 18:27:01 +00:00
```php
$url = "";
$options = array(
'http'=>array(
'method'=>"GET",
'header'=>"Accept-language: en\r\n" .
"Cookie: foo=bar\r\n" . // check function.stream-context-create on php.net
"User-Agent: Mozilla/5.0 (iPad; U; CPU OS 3_2 like Mac OS X; en-us) AppleWebKit/531.21.10 (KHTML, like Gecko) Version/4.0.4 Mobile/7B334b Safari/531.21.102011-10-16 20:23:10\r\n" // i.e. An iPad
)
2023-01-22 18:27:01 +00:00
);
$context = stream_context_create($options);
$file = file_get_contents($url, false, $context);
```
{% 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)
2023-01-22 18:27:01 +00:00
<details>
<summary>Supporte o HackTricks</summary>
2023-01-22 18:27:01 +00:00
* 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.
2023-01-22 18:27:01 +00:00
</details>
{% endhint %}