aktualisieren.
Code: Select all
echo '0 502 1' > /proc/[PID]/uid_map
echo '0 502 1' > /proc/[PID]/gid_map
Code: Select all
nobody
Code: Select all
import signal
import os
import ctypes
import sys
CLONE_NEWUTS = 0x04000000
CLONE_NEWUSER = 0x10000000
def write_file(path, content):
try:
with open(path, "w") as f:
f.write(content)
except Exception as e:
sys.exit(f"[Error] Failed to write mapping {content} to {path}: {e}")
def child_func():
input("...>")
os.execlp("bash", "sh") # Start a new shell
libc = ctypes.CDLL("libc.so.6", use_errno=True)
STACK_SIZE = 1024 * 1024
stack = ctypes.create_string_buffer(STACK_SIZE)
child_stack = ctypes.c_void_p(ctypes.addressof(stack) + STACK_SIZE)
pid = libc.clone(
ctypes.CFUNCTYPE(ctypes.c_int)(child_func),
child_stack,
CLONE_NEWUTS | CLONE_NEWUSER | signal.SIGCHLD,
)
if pid == -1:
sys.exit("Failed to create new namespace")
print(pid)
write_file(f"/proc/{pid}/setgroups", "deny\n")
write_file(f"/proc/{pid}/uid_map", f"0 502 1\n")
write_file(f"/proc/{pid}/gid_map", f"0 502 1\n")
os.waitpid(pid, 0)
< /code>
Was ich überprüft habe: < /strong> < /p>
Das Skript wird mit Root -Berechtigungen ausgeführt. /li>
Die UID- und GID -Zuordnungsdateien werden nach dem Klon < /code> call aktualisiert. < /li>
< /ul>
Trotz dieser Schritte, Der Benutzer im Namespace bleibt niemand