Skip to content

Instantly share code, notes, and snippets.

@tianon
Last active August 29, 2015 13:56
Show Gist options
  • Save tianon/8868936 to your computer and use it in GitHub Desktop.
Save tianon/8868936 to your computer and use it in GitHub Desktop.
randinit, for paultag
randinit: randinit.go
go build -o $@ -ldflags -d $<
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