kclcybersoc ~ patch-wednesday
cd ..
// workshop · blue team · ran wed 28.10.26

patch wednesday

last week you broke things. this week you fix them. we hand you a small members-portal web app with five deliberate security bugs. find each one, run the exploit, read the real-world CVE, and ship the proper fix.

$ cat how-it-works

the app is a tiny flask members portal. every bug lives in its own file under challenges/, and every bug ships with two kinds of test: an exploit test that fails while the bug is there, and normal-use tests that check the feature still works. so you can't win by deleting the feature, and you can't win with a blocklist of "bad characters" — the exploit tests try several shapes of the same trick. a fix counts when the tests go green.

  1. on the template repo, click use this template → create a new repository, keep it public, and clone your copy.
  2. open the actions tab: your first run is a red cross with five failing tests, one per bug.
  3. pick a bug below, open its file in challenges/, and fix the one function it points at.
  4. git add . && git commit -m "fix" && git push — github re-runs the tests. green means patched.

each lab below runs the real exploit in your browser against a faithful copy of the broken logic — nothing is sent anywhere, and no real system is touched. flip the vulnerable / patched switch to watch the same payload stop working once the bug is fixed.

$ ls challenges/
01 login — SQL injection CWE-89 walkthrough

the login query pastes your username and password straight into a SQL string, so a crafted username can change what the query means and log you in with no valid password. the fix is to stop mixing input into the query text at all — use placeholders.

// challenges/login.py · fix check_login()

POST /login
// seen in the wild
CVE-2014-3704 — "Drupalgeddon"

a pre-auth SQL injection in Drupal 7 core's database layer. sites were mass-compromised within hours of disclosure — Drupal later said any site not patched within 7 hours should be assumed hacked.

the fix: Drupal 7.32 changed the database API to expand array arguments as proper parameterized placeholders instead of building the query by hand — exactly what you'll do here. OWASP SQLi prevention →

02 notes — broken access control (IDOR) CWE-639

logged-in members read notes at /notes/<id>. the handler looks the note up by id and hands it back — without checking who it belongs to. change the number in the URL and you read anyone's notes. the fix is a missing ownership check.

// challenges/notes.py · fix handle()

GET /notes/<id>  as alice
// seen in the wild
CVE-2023-4836 — WordPress "User Private Files"

an authenticated user could download other members' private files just by changing the file id in the request — the same missing-ownership-check you're fixing, one ?id= apart.

the fix: check that the logged-in user actually owns the object before returning it; treat someone else's id exactly like one that doesn't exist. PortSwigger: IDOR →

context: OWASP ranks Broken Access Control the #1 web risk.

03 files — path traversal CWE-22

the download handler joins the name you give it onto the public files folder and opens whatever comes out. put ../ segments in the name and you walk out of the folder and read files you shouldn't. blocking the literal "../" is not enough — resolve the real path and check it stays inside the folder.

// challenges/files.py · fix download()

GET /files/download?name=
// seen in the wild
CVE-2021-41773 — Apache httpd 2.4.49

a path-traversal flaw in the Apache web server: ..%2e-style sequences escaped the document root to read (and, with CGI, run) arbitrary files. actively exploited in the wild within days.

the fix: Apache 2.4.50/2.4.51 properly normalised and confined the resolved path to the configured root. in your version: resolve the real path and require it to live inside the public folder (flask's send_from_directory does this). OWASP: Path Traversal →

04 continue — open redirect CWE-601 bonus

links bounce you onward through /go?next=..., and the handler redirects to whatever next says — including a full URL on another site. an attacker sends a link to our trusted domain that quietly forwards to a lookalike phishing page. allow only redirects that stay on this site.

// challenges/redirect_after_login.py · fix safe_target()

GET /go?next=
// seen in the wild
CVE-2024-54050 — Adobe Connect

a "URL redirection to untrusted site" bug: the app would forward users to an attacker-supplied address, handing phishers a link that starts on a trusted domain. the classic shape is a login ?next= parameter — exactly this one.

the fix: accept only a single local path (empty host, starts with one / but not //); anything pointing at another host falls back to /. OWASP: unvalidated redirects →

05 tools — OS command injection CWE-78 bonus

the "reachability check" pastes the host you type into a shell command string. shell punctuation (;, &&, |) lets you tack on a second command of your choice. the fix is to stop using a shell at all — pass the program and its arguments as a list, so the input can only ever be one argument.

// challenges/tools.py · fix run_check()

POST /tools  runs: echo resolving <host>
// seen in the wild
CVE-2014-6271 — "Shellshock"

a flaw in Bash let attacker-controlled data smuggle trailing commands into a shell — a web request could run arbitrary commands on the server. one of the most widely exploited bugs of the decade.

the fix: never hand untrusted input to a shell. pass the program and its args as a list with no shell=True, so the whole input is a single argument and nothing extra can run. OWASP: command injection defense →

heads up: these are deliberately-vulnerable teaching copies, running entirely in your browser for this workshop. use what you learn only on systems you own or are allowed to test — running exploits against anything else is a crime under the Computer Misuse Act. the point of blue team is to spot and close these in real code before anyone else finds them.
$ cat links
[patch wednesday]5 bugs · blue team · fix one function eachkclsu