Skip to main content
← Back to lab
SEC401 - Vulnerability Management and Response | Printable command sheet
Lab 3.3 - Web App Exploitation

Lab 3.3 - Web App Exploitation

Web Application Security | SEC401 | Apr 2026

Discovered a SQL injection in Catalog.php's search parameter (LIKE '%<input>%'), dumped all products, enumerated databases and tables via stacked queries, then deployed the lab WAF and confirmed identical payloads were blocked with HTTP 418.

Tools: Firefox, PHP/MySQL web app, Manual SQL injection, WAF (lab-provided)

Commands

1. Lab environment startup

Started the lab stack. Initial errors from stale containers, then three services came up: lab-33-php-nginx, lab-33-database, and lab-33-php-fpm. That's a classic PHP/MySQL storefront topology.

cd /sec401/labs/3.3/ && ./start_3.3.sh

2. Inspect the target app

Loaded store.alphainc.ca:8080/Catalog.php. The page exposes a category picker (attire, energy, exercise, lighting, toys, training) and a free-text search bar. The search bar is the obvious attack surface.

3. Leaking the query via error

Submitted an empty search. The page printed both Array () (an empty result set) and a full PHP exception with the rendered SQL: SELECT * FROM Merchandise WHERE name LIKE '%'%'. That single line reveals: it's a LIKE query, the input is wrapped in single quotes, and stack traces are leaking to users — three serious issues before any payload.

4. Confirm injection with a single quote

Submitted ' as the search term to confirm the injection context.

5. Baseline: a legitimate search result

Ran a normal search to confirm the app returns product records with fields: Product Number, Item, Description, Price, Picture. The target table is clearly Merchandise.

6. Probe the LIKE boundary with ';--

Submitted ';-- to close the string and try to comment out the trailing %'. The error message confirmed the resulting query: SELECT * FROM Merchandise WHERE name LIKE '%':--%', meaning MySQL didn't treat -- as a comment because it wasn't followed by whitespace.

7. Observed error response

The server echoed the unsafe query directly back in the stack trace — a defender's nightmare because it tells the attacker exactly how to refine the payload.

8. Fix the payload: '; -- with trailing space

MySQL's -- comment syntax requires a trailing space. Retried with '; -- (single quote, semicolon, dash-dash, space).

9. Full table dump via broken WHERE clause

The payload produced SELECT * FROM Merchandise WHERE name LIKE '%'; -- %'. The first statement returned everything (LIKE '%' matches all rows), the rest got commented out. Result: all 17 products returned, confirming full data exfiltration from the table.

10. Stacked query: enumerate databases

Graduated from data theft to server reconnaissance. Payload: qq'; show databases; -- . The mysqli driver in this app supports multiple statements, so the second statement executed.

11. Database enumeration success

The page printed Array ( [0] => Database [1] => information_schema [2] => OnlineShop ). Confirmed the app's database is OnlineShop and stacked queries are fully allowed. From here an attacker can drop tables, write files, or escalate — the worst-case SQLi scenario.

12. Deploy the WAF

Ran the lab's WAF enable script to put a filtering proxy in front of the app.

scripts/enable_waf.sh

13. Re-test the same payload

Replayed the stacked-query payload: qq'; show tables; -- . Same request, same target.

14. WAF blocks the request (HTTP 418)

The WAF returned HTTP 418 ('I'm a teapot', a common non-standard block response). Identical payload, defeated. The app is still vulnerable at the code level, but the WAF gives the team time to fix it without leaving the front door open.

Key Findings

  • Search input directly concatenated into LIKE '%...%'
  • PHP exceptions leak the full SQL query to the browser
  • Stacked queries enabled on the mysqli connection
  • Full dump of Merchandise table achievable with '; --
  • information_schema + OnlineShop databases disclosed via SHOW DATABASES
  • WAF correctly blocks the same payloads after enablement (HTTP 418)

Security Controls

  • Parameterized queries / prepared statements
  • LIKE wildcard escaping (%, _)
  • Disabling multi_query / stacked statements at the driver level
  • Suppressing verbose error output in production
  • WAF rules for SQLi (OWASP CRS)
  • Least-privilege DB accounts (no SHOW DATABASES for app user)