Skip to content

Commit

Permalink
[+] #13 Adding a current session prompt setting showing what session …
Browse files Browse the repository at this point in the history
…the user is interacting with.
  • Loading branch information
WangYihang committed Mar 1, 2020
1 parent 68f0698 commit a32786c
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 8 deletions.
11 changes: 7 additions & 4 deletions lib/cli/dispatcher/command_dispatcher.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ import (

type Dispatcher struct{}

var ReadLineInstance *readline.Instance

func parseInput(input string) (string, []string) {
methods := reflection.GetAllMethods(Dispatcher{})
args := strings.Split(strings.TrimSpace(input), " ")
Expand Down Expand Up @@ -58,7 +60,8 @@ func Run() {
completer.SetChildren(children)

// Construct the IO
l, err := readline.NewEx(&readline.Config{
var err error
ReadLineInstance, err = readline.NewEx(&readline.Config{
Prompt: context.Ctx.CommandPrompt,
HistoryFile: "/tmp/platypus.history",
AutoComplete: completer,
Expand All @@ -71,13 +74,13 @@ func Run() {
if err != nil {
panic(err)
}
defer l.Close()
// defer l.Close()

log.Logger.SetOutput(l.Stderr())
log.Logger.SetOutput(ReadLineInstance.Stderr())

// Command loop
for {
line, err := l.Readline()
line, err := ReadLineInstance.Readline()
if err == readline.ErrInterrupt {
if len(line) == 0 {
break
Expand Down
20 changes: 20 additions & 0 deletions lib/cli/dispatcher/jump.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (

"github.com/WangYihang/Platypus/lib/context"
"github.com/WangYihang/Platypus/lib/util/log"
"github.com/fatih/color"
)

func (dispatcher Dispatcher) Jump(args []string) {
Expand All @@ -19,6 +20,25 @@ func (dispatcher Dispatcher) Jump(args []string) {
if strings.HasPrefix(client.Hash, strings.ToLower(args[0])) {
context.Ctx.Current = client
log.Success("The current interactive shell is set to: %s", client.FullDesc())

// Update prompt
// BUG:
// The prompt will set only at the `Jump` command once.
// If we jump to a client before the os & user is detected
// So the prompt will be:
// (Unknown) 127.0.0.1:43802 [unknown] »
var user string
if client.User == "" {
user = "unknown"
} else {
user = client.User
}
ReadLineInstance.SetPrompt(color.CyanString(
"(%s) %s [%s] » ",
client.OS.String(),
client.Conn.RemoteAddr().String(),
user,
))
return
}
}
Expand Down
5 changes: 1 addition & 4 deletions lib/context/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -185,13 +185,10 @@ func (s *TCPServer) AsTable() {
(*s).Port,
len((*s).Clients),
))
t.AppendHeader(table.Row{"ID", "Hash", "Network", "OS", "User", "Time"})
t.AppendHeader(table.Row{"Hash", "Network", "OS", "User", "Time"})

i := 0
for chash, client := range s.Clients {
i++
t.AppendRow([]interface{}{
i,
chash,
client.Conn.RemoteAddr().String(),
client.OS.String(),
Expand Down

0 comments on commit a32786c

Please sign in to comment.