CWE-532: Insertion of Sensitive Information into Log Files is a critical security weakness where applications log sensitive data (passwords, tokens, private messages) that can be exploited by attackers.
Scenario: TechCorp is a mid-sized technology company rolling out an internal team chat platform for 50-100 employees across Engineering, Marketing, and Operations departments. Their goal is to use this tool to streamline internal communication for employees to chat with personnel of any department to allow for easier cross-department synchronicity.
- Registration requires invite code (
TECHCORP2025) shared during onboarding - Username/password authentication for existing employees
- Logging enabled during "pilot phase" to troubleshoot authentication issues
- System shows most recent activity on the server so that IT can determine root cause of issues
The Vulnerability: During the pilot phase, developers enabled comprehensive debug logging to diagnose issues. In case of issues, they wanted a complete picture of recent events on the chat server to help them diagnose:
- Employee passwords during login attempts
- Invitation codes during registration
- Private message content between employees
- All authentication credentials
Attacker Profile: TechCorp employee was not given a raise they were working hard to get for the last 2 years.
- They know the invitation code from their own onboarding (
TECHCORP2025) - Authenticates successfully and uses
LOGcommand to view recent server logs - Extracts employee passwords from failed/successful login attempts
- Harvests private messages between employees discussing confidential projects
- Uses stolen credentials to access other TechCorp systems (email, file servers, databases)
- Leaks company information to direct competitor
Attacker Profile: External threat obtained the invitation code:
- Committed to public GitHub repo
- Visible on office photographs
- Never changed over the years
- Attacker finds
TECHCORP2025in a GitHub commit history search - Registers account, authenticates, and runs
LOGcommand repeatedly - Automates log extraction over days to capture:
- All employee credentials as they authenticate
- Confidential messages about product launches, discussions, financial data
Attacker Profile: Sophisticated phisher targeting TechCorp employees
- Attacker calls TechCorp reception desk posing as new hire: "Hi, I start Monday in Engineering. HR was supposed to email me the chat invitation code but I can't find it. Can you help?"
- Helpful receptionist provides the code: "Oh sure, it's TECHCORP2025. Welcome aboard!"
- Attacker registers account using believable username (
sarah_eng) - Monitors logs to identify high-value targets (executives, admin accounts)
- Uses extracted passwords to impersonate authenticated personnel
Attacker Profile: Contractor working for TechCorp's IT support vendor
- Vendor employee legitimately receives invitation code for support purposes
- Vendor employee (curious or malicious) registers personal account
- Periodically checks logs to gather intelligence on TechCorp operations
- Sells harvested credentials on dark web forums
Key Vulnerabilities:
- Password Logging During Login
- Credential Logging During Registration
- Message Content Logging
- LOG Command Access
- Debug Mode Enabled
Security Improvements:
- Debug Mode Disabled
- Sanitized Login Logging
- Sanitized Registration Logging
- Metadata-Only Message Logging
Simple chat client.
javac vulnserver/VulnerableServer.java
javac fixserver/FixedServer.java
javac client/Client.javaPlease choose one server version, and ensure the server is running prior to running clients. You can run as many clients in separate terminals as you like. Each of -server- or -client- requires its own instance of terminal.
IF RUNNING SERVER AND CLIENT ON SCHOOL SERVERS, PLEASE ENSURE YOU ARE CONNECTED TO THE SAME MACHINE (CSX1, 2, 3) BECAUSE CLIENTS ATTEMPT TO CONNECT TO SOCKETS ON THE SAME LOCAL MACHINE
java vulnserver.VulnerableServerjava fixserver.FixedServerIn a new terminal (for each unique client):
java client.ClientThe actual attack.py file is sophisticated enough to be realistically usable by a bad actor, allowing the attacker to decide length of time and number of times to run the log file. An attacker would let this program run over a long period, extracting as much data as possible and parsing that data using regular expressions to find sensitive information.
IMPORTANT: The python script takes command line arguments. On no arguments, default values are used. Invitation code only exists to visualize a real attack vector - this will not work with any other codes at this time (use defaults).
python exploit/attack.py [OPTIONS]Available Options:
-d <seconds>- Duration to monitor logs (0 = single poll, default: 0)-i <seconds>- Polling interval between checks (default: 60)-u <username>- Attacker username (default: badguy)-p <password>- Attacker password (default: pwnd)-c <code>- Invitation code (default: TECHCORP2025)
Examples:
python exploit/attack.py
python exploit/attack.py -d 300 -i 30
python exploit/attack.py -u hacker -p password123 -c TECHCORP2025private static boolean debugMode = false;In the scope of this project, this act is sufficient to prevent the exploit from working. However, we cannot be certain that no other bugs exist across the rest of the code that may expose our logging information to bad actors. The same server written in a variant of C may be exposed to buffer overflow attacks, which can redirect code execution to force debugMode functions to be called. Logs can still leak, files can still be misconfigured, and end-points can still be unsecure - so this is actually a mitigation step - see below for more concrete prevention strategies.
Never log:
- Passwords or password hashes
- API keys, tokens, session IDs
- Invitation codes or access codes
- Message content or private data
- Credit card numbers, SSNs, PII
Instead, log:
- Usernames (if not considered PII)
- Timestamps and event types
- Success/failure status
- Metadata, not content
- Restrict log access to security/operations teams only
- Remove user-accessible log commands from production
- Review all
log(),println(),write(), and other relevant calls for sensitive data
If logs must contain sensitive data:
- Encrypt log files
- Implement deletion policies
- Audit who accesses log files and when
- Alert on unusual log access patterns
- Implement least-privilege principle for log readers