Repository navigation
Expand file tree
/
Copy pathbootstrap_upstream.py
More file actions
executable file
·51 lines (40 loc) · 1.72 KB
/
Copy pathbootstrap_upstream.py
File metadata and controls
executable file
·51 lines (40 loc) · 1.72 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
#!/usr/bin/env python3
"""Fetch the pinned 9bie upstream.
The upstream repository has no explicit license, so its source is not vendored
and no patch file is redistributed. This script only clones the pinned commit.
The toolkit applies the SNI fix and the heap-parameter overrides in place at
runtime; the same changes are documented in docs/upstream-changes.md for manual
use.
Usage:
python3 tools/bootstrap_upstream.py
"""
from __future__ import annotations
import subprocess
import sys
from pathlib import Path
ROOT = Path(__file__).resolve().parent.parent
VENDOR = ROOT / "vendor" / "php2shell-upstream"
URL = "https://github.com/9bie/php2shell-bypass-aslr-exp.git"
PIN = "4586f5c"
def run(cmd: list[str], check: bool = True) -> subprocess.CompletedProcess:
return subprocess.run(cmd, check=check, text=True, capture_output=True)
def main() -> int:
if VENDOR.exists() and not (VENDOR / ".git").is_dir():
print(f"{VENDOR} exists but is not a git checkout; remove it and retry", file=sys.stderr)
return 2
if not (VENDOR / "exploit.py").is_file():
VENDOR.parent.mkdir(parents=True, exist_ok=True)
print(f"cloning {URL}")
result = run(["git", "clone", URL, str(VENDOR)], check=False)
if result.returncode != 0:
print(result.stderr.strip(), file=sys.stderr)
return result.returncode
result = run(["git", "-C", str(VENDOR), "checkout", PIN], check=False)
if result.returncode != 0:
print(f"cannot checkout {PIN}: {result.stderr.strip()}", file=sys.stderr)
return result.returncode
print(f"upstream ready: {VENDOR}")
print("runtime changes: docs/upstream-changes.md")
return 0
if __name__ == "__main__":
sys.exit(main())