Created
July 31, 2026 06:29
-
-
Save fixploit03/57ab41c0ed0e95317be9d212334b9b82 to your computer and use it in GitHub Desktop.
patch PMKID hostapd
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/usr/bin/env python3 | |
| import shutil | |
| import sys | |
| from pathlib import Path | |
| TARGET = Path("src/ap/wpa_auth.c") | |
| OLD = ( | |
| "\tif (sm->wpa == WPA_VERSION_WPA2 &&\n" | |
| "\t (wpa_key_mgmt_wpa_ieee8021x(sm->wpa_key_mgmt) ||\n" | |
| "\t (sm->wpa_key_mgmt == WPA_KEY_MGMT_OWE && sm->pmksa) ||\n" | |
| "\t wpa_key_mgmt_sae(sm->wpa_key_mgmt)) &&\n" | |
| "\t sm->wpa_key_mgmt != WPA_KEY_MGMT_OSEN) {\n" | |
| ) | |
| NEW = "\tif (sm->wpa == WPA_VERSION_WPA2) {\n" | |
| if not TARGET.is_file(): | |
| print(f"[ERROR] Target file not found: {TARGET}", file=sys.stderr) | |
| sys.exit(1) | |
| BACKUP = TARGET.with_suffix(TARGET.suffix + ".bak") | |
| try: | |
| shutil.copy2(TARGET, BACKUP) | |
| except Exception as e: | |
| print(f"[ERROR] Failed to create backup '{BACKUP}': {e}", file=sys.stderr) | |
| sys.exit(1) | |
| try: | |
| src = TARGET.read_text(encoding="utf-8") | |
| except Exception as e: | |
| print(f"[ERROR] Failed to read '{TARGET}': {e}", file=sys.stderr) | |
| sys.exit(1) | |
| occurrences = src.count(OLD) | |
| if occurrences == 0: | |
| print( | |
| "[ERROR] Pattern not found. The source file may already be patched or has changed.", | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) | |
| if occurrences > 1: | |
| print( | |
| f"[ERROR] Pattern found {occurrences} times. Aborting to avoid patching the wrong location.", | |
| file=sys.stderr, | |
| ) | |
| sys.exit(1) | |
| patched = src.replace(OLD, NEW, 1) | |
| try: | |
| TARGET.write_text(patched, encoding="utf-8") | |
| except Exception as e: | |
| print(f"[ERROR] Failed to write '{TARGET}': {e}", file=sys.stderr) | |
| sys.exit(1) | |
| print(f"[OK] Successfully patched '{TARGET}'.") | |
| print(f"[OK] Backup created at '{BACKUP}'.") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment