Skip to content

Commit

Permalink
New option "raw" to disable the raw terminal
Browse files Browse the repository at this point in the history
  • Loading branch information
nodauf committed Apr 13, 2021
1 parent 83ef5ca commit d52fe57
Show file tree
Hide file tree
Showing 5 changed files with 29 additions and 3 deletions.
1 change: 1 addition & 0 deletions src/prompt/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ var optionsSubCommand = []prompt.Suggest{
{Text: "debug", Description: "Manage debug option"},
{Text: "port", Description: "Manage port listener option"},
{Text: "conpty", Description: "Manage conpty option"},
{Text: "raw", Description: "Manage the activation of raw terminal"},
}

var conptySubCommand = []prompt.Suggest{
Expand Down
1 change: 1 addition & 0 deletions src/prompt/helper.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ func helpConnect() {
func helpOptions() {
fmt.Println(`debug: enable/disable debug output
port: update listener port
raw: true (default) the terminal will be set to raw mode. Otherwise will stay in cooked mode
conpty
disableconpty: In the case of conpty causing issue on your reverse shell you could disable it but your reverse shell will not be interactive
onlywebserver: if you have already a powershell commande execution you can use this option to serve the ConPty scripts and get your interactive reverse shell`)
Expand Down
6 changes: 6 additions & 0 deletions src/prompt/prompt.go
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,12 @@ func executor(in string) {
} else {
sessions.PrintPortOptions()
}
case "raw":
if len(command) > 2 {
sessions.SetRaw(command[2])
} else {
sessions.PrintRawOptions()
}
case "conpty":
if len(command) > 2 {
third := command[2]
Expand Down
21 changes: 19 additions & 2 deletions src/sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ import (
logging "github.com/op/go-logging"
)

// OptionsSession contains the option of the futur terminal and the listener
var OptionsSession terminal.Options
// OptionsSession contains the option of the futur terminal and the listener. Default enable the terminal to be set in raw mode
var OptionsSession = terminal.Options{Raw: true}

// PrintSessions will list all active sessions
func PrintSessions() {
Expand Down Expand Up @@ -89,6 +89,17 @@ func SetPort(portString string) {
}
}

// SetRaw update the option Raw
func SetRaw(rawString string) {
if raw, err := strconv.ParseBool(rawString); err == nil {
OptionsSession.Raw = raw
PrintRawOptions()
Restart()
} else {
log.Error("Raw option " + rawString + " invalid")
}
}

// SetDisableConPTY update the option DisableConPTY
func SetDisableConPTY(disableConPTYString string) {
if disableConPTY, err := strconv.ParseBool(disableConPTYString); err == nil {
Expand Down Expand Up @@ -125,6 +136,11 @@ func PrintPortOptions() {
fmt.Println("Port => " + strconv.Itoa(OptionsSession.Port))
}

// PrintRawOptions print the value of Raw options
func PrintRawOptions() {
fmt.Println("Raw => " + strconv.FormatBool(OptionsSession.Raw))
}

// PrintDisableConPTYOptions print the value of DisableConPTY options
func PrintDisableConPTYOptions() {
fmt.Println("DisableConPTY => " + strconv.FormatBool(OptionsSession.DisableConPTY))
Expand All @@ -139,6 +155,7 @@ func PrintOnlyWebserverOptions() {
func PrintOptions() {
PrintDebugOptions()
PrintPortOptions()
PrintRawOptions()
PrintDisableConPTYOptions()
PrintOnlyWebserverOptions()
}
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ type Options struct {
Debug bool
DisableConPTY bool
OnlyWebserver bool
Raw bool
}

// New will initialize the logging configuration and start the listener and wait for client.
Expand Down Expand Up @@ -139,7 +140,7 @@ func (terminal *Terminal) Connect() int {
}
// The terminal is natively in raw mode with go-prompt, we need to disable the raw mode when this is not necessary
// If the client is windows OS and we disable ConPTY, the raw mode is not needed
if terminal.OS == "windows" && terminal.Options.DisableConPTY {
if !terminal.Options.Raw || (terminal.OS == "windows" && terminal.Options.DisableConPTY) {
terminal.sttyRawEcho("disable")
}

Expand Down

0 comments on commit d52fe57

Please sign in to comment.