Created
July 30, 2014 18:58
-
-
Save mrunalp/4365565f94e9c9fd737c to your computer and use it in GitHub Desktop.
Test program to show user namespace POC in go
This file contains hidden or 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
package main | |
import ( | |
"log" | |
"os" | |
"os/exec" | |
"syscall" | |
) | |
func main() { | |
cmd := exec.Command("/bin/sh") | |
cmd.SysProcAttr = &syscall.SysProcAttr{} | |
cmd.SysProcAttr.Cloneflags = syscall.CLONE_NEWUSER | syscall.CLONE_NEWNS | syscall.CLONE_NEWUTS | syscall.CLONE_NEWPID | syscall.CLONE_NEWIPC | syscall.CLONE_NEWNET | |
cmd.SysProcAttr.Credential = &syscall.Credential{ | |
Uid: 0, | |
Gid: 0, | |
UidMappings: "0 1000 1", | |
GidMappings: "0 1000 1", | |
} | |
cmd.Stdin = os.Stdin | |
cmd.Stderr = os.Stderr | |
cmd.Stdout = os.Stdout | |
if err := cmd.Start(); err != nil { | |
log.Fatalf("Failed to start command: %s", err) | |
} | |
log.Println("Command started") | |
if err := cmd.Wait(); err != nil { | |
if _, ok := err.(*exec.ExitError); !ok { | |
log.Fatalf("Failed to exit: %s", err) | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment