一弃舒、漏洞詳情
CVE-2020-7471:通過StringAgg(分隔符)的潛在SQL注入
django.contrib.postgres.aggregates.StringAgg聚合函數(shù)使用適當(dāng)設(shè)計的定界符進(jìn)行了SQL注入藐守。
Django是高水準(zhǔn)的由Python編程語言驅(qū)動的一個開源Web應(yīng)用程序框架,起源于開源社區(qū)洪唐。使用Django,程序員可以方便客扎、快捷地創(chuàng)建高品質(zhì)饺律、易維護(hù)、數(shù)據(jù)庫驅(qū)動的應(yīng)用程序矢棚,應(yīng)用廣泛郑什。
二、影響范圍
受影響版本:
Django 1.11.x < 1.11.28
Django 2.2.x < 2.2.10
Django 3.0.x < 3.0.3
Django 主開發(fā)分支
不受影響產(chǎn)品版本:
Django 1.11.28
Django 2.2.10
Django 3.0.3
三蒲肋、環(huán)境搭建
1蘑拯、安裝 django 漏洞版本,本次測試用的是(django==3.0.2)
pip install django==3.0.2-i https://pypi.tuna.tsinghua.edu.cn/simplepip?install?django==2.2-i?https://pypi.tuna.tsinghua.edu.cn/simple
注意:如果是pip安裝用python3也可以直接使用下面語句
python3?-m pip?install?django==3.0.2-i?https://pypi.tuna.tsinghua.edu.cn/simplepython3 -m pip?install?django==2.2-i?https://pypi.tuna.tsinghua.edu.cn/simple
2兜粘、安裝postgre 數(shù)據(jù)庫
sudo apt-getupdatesudo apt-getinstallpostgresql postgresql-client
啟動postgre 數(shù)據(jù)庫
連接postgre 數(shù)據(jù)庫在安裝完畢后申窘,系統(tǒng)會創(chuàng)建一個數(shù)據(jù)庫超級用戶 postgres并且密碼為空。然后我們以管理員身份 postgres 登陸(注:這里postgres是系統(tǒng)用戶)
切換到postgres這個用戶之后我們輸入psql進(jìn)入postgres的shell孔轴,并且我們可以看到我們這里psql的版本是9.5.21
修改postgre的密碼為root并創(chuàng)建一個thelostworld的數(shù)據(jù)庫
ALTERUSERpostgresWITHPASSWORD'root';CREATEDATABASEthelostworld;
修改 sqlvul_projects/settings.py 里面的數(shù)據(jù)庫配置
(可后臺回復(fù)“CVE-2020-7471”獲取環(huán)境和POC)
DATABASES = {'default': {'ENGINE':'django.db.backends.postgresql','NAME':'thelostworld',# 數(shù)據(jù)庫名稱'USER':'postgres','PASSWORD':'root','HOST':'127.0.0.1','PORT':'5432',? ? }}
通過 django 初始化數(shù)據(jù)表
python3manage.pymigratepython3manage.pymakemigrationsvul_apppython3manage.pymigratevul_app
運(yùn)行結(jié)果
python3 manage.py makemigrations vul_app?
運(yùn)行沒有改變數(shù)據(jù)沒關(guān)系
初始化環(huán)境完成
四剃法、漏洞復(fù)現(xiàn)
開始查看數(shù)據(jù)表
postgres=# \c thelostworld進(jìn)入數(shù)據(jù)庫thelostworld=# \d查看全部表
查看vul_app_info表的信息
thelostworld=# select * from vul_app_info;
目前表里面沒有數(shù)據(jù)
查看POC
執(zhí)行POC
再次查看數(shù)據(jù)前后對比
POC里面的數(shù)據(jù)寫入到數(shù)據(jù)庫中,注入成功
五路鹰、加固修復(fù)
升級到Django最新版3.0.3即可
參考:
https://mp.weixin.qq.com/s/KLgksoj918i2Whbjor6s7g
https://github.com/SNCKER/CVE-2020-7471
https://github.com/Saferman/CVE-2020-7471
后臺回復(fù)“CVE-2020-7471”獲取POC和初始化環(huán)境
免責(zé)聲明:本站提供安全工具贷洲、程序(方法)可能帶有攻擊性收厨,僅供安全研究與教學(xué)之用,風(fēng)險自負(fù)!
訂閱查看更多復(fù)現(xiàn)文章优构、學(xué)習(xí)筆記
thelostworld
安全路上诵叁,與你并肩前行!A┛椤@栊荨!
個人知乎:https://www.zhihu.com/people/fu-wei-43-69/columns
個人簡書:http://www.reibang.com/u/bf0e38a8d400
?原文連接: