Implement backend for RCE

This commit is contained in:
raul 2024-06-06 09:32:35 +02:00
parent 4a0aafe237
commit 513d707df4
1 changed files with 18 additions and 2 deletions

View File

@ -5,6 +5,7 @@ import (
"fmt" "fmt"
"net/http" "net/http"
"strconv" "strconv"
"strings"
"github.com/gin-gonic/gin" "github.com/gin-gonic/gin"
"github.com/spf13/viper" "github.com/spf13/viper"
@ -54,10 +55,25 @@ func getCommands(c *gin.Context) {
} }
c.HTML(http.StatusOK, "templates/command.html", gin.H{ c.HTML(http.StatusOK, "templates/command.html", gin.H{
"UserAgent": c.Request.UserAgent(), "UserAgent": c.Request.UserAgent(),
"client": client, "Client": client,
}) })
} }
func execCMD(c *gin.Context) { func execCMD(c *gin.Context) {
fmt.Println("HELLO") id := c.Param("clientid")
idInt, err := strconv.Atoi(id)
if err != nil {
c.String(http.StatusInternalServerError, "Error happened, please make this a proper error later")
return
}
command, _ := c.GetPostForm("cmd")
out, err := sendCommand(idInt, command)
if err != nil {
e := fmt.Sprintf("Error happened executing command: %v\n", err)
c.String(http.StatusOK, e)
return
}
prettyOut := strings.Replace(out, "\n", "<br>", -1)
c.String(http.StatusOK, "$ "+prettyOut)
} }