Persistence Module
cyber_modules/persistence.py demonstrates how malware establishes and removes startup persistence on Windows, Linux, and macOS. In Virus Hunter: Code Defender this is triggered at Level 3 when the player interacts with the quarantine terminal.
Constants
| Constant | Value | Description |
|---|---|---|
SIMULATED_STARTUP_DIR | cyber_modules/simulated_startup/ | Directory created to hold the marker file. Created with mkdir(parents=True, exist_ok=True) on first use. |
PERSISTENCE_MARKER | cyber_modules/simulated_startup/system_defender_autorun.txt | Text file written to confirm persistence is active. Contains the target platform and agent command. |
create_persistence(host)
Establishes startup persistence using the OS-appropriate mechanism, writes a marker file, and immediately spawns a detached background agent process.
IP address passed to the spawned agent via
--host. The agent uses this to connect the reverse shell.A 2-tuple of
(success, PERSISTENCE_MARKER). success is True if the detached agent process was launched successfully, False if the launch raised an exception. The marker path is always returned regardless of outcome.Agent command construction
The function first detects whether it is running as a frozen PyInstaller executable or as a plain Python script:--bg flag causes main() to skip Pygame and run only the reverse shell.
Platform-specific startup registration
- Windows
- Linux
- macOS
Adds a The agent command runs each time the current user logs in.
REG_SZ value named "VirusHunterAgent" to the current user’s Run key:Marker file
After the platform step, a text file is written regardless of whether the registry/crontab/plist step succeeded:Immediate detached launch
A background process is spawned right away so the shell connects without waiting for a reboot:| Flag | Value | Meaning |
|---|---|---|
DETACHED_PROCESS | 0x00000008 | Detaches from the parent console. |
CREATE_NEW_PROCESS_GROUP | 0x00000200 | Creates an independent process group. |
start_new_session | True (POSIX) | Calls setsid(), fully detaching from the parent session. |
remove_persistence()
Reverses all persistence mechanisms set by create_persistence() and terminates any running agent processes.
Always returns
(True, PERSISTENCE_MARKER). The marker is deleted if it exists.- Windows
- Linux
- macOS
- Deletes the
"VirusHunterAgent"registry value: - Force-terminates any running instances: