-
Notifications
You must be signed in to change notification settings - Fork 4
/
kvm_x7.py
executable file
·155 lines (136 loc) · 3.63 KB
/
kvm_x7.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
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
#!/usr/bin/env python3
import bs4 as BeautifulSoup
import collections
import os
import os.path
import requests
import subprocess
import sys
import urllib3
if len(sys.argv) != 4:
print("%s <user> <password> <ipmi address>" % (sys.argv[0],))
sys.exit(1)
user = sys.argv[1]
pswd = sys.argv[2]
host = sys.argv[3]
# Silence SSL Certification warnings
urllib3.disable_warnings(urllib3.exceptions.InsecureRequestWarning)
# Start a requests Session to have persistent cookies
s = requests.Session()
s.headers.update(
{
"User-Agent": "Mozilla/5.0 (Macintosh; Intel Mac OS X 10.14; rv:63.0) Gecko/20100101 Firefox/63.0",
"Accept-Language": "en-US,en;q=0.5",
}
)
s.verify = False
# Grab login page
s.get("https://%s/auth.asp" % (host,))
# Login
data = collections.OrderedDict(
[
("action_login.x", 12),
("action_login.y", 12),
("login", user),
("nickname", ""),
("password", pswd),
]
)
r = s.post(
"https://%s/auth.asp" % (host,),
headers={"Referer": "https://%s/auth.asp" % (host,)},
data=data,
)
# Verify we correctly authenticated
assert "Authenticate with Login and Password" not in r.text
# Download the applet page
r = s.get(
"https://%s/title_app.asp" % (host,),
headers={"Referer": "https://%s/auth.asp" % (host,)},
)
# Verify we actually got some data
assert len(r.text) > 0
soup = BeautifulSoup.BeautifulSoup(r.text, "html.parser")
orig_port = None
redir_port = 4443
params = {
"REAL_HOST": host,
"HOTKEYNAME_0": "Ctrl+Alt+Delete",
"SOFTKBD_MAPPING": "en",
"EXCLUSIVE_MOUSE": False,
"LOCAL_CURSOR": False,
"PORT": redir_port,
"SSLPORT": redir_port,
"PORT_ID": redir_port,
"CLUSTER_PORT_ID": redir_port,
"VS_TYPE": "no",
"logo": False,
"logo_off": "no",
}
for p in soup.find_all("param"):
if p["name"] in ["PORT", "SSLPORT"]:
orig_port = p["value"]
try:
p["value"] = params[p["name"]]
except KeyError:
pass
with open("viewer.html", "w") as f:
f.write(soup.prettify())
jars = [x.strip() for x in soup("applet")[0]["archive"].replace(",", " ").split()]
for jar in jars:
r = s.get(
"https://%s/%s" % (host, jar),
headers={"Referer": "https://%s/title_app.asp" % (host,)},
)
assert len(r.text) > 0
with open(jar, "wb") as f:
f.write(r.content)
# Write out temporary weak java security settings. Just to make sure we're not breaking on old KVM viewers
with open("java.security", "w") as f:
f.write(
"""jdk.certpath.disabledAlgorithms=
jdk.jar.disabledAlgorithms=
jdk.tls.disabledAlgorithms=
jdk.tls.legacyAlgorithms= \
K_NULL, C_NULL, M_NULL, \
DHE_DSS_EXPORT, DHE_RSA_EXPORT, DH_anon_EXPORT, DH_DSS_EXPORT, \
DH_RSA_EXPORT, RSA_EXPORT, \
DH_anon, ECDH_anon, \
RC4_128, RC4_40, DES_CBC, DES40_CBC, \
3DES_EDE_CBC"""
)
with open("java.policy", "w") as f:
f.write(
"""grant {
permission java.security.AllPermission;
};"""
)
# Start port redirection
redirect = subprocess.Popen(
[
"socat",
"TCP-LISTEN:%s,fork,reuseaddr" % (redir_port,),
"TCP:%s:%s" % (host, orig_port),
]
)
# Start javaws viewer
subprocess.call(
[
"appletviewer",
"-J-Djava.security.properties=java.security",
"-J-Djava.security.policy=java.policy",
"viewer.html",
]
)
# Stop port redirection
redirect.kill()
# Remove our temporary files
os.remove("viewer.html")
os.remove("java.security")
os.remove("java.policy")
for jar in jars:
os.remove(jar)
# Logout
r = s.post(
"https://%s/logout" % (host,), headers={"Referer": "https://%s/auth.asp" % (host,)}
)