mirror of
https://github.com/bettercap/bettercap
synced 2025-07-16 10:03:39 -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"
|
"io/ioutil"
|
||||||
"net/http"
|
"net/http"
|
||||||
"os"
|
"os"
|
||||||
|
"regexp"
|
||||||
"strconv"
|
"strconv"
|
||||||
"strings"
|
"strings"
|
||||||
|
|
||||||
|
@ -17,6 +18,10 @@ import (
|
||||||
"github.com/gorilla/mux"
|
"github.com/gorilla/mux"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
var (
|
||||||
|
ansiEscapeRegex = regexp.MustCompile(`\x1b\[[0-9;]*[a-zA-Z]`)
|
||||||
|
)
|
||||||
|
|
||||||
type CommandRequest struct {
|
type CommandRequest struct {
|
||||||
Command string `json:"cmd"`
|
Command string `json:"cmd"`
|
||||||
}
|
}
|
||||||
|
@ -236,7 +241,8 @@ func (mod *RestAPI) runSessionCommand(w http.ResponseWriter, r *http.Request) {
|
||||||
out, _ := io.ReadAll(stdoutReader)
|
out, _ := io.ReadAll(stdoutReader)
|
||||||
os.Stdout = rescueStdout
|
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 {
|
func (mod *RestAPI) getEvents(limit int) []session.Event {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue