CrateCTF 2025 Writeup: Evenemang
The is a forensics challenge where a user accidentally ran a mal program hidden among 1000 other numbered programs (1.exe to 1000.exe) in a folder on their desktop. Instead of manually checking each program, they ran all of them and captured the system logs to analyze which one behaved suspiciously.
The Files Provided:
system.evtx- Windows System Event Logsecurity.evtx- Windows Security Event Logsystem_1033.MTA- Message Table Archive filessecurity_1033.MTA- Message Table Archive files
What Are Windows Event Logs?
Windows Event Logs (.evtx files) are binary files that record important system events, including:
- System Log: Hardware events, driver issues, service installations
- Security Log: Login attempts, process creation/termination, privilege usage
These logs are crucial for forensic investigations because they provide a timeline of what happened on a system.
Initial Analysis
Step 1: Understanding the Challenge
The scenario tells us:
- There are 1000 programs numbered from 1.exe to 1000.exe
- One of them is malicious
- All programs were executed
- We need to analyze the logs to find the suspicious one
Step 2: Setting Up the Environment
To analyze Windows Event Logs on Linux, I used the python-evtx library:
pip install python-evtx --break-system-packages
This library allows us to parse binary .evtx files and extract the XML-formatted event records.
Deep Dive: Parsing Windows Event Logs
Understanding Event IDs
Windows uses specific Event IDs to categorize different types of events. The most relevant ones for this challenge:
| Event ID | Description | Log Type |
|---|---|---|
| 4688 | Process Creation | Security |
| 4689 | Process Termination | Security |
| 7045 | Service Installation | System |
| 1000 | Application Error | System |
| 1001 | Application Crash | System |
Step 3: Writing the Parser
First, I wrote a Python script to parse the event logs and extract information:
import Evtx.Evtx as evtx
import xml.etree.ElementTree as ET
def parse_evtx(file_path):
"""Parse EVTX file and extract relevant events"""
events = []
with evtx.Evtx(file_path) as log:
for record in log.records():
xml_str = record.xml()
root = ET.fromstring(xml_str)
# Extract event ID
event_id_elem = root.find('.//{http://schemas.microsoft.com/win/2004/08/events/event}EventID')
event_id = event_id_elem.text if event_id_elem is not None else None
# Extract timestamp
time_elem = root.find('.//{http://schemas.microsoft.com/win/2004/08/events/event}TimeCreated')
timestamp = time_elem.get('SystemTime') if time_elem is not None else None
events.append({
'event_id': event_id,
'timestamp': timestamp,
'xml': xml_str
})
return events
Finding the Anomaly
Step 4: Looking for Suspicious Patterns
I analyzed the logs looking for several indicators:
1. Mismatched Process Creation/Termination
Normal programs should have:
- 1 Process Creation event (4688)
- 1 Process Termination event (4689)
I wrote code to count these events for each program:
for prog in creations:
create_count = len(creations[prog])
term_count = len(terminations.get(prog, []))
if create_count != term_count:
print(f"{prog}: {creates} creations, {terms} terminations")
Finding: 756.exe had 2 creation events but only 1 termination event!
2. Service Installation Events
Malware often installs Windows services for persistence. Event ID 7045 indicates a new service was installed.
if event_id == '7045':
print("Service Installation Found!")
Finding: A service called PSEXESVC was installed around the same time 756.exe was running.
Step 5: Detailed Analysis of 756.exe
I extracted all events related to 756.exe to understand the timeline:
Event 1 - Process Creation (4688)
Time: 2025-10-10 11:28:36.667421
- NewProcessName: C:\Users\Administrator\Desktop\program\756.exe
- ParentProcessName: C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe
- ProcessId: 0x2cfc
Event 2 - Process Creation (4688)
Time: 2025-10-10 11:28:36.672235
- NewProcessName: C:\Users\Administrator\Desktop\PsExec64.exe
- ParentProcessName: C:\Users\Administrator\Desktop\program\756.exe
- ProcessId: 0x2d10
Event 3 - Process Termination (4689)
Time: 2025-10-10 11:28:36.673496
- ProcessName: C:\Users\Administrator\Desktop\program\756.exe
- ProcessId: 0x2cfc
Event 4 - Service Installation (7045)
Time: 2025-10-10 11:28:36.860695
- ServiceName: PSEXESVC
- ImagePath: %SystemRoot%\PSEXESVC.exe
- StartType: demand start
- AccountName: LocalSystem
Understanding the Attack
What is PsExec?
PsExec (Process Execute) is a legitimate Microsoft Sysinternals tool that allows administrators to execute processes on remote systems. However, it's also commonly used by attackers for:
- Lateral Movement: Moving between systems in a network
- Remote Command Execution: Running commands without being physically present
- Privilege Escalation: Running processes with SYSTEM-level privileges
- Persistence: Installing services that survive reboots
Attack Chain Analysis
Here's what 756.exe did:
- Initial Execution: PowerShell launched 756.exe (along with all other programs)
- Malicious Payload: 756.exe spawned PsExec64.exe as a child process
- Service Installation: PsExec installed PSEXESVC service with LocalSystem privileges
- Cleanup: The original 756.exe terminated, but PsExec remained running
- Persistence: The PSEXESVC service stays installed for future use
This is a classic example of Living off the Land (LotL) techniques, where attackers use legitimate system tools to avoid detection.
Red Flags Identified
- Unbalanced Process Events: 2 creations vs 1 termination
- Parent-Child Process Relationship: 756.exe spawned PsExec
- Service Installation: New service created (PSEXESVC)
- Elevated Privileges: Service running as LocalSystem
- Suspicious Tool: PsExec is often abused by malware
Solution
The malicious program is 756.exe... And the flag: cratectf{756.exe}
Technical Details
Tools Used:
- Python 3 - Scripting and automation
- python-evtx - Parsing Windows Event Logs
- xml.etree.ElementTree - XML parsing
- Regular Expressions - Pattern matching for .exe filenames
Event Log Structure:
Windows Event Logs use XML format internally. Each event contains:
<Event xmlns="http://schemas.microsoft.com/win/2004/08/events/event">
<System>
<Provider Name="..." Guid="..." />
<EventID>4688</EventID>
<TimeCreated SystemTime="2025-10-10T11:28:36.667421Z"/>
...
</System>
<EventData>
<Data Name="NewProcessName">C:\...\756.exe</Data>
<Data Name="ParentProcessName">C:\...\powershell.exe</Data>
...
</EventData>
</Event>
Python Code Snippet for Finding the Malicious Program:
import Evtx.Evtx as evtx
import xml.etree.ElementTree as ET
from collections import defaultdict
def find_malicious_program(security_log_path):
process_creations = defaultdict(int)
process_terminations = defaultdict(int)
with evtx.Evtx(security_log_path) as log:
for record in log.records():
xml_str = record.xml()
root = ET.fromstring(xml_str)
event_id = root.find('.//{...}EventID').text
# Extract process name
for data in root.findall('.//{...}Data'):
if data.get('Name') == 'NewProcessName':
process_name = data.text.split('\\')[-1]
if event_id == '4688':
process_creations[process_name] += 1
elif event_id == '4689':
process_terminations[process_name] += 1
# Find mismatches
for prog in process_creations:
if process_creations[prog] != process_terminations[prog]:
print(f"Suspicious: {prog}")
return prog
Conclusion
This challenge demonstrates the importance of Windows Event Log analysis in digital forensics. By understanding how to parse and correlate events, we can identify malicious behavior even when it's hidden among legitimate activity.
The key was recognizing that:
- Process creation/termination events should balance out
- Service installations are high-risk events
- Legitimate tools (like PsExec) can be used maliciously
- Timeline analysis reveals the complete attack chain
Key Takeaways
For CTF Players:
- Event Correlation: Don't look at events in isolation - correlate them by time, process ID, and relationships
- Know Your Event IDs: Familiarize yourself with common Windows Event IDs
- Look for Anomalies: Normal behavior patterns help identify abnormal ones
- Parent-Child Relationships: Process spawning behavior can reveal malicious activity
For Security Analysts:
- Enable Logging: Process creation auditing (4688/4689) is critical for forensics
- Baseline Normal: Understanding normal system behavior helps spot anomalies
- Tool Awareness: Know legitimate tools (like PsExec) that can be weaponized
- Timeline Analysis: Creating an event timeline reveals the attack chain