Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
import os, sys
from ctypes import CDLL
libc = CDLL("libc.so.6")
CLONE_NEWNS = 0x00020000
CLONE_NEWCGROUP = 0x02000000
CLONE_NEWUTS = 0x04000000
CLONE_NEWIPC = 0x08000000
CLONE_NEWUSER = 0x10000000
CLONE_NEWPID = 0x20000000
CLONE_NEWNET = 0x40000000
CLONE_NEWTIME = 0x00000080
items = [
[ "cgroup", CLONE_NEWCGROUP, ],
[ "ipc", CLONE_NEWIPC, ],
[ "uts", CLONE_NEWUTS, ],
[ "net", CLONE_NEWNET, ],
[ "pid", CLONE_NEWPID, ],
[ "mnt", CLONE_NEWNS, ],
[ "time", CLONE_NEWTIME, ],
]
PID = 2475362
for path, nstype in items:
fd = open(f"/proc/{PID}/ns/{path}")
libc.setns(fd.fileno(), nstype)
fd.close()
def list(path, level):
if path == "/proc" or path == "/sys" or path == "/dev/fd": return
for f in os.scandir(path):
print(f.path)
if level > 0 and f.is_dir():
list(f.path, level - 1)
list("/", 10)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment