Skip to content

Commit

Permalink
Improved state mgmt
Browse files Browse the repository at this point in the history
  • Loading branch information
moloch-- committed Sep 1, 2022
1 parent 33e5525 commit 5a352de
Show file tree
Hide file tree
Showing 6 changed files with 109 additions and 4 deletions.
2 changes: 1 addition & 1 deletion client/command/commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -3313,7 +3313,7 @@ func BindCommands(con *console.SliverConsoleClient) {
},
Run: func(ctx *grumble.Context) error {
con.Println()
con.Println("You must specify a subcommand, see --help for options")
cursed.CursedCmd(ctx, con)
con.Println()
return nil
},
Expand Down
7 changes: 4 additions & 3 deletions client/command/cursed/cursed-chrome.go
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ func CursedChromeCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
}
if chromeExt != nil {
con.Printf("success!\n")
con.PrintInfof("Found viable Chrome extension: %s%s%s (%s)\n", console.Bold, chromeExt.Title, console.Normal, chromeExt.ID)
con.PrintInfof("Found viable Chrome extension %s%s%s (%s)\n", console.Bold, chromeExt.Title, console.Normal, chromeExt.ID)
con.PrintInfof("Injecting payload ... ")

ctx, _, _ := overlord.GetChromeContext(chromeExt.WebSocketDebuggerURL, curse)
Expand Down Expand Up @@ -185,18 +185,19 @@ func startCursedChromeProcess(restore bool, session *clientpb.Session, ctx *grum
core.Portfwds.Add(tcpProxy, channelProxy)

curse := &core.CursedProcess{
SessionID: session.ID,
BindTCPPort: bindPort,
Platform: session.GetOS(),
ChromeExePath: chromeExePath,
ChromeUserDataDir: chromeUserDataDir,
}
core.CursedProcesses.Store(session.ID, curse)
core.CursedProcesses.Store(bindPort, curse)
go func() {
err := tcpProxy.Run()
if err != nil {
log.Printf("Proxy error %s", err)
}
core.CursedProcesses.Delete(session.ID)
core.CursedProcesses.Delete(bindPort)
}()

con.PrintInfof("Port forwarding %s -> %s\n", bindAddr, remoteAddr)
Expand Down
34 changes: 34 additions & 0 deletions client/command/cursed/cursed-stop.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
package cursed

/*
Sliver Implant Framework
Copyright (C) 2022 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 (
"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/client/core"
"github.com/desertbit/grumble"
)

func CursedStopCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
session := con.ActiveTarget.GetSessionInteractive()
if session == nil {
return
}
bindPort := ctx.Args.Int("bind-port")
core.CursedProcesses.Delete(bindPort)
}
58 changes: 58 additions & 0 deletions client/command/cursed/cursed.go
Original file line number Diff line number Diff line change
@@ -1 +1,59 @@
package cursed

/*
Sliver Implant Framework
Copyright (C) 2022 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 (
"fmt"
"strings"

"github.com/bishopfox/sliver/client/command/settings"
"github.com/bishopfox/sliver/client/console"
"github.com/bishopfox/sliver/client/core"
"github.com/desertbit/grumble"
"github.com/jedib0t/go-pretty/v6/table"
)

// CursedChromeCmd - Execute a .NET assembly in-memory
func CursedCmd(ctx *grumble.Context, con *console.SliverConsoleClient) {
cursedProcesses := [][]string{}
core.CursedProcesses.Range(func(key, value interface{}) bool {
curse := value.(*core.CursedProcess)
cursedProcesses = append(cursedProcesses, []string{
fmt.Sprintf("%d", curse.BindTCPPort), strings.Split(curse.SessionID, "-")[0], curse.Platform, curse.ChromeExePath, curse.DebugURL().String(),
})
return true
})
if 0 < len(cursedProcesses) {
tw := table.NewWriter()
tw.SetStyle(settings.GetTableStyle(con))
tw.AppendHeader(table.Row{
"Bind Port", "Session ID", "Platform", "Executable", "Debug URL",
})
for _, rowEntries := range cursedProcesses {
row := table.Row{}
for _, entry := range rowEntries {
row = append(row, entry)
}
tw.AppendRow(table.Row(row))
}
con.Printf("%s\n", tw.Render())
} else {
con.PrintInfof("No cursed processes\n")
}
}
1 change: 1 addition & 0 deletions client/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,7 @@ func (con *SliverConsoleClient) EventLoop() {
shortID, session.Name, session.RemoteAddress, session.Hostname, session.OS, session.Arch, currentTime)
activeSession := con.ActiveTarget.GetSession()
core.GetTunnels().CloseForSession(session.ID)
core.CloseCursedProcesses(session.ID)
if activeSession != nil && activeSession.ID == session.ID {
con.ActiveTarget.Set(nil, nil)
con.PrintEventErrorf("Active session disconnected")
Expand Down
11 changes: 11 additions & 0 deletions client/core/curses.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@ var (
)

type CursedProcess struct {
SessionID string
BindTCPPort int
Platform string
ChromeExePath string
Expand All @@ -43,3 +44,13 @@ func (c *CursedProcess) DebugURL() *url.URL {
Path: "/json",
}
}

func CloseCursedProcesses(sessionID string) {
CursedProcesses.Range(func(key, value interface{}) bool {
cursedProcess := value.(*CursedProcess)
if cursedProcess.SessionID == sessionID {
defer CursedProcesses.Delete(key)
}
return true
})
}

0 comments on commit 5a352de

Please sign in to comment.