Skip to content

Commit

Permalink
Merge pull request #1704 from BishopFox/improve_socks_menu
Browse files Browse the repository at this point in the history
Improve socks menu
  • Loading branch information
moloch-- authored May 31, 2024
2 parents 015942a + 321da76 commit 2bc3fe8
Show file tree
Hide file tree
Showing 3 changed files with 54 additions and 0 deletions.
2 changes: 2 additions & 0 deletions client/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@ import (
"github.com/bishopfox/sliver/client/command/sessions"
"github.com/bishopfox/sliver/client/command/settings"
sgn "github.com/bishopfox/sliver/client/command/shikata-ga-nai"
"github.com/bishopfox/sliver/client/command/socks"
"github.com/bishopfox/sliver/client/command/taskmany"
"github.com/bishopfox/sliver/client/command/update"
"github.com/bishopfox/sliver/client/command/use"
Expand Down Expand Up @@ -105,6 +106,7 @@ func ServerCommands(con *client.SliverClient, serverCmds func() []*cobra.Command
websites.Commands,
wireguard.Commands,
c2profiles.Commands,
socks.RootCommands,
)

// Payloads
Expand Down
46 changes: 46 additions & 0 deletions client/command/socks/rootCommands.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package socks

import (
"github.com/bishopfox/sliver/client/command/flags"
"github.com/bishopfox/sliver/client/command/help"
"github.com/bishopfox/sliver/client/console"
consts "github.com/bishopfox/sliver/client/constants"
"github.com/rsteube/carapace"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
)

// Commands returns the “ command and its subcommands.
func RootCommands(con *console.SliverClient) []*cobra.Command {
socksCmd := &cobra.Command{
Use: consts.Socks5Str,
Short: "In-band SOCKS5 Proxy",
Long: help.GetHelpFor([]string{consts.Socks5Str}),
GroupID: consts.NetworkHelpGroup,
Annotations: flags.RestrictTargets(consts.SessionCmdsFilter),
Run: func(cmd *cobra.Command, args []string) {
SocksCmd(cmd, con, args)
},
}
flags.Bind("", true, socksCmd, func(f *pflag.FlagSet) {
f.Int64P("timeout", "t", flags.DefaultTimeout, "grpc timeout in seconds")
})

socksStopCmd := &cobra.Command{
Use: consts.StopStr,
Short: "Stop a SOCKS5 proxy",
Long: help.GetHelpFor([]string{consts.Socks5Str}),
Run: func(cmd *cobra.Command, args []string) {
SocksStopCmd(cmd, con, args)
},
}
socksCmd.AddCommand(socksStopCmd)
flags.Bind("", false, socksStopCmd, func(f *pflag.FlagSet) {
f.Uint64P("id", "i", 0, "id of portfwd to remove")
})
flags.BindFlagCompletions(socksStopCmd, func(comp *carapace.ActionMap) {
(*comp)["id"] = SocksIDCompleter(con)
})

return []*cobra.Command{socksCmd}
}
6 changes: 6 additions & 0 deletions client/command/socks/socks.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,8 @@ func SocksCmd(cmd *cobra.Command, con *console.SliverClient, args []string) {
return socks[i].ID < socks[j].ID
})

session := con.ActiveTarget.GetSession()

tw := table.NewWriter()
tw.SetStyle(settings.GetTableStyle(con))
tw.AppendHeader(table.Row{
Expand All @@ -52,6 +54,10 @@ func SocksCmd(cmd *cobra.Command, con *console.SliverClient, args []string) {
"Passwords",
})
for _, p := range socks {
// if we're in an active session, just display socks proxies for the session
if session != nil && session.ID != p.SessionID {
continue
}
tw.AppendRow(table.Row{p.ID, p.SessionID, p.BindAddr, p.Username, p.Password})
}

Expand Down

0 comments on commit 2bc3fe8

Please sign in to comment.