
Dimostra lo sfruttamento di SSRF tramite differenze nel parser URL tra urllib.parse e requests, includendo il servizio vulnerabile e lo script di exploit PoC.
# vulnerable_service.py - Validates URL with urllib.parse, fetches with requests
from flask import Flask, request
import requests
import urllib.parse
app = Flask(__name__)
def is_allowed_url(url):
parsed = urllib.parse.urlparse(url)
# Only allow http://localhost and http://127.0.0.1
return parsed.hostname in ('localhost', '127.0.0.1')
@app.route('/fetch')
def fetch():
url = request.args.get('url')
if not is_allowed_url(url):
return "Blocked", 403
# Fetch with requests (different parser)
r = requests.get(url, timeout=5)
return r.text
if __name__ == '__main__':
app.run(port=5000)
Un servizio utilizza urllib.parse.urlparse di Python per validare gli URL ma poi li recupera con la libreria requests. Le discrepanze nel modo in cui i due parser gestiscono i caratteri speciali (come @) consentono a un attaccante di aggirare la whitelist e accedere a risorse interne.
urlparse tratta [email protected] come avente hostname localhost (la parte prima di @ è il nome utente), mentre requests interpreta l'host come evil.com.pip install flask requests
python vulnerable_service.py
python exploit_ssrf_parser_diff.py