Skip to content

Instantly share code, notes, and snippets.

@ayosec
Created May 26, 2022 09:15
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ayosec/c34798150baa705c5659c418e4b59c9e to your computer and use it in GitHub Desktop.
Save ayosec/c34798150baa705c5659c418e4b59c9e to your computer and use it in GitHub Desktop.
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