webshell/main.go

42 lines
780 B
Go

package main
import (
"fmt"
"log"
"net/http"
"github.com/bitfield/script"
"github.com/gin-gonic/gin"
)
var listenPort string = "1302"
type Shell struct {
Command string
Output string
}
func main() {
fmt.Println()
router := gin.Default()
router.GET("/cmd/:id", sendCommand)
router.Run("localhost:" + listenPort)
}
func sendCommand(c *gin.Context) {
var err error
cmd := c.Param("id")
newCMD := Shell{}
newCMD.Command = cmd
newCMD.Output, err = script.ListFiles(".").String()
if err != nil {
log.Printf("Error occurred with command: %v\n", err)
}
c.String(http.StatusOK, newCMD.Output)
// c.IndentedJSON(http.StatusOK, newCMD)
// c.HTML(http.StatusOK, newCMD)
fmt.Printf("The command \"%s\" has been called\n", cmd)
script.ListFiles(".").Stdout()
}