-
Notifications
You must be signed in to change notification settings - Fork 0
/
13.py
executable file
·35 lines (22 loc) · 1018 Bytes
/
13.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
#!/usr/bin/env python3
import secrets
from mycrypto import aes_128_ecb_decrypt, aes_128_ecb_encrypt, chop, pad
key = secrets.token_bytes(16)
def parse_query(query: bytes) -> dict[bytes, bytes]:
pairs = [pair.split(b'=') for pair in query.split(b'&')]
return {p[0]: p[1] for p in pairs}
def profile_for(email: bytes) -> bytes:
email = email.replace(b'&', b'')
email = email.replace(b'=', b'')
return b'email=' + email + b'&uid=10&role=user'
def get_encrypted_profile(email: bytes) -> bytes:
return aes_128_ecb_encrypt(profile_for(email), key)
def parse_encrypted_profile(data: bytes) -> dict[bytes, bytes]:
return parse_query(aes_128_ecb_decrypt(data, key))
def main():
print(parse_encrypted_profile(get_encrypted_profile(b'foo@bar.com')))
profile = b''.join(chop(get_encrypted_profile(b'aaaaaaaa@x.co'))[:-1])
profile += chop(get_encrypted_profile(b'aaaaa@x.co' + pad(b'admin')))[1]
print(parse_encrypted_profile(profile))
if __name__ == "__main__":
main()