Created
May 26, 2022 09:15
-
-
Save ayosec/c34798150baa705c5659c418e4b59c9e to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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