Lesson 4 of 12 · 22m
How Web Attacks Actually Work: Injection to SSRF
SQLi, command injection, traversal, and SSRF as interpreter-reach bugs — and the fixes that close the mechanism, not the payload.
Every "web vulnerability class" is the same underlying bug wearing different clothes: attacker-controlled data reaches an interpreter — a SQL parser, a shell, a filesystem resolver, a template engine — that treats it as instructions. Once you see the mechanism, the checklists in OWASP write themselves. Here is how the four you'll meet most actually work, and what each fix actually closes.
SQL injection: data becoming program
query = "SELECT * FROM users WHERE id = '" + request.args["id"] + "'"Send id = ' OR '1'='1 and the parser sees the string close early, then executes a second clause it was never meant to. The wrong mental model is that the fix is "strip quotes." Blacklists lose to encodings, comments, and nested payloads forever — there is no filter list that makes string-interpolated SQL safe.
The fix that kills the mechanism is parameterization: cursor.execute("SELECT * FROM users WHERE id = %s", (uid,)). The parser builds the query plan with a placeholder first; the user data arrives as data and can never become syntax. Real-world cost of the alternative: the MOVEit Transfer SQLi (CVE-2023-34362, May 2023) let the Cl0p gang exfiltrate from thousands of organizations through a file-transfer appliance — a single injectable parameter behind a login. Equifax's Struts bug (CVE-2017-5638) wasn't SQLi but was the same shape: a patch available for two months, 147 million records, because an OGNL expression reached an interpreter through a crafted header.
Command injection: the shell doing concat for you
os.system("ping -c1 " + host)host = "127.0.0.1; cat /etc/passwd" — the semicolon ends one command and starts the next; the shell happily runs both. Same class, different interpreter. The durable fix is to never give a shell the chance: use execve-style APIs with an argv array — subprocess.run(["ping", "-c1", host]) in Python, spawn("ping", ["-c1", host]) in Node, ProcessBuilder in Java. With argv, the metacharacters are just bytes in an argument; there is no shell to interpret them.
Path traversal: the resolver walking upward
/download?file=../../etc/passwd — the app joins a base directory with user input and the resolver obeys ... Apache httpd's CVE-2021-41773 (October 2021) was a traversal in its own path normalization: %2e%2e/ slipped the .. check, attackers read files outside the docroot within days, and the incomplete fix got bypassed again as CVE-2021-42013 — this time to remote code execution where mod_cgi was loaded. The durable fix is canonicalize-then-confine: resolve the final path (realpath/filepath.Abs) and verify it still sits under the intended directory prefix. Regex-deleting ../ loses to %2e, ..;/, and double-encoding the same way quote-stripping loses to SQLi.
SSRF: your server as their browser
The endpoint fetches a URL for the user — a thumbnail fetcher, a webhook tester, a PDF renderer. Send url = http://169.254.169.254/latest/meta-data/iam/security-credentials/ and your server makes the request, from inside your network, with your instance's privileges. That's how the Capital One breach worked in 2019: SSRF → metadata service → the WAF-host's IAM credentials → ~100 million records out of S3.
The durable fix is layered and none of the layers is "block 169. in a regex" (it loses to DNS rebinds, decimal/octal IPs, IPv6-mapped forms, and 30 other encodings): resolve the hostname yourself and reject link-local/private/reserved ranges after resolution, pin egress through a proxy or an egress security-group allowlist, and enforce IMDSv2 — which requires a PUT for the session token and neuters most naive GET-based SSRF against the metadata service.
The pattern to keep
Validation-filter fixes are payload whack-a-mole; mechanism fixes are structural. Parameterize, use argv APIs, canonicalize-and-confine, allowlist egress. When you read the next CVE, the question to ask isn't "what's the payload" — it's "which interpreter was reached, and what does the patch remove: the reach, or the examples?"
Try this
In a codebase you own, grep -rn for os.system, exec(, Runtime.getRuntime().exec, subprocess.*shell=True, and string-built SQL. For each hit, trace whether user input reaches it, then rewrite one to the argv or parameterized form. On a cloud VM, test your own metadata exposure: curl http://169.254.169.254/latest/meta-data/ should need IMDSv2 and fail without a token.
Field notes
- A WAF is a compensating control, not a fix — useful for buying patch time, bypassed as a permanent wall. MOVEit and Equifax both sat behind WAF-capable infrastructure.
- Log4Shell (CVE-2021-44228) is the same lesson at maximum scale: a feature — JNDI lookups in log strings — evaluated attacker data. The fix wasn't a filter; 2.16.0 disabled JNDI by default and later builds removed the lookup entirely. Dangerous features are attack surface.
Was this lesson helpful?
Keep reading
Related articles from the SudoSecurity blog.
LAPSUS$: How Teenagers Breached Microsoft and Okta
Claire Tills, senior research engineer at Tenable, describes the methods of the hacking group Lapsus$ as bold, illogical and poorly thought out. The criminals attacked renowned companies such as Microsoft, Samsung, Nvidia, Vodafone, Ubisoft and Okta. They stole data and sometimes used ransomware…
A Fake GTA 6 ISO Didn’t Install a Game. It Installed a Wiper.
A fake GTA 6 ISO used a believable installer error to cover remote-access malware, browser-data theft, and destructive file wiping. The “License not found” message wasn’t the crack failing. It was there so the victim would stop looking.
Hacktivism, 2021 to Today: From Steel Mills to Power Grids
Part 1 ended on a 70-gigabyte breach in 2021. Since then, hacktivists derailed trains, dumped molten steel on camera, and reached grids in three countries.
What is Social Engineering? The Attacks That Bypass Every Technical Control
Phishing, vishing, pretexting, physical infiltration — here's how every technique works, how attackers use them in production breaches, and how to actually defend against them.