This project is strictly for educational purposes only as part of the Fundamentals of Malware Analysis course.
It was developed and tested in a controlled lab environment (VM setup) to understand malware behavior, not for any real-world or malicious use.
This project is a simple malware analysis simulation that includes:
- Windows-based keylogger (victim machine)
- Python-based C2 server (attacker machine - Kali Linux)
- Trigger-based execution system
- Persistence mechanism using Windows Registry
- Keystroke logging + data exfiltration simulation
The idea is to understand how real malware behaves from both sides:
- infected system (Windows VM)
- attacker system (Kali Linux)
keylogger.exe- Captures keystrokes using Windows API hooks
- Runs in stealth mode
- Waits for trigger before activation
- Stores logs locally
- Sends data to C2 server after activation
- Adds persistence via registry Run key
-
c2_server.py -
HTTP-based command & control server
-
Receives keystrokes from victim machine
-
Stores logs in:
.logfile (human readable).jsonfile (structured format)
-
Displays real-time incoming data
-
Stealth execution (hidden window)
-
Windows API keyboard hooking
-
Trigger-based activation:
- USB insertion
- Calculator process detection
- Ctrl + Alt + Esc hotkey
-
Registry persistence (Run key)
-
Buffered keystroke logging
-
HTTP communication to C2 server
-
Simple HTTP server using Python
-
Receives POST requests from victim
-
Stores data in two formats:
keystrokes.logkeystrokes.json
-
Web interface for viewing logs
-
Real-time terminal logging
Run the server:
python3 c2_server.pyServer starts on:
http://0.0.0.0:8080
You can view:
- Logs:
http://localhost:8080/logs - JSON:
http://localhost:8080/json
Compile command:
g++ -static -mwindows -std=c++11 -O2 keylogger.cpp -o keylogger.exe -luser32 -lgdi32 -lwininet -lpthread -ladvapi32Run:
keylogger.exe
- Keylogger starts in dormant mode
- No logging happens initially
- Only monitors system activity
Keylogger activates when ANY of these happen:
- USB drive inserted
- Calculator opened
- Ctrl + Alt + Esc pressed
Once triggered:
- Keyboard hook becomes active
- Logging starts
- Captures all keystrokes
- Stores them in buffer
- Writes to:
C:\Windows\Temp\system_log.dat
After activation:
- Logs are sent to Kali server
- Server receives POST requests at:
http://<kali-ip>:8080/log
-
Data is stored in:
keystrokes.logkeystrokes.json
- Adds entry to Windows registry:
HKCU\Software\Microsoft\Windows\CurrentVersion\Run
- Ensures program runs on startup automatically
This script runs on Kali Linux and acts as the attacker control panel.
- Accepts incoming HTTP POST data
- Extracts keystrokes
- Saves logs with timestamps
- Provides simple web UI to view logs
/→ Status page/logs→ Plain text logs/json→ Structured JSON logs/log→ Receives data from victim
This project helps understand:
- Windows API hooking
- Malware persistence techniques
- Trigger-based execution logic
- Data exfiltration concepts
- Basic command & control architecture
- Victim vs attacker communication flow
From a security perspective, this behavior can be detected via:
- Suspicious registry Run entries
- Keyboard hook detection
- Hidden process execution
- Unusual HTTP POST traffic
- Temp directory log creation
- Hammad