-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathpin-timing-attack.py
55 lines (42 loc) · 1.44 KB
/
pin-timing-attack.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
54
55
# Title: Pin Timing Attack
# Author: Kalana Sankalpa (Anon LK)
#!/usr/bin/python
import os
import time
timeDiff = 50 #Set maximum time difference
exePath = "./program" # Set path to the program
def get_response_time(pin):
# Convert pin list to a string
pin_str = ''.join(map(str, pin))
print("Trying:", pin_str)
# Run command (eg: echo 00000000 | ./program)
cmd = f'echo {pin_str} | {exePath}'
# Measure execution time before and after running the command
start = time.time()
os.system(cmd)
end = time.time()
# Calculate and return the response time in milliseconds
return (end - start) * 1000
pin = [0] * 8 # Initialize the pin to all zeros
res_time = get_response_time(pin)
max_time = res_time
print("First Response time:", res_time)
# Loop through each digit in the pin
for i in range(8):
# Try each digit (0 to 9) for the current position in the pin
for num in range(10):
pin[i] = num
res_time = get_response_time(pin)
# Check if the pin was 0
if max_time > res_time + timeDiff and num == 1:
pin[i] = num - 1
break
# Find the correct pin by comparing maxTime with the current resTime
if max_time + timeDiff < res_time:
max_time = res_time
break
print("ResTime:", res_time)
print("MaxTime:", max_time)
# print the correct pin
pin_str = ''.join(map(str, pin))
print("\nPin Found:", pin_str)