Skip to content

Commit

Permalink
removed name from implantconfig, implant names are only tied to builds
Browse files Browse the repository at this point in the history
  • Loading branch information
TimBF committed Oct 24, 2023
1 parent 02d1eb5 commit 99281ba
Show file tree
Hide file tree
Showing 17 changed files with 1,721 additions and 1,626 deletions.
4 changes: 2 additions & 2 deletions client/command/generate/generate-beacon.go
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@ var (

// GenerateBeaconCmd - The main command used to generate implant binaries
func GenerateBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) {
config := parseCompileFlags(cmd, con)
name, config := parseCompileFlags(cmd, con)
if config == nil {
return
}
Expand All @@ -35,7 +35,7 @@ func GenerateBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient, arg
if external, _ := cmd.Flags().GetBool("external-builder"); !external {
compile(config, save, con)
} else {
externalBuild(config, save, con)
externalBuild(name, config, save, con)
}
}

Expand Down
41 changes: 20 additions & 21 deletions client/command/generate/generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -90,7 +90,7 @@ var (

// GenerateCmd - The main command used to generate implant binaries
func GenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []string) {
config := parseCompileFlags(cmd, con)
name, config := parseCompileFlags(cmd, con)
if config == nil {
return
}
Expand All @@ -101,7 +101,7 @@ func GenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args []st
if external, _ := cmd.Flags().GetBool("external-builder"); !external {
compile(config, save, con)
} else {
_, err := externalBuild(config, save, con)
_, err := externalBuild(name, config, save, con)
if err != nil {
if err == ErrNoExternalBuilder {
con.PrintErrorf("There are no external builders currently connected to the server\n")
Expand Down Expand Up @@ -182,14 +182,14 @@ func nameOfOutputFormat(value clientpb.OutputFormat) string {
}

// Shared function that extracts the compile flags from the grumble context
func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *clientpb.ImplantConfig {
func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) (string, *clientpb.ImplantConfig) {
var name string
if nameF, _ := cmd.Flags().GetString("name"); nameF != "" {
name = strings.ToLower(nameF)

if err := util.AllowedName(name); err != nil {
con.PrintErrorf("%s\n", err)
return nil
return "", nil
}
}

Expand All @@ -199,15 +199,15 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
mtlsC2, err := ParseMTLSc2(mtlsC2F)
if err != nil {
con.PrintErrorf("%s\n", err.Error())
return nil
return "", nil
}
c2s = append(c2s, mtlsC2...)

wgC2F, _ := cmd.Flags().GetString("wg")
wgC2, err := ParseWGc2(wgC2F)
if err != nil {
con.PrintErrorf("%s\n", err.Error())
return nil
return "", nil
}
wgKeyExchangePort, _ := cmd.Flags().GetUint32("key-exchange")
wgTcpCommsPort, _ := cmd.Flags().GetUint32("tcp-comms")
Expand All @@ -218,31 +218,31 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
httpC2, err := ParseHTTPc2(httpC2F)
if err != nil {
con.PrintErrorf("%s\n", err.Error())
return nil
return "", nil
}
c2s = append(c2s, httpC2...)

dnsC2F, _ := cmd.Flags().GetString("dns")
dnsC2, err := ParseDNSc2(dnsC2F)
if err != nil {
con.PrintErrorf("%s\n", err.Error())
return nil
return "", nil
}
c2s = append(c2s, dnsC2...)

namedPipeC2F, _ := cmd.Flags().GetString("named-pipe")
namedPipeC2, err := ParseNamedPipec2(namedPipeC2F)
if err != nil {
con.PrintErrorf("%s\n", err.Error())
return nil
return "", nil
}
c2s = append(c2s, namedPipeC2...)

tcpPivotC2F, _ := cmd.Flags().GetString("tcp-pivot")
tcpPivotC2, err := ParseTCPPivotc2(tcpPivotC2F)
if err != nil {
con.PrintErrorf("%s\n", err.Error())
return nil
return "", nil
}
c2s = append(c2s, tcpPivotC2...)

Expand All @@ -256,7 +256,7 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl

if len(mtlsC2) == 0 && len(wgC2) == 0 && len(httpC2) == 0 && len(dnsC2) == 0 && len(namedPipeC2) == 0 && len(tcpPivotC2) == 0 {
con.PrintErrorf("Must specify at least one of --mtls, --wg, --http, --dns, --named-pipe, or --tcp-pivot\n")
return nil
return "", nil
}

rawCanaries, _ := cmd.Flags().GetString("canary")
Expand Down Expand Up @@ -320,20 +320,20 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
targetArch := strings.ToLower(targetArchF)
targetOS, targetArch = getTargets(targetOS, targetArch, con)
if targetOS == "" || targetArch == "" {
return nil
return "", nil
}
if configFormat == clientpb.OutputFormat_SHELLCODE && targetOS != "windows" {
con.PrintErrorf("Shellcode format is currently only supported on Windows\n")
return nil
return "", nil
}
if len(namedPipeC2) > 0 && targetOS != "windows" {
con.PrintErrorf("Named pipe pivoting can only be used in Windows.")
return nil
return "", nil
}

// Check to see if we can *probably* build the target binary
if !checkBuildTargetCompatibility(configFormat, targetOS, targetArch, con) {
return nil
return "", nil
}

var tunIP net.IP
Expand All @@ -342,7 +342,7 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
tunIP = net.ParseIP(uniqueWGIP.IP)
if err != nil {
con.PrintErrorf("Failed to generate unique ip for wg peer tun interface")
return nil
return "", nil
}
con.PrintInfof("Generated unique ip for wg peer tun interface: %s\n", tunIP.String())
}
Expand All @@ -353,7 +353,7 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
connectionStrategy, _ := cmd.Flags().GetString("strategy")
if connectionStrategy != "" && connectionStrategy != "s" && connectionStrategy != "r" && connectionStrategy != "rd" {
con.PrintErrorf("Invalid connection strategy: %s\n", connectionStrategy)
return nil
return "", nil
}

// Parse Traffic Encoder Args
Expand All @@ -368,7 +368,6 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
config := &clientpb.ImplantConfig{
GOOS: targetOS,
GOARCH: targetArch,
Name: name,
Debug: debug,
Evasion: evasion,
SGNEnabled: sgnEnabled,
Expand Down Expand Up @@ -407,7 +406,7 @@ func parseCompileFlags(cmd *cobra.Command, con *console.SliverConsoleClient) *cl
HTTPC2ConfigName: c2Profile,
}

return config
return name, config
}

// parseTrafficEncoderArgs - parses the traffic encoder args and returns a bool indicating if traffic encoders are enabled
Expand Down Expand Up @@ -784,7 +783,7 @@ func ParseTCPPivotc2(args string) ([]*clientpb.ImplantC2, error) {
return c2s, nil
}

func externalBuild(config *clientpb.ImplantConfig, save string, con *console.SliverConsoleClient) (*commonpb.File, error) {
func externalBuild(name string, config *clientpb.ImplantConfig, save string, con *console.SliverConsoleClient) (*commonpb.File, error) {
potentialBuilders, err := findExternalBuilders(config, con)
if err != nil {
return nil, err
Expand Down Expand Up @@ -824,6 +823,7 @@ func externalBuild(config *clientpb.ImplantConfig, save string, con *console.Sli

con.PrintInfof("Creating external build ... ")
externalImplantConfig, err := con.Rpc.GenerateExternal(context.Background(), &clientpb.ExternalGenerateReq{
Name: name,
Config: config,
BuilderName: externalBuilder.Name,
})
Expand All @@ -833,7 +833,6 @@ func externalBuild(config *clientpb.ImplantConfig, save string, con *console.Sli
}
con.Printf("done\n")

var name string
msgF := "Waiting for external builder to acknowledge build (template: %s) ... %s"
for waiting {
select {
Expand Down
9 changes: 1 addition & 8 deletions client/command/generate/profiles-generate.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,6 @@ package generate
*/

import (
"context"
"os"
"path/filepath"
"strings"
Expand Down Expand Up @@ -50,16 +49,10 @@ func ProfilesGenerateCmd(cmd *cobra.Command, con *console.SliverConsoleClient, a
if SGNDisabled, _ := cmd.Flags().GetBool("disable-sgn"); SGNDisabled {
profile.Config.SGNEnabled = !SGNDisabled
}
implantFile, err := compile(profile.Config, save, con)
_, err := compile(profile.Config, save, con)
if err != nil {
return
}
profile.Config.Name = buildImplantName(implantFile.Name)
_, err = con.Rpc.SaveImplantProfile(context.Background(), profile)
if err != nil {
con.PrintErrorf("could not update implant profile: %v\n", err)
return
}
} else {
con.PrintErrorf("No profile with name '%s'", name)
}
Expand Down
4 changes: 2 additions & 2 deletions client/command/generate/profiles-new.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ func ProfilesNewCmd(cmd *cobra.Command, con *console.SliverConsoleClient, args [
name = args[0]
}
// name := ctx.Args.String("name")
config := parseCompileFlags(cmd, con)
_, config := parseCompileFlags(cmd, con)
if config == nil {
return
}
Expand All @@ -60,7 +60,7 @@ func ProfilesNewBeaconCmd(cmd *cobra.Command, con *console.SliverConsoleClient,
con.PrintErrorf("No profile name specified\n")
return
}
config := parseCompileFlags(cmd, con)
_, config := parseCompileFlags(cmd, con)
if config == nil {
return
}
Expand Down
1 change: 0 additions & 1 deletion client/console/console.go
Original file line number Diff line number Diff line change
Expand Up @@ -547,7 +547,6 @@ func (con *SliverConsoleClient) GetActiveSessionConfig() *clientpb.ImplantConfig
Priority: uint32(0),
})
config := &clientpb.ImplantConfig{
Name: session.GetName(),
GOOS: session.GetOS(),
GOARCH: session.GetArch(),
Debug: true,
Expand Down
Loading

0 comments on commit 99281ba

Please sign in to comment.