Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve socks menu #1704

Merged
merged 3 commits into from
May 31, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
141 changes: 141 additions & 0 deletions client/command/clean/clean.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,141 @@
package clean

/*
Sliver Implant Framework
Copyright (C) 2023 Bishop Fox

This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program. If not, see <https://www.gnu.org/licenses/>.
*/

import (
"context"

"github.com/AlecAivazis/survey/v2"
"github.com/bishopfox/sliver/client/command/flags"
"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/client/constants"
"github.com/bishopfox/sliver/protobuf/clientpb"
"github.com/bishopfox/sliver/protobuf/commonpb"
"github.com/bishopfox/sliver/protobuf/sliverpb"
"github.com/spf13/cobra"
)

// CleanCmd - Remove all profiles, beacons, sessions and implant builds (Builds and logs will still exist on disk in .sliver)
func CleanCmd(cmd *cobra.Command, con *console.SliverClient, args []string) {
con.Printf("This command will kill and remove all sessions, beacons and profiles \n")
confirm := false
prompt := &survey.Confirm{Message: "Are you sure you want to destroy everything?"}
survey.AskOne(prompt, &confirm)
if !confirm {
return
}
err := removeSessionsAndBeacons(con)
if err != nil {
con.PrintErrorf("%s\n", err)
return
}

err = removeImplantBuilds(con)
if err != nil {
con.PrintErrorf("%s\n", err)
return
}

err = removeProfiles(con)
if err != nil {
con.PrintErrorf("%s\n", err)
return
}
con.Printf("All done !\n")
}

func removeImplantBuilds(con *console.SliverClient) error {
builds, err := con.Rpc.ImplantBuilds(context.Background(), &commonpb.Empty{})
if err != nil {
return err
}
for name, _ := range builds.Configs {
_, err := con.Rpc.DeleteImplantBuild(context.Background(), &clientpb.DeleteReq{
Name: name,
})
if err != nil {
return err
}
}

return nil
}

func removeProfiles(con *console.SliverClient) error {
profiles, err := con.Rpc.ImplantProfiles(context.Background(), &commonpb.Empty{})
if err != nil {
return err
}

for _, profile := range profiles.Profiles {
_, err := con.Rpc.DeleteImplantProfile(context.Background(), &clientpb.DeleteReq{
Name: profile.Name,
})
if err != nil {
return err
}
}

return nil
}

func removeSessionsAndBeacons(con *console.SliverClient) error {
sessions, err := con.Rpc.GetSessions(context.Background(), &commonpb.Empty{})
if err != nil {
return err
}

for _, session := range sessions.Sessions {
_, err := con.Rpc.Kill(context.Background(), &sliverpb.KillReq{
Request: &commonpb.Request{
SessionID: session.ID,
Timeout: flags.DefaultTimeout,
},
Force: false,
})
if err != nil {
return err
}
}

beacons, err := con.Rpc.GetBeacons(context.Background(), &commonpb.Empty{})
if err != nil {
return err
}

for _, beacon := range beacons.Beacons {
_, err = con.Rpc.RmBeacon(context.Background(), &clientpb.Beacon{ID: beacon.ID})
if err != nil {
return err
}
}
return nil
}

// Commands returns the `exit` command.
func Command(con *console.SliverClient) []*cobra.Command {
return []*cobra.Command{{
Use: "clean",
Short: "Remove all profiles, beacons, sessions, implant builds and HTTP profiles (Builds and logs will still exist on disk in .sliver)",
Run: func(cmd *cobra.Command, args []string) {
CleanCmd(cmd, con, args)
},
GroupID: constants.GenericHelpGroup,
}}
}
4 changes: 4 additions & 0 deletions client/command/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ import (
"github.com/bishopfox/sliver/client/command/builders"
"github.com/bishopfox/sliver/client/command/c2profiles"
"github.com/bishopfox/sliver/client/command/certificates"
"github.com/bishopfox/sliver/client/command/clean"
"github.com/bishopfox/sliver/client/command/crack"
"github.com/bishopfox/sliver/client/command/creds"
"github.com/bishopfox/sliver/client/command/exit"
Expand All @@ -42,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 @@ -95,6 +97,7 @@ func ServerCommands(con *client.SliverClient, serverCmds func() []*cobra.Command
creds.Commands,
crack.Commands,
certificates.Commands,
clean.Command,
)

// C2 Network
Expand All @@ -103,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
Loading