Skip to content

Instantly share code, notes, and snippets.

@0xc0d
Last active November 5, 2020 23:30
Show Gist options
  • Save 0xc0d/9bb48327fc7142c550e2239fe8369877 to your computer and use it in GitHub Desktop.
Save 0xc0d/9bb48327fc7142c550e2239fe8369877 to your computer and use it in GitHub Desktop.
change current process namespace
err := syscall.Unshare(syscall.CLONE_NEWPID|syscall.CLONE_NEWUTS)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
err = syscall.Sethostname([]byte("container"))
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
cmd := exec.Command("/bin/sh")
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
cmd.Run()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment