Modifying HTTP Request Method
A walkthrough of a file inclusion challenge where switching the request method, tampering a cookie, and a nullbyte each defeat a different filter. The goal of each stage is a flag under /etc.
To change the HTTP request method in Burp Suite, double click the type (GET or whatever is listed), right click, and select this:
Challenge Walkthrough
Capture Flag1 at /etc/flag1
We need to get this executed: ../../../../etc/flag1, but they want us to use POST instead of GET. GET is normally used to retrieve files from a server.
- Open Burp Suite and open challenge #1.
- Activate the proxy.
- Put the path to the file in the include form.
- Go to Burp and make sure Intercept is on.
- Put the file path in the include form and click Include.
- Right click on the request in the Proxy tab in Burp.
Once this is done, click Forward and you will receive the flag1 file.
FYI: check this awesome page out https://security.szurek.pl/en/burp-12-tricks-for-burp-repeater/
2. Capture Flag2 at /etc/flag2
Let's tamper the cookie.
- Open challenge #2 and we see that we are not able to access it.
- Open Inspect Element and go to Storage where the cookies are.
- Change the value of the cookie to our desired path ../../../../etc/flag2.
- It failed. Why? Because, as you can see in the error message, the validation is done to open .php files only. However, it can be omitted by adding %00 at the end.
- So now the value should look like below. Refresh the page and boom, Flag#2 is there.
- See what kind of filtering we have there. We input ../../../../etc/flag3 and the output is filtered to etcflag — no number 3, no path traversal possible, plain strings only.
- But when we change the method to POST instead of GET in Burp, the filter is gone.
- So just a slight adjustment. It still asks for a .php file, which we know how to omit by adding %00.
- In the browser put ?file=../../../../etc/flag3%00 and press enter.
- Jump into Burp and change the request to POST as in the example above.
- Done.
Challenge 4 — Gain RCE in Lab #Playground /playground.php with RFI to execute the hostname command. What is the output?
Start a Python server to host the file you want to include.
In the same directory the server is running, create a PHP file to include (in this case named host.txt):
<?php print exec('hostname'); ?>
Check your IP (I know the THM box shows it, but let's do it comprehensively).
Everything is set, now let's exploit the server. We need to provide the link to our file here, so after = there should be a link to the server.
From this:
To this — do not forget about the port number.
Success.
That is the end of our journey with File Inclusion.