-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbonus.py
More file actions
56 lines (45 loc) · 1.35 KB
/
bonus.py
File metadata and controls
56 lines (45 loc) · 1.35 KB
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
import os
import json
SECRET_KEY = os.urandom(32)
class Profile:
def __init__(self):
self.secret_key = None
self.name = "Default name"
self.address = "Default address"
self.age = -1
self.extra = {
"hobbies": ["Default hobby"],
}
def __str__(self):
return json.dumps(
{
"name": self.name,
"address": self.address,
"age": self.age,
"extra": self.extra,
},
indent=4,
)
def merge(src, dst):
# Recursive merge function
for k, v in src.items():
if hasattr(dst, "__getitem__"):
if dst.get(k) and type(v) == dict:
merge(v, dst.get(k))
else:
dst[k] = v
elif hasattr(dst, k) and type(v) == dict:
merge(v, getattr(dst, k))
else:
setattr(dst, k, v)
profile = Profile()
for _ in range(100):
try:
merge(json.loads(input("input json info to update profile>>>")), profile)
except Exception as e:
print("Error: ", e)
continue
if profile.secret_key == SECRET_KEY:
print("You found the secret key! Now show your exploit to the tutor.")
break
print("Profile updated: ", profile)