mirror of
https://github.com/bettercap/bettercap
synced 2025-07-07 21:42:06 -07:00
fix: removing bash escape sequences from stdout before sending it as api response
This commit is contained in:
parent
6ff2839e15
commit
2662831fab
1 changed files with 7 additions and 1 deletions
|
@ -8,6 +8,7 @@ import (
|
|||
"io/ioutil"
|
||||
"net/http"
|
||||
"os"
|
||||
"regexp"
|
||||
"strconv"
|
||||
"strings"
|
||||
|
||||
|
@ -17,6 +18,10 @@ import (
|
|||
"github.com/gorilla/mux"
|
||||
)
|
||||
|
||||
var (
|
||||
ansiEscapeRegex = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
|
||||
)
|
||||
|
||||
type CommandRequest struct {
|
||||
Command string `json:"cmd"`
|
||||
}
|
||||
|
@ -236,7 +241,8 @@ func (mod *RestAPI) runSessionCommand(w http.ResponseWriter, r *http.Request) {
|
|||
out, _ := io.ReadAll(stdoutReader)
|
||||
os.Stdout = rescueStdout
|
||||
|
||||
mod.toJSON(w, APIResponse{Success: true, Message: string(out)})
|
||||
// remove ANSI escape sequences (bash color codes) from output
|
||||
mod.toJSON(w, APIResponse{Success: true, Message: ansiEscapeRegex.ReplaceAllString(string(out), "")})
|
||||
}
|
||||
|
||||
func (mod *RestAPI) getEvents(limit int) []session.Event {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue