// Isolation probe: the program is not root and cannot become root, change // ownership to root, or raise its limits. package main import ( "fmt" "os" "syscall" ) func main() { ok := os.Getuid() != 0 && os.Geteuid() != 0 && os.Getgid() != 0 && os.Getegid() != 0 ok = ok && syscall.Setuid(0) != nil && syscall.Setgid(0) != nil if err := os.WriteFile("/tmp/owned", nil, 0o600); err == nil { ok = ok && os.Chown("/tmp/owned", 0, 0) != nil } limit := syscall.Rlimit{Cur: 1 << 40, Max: 1 << 40} ok = ok && syscall.Setrlimit(syscall.RLIMIT_NOFILE, &limit) != nil if ok { fmt.Println("unprivileged") return } fmt.Println("privileged") }