#!/usr/bin/env python3 """Exhaustive small-payload fuzzing of the BNW GN2 entry point. Generates small (7-sample) datasets across the input space -- sizes, data types, special characters, missing data, separators -- posts each to /bn_genenet.php and classifies the response: PREPARED prepared page rendered (input accepted) REJECTED clear validation error page ("could not be used") FAILED structure-learning failure page (after clicking through) PHP-FATAL PHP fatal/warning text leaked into the page HTTP-ERR non-200 response OTHER anything else (investigate!) Usage: BASE_URL=http://127.0.0.1:8881 python3 fuzz_bnw.py """ import itertools import os import random import sys import time import urllib.error import urllib.parse import urllib.request BASE_URL = os.environ.get("BASE_URL", "http://127.0.0.1:8881").rstrip("/") def post_gn2(payload, key, timeout=120): data = urllib.parse.urlencode({"My_Gennenet": payload, "My_key": key}).encode() req = urllib.request.Request(BASE_URL + "/bn_genenet.php", data=data, headers={"User-Agent": "bnw-fuzz/1.0"}) try: r = urllib.request.urlopen(req, timeout=timeout) return r.status, r.read().decode(errors="replace") except urllib.error.HTTPError as e: return e.code, e.read().decode(errors="replace") except Exception as e: return -1, str(e) def run_learning(key, timeout=300): """click through: progress -> execute -> layout; classify the end""" def get(path): req = urllib.request.Request(f"{BASE_URL}{path}", headers={"User-Agent": "bnw-fuzz/1.0"}) try: r = urllib.request.urlopen(req, timeout=timeout) return r.status, r.read().decode(errors="replace") except urllib.error.HTTPError as e: return e.code, e.read().decode(errors="replace") except Exception as e: return -1, str(e) get(f"/executionprogress_default.php?My_key={key}") st, body = get(f"/execute_bn_gom.php?My_key={key}") if st != 200: return f"HTTP-ERR {st}", body[:200] if "Structure learning FAILED" in body: # informative failure page (works as designed) -- but still a # learning failure for a payload that passed validation return "FAILED", body if "Fatal error" in body or "Uncaught" in body: return "PHP-FATAL", body st2, body2 = get(f"/layout_svg_no.php?My_key={key}") if st2 == 200 and " 1 else None results = {} details = {} n = 0 for name, pl in cases(): if only and only not in name: continue n += 1 key = f"f{n % 100:02d}" st, body = post_gn2(pl, key) cat = classify(st, body) if cat == "PREPARED" and do_learning: cat, extra = run_learning(key) if cat not in ("OK-NETWORK", "FAILED"): details[name] = extra results.setdefault(cat, []).append(name) if cat not in ("PREPARED", "REJECTED", "OK-NETWORK", "FAILED"): details[name] = f"status={st} " + body[:300] print(f"{cat:<12} {name}", flush=True) print("\n=== SUMMARY ===") for cat in sorted(results): print(f"{cat:<12} {len(results[cat]):3d} {', '.join(results[cat][:6])}{' ...' if len(results[cat])>6 else ''}") if details: print("\n=== DETAILS (unexpected) ===") for k, v in details.items(): print(f"--- {k}\n{v}\n") if __name__ == "__main__": main()