File Inclusion on TryHackMe: three defences and how each one failed
| Field | Value |
|---|---|
| Platform | TryHackMe, room File Inclusion (Jr Penetration Tester path, section 8) |
| Difficulty | Easy / learning room with 3 hands-on challenges |
| OS | Linux, Apache + old PHP (5.2) |
| Date completed | 2026-11-18 |
| Time spent | ~2 h for the room incl. challenges (hints used: no) |
| Skills | Local file inclusion (LFI), path traversal, filter bypasses, request tampering with DevTools + Burp |
| Weakness | User input used as a file path in include() (CWE-98 / CWE-22) |
| OWASP Top 10 | A01 Broken Access Control (path traversal), A05 Injection |
| Status | Public THM room. This writeup describes the approach only: no task answers, no flags |
TL;DR
Three small PHP apps each take a file name from the user and pass it to include(). Each one tries a different defence: a broken form, a value hidden in a cookie, and a filter that strips characters and adds .php. None of them holds, because the server still trusts whatever path reaches it. Tools: the browser, DevTools and Burp; no terminal needed.
The idea in one paragraph
A file inclusion bug happens when an app builds a file path from user input, like include($_GET['lang'] . '.php'). With ../ you climb out of the web folder (/var/www/html) and reach any file the web server may read, e.g. /etc/passwd. Filters try to stop this by removing ../, adding an extension, or only accepting certain request types. Each filter only blocks one shape of input, so the attacker changes the shape.
Challenge 1: the "broken" form
Defence: the input form didn't seem to work; the request never carried the file name the way the app expected.
What I did: opened DevTools, looked at the form in the HTML and saw it sent the wrong request method. The server-side code read the parameter from a POST body, the form used GET. I edited the form's method in DevTools to POST and sent it again → the file was included.
Why it fails: the server treats "the form is broken" as protection. But the browser runs whatever HTML I give it, and any client can send any method.
Challenge 2: the value in the cookie
Defence: no visible input to abuse; access depended on who the app thought I was.
What I did: clicked around without a plan first, then thought: the app has to remember my role somewhere, probably in a cookie. DevTools → Application → Cookies showed a cookie whose value the app used. Changing it showed that the cookie value ended up in the file path. From there it was the same traversal as before, just placed in the cookie instead of a form field: climb up with ../, and stop the appended .php with a null byte (%00).

Why it fails: cookies are user input too. Anything the browser stores, the user can edit.
Challenge 3: the filter
Defence: a plain absolute path didn't work. The error message showed why: the app removed the / characters and appended .php:

That error message was a gift: it showed the filter, the full server path (/var/www/html/chall3.php) and the PHP version (5.2).
What I did:
- The form used GET. Switched it to POST in DevTools → the slashes now survived (the filter only cleaned the GET parameter).
- POST + traversal + null byte still failed, so I sent the request through Burp. There I saw two places carrying a path: the cookie left over from challenge 2 and a token with the file path.
- Put the same traversal + null-byte payload into both → the file was included.
Why it fails: the filter only covered one input channel (GET). The null byte works because PHP before 5.3.4 cut the string at %00, so the appended .php was ignored.
Remediation (how the developer fixes it)
- Never pass user input to
include()/ file functions. Map choices to an allow-list:?lang=en→ the server picksen.phpfrom a fixed list. - If a file name must come from the user: take
basename(), build the full path, canonicalise it (realpath()) and check it still starts with the allowed folder. - Treat every input channel the same: GET, POST, cookies, headers. Validate on the server after the request arrives, not per channel.
- Update PHP. The null-byte trick has been dead since PHP 5.3.4.
- Turn off detailed error messages in production (
display_errors = Off). Challenge 3's error gave away the filter and the server path. - Disable
allow_url_includeso local inclusion can't turn into remote inclusion. - A WAF can catch common
../and%00payloads, but only as an extra layer, never as the fix.
Defender's view
- Web server logs show it:
../sequences,%2e%2e%2f,%00or/etc/passwdin a parameter, a POST body or a cookie. Cookies aren't in the default Apache access log, so log them (or use a WAF / reverse proxy log) if you want to see challenge 2-style attacks. - PHP warnings like
include(...): failed to open streamin the error log are a strong sign that someone is probing. - In Wazuh: the web-attack rules (rule group
web/attack) flag common traversal strings in access logs; a custom rule for%00and../in any request field would be a good next detection.
Lessons learned
- Error messages are recon. One warning showed me the filter, the path and the PHP version.
- Every part of a request is input: the method, the body, cookies, hidden tokens. When one channel is filtered, try the others.
- Think about where the app keeps state. On challenge 2 I clicked around without a plan until I asked "where does it remember my role?" That question found the cookie.
- Burp shows the whole request. DevTools let me change the form, but only Burp showed me the second place (the token) that also carried the path.
References
About the author
- 30 years in creative leadership (in the ad industry as a Creative Director) taught me one core skill: dissecting complex systems and finding the flaw before someone else does. My tech roots run back to 8-bit machine code on a C64 (yeah – 80s, baby!) Today, I’m combining that legacy hacker curiosity with modern threat detection and offensive security. BATTLE-TESTED LOGIC: Decades of high-pressure problem solving and systems analysis. HACKER MINDSET: I don't just follow playbooks; I reverse-engineer how the attack path actually works. CONTINOUS SKILL-UP: CompTIA Security+ certified (among other certs), building home labs, and constantly training for L1 ops to future Pentesting.
Comments
Join the discussionNo comments yet. Be the first to comment.
From SOC to Pentest
My path from the SOC to pentesting: a home lab, detections I write for my own attacks, lab and pentest writeups, and the SAL1, AI1 and PT1 certifications. Everything built and tested by me.




