Abusare dei Cloudflare Workers come pass-through proxies (rotazione IP, stile FireProx)
Tip
Impara e pratica il hacking AWS:
HackTricks Training AWS Red Team Expert (ARTE)
Impara e pratica il hacking GCP:HackTricks Training GCP Red Team Expert (GRTE)
Impara e pratica il hacking Azure:
HackTricks Training Azure Red Team Expert (AzRTE)
Supporta HackTricks
- Controlla i piani di abbonamento!
- Unisciti al đŹ gruppo Discord o al gruppo telegram o seguici su Twitter đŚ @hacktricks_live.
- Condividi trucchi di hacking inviando PR ai HackTricks e HackTricks Cloud repos su github.
Cloudflare Workers possono essere deployati come proxy HTTP trasparenti pass-through dove lâURL di destinazione upstream è fornito dal client. Le richieste escono dalla rete di Cloudflare, quindi il target osserva gli IP di Cloudflare invece di quelli del client. Questo rispecchia la nota tecnica FireProx su AWS API Gateway, ma utilizza Cloudflare Workers.
FunzionalitĂ principali
- Supporto per tutti i metodi HTTP (GET, POST, PUT, DELETE, PATCH, OPTIONS, HEAD)
- Il target può essere fornito tramite parametro di query (?url=âŚ), un header (X-Target-URL), o anche codificato nel path (es., /https://target)
- Headers e body sono proxati attraverso con filtraggio di hop-by-hop/header se necessario
- Le risposte vengono relayate al client preservando il codice di stato e la maggior parte degli header
- Spoofing opzionale di X-Forwarded-For (se il Worker lo imposta da un header controllato dallâutente)
- Rotazione estremamente rapida/facile distribuendo piĂš endpoint Worker e distribuendo le richieste
Come funziona (flusso)
- Il client invia una richiesta HTTP a un Worker URL (
<name>.<account>.workers.devo una route di dominio custom). - Il Worker estrae il target da un parametro di query (?url=âŚ), dallâheader X-Target-URL, o da un segmento del path se implementato.
- Il Worker inoltra il metodo, gli header e il body in ingresso allâURL upstream specificato (filtrando gli header problematici).
- La risposta upstream viene streamata indietro al client attraverso Cloudflare; lâorigin vede gli IP di egress di Cloudflare.
Esempio di implementazione del Worker
- Legge lâURL di destinazione dal parametro di query, dallâheader o dal path
- Copia un sottoinsieme sicuro di header e inoltra il metodo/body originale
- Opzionalmente imposta X-Forwarded-For usando un header controllato dallâutente (X-My-X-Forwarded-For) o un IP casuale
- Aggiunge CORS permissivo e gestisce il preflight
Esempio Worker (JavaScript) per proxy pass-through
```javascript /** * Minimal Worker pass-through proxy * - Target URL from ?url=, X-Target-URL, or /https://... * - Proxies method/headers/body to upstream; relays response */ addEventListener('fetch', event => { event.respondWith(handleRequest(event.request)) })async function handleRequest(request) { try { const url = new URL(request.url) const targetUrl = getTargetUrl(url, request.headers)
if (!targetUrl) { return errorJSON(âNo target URL specifiedâ, 400, { usage: { query_param: â?url=https://example.comâ, header: âX-Target-URL: https://example.comâ, path: â/https://example.comâ } }) }
let target try { target = new URL(targetUrl) } catch (e) { return errorJSON(âInvalid target URLâ, 400, { provided: targetUrl }) }
// Forward original query params except control ones const passthru = new URLSearchParams() for (const [k, v] of url.searchParams) { if (![âurlâ, â_cbâ, â_tâ].includes(k)) passthru.append(k, v) } if (passthru.toString()) target.search = passthru.toString()
// Build proxied request const proxyReq = buildProxyRequest(request, target) const upstream = await fetch(proxyReq)
return buildProxyResponse(upstream, request.method) } catch (error) { return errorJSON(âProxy request failedâ, 500, { message: error.message, timestamp: new Date().toISOString() }) } }
function getTargetUrl(url, headers) { let t = url.searchParams.get(âurlâ) || headers.get(âX-Target-URLâ) if (!t && url.pathname !== â/â) { const p = url.pathname.slice(1) if (p.startsWith(âhttpâ)) t = p } return t }
function buildProxyRequest(request, target) { const h = new Headers() const allow = [ âacceptâ,âaccept-languageâ,âaccept-encodingâ,âauthorizationâ, âcache-controlâ,âcontent-typeâ,âoriginâ,ârefererâ,âuser-agentâ ] for (const [k, v] of request.headers) { if (allow.includes(k.toLowerCase())) h.set(k, v) } h.set(âHostâ, target.hostname)
// Optional: spoof X-Forwarded-For if provided const spoof = request.headers.get(âX-My-X-Forwarded-Forâ) h.set(âX-Forwarded-Forâ, spoof || randomIP())
return new Request(target.toString(), { method: request.method, headers: h, body: [âGETâ,âHEADâ].includes(request.method) ? null : request.body }) }
function buildProxyResponse(resp, method) { const h = new Headers() for (const [k, v] of resp.headers) { if (![âcontent-encodingâ,âcontent-lengthâ,âtransfer-encodingâ].includes(k.toLowerCase())) { h.set(k, v) } } // Permissive CORS for tooling convenience h.set(âAccess-Control-Allow-Originâ, ââ) h.set(âAccess-Control-Allow-Methodsâ, âGET, POST, PUT, DELETE, OPTIONS, PATCH, HEADâ) h.set(âAccess-Control-Allow-Headersâ, ââ)
if (method === âOPTIONSâ) return new Response(null, { status: 204, headers: h }) return new Response(resp.body, { status: resp.status, statusText: resp.statusText, headers: h }) }
function errorJSON(msg, status=400, extra={}) { return new Response(JSON.stringify({ error: msg, âŚextra }), { status, headers: { âContent-Typeâ: âapplication/jsonâ } }) }
function randomIP() { return [1,2,3,4].map(() => Math.floor(Math.random()*255)+1).join(â.â) }
</details>
### Automatizzare la distribuzione e la rotazione con FlareProx
FlareProx è uno strumento Python che utilizza la Cloudflare API per distribuire molti endpoint Worker e ruotare tra di essi. Questo fornisce una rotazione degli IP simile a FireProx sfruttando la rete di Cloudflare.
Configurazione
1) Crea un Cloudflare API Token usando il template âEdit Cloudflare Workersâ e ottieni il tuo Account ID dalla dashboard.
2) Configura FlareProx:
```bash
git clone https://github.com/MrTurvey/flareprox
cd flareprox
pip install -r requirements.txt
Crea il config file flareprox.json:
{
"cloudflare": {
"api_token": "your_cloudflare_api_token",
"account_id": "your_cloudflare_account_id"
}
}
Uso della CLI
- Crea N Worker proxies:
python3 flareprox.py create --count 2
- Elenca endpoints:
python3 flareprox.py list
- Endpoint per il controllo dello stato:
python3 flareprox.py test
- Eliminare tutti gli endpoints:
python3 flareprox.py cleanup
Instradamento del traffico attraverso un Worker
- Forma con parametro di query:
curl "https://your-worker.account.workers.dev?url=https://httpbin.org/ip"
- Formato intestazione:
curl -H "X-Target-URL: https://httpbin.org/ip" https://your-worker.account.workers.dev
- Formato del path (se implementato):
curl https://your-worker.account.workers.dev/https://httpbin.org/ip
- Esempi di metodo:
# GET
curl "https://your-worker.account.workers.dev?url=https://httpbin.org/get"
# POST (form)
curl -X POST -d "username=admin" \
"https://your-worker.account.workers.dev?url=https://httpbin.org/post"
# PUT (JSON)
curl -X PUT -d '{"username":"admin"}' -H "Content-Type: application/json" \
"https://your-worker.account.workers.dev?url=https://httpbin.org/put"
# DELETE
curl -X DELETE \
"https://your-worker.account.workers.dev?url=https://httpbin.org/delete"
X-Forwarded-For controllo
Se il Worker rispetta X-My-X-Forwarded-For, puoi influenzare il valore X-Forwarded-For a monte:
curl -H "X-My-X-Forwarded-For: 203.0.113.10" \
"https://your-worker.account.workers.dev?url=https://httpbin.org/headers"
Uso programmatico
Usare la libreria FlareProx per creare/elencare/testare endpoint e instradare richieste da Python.
Esempio Python: Inviare una richiesta POST tramite un endpoint Worker casuale
```python #!/usr/bin/env python3 from flareprox import FlareProx, FlareProxError import jsonInitialize
flareprox = FlareProx(config_file=âflareprox.jsonâ) if not flareprox.is_configured: print(âFlareProx not configured. Run: python3 flareprox.py configâ) exit(1)
Ensure endpoints exist
endpoints = flareprox.sync_endpoints() if not endpoints: print(âCreating proxy endpointsâŚâ) flareprox.create_proxies(count=2)
Make a POST request through a random endpoint
try: post_data = json.dumps({ âusernameâ: âtestuserâ, âmessageâ: âHello from FlareProx!â, âtimestampâ: â2025-01-01T12:00:00Zâ })
headers = { âContent-Typeâ: âapplication/jsonâ, âUser-Agentâ: âFlareProx-Client/1.0â }
response = flareprox.redirect_request( target_url=âhttps://httpbin.org/postâ, method=âPOSTâ, headers=headers, data=post_data )
if response.status_code == 200: result = response.json() print(ââ POST successful via FlareProxâ) print(fâOrigin IP: {result.get(âoriginâ, âunknownâ)}â) print(fâPosted data: {result.get(âjsonâ, {})}â) else: print(fâRequest failed with status: {response.status_code}â)
except FlareProxError as e: print(fâFlareProx error: {e}â) except Exception as e: print(fâRequest error: {e}â)
</details>
**Integrazione Burp/Scanner**
- Puntare gli strumenti (per esempio, Burp Suite) sull'URL del Worker.
- Fornire l'upstream reale usando ?url= o X-Target-URL.
- La semantica HTTP (methods/headers/body) viene preservata mentre si maschera il tuo indirizzo IP sorgente dietro Cloudflare.
**Note operative e limiti**
- Il piano Free di Cloudflare Workers consente approssimativamente 100.000 richieste/giorno per account; usa piĂš endpoint per distribuire il traffico se necessario.
- I Workers girano sulla rete di Cloudflare; molti target vedranno soltanto gli IP/ASN di Cloudflare, il che può eludere liste naive di allow/deny basate su IP o euristiche geografiche.
- Usare responsabilmente e solo con autorizzazione. Rispettare i ToS e robots.txt.
## Riferimenti
- [FlareProx (Cloudflare Workers pass-through/rotation)](https://github.com/MrTurvey/flareprox)
- [Cloudflare Workers fetch() API](https://developers.cloudflare.com/workers/runtime-apis/fetch/)
- [Cloudflare Workers pricing and free tier](https://developers.cloudflare.com/workers/platform/pricing/)
- [FireProx (AWS API Gateway)](https://github.com/ustayready/fireprox)
> [!TIP]
> Impara e pratica il hacking AWS:<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training AWS Red Team Expert (ARTE)**](https://training.hacktricks.xyz/courses/arte)<img src="../../../../../images/arte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">\
> Impara e pratica il hacking GCP: <img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training GCP Red Team Expert (GRTE)**](https://training.hacktricks.xyz/courses/grte)<img src="../../../../../images/grte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
> Impara e pratica il hacking Azure: <img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">[**HackTricks Training Azure Red Team Expert (AzRTE)**](https://training.hacktricks.xyz/courses/azrte)<img src="../../../../../images/azrte.png" alt="" style="width:auto;height:24px;vertical-align:middle;">
>
> <details>
>
> <summary>Supporta HackTricks</summary>
>
> - Controlla i [**piani di abbonamento**](https://github.com/sponsors/carlospolop)!
> - **Unisciti al** đŹ [**gruppo Discord**](https://discord.gg/hRep4RUj7f) o al [**gruppo telegram**](https://t.me/peass) o **seguici** su **Twitter** đŚ [**@hacktricks_live**](https://twitter.com/hacktricks_live)**.**
> - **Condividi trucchi di hacking inviando PR ai** [**HackTricks**](https://github.com/carlospolop/hacktricks) e [**HackTricks Cloud**](https://github.com/carlospolop/hacktricks-cloud) repos su github.
>
> </details>
HackTricks Cloud

