Last active
August 29, 2015 13:56
-
-
Save tianon/8868936 to your computer and use it in GitHub Desktop.
randinit, for paultag
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
randinit: randinit.go | |
go build -o $@ -ldflags -d $< |
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 ( | |
"math/rand" | |
"os/exec" | |
"syscall" | |
"time" | |
) | |
var inits = []string{} | |
func addInit(init string) bool { | |
var err error | |
if init, err = exec.LookPath(init); err != nil { | |
return false | |
} | |
inits = append(inits, init) | |
return true | |
} | |
func main() { | |
rand.Seed(time.Now().UnixNano()) | |
addInit("/sbin/init") // sysvinit, openrc, upstart (seriously, what's this all about guys? play nice plz) | |
addInit("/bin/systemd") | |
if len(inits) == 0 { | |
panic("wtf bru, you has no inits") | |
} | |
init := inits[rand.Intn(len(inits))] | |
syscall.Exec(init, []string{init}, []string{}) | |
panic("wtf bru, srsly") | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment