-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprob37.py
More file actions
85 lines (80 loc) · 2.85 KB
/
Copy pathprob37.py
File metadata and controls
85 lines (80 loc) · 2.85 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
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
#!/usr/bin/env python
# Written against python 3.3.1
# Matasano Problem 37
# Break SRP with a zero key
from prob36 import SRP_p, SRP_g, SRP_k, SRP_step1, SRP_validate, SRP_step7,\
SRP_step6, SRP_step5, SRP_step4, SRP_step3, SRP_step2
from prob33 import intToBytes
from hashlib import sha256
from random import randrange
# Get your SRP working in an actual client-server setting. "Log in" with
# a valid password using the protocol.
def run_SRP():
state = { "p" : SRP_p,
"g" : SRP_g,
"k" : SRP_k,
"I" : b"matasano_prob37@reschly.com",
"P" : b'GANDALF THE GREY'}
state = SRP_step1(state);
state = SRP_step2(state);
state = SRP_step3(state);
state = SRP_step4(state);
state = SRP_step5(state);
state = SRP_step6(state);
state = SRP_step7(state);
assert(SRP_validate(state));
# Now log in without your password by having the client send 0 as its
# "A" value. What does this to the "S" value that both sides compute?
''' If A = 0, the server calculates:
S = (A * v**u) ** b % N =
= (0*something)^something mod N = 0
The client, being the evil one, just sets S to 0
'''
def client0_SRP():
state = { "p" : SRP_p,
"g" : SRP_g,
"k" : SRP_k,
"I" : b"matasano_prob37@reschly.com",
"P" : b'GANDALF THE GREY'}
state = SRP_step1(state);
state = SRP_step2(state);
state["A"] = 0;
state = SRP_step3(state);
state = SRP_step4(state);
#state = SRP_step5(state);
'''Step 5 is the one in the client would use the password.
This client doesn't know the password, but instead does:'''
state["C_K"] = sha256(intToBytes(0)).digest();
state = SRP_step6(state);
state = SRP_step7(state);
assert(SRP_validate(state));
# Now log in without your password by having the client send N, N*2, &c.
''' If A = k*N, the server calculates:
S = (A * v**u) ** b % N =
= (k*N*something)^something mod N = 0 mod N
again, the client, being the evil one, just sets S to 0
'''
def clientN_SRP():
state = { "p" : SRP_p,
"g" : SRP_g,
"k" : SRP_k,
"I" : b"matasano_prob37@reschly.com",
"P" : b'GANDALF THE GREY'}
state = SRP_step1(state);
state = SRP_step2(state);
k = randrange(1, 30)
state["A"] = k*SRP_p;
state = SRP_step3(state);
state = SRP_step4(state);
#state = SRP_step5(state);
'''Step 5 is the one in the client would use the password.
This client doesn't know the password, but instead does:'''
state["C_K"] = sha256(intToBytes(0)).digest();
state = SRP_step6(state);
state = SRP_step7(state);
assert(SRP_validate(state));
if __name__ == "__main__":
run_SRP();
client0_SRP()
clientN_SRP()
print("Problem 37 success");