-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathInlook-1-signature-flaw.py
41 lines (32 loc) · 1.11 KB
/
Inlook-1-signature-flaw.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
#!/usr/bin/env python3
import sys
import string
import random
import json
from client import Client
from math import gcd
from Crypto.Util.number import *
from cipher import *
from gmpy2 import iroot
PORT = 1337
alphabet = string.ascii_letters + string.digits
def get_random_str(len):
return ''.join(random.choice(alphabet) for i in range(len))
def exploit(ip, flag_id):
client = Client(ip, PORT)
client.connect()
client.register(get_random_str(20), get_random_str(20), get_random_str(20), get_random_str(20))
my_p, my_q = client.sk
target_result = client.get_encrypted_email(flag_id["address"], flag_id["email_id"])
target_n, target_g, _ = target_result["pk_sig"]
enc_flag = bytes.fromhex(target_result["content"])
target_q = gcd(target_g-1, target_n)
assert target_q != 1 and target_q != target_n and target_n%target_q == 0
target_p = iroot(target_n//target_q, 2)
assert target_p[1]
target_p = int(target_p[0])
return decrypt(enc_flag, (target_p, target_q))
if __name__ == "__main__":
ip = sys.argv[1]
flag_id = json.loads(sys.argv[2])
print(exploit(ip, flag_id))