Skip to content

Commit

Permalink
Add option timeBuffer to adjust waiting time #24
Browse files Browse the repository at this point in the history
  • Loading branch information
nodauf committed May 11, 2021
1 parent b6717a2 commit 42c8275
Show file tree
Hide file tree
Showing 6 changed files with 29 additions and 2 deletions.
1 change: 1 addition & 0 deletions src/prompt/completer.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ var optionsSubCommand = []prompt.Suggest{
{Text: "port", Description: "Manage port listener option"},
{Text: "conpty", Description: "Manage conpty option"},
{Text: "raw", Description: "Manage the activation of raw terminal"},
{Text: "timerBuffer", Description: "Time to wait to clear terminal's buffer when executing command (in ms)"},
}

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 @@ -16,6 +16,7 @@ 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
bufferTimer: Time to wait to clear terminal's buffer when executing command (in ms). Mostly use for Windows.
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 @@ -92,6 +92,12 @@ func executor(in string) {

}
}
case "timerbuffer":
if len(command) > 2 {
sessions.SetTimerBuffer(command[2])
} else {
sessions.PrintTimerBufferOptions()
}
default:
fmt.Println("Invalid options command")

Expand Down
19 changes: 18 additions & 1 deletion src/sessions/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import (
)

// 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}
var OptionsSession = terminal.Options{Raw: true, TimerBuffer: 2000}

// PrintSessions will list all active sessions
func PrintSessions() {
Expand Down Expand Up @@ -101,6 +101,17 @@ func SetRaw(rawString string) {
}
}

// SetTimerBuffer update the option Port
func SetTimerBuffer(timerString string) {
if timer, err := strconv.Atoi(timerString); err == nil {
OptionsSession.TimerBuffer = timer
PrintTimerBufferOptions()
Restart()
} else {
log.Error("TimerBuffer option " + timerString + " invalid")
}
}

// SetDisableConPTY update the option DisableConPTY
func SetDisableConPTY(disableConPTYString string) {
if disableConPTY, err := strconv.ParseBool(disableConPTYString); err == nil {
Expand Down Expand Up @@ -145,6 +156,11 @@ func PrintRawOptions() {
fmt.Println("Raw => " + strconv.FormatBool(OptionsSession.Raw))
}

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

// PrintDisableConPTYOptions print the value of DisableConPTY options
func PrintDisableConPTYOptions() {
fmt.Println("DisableConPTY => " + strconv.FormatBool(OptionsSession.DisableConPTY))
Expand All @@ -160,6 +176,7 @@ func PrintOptions() {
PrintDebugOptions()
PrintPortOptions()
PrintRawOptions()
PrintTimerBufferOptions()
PrintDisableConPTYOptions()
PrintOnlyWebserverOptions()
}
Expand Down
3 changes: 2 additions & 1 deletion src/terminal/terminal-utils.go
Original file line number Diff line number Diff line change
Expand Up @@ -285,7 +285,8 @@ func (terminal *Terminal) cleanCmd(cmd string) {

func (terminal *Terminal) clearBufferReadTerminal() {
bufTemp := make([]byte, 10240)
terminal.Con.SetReadDeadline(time.Now().Add(5000 * time.Millisecond))
timeToWait := time.Duration(terminal.Options.TimerBuffer) * time.Millisecond
terminal.Con.SetReadDeadline(time.Now().Add(timeToWait))
for {
if _, err := terminal.Con.Read(bufTemp); err != nil {
break
Expand Down
1 change: 1 addition & 0 deletions src/terminal/terminal.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@ type Options struct {
DisableConPTY bool
OnlyWebserver bool
Raw bool
TimerBuffer int
}

// New will initialize the logging configuration and start the listener and wait for client.
Expand Down

0 comments on commit 42c8275

Please sign in to comment.