-
Notifications
You must be signed in to change notification settings - Fork 5
/
Copy path31.py
53 lines (33 loc) · 1.38 KB
/
31.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
from .. import mac
from .. import random_helper
from .. import timing_attack
class Challenge():
def __init__(self):
self._secret = random_helper.random_bytes(16)
def upload(self, file, signature, known_bytes=None):
"""Imagine this is an HTTP GET..."""
hmac = mac.hmac_sha1(self._secret, file)
if not timing_attack.insecure_compare(
hmac, signature, delay_ms=2, known_bytes=known_bytes):
return 500
print("Successful upload of %s.", file)
return 200
def _peek(self, file):
"""Only used to provide debug info in print."""
hmac = mac.hmac_sha1(self._secret, file)
print("Psst. You're looking for ", hmac.hex())
challenge = Challenge()
file = b"evil_payload.exe"
challenge._peek(file)
# If this is 'None', we don't "cheat" by skipping delays (extra noise)
# before the last known byte. Adding this to play nice with Travis.
known_bytes = 0
def try_hmac(hmac):
challenge.upload(file, hmac, known_bytes)
def on_byte_found(hmac, byte_idx):
global known_bytes
known_bytes = byte_idx + 1
print("Byte %d of hmac is %x" % (byte_idx, hmac[byte_idx]))
hmac = timing_attack.comparison_time_attack(
bytes([0] * 20), try_hmac, per_byte_rounds=10, progress_callback=on_byte_found)
assert challenge.upload(file, hmac) == 200