-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathsandbox_detect.py
86 lines (73 loc) · 2.8 KB
/
sandbox_detect.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
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
from ctypes import byref, c_uint, c_ulong, sizeof, Structure, windll
import random
import sys
import time
import win32api
class LASTINPUTINFO(Structure):
_fields_ = [
('cbSize', c_uint),
('dwTime', c_ulong)
]
def get_last_input():
struct_lastinputinfo = LASTINPUTINFO()
struct_lastinputinfo.cbSize = sizeof(LASTINPUTINFO)
windll.user32.GetLastInputInfo(byref(struct_lastinputinfo))
run_time = windll.kernel32.GetTickCount()
elapsed = run_time - struct_lastinputinfo.dwTime
print(f"[*] It's been {elapsed} milliseconds since the last input event.")
return elapsed
# while True:
# get_last_input()
# time.sleep(1)
class Detector:
def __init__(self):
self.double_clicks = 0
self.keystrokes = 0
self.mouse_clicks = 0
def get_key_press(self):
for i in range(0, 0xff):
state = win32api.GetAsyncKeyState(i)
if state & 0x0001:
if i == 0x1:
self.mouse_clicks += 1
return time.time()
elif i > 32 and i < 127:
self.keystrokes += 1
return None
def detect(self):
previous_timestamp = None
first_double_click = None
double_click_threshold = 0.35
max_double_clicks = 10
max_keystrokes = random.randint(10,25)
max_mouse_clicks = random.randint(5,25)
max_input_threshold = 30000
last_input = get_last_input()
if last_input >= max_input_threshold:
sys.exit(0)
detection_complete = False
while not detection_complete:
keypress_time = self.get_key_press()
if keypress_time is not None and previous_timestamp is not None:
elapsed = keypress_time - previous_timestamp
if elapsed <= double_click_threshold:
self.mouse_clicks -= 2
self.double_clicks += 1
if first_double_click is None:
first_double_click = time.time()
else:
if self.double_clicks >= max_double_clicks:
if (keypress_time - first_double_click <=
(max_double_clicks*double_click_threshold)):
sys.exit(0)
if (self.keystrokes >= max_keystrokes and
self.double_clicks >= max_double_clicks and
self.mouse_clicks >= max_mouse_clicks):
detection_complete = True
previous_timestamp = keypress_time
elif keypress_time is not None:
previous_timestamp = keypress_time
if __name__ == '__main__':
d = Detector()
d.detect()
print('okay.')