aboutsummaryrefslogtreecommitdiffstats
path: root/hosts/darkstar/mitmproxy-c64u.py
diff options
context:
space:
mode:
authorMark Nipper <nipsy@bitgnome.net>2026-01-04 16:09:00 -0800
committerMark Nipper <nipsy@bitgnome.net>2026-01-04 16:09:00 -0800
commit201056b1bb82249671e9101b526c8331e1783ef1 (patch)
treef1587a0932f19c84303087d444d8e3642a38c49f /hosts/darkstar/mitmproxy-c64u.py
parentfc6e5fed904ff2e95261ea3af87a3cc38daec58f (diff)
downloadnix-201056b1bb82249671e9101b526c8331e1783ef1.tar
nix-201056b1bb82249671e9101b526c8331e1783ef1.tar.gz
nix-201056b1bb82249671e9101b526c8331e1783ef1.tar.bz2
nix-201056b1bb82249671e9101b526c8331e1783ef1.tar.lz
nix-201056b1bb82249671e9101b526c8331e1783ef1.tar.xz
nix-201056b1bb82249671e9101b526c8331e1783ef1.tar.zst
nix-201056b1bb82249671e9101b526c8331e1783ef1.zip
Add mitmproxy @darkstar to allow Assembly64 content to work with loadstar
Diffstat (limited to 'hosts/darkstar/mitmproxy-c64u.py')
-rw-r--r--hosts/darkstar/mitmproxy-c64u.py90
1 files changed, 90 insertions, 0 deletions
diff --git a/hosts/darkstar/mitmproxy-c64u.py b/hosts/darkstar/mitmproxy-c64u.py
new file mode 100644
index 0000000..520112a
--- /dev/null
+++ b/hosts/darkstar/mitmproxy-c64u.py
@@ -0,0 +1,90 @@
+import json
+import os
+from mitmproxy import http
+from datetime import datetime
+
+STATE_FILE = "clients.json"
+
+def load_state():
+ if os.path.exists(STATE_FILE):
+ with open(STATE_FILE, "r") as f:
+ return json.load(f)
+ return {}
+
+def save_state(state):
+ with open(STATE_FILE, "w") as f:
+ json.dump(state, f, indent=4)
+
+def request(flow: http.HTTPFlow) -> None:
+ client_ip = flow.client_conn.peername[0]
+ timestamp = datetime.now().strftime("%Y-%m-%d %H:%M:%S")
+
+ # Get Client-Id header to detect device type
+ client_id_header = flow.request.headers.get("Client-Id")
+
+ # Load saved server choice for this client (assembly64 or commoserve)
+ state = load_state()
+ server_choice = state.get(client_ip)
+
+ # Default: give them what they can't normally access
+ # C64U (Commodore) -> default to assembly64
+ # Ultimate64 (Ultimate) -> default to commoserve
+ if server_choice is None:
+ if client_id_header == "Ultimate":
+ server_choice = "commoserve"
+ else:
+ server_choice = "assembly64"
+
+ query_string = flow.request.query.get("query", "").lower()
+
+ # 1. KEYWORD LOGIC
+ if "assembly64" in query_string:
+ state[client_ip] = "assembly64"
+ save_state(state)
+ server_choice = "assembly64"
+ print(f"[{timestamp}] SWITCH: {client_ip} -> Assembly64")
+
+ elif "commoserve" in query_string:
+ state[client_ip] = "commoserve"
+ save_state(state)
+ server_choice = "commoserve"
+ print(f"[{timestamp}] SWITCH: {client_ip} -> Commoserve")
+
+ # 2. HELP FEATURE
+ elif "help" in query_string:
+ device = "Ultimate64" if client_id_header == "Ultimate" else "C64U"
+ help_text = (
+ "PROXY HELP:\n"
+ f"Device: {device}\n"
+ f"Current: {server_choice}\n"
+ "Search 'commoserve' or 'assembly64' to switch."
+ )
+ flow.response = http.Response.make(
+ 200,
+ json.dumps({"results": [{"name": help_text}]}),
+ {"Content-Type": "application/json"}
+ )
+ return
+
+ # 3. BOT PROTECTION
+ if not client_id_header and "/leet/search/" not in flow.request.path:
+ flow.kill()
+ return
+
+ # 4. APPLY HEADER PATCH
+ # C64U (Commodore) accessing assembly64 -> patch to Ultimate
+ # Ultimate64 (Ultimate) accessing commoserve -> patch to Commodore
+ if client_id_header == "Commodore" and server_choice == "assembly64":
+ flow.request.headers["Client-Id"] = "Ultimate"
+ print(f"[{timestamp}] PATCHED: {client_ip} (C64U) -> Assembly64")
+ elif client_id_header == "Ultimate" and server_choice == "commoserve":
+ flow.request.headers["Client-Id"] = "Commodore"
+ print(f"[{timestamp}] PATCHED: {client_ip} (Ultimate64) -> Commoserve")
+ else:
+ device = "Ultimate64" if client_id_header == "Ultimate" else "C64U"
+ print(f"[{timestamp}] FORWARDED: {client_ip} ({device}) -> {server_choice}")
+
+ # 5. FORWARDING
+ flow.request.host = "185.187.254.229"
+ flow.request.port = 80
+ flow.request.headers["Host"] = "hackerswithstyle.se"