Automated Malware Discovery, C2 Indicator Extraction & Threat Remediation Tool
Defuse is a lightweight, modular cybersecurity automation framework developed in Python for malware response and threat eradication inside Virtual Machine. Given only a malware filename or name stem (e.g. mal-track or maltrack), Defuse automatically discovers the binary payload, extracts Command & Control (C2) IPv4 indicators, terminates active malware processes safely, strips autostart registry persistence, deletes malicious file copies, and cleans up empty directories left behind.
- π Targeted Malware Discovery: Automatically scans common malware drop paths (
Desktop,Documents,Downloads,AppData,Temp,Startup) to locate the payload by normalized filename or stem. - π C2 IP Extraction: Parses raw ASCII and UTF-16LE binary strings without external utilities to extract valid C2 IPv4 addresses (filtering out invalid or broadcast IPs like
0.0.0.0and255.255.255.255). - β‘ Process Termination: Terminates running malware processes by matching the process name, executable path, and command line.
- π Registry Persistence Removal: Dynamically enumerates and removes malicious autostart entries across User (
HKCU) and System (HKLM)RunandRunOnceregistry keys. - π§Ή File & Folder Remediation: Sweeps common malware locations to erase dropped executables (
.exe), shortcuts (.lnk), scripts (.bat), or matching payload copies, and automatically removes empty parent folders. - β‘ Clean & Modular Architecture: Built with simple, high-performance, single-responsibility modules.
- Python 3.8+
- psutil (
pip install -r requirements.txt) - Windows 10 / 11 VM
- Administrator Privileges (required for HKLM registry & system startup cleanup)
Caution
Windows Defender may automatically quarantine or delete malware samples during dynamic analysis. Disable real-time protection in your isolated VM before running tests.
Run PowerShell as Administrator and execute:
Set-MpPreference -DisableRealtimeMonitoring $true(Note: Ensure Tamper Protection is turned off in Windows Security settings if execution is blocked).
- Unblock Downloaded Analysis Tools & Malware Files Run PowerShell as Administrator and execute:
Get-ChildItem -Path "C:\Users\soha\Downloads" -Recurse | Unblock-File# Clone repository
git clone https://learn.zone01oujda.ma/git/sohachimi/defuse
# Navigate into project directory
cd defuse
# Install dependencies
python -m pip install -r requirements.txtpython src/main.py <malware_filename_or_stem>python src/main.py maltrack
:: or
python src/main.py mal-track
:: or
python src/main.py mal-track.exeNote
You do not need to specify a full file path β Defuse automatically discovers the sample in common system drop locations.
========================================
DEFUSE
========================================
Target: mal-track.exe
[+] Malware found
[+] Attacker IP: 127.0.0.1
[+] Terminated process: maltrack.exe (PID: 2844)
[+] Process terminated
[+] Deleted registry value: maltrack
[+] Registry persistence removed
[+] Deleted file: C:\Users\soha\Documents\maltrack\maltrack.exe
[+] Removed empty directory: C:\Users\soha\Documents\maltrack
[+] Malware files deleted
========================================
Summary
========================================
Process : OK
Registry : OK
Files : OK
IP : 127.0.0.1
Defuse consists of seven clean, single-purpose Python modules:
defuse/
β
βββ src/
β βββ main.py # CLI entry point & execution orchestrator
β βββ finder.py # Targeted payload discoverer across common drop locations
β βββ strings.py # Binary string extractor & IPv4 C2 parser
β βββ process.py # Safe process detector & killer (ignores python & current PID)
β βββ registry.py # Windows Registry Run/RunOnce persistence cleaner
β βββ remover.py # Payload copy eraser & empty directory cleaner
β βββ utils.py # Path resolvers, string normalizer & safe file deleter
β
βββ requirements.txt # Project dependencies (psutil)
βββ README.md # Comprehensive documentation & mitigation report
| Module | Function | Description |
|---|---|---|
main.py |
main() |
CLI entry point orchestrating discovery, string extraction, process termination, registry cleaning, and file removal. |
finder.py |
find_malware() |
Searches recursively within common malware locations (Desktop, Documents, Downloads, AppData, Temp, Startup). |
strings.py |
extract_ip() |
Extracts ASCII & UTF-16LE binary strings to find the C2 IPv4 address, filtering out 0.0.0.0 and 255.255.255.255. |
process.py |
terminate_process() |
Scans active processes by name, path, and command line; terminates malware while ignoring python and os.getpid(). |
registry.py |
clean_registry() |
Scans and deletes matching autostart values from HKCU and HKLM Run and RunOnce keys dynamically. |
remover.py |
remove_files() |
Sweeps target malware locations for matching .exe, .lnk, .bat or stem copies, deletes files, and removes empty folders. |
utils.py |
normalize_name(), get_malware_locations(), safe_delete_file() |
Provides string normalization, malware search paths, and read-only permission reset for file deletion. |
During dynamic analysis inside an isolated Windows 10 VM, the following behavior was documented:
- Original Sample Name:
mal-track.exe - Dropped Payload Path:
C:\Users\soha\Documents\maltrack\maltrack.exe - Active Execution Name:
maltrack.exe - Command & Control (C2) IP:
127.0.0.1 - Autostart Persistence:
- Registry entry created under:
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- Registry entry created under:
- Launch the malware inside an isolated Windows VM.
- Observe its behavior using Process Explorer, Process Monitor, Registry Editor and Wireshark.
- Run Defuse with the malware filename.
- Defuse locates the malware automatically.
- The C2 IP address is extracted from the binary.
- Running malware processes are terminated.
- Registry persistence entries are removed.
- Malware files are deleted from common locations.
- Verify that the malware process, registry entry and dropped files no longer exist.
The malware copied itself to C:\Users\soha\Documents\maltrack\maltrack.exe to establish a persistent footprint.
Process Explorer showing maltrack.exe running as an active background process.
Process Monitor showing the malware creating files and modifying the Windows Registry during execution.
The malware creates a persistence entry under HKCU\Software\Microsoft\Windows\CurrentVersion\Run.
Wireshark capturing the malware communication with the C2 IP address 127.0.0.1.
To safeguard enterprise endpoints against similar threats:
- Principle of Least Privilege (PoLP): Restrict standard user accounts from possessing local administrator rights to prevent unauthorized modification of
HKLMregistry hives. - Endpoint Detection & Response (EDR): Configure EDR tools to alert on untrusted executable creation originating from user directories (
Documents,AppData,Temp). - Application Control (AppLocker / WDAC): Enforce rules that block untrusted executable binaries running outside
%ProgramFiles%. - Registry Integrity Monitoring: Monitor key autostart registry paths (
Run,RunOnce) for unexpected modifications.
Malware analysis must always take place inside isolated Virtual Machines (e.g., VirtualBox with Host-Only networking). Isolation guarantees malicious code cannot exfiltrate sensitive data, spread across the network, or compromise host environments.
Security professionals must operate strictly within legal permissions and ethical boundaries. Reverse engineering and analyzing malware is lawful and necessary when performed inside authorized lab environments for defensive research.
Executing live malware on non-isolated systems can cause severe data loss, ransomware encryption, unauthorized remote access, lateral network movement, and accidental system destruction.
To: security@zone01.com
Subject: Malware Analysis Report: Mitigation of maltrack
Dear Security Team,
I am writing to report the successful analysis and mitigation of maltrack identified during an educational malware analysis exercise. Below are the details:
Summary:
The malware established persistence by creating a registry entry under HKCU\Software\Microsoft\Windows\CurrentVersion\Run, communicated with the C2 IP address 127.0.0.1, and executed as the process maltrack.exe.
Proof of Mitigation:
The malware process was successfully terminated, the registry persistence entry was removed, and the malware executable and its dropped copy were deleted from the system using the Defuse malware removal tool.
Attacker Information:
The malware communicated with the following IP address: 127.0.0.1.
Please feel free to reach out for further clarification or additional details.
Best regards,
Sohachimi
sohachimi.dev@gmail.com