This sample malware shows three progressively more capable self-replicating programs:
FooVIrus.py: Local single-host file infector for files ending in.foo.FooWorm.py: Network-aware worm that connects via SSH, looks for.foofiles on a remote host, exfiltrates and re-uploads infected copies, and drops itself.AbraWorm.py: Polymorphic SSH worm that searches for files containing the stringabracadabra, exfiltrates them, uploads a mutated copy of itself, and supports a debug mode for safe testing.
The code is intentionally simplified to make core concepts observable: discovery, infection logic, propagation, exfiltration, and basic anti-reinfection checks.
FooVIrus.py— local file infector that targets.foofiles (no networking)FooWorm.py— SSH-based worm targeting.foofiles on remote hostsAbraWorm.py— SSH/SCP polymorphic worm targeting files containingabracadabraREADME.md— this document
- Python 3.8+
- Linux-based hosts or containers for the target systems (for SSH-based runs)
- Python packages:
paramiko(SSH client)scp(SCP over paramiko)
Install dependencies in an isolated environment:
python -m venv .venv
source .venv/bin/activate # Windows PowerShell: .venv\Scripts\Activate.ps1
pip install --upgrade pip
pip install paramiko scpBoth FooWorm.py and AbraWorm.py implement a debug = 1 mode to make testing predictable and self-contained:
- Uses fixed credentials: username
seed, passworddees. - Uses fixed target IPs:
10.0.2.10and10.0.2.11. - Exfiltration server:
10.0.2.9(alsoseed/dees). - Halts after the first full iteration to prevent endless scanning.
Example topology (private, isolated network recommended):
- Host A (Operator): run the scripts from this repository.
- Host B (Target 1): IP
10.0.2.10, SSH enabled, userseed/ passdees. - Host C (Target 2): IP
10.0.2.11, SSH enabled, userseed/ passdees. - Host D (Exfil server): IP
10.0.2.9, SSH enabled, userseed/ passdees.
Ensure SSH is running on all target hosts, accounts exist, and the network allows traffic among these IPs only.
Purpose: minimal self-replicating infector without networking.
- Reads its own first ~50 lines into memory (
virus_code). - Walks the filesystem (as coded:
/home/) and targets files ending with.foo. - Skips files that appear already infected (checks for a marker string containing
FooWorm). - Grants write permission (
chmod 777) to ensure it can write the file. - Prepends its own code and comments out the original file contents.
Run locally in a safe directory that contains test .foo files. Example:
python FooVIrus.pyNote: Paths are currently Linux-centric; adjust for your environment (or run inside a Linux VM).
Purpose: remote discovery, infection, and exfiltration via SSH/SCP.
- In
debug = 1:- Cycles over predefined users/passwords (
seed/dees) and IPs (10.0.2.10,10.0.2.11). - Connects via SSH, runs
lsto check if the target is already infected (looks forFooWorm). - Locates
.foofiles withls *.foo 2>/dev/null. - If found: downloads them via SCP, then creates an infected version by prepending the worm code and commenting the original lines; uploads back and also uploads
FooWorm.pyitself to the target. - If files were collected, attempts to exfiltrate them to
10.0.2.9via SCP.
- Cycles over predefined users/passwords (
- In
debug = 0:- Username/password/IP generation becomes randomized. Do not use outside environments you explicitly control.
Run in debug mode (default in the provided code):
python FooWorm.pyPurpose: polymorphism plus targeted file discovery by content.
- In
debug = 1:- Uses fixed credentials (
seed/dees) and IPs (10.0.2.10,10.0.2.11). - On a target host, avoids reinfection by checking for
AbraWorminlsoutput. - Searches for files containing the string
abracadabrawithgrep -ls abracadabra *. - Downloads any matching files via SCP.
- Creates a polymorphic variant of itself by inserting random newlines and random comment lines in a temp copy; uploads the modified file as
AbraWorm.pyto the target. - If files were collected, attempts to exfiltrate them to
10.0.2.9.
- Uses fixed credentials (
- In
debug = 0:- Randomized usernames/passwords/IPs are generated. Use only in environments you explicitly control.
Run in debug mode (default in the provided code):
python AbraWorm.pyOn the target hosts:
-
For
FooWorm.py/FooVIrus.py:echo "sample" > /home/seed/test1.foo echo "another" > /home/seed/docs/report.foo
-
For
AbraWorm.py(files containingabracadabra):echo "nothing here" > /home/seed/notes.txt echo "abracadabra magic" > /home/seed/secrets.txt
Ensure file permissions allow read/write for the test user.
- Default behavior for the SSH worms presumes password authentication is enabled on targets.
- Host key verification is disabled (
AutoAddPolicy) for simplicity in this project. - Timeouts are short (e.g., 5s) to keep runs responsive; adjust for your environment if needed.
- Exfiltration steps require the exfil server to be reachable and writable with the same credentials.
- "Connection failed" or timeouts:
- Verify IPs, SSH service status, credentials, and network connectivity.
- Confirm you are running within the isolated lab network.
- "No files found":
- Ensure the target host actually has
.foofiles (forFooWorm.py) or files containingabracadabra(forAbraWorm.py).
- Ensure the target host actually has
- Permission errors writing files:
- Create test files under a user-writable directory and keep ownership consistent with the SSH user.
- Windows hosts:
- These scripts target Linux paths and tools (
grep, Unix permissions). Use Linux VMs or WSL for faithful behavior.
- These scripts target Linux paths and tools (
- Delete any infected
.fooorabracadabrafiles you created for testing. - Remove uploaded worm scripts from target hosts (
FooWorm.py,AbraWorm.py). - Restore from snapshots if you took them before running tests (recommended).
- Disable or reset the test accounts and passwords used for this project.
This project is for defensive education: to understand how worms operate so you can detect, prevent, and respond. Never deploy code resembling this without explicit authorization and all necessary approvals.
Educational use only. If you intend to redistribute or adapt, consult your instructor and institution policies and apply an appropriate license.