Skip to content

Commit

Permalink
Merge pull request #258 from guervild/190_change-agent-name
Browse files Browse the repository at this point in the history
Issue #190 Change agent name
  • Loading branch information
moloch-- authored Oct 4, 2020
2 parents f9d4f5e + 1845e77 commit 7a339ed
Show file tree
Hide file tree
Showing 9 changed files with 133 additions and 4 deletions.
17 changes: 17 additions & 0 deletions client/command/bind-commands.go
Original file line number Diff line number Diff line change
Expand Up @@ -352,6 +352,7 @@ func BindCommands(app *grumble.App, rpc rpcpb.SliverRPCClient) {
Flags: func(f *grumble.Flags) {
f.String("o", "os", "windows", "operating system")
f.String("a", "arch", "amd64", "cpu architecture")
f.String("n", "name", "", "agent name")
f.Bool("d", "debug", false, "enable debug features")
f.Bool("e", "evasion", false, "enable evasion features")
f.Bool("b", "skip-symbols", false, "skip symbol obfuscation")
Expand Down Expand Up @@ -1241,4 +1242,20 @@ func BindCommands(app *grumble.App, rpc rpcpb.SliverRPCClient) {
return nil
},
})

app.AddCommand(&grumble.Command{
Name: consts.SetStr,
Help: "Set agent option",
LongHelp: help.GetHelpFor(consts.SetStr),
Flags: func(f *grumble.Flags) {
f.String("n", "name", "", "agent name to change to")
},
Run: func(ctx *grumble.Context) error {
fmt.Println()
setCmd(ctx, rpc)
fmt.Println()
return nil
},
HelpGroup: consts.SliverHelpGroup,
})
}
26 changes: 26 additions & 0 deletions client/command/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"os"
"path"
"path/filepath"
"regexp"
"strings"
"text/tabwriter"

Expand All @@ -40,6 +41,7 @@ import (
"github.com/bishopfox/sliver/protobuf/clientpb"
"github.com/bishopfox/sliver/protobuf/commonpb"
"github.com/bishopfox/sliver/protobuf/rpcpb"
server "github.com/bishopfox/sliver/server/generate"
"github.com/desertbit/grumble"
)

Expand Down Expand Up @@ -235,6 +237,29 @@ func parseCompileFlags(ctx *grumble.Context) *clientpb.ImplantConfig {
targetOS := strings.ToLower(ctx.Flags.String("os"))
arch := strings.ToLower(ctx.Flags.String("arch"))

name := strings.ToLower(ctx.Flags.String("name"))

if name != "" {
isAlphanumeric := regexp.MustCompile(`^[[:alnum:]]+$`).MatchString
if !isAlphanumeric(name) {
fmt.Printf(Warn + "Agent's name must be in alphanumeric only\n")
return nil
}

sliversDir := server.GetSliversDir() // ~/.sliver/slivers
projectGoPathDir := path.Join(sliversDir, targetOS, arch, name)

if _, err := os.Stat(projectGoPathDir); !os.IsNotExist(err) {
prompt := &survey.Confirm{Message: "Agent already exists with this name. Overwrite existing file?"}
var confirm bool
survey.AskOne(prompt, &confirm)
if !confirm {
fmt.Printf(Warn + "File exists\n")
return nil
}
}
}

c2s := []*clientpb.ImplantC2{}

mtlsC2 := parseMTLSc2(ctx.Flags.String("mtls"))
Expand Down Expand Up @@ -330,6 +355,7 @@ func parseCompileFlags(ctx *grumble.Context) *clientpb.ImplantConfig {
config := &clientpb.ImplantConfig{
GOOS: targetOS,
GOARCH: arch,
Name: name,
Debug: ctx.Flags.Bool("debug"),
Evasion: ctx.Flags.Bool("evasion"),
ObfuscateSymbols: symbolObfuscation,
Expand Down
58 changes: 58 additions & 0 deletions client/command/set.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
package command

/*
Sliver Implant Framework
Copyright (C) 2019 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"
"regexp"

//consts "github.com/bishopfox/sliver/client/constants"
"github.com/bishopfox/sliver/protobuf/rpcpb"
"github.com/bishopfox/sliver/server/core"

"github.com/desertbit/grumble"
)

func setCmd(ctx *grumble.Context, rpc rpcpb.SliverRPCClient) {

// Option to change the agent name
name := ctx.Flags.String("name")

if name != "" {
setName(name)
}

}

func setName(name string) {

isAlphanumeric := regexp.MustCompile(`^[[:alnum:]]+$`).MatchString
if !isAlphanumeric(name) {
fmt.Printf(Warn + "Name must be in alphanumeric only\n")
return
}

activeSessionId := ActiveSession.session.ID
currentSession := core.Sessions.Get(activeSessionId)
currentSession.Name = name

core.Sessions.UpdateSession(currentSession)
ActiveSession.Set(currentSession.ToProtobuf())

}
5 changes: 5 additions & 0 deletions client/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -152,6 +152,11 @@ func eventLoop(app *grumble.App, rpc rpcpb.SliverRPCClient) {
session.ID, session.Name, session.RemoteAddress, session.Hostname, session.OS, session.Arch, currentTime)
}

case consts.SessionUpdateEvent:
session := event.Session
currentTime := time.Now().Format(time.RFC1123)
fmt.Printf(clearln+Info+"Session #%d has been updated - %v\n", session.ID, currentTime)

case consts.SessionClosedEvent:
session := event.Session
fmt.Printf(clearln+Warn+"Lost session #%d %s - %s (%s) - %s/%s\n",
Expand Down
3 changes: 3 additions & 0 deletions client/constants/constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,8 @@ const (
SessionOpenedEvent = "connected"
// DisconnectedEvent - Sliver disconnected
SessionClosedEvent = "disconnected"
// UpdateEvent - Sliver updated
SessionUpdateEvent = "updated"

// JoinedEvent - Player joined the game
JoinedEvent = "joined"
Expand All @@ -62,6 +64,7 @@ const (
BackgroundStr = "background"
InfoStr = "info"
UseStr = "use"
SetStr = "set"

GenerateStr = "generate"
RegenerateStr = "regenerate"
Expand Down
11 changes: 11 additions & 0 deletions server/core/sessions.go
Original file line number Diff line number Diff line change
Expand Up @@ -205,3 +205,14 @@ func NextSessionID() uint32 {
(*hiveID)++
return newID
}

func (s *sessions) UpdateSession(session *Session) *Session {
s.mutex.Lock()
defer s.mutex.Unlock()
(*s.sessions)[session.ID] = session
EventBroker.Publish(Event{
EventType: consts.SessionUpdateEvent,
Session: session,
})
return session
}
5 changes: 4 additions & 1 deletion server/generate/binaries.go
Original file line number Diff line number Diff line change
Expand Up @@ -448,7 +448,10 @@ func renderSliverGoCode(config *ImplantConfig, goConfig *gogo.GoConfig) (string,

sliversDir := GetSliversDir() // ~/.sliver/slivers
projectGoPathDir := path.Join(sliversDir, config.GOOS, config.GOARCH, config.Name)
os.MkdirAll(projectGoPathDir, 0700)
if _, err := os.Stat(projectGoPathDir); os.IsNotExist(err) {
os.MkdirAll(projectGoPathDir, 0700)
}

goConfig.GOPATH = projectGoPathDir

// Cert PEM encoded certificates
Expand Down
8 changes: 5 additions & 3 deletions server/gobfuscate/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,9 +47,11 @@ func Gobfuscate(config gogo.GoConfig, encKey string, pkgName string, outPath str
defer os.Setenv("GO111MODULE", "")

newGopath := outPath
if err := os.Mkdir(newGopath, 0700); err != nil {
obfuscateLog.Errorf("Failed to create destination: %v", err)
return "", err
if _, err := os.Stat(newGopath); os.IsNotExist(err) {
if err := os.Mkdir(newGopath, 0700); err != nil {
obfuscateLog.Errorf("Failed to create destination: %v", err)
return "", err
}
}

obfuscateLog.Infof("Copying GOPATH (%s) ...\n", ctx.GOPATH)
Expand Down
4 changes: 4 additions & 0 deletions server/rpc/rpc-generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,10 @@ func (rpc *Server) Generate(ctx context.Context, req *clientpb.GenerateReq) (*cl
fPath, err = generate.SliverShellcode(config)
}

if err != nil {
return nil, err
}

filename := path.Base(fPath)
filedata, err := ioutil.ReadFile(fPath)
if err != nil {
Expand Down

0 comments on commit 7a339ed

Please sign in to comment.