Skip to content

Commit

Permalink
Merge pull request #1841 from BishopFox/fix_c2profile_display
Browse files Browse the repository at this point in the history
fix broken pr for http headers and add additional constraints for c2p…
  • Loading branch information
moloch-- authored Jan 3, 2025
2 parents 31265c6 + f011365 commit 9ecb68f
Show file tree
Hide file tree
Showing 5 changed files with 32 additions and 29 deletions.
10 changes: 5 additions & 5 deletions client/assets/c2profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,10 @@ type HTTPC2ServerConfig struct {
}

type NameValueProbability struct {
Name string `json:"name"`
Value string `json:"value"`
Probability int `json:"probability"`
Methods []string `json:"methods"`
Name string `json:"name"`
Value string `json:"value"`
Probability int `json:"probability"`
Method string `json:"method"`
}

// HTTPC2ImplantConfig - Implant configuration options
Expand All @@ -56,7 +56,7 @@ type HTTPC2ImplantConfig struct {

NonceQueryArgChars string `json:"nonce_query_args"`
URLParameters []NameValueProbability `json:"url_parameters"`
Headers []NameValueProbability `json:"client_headers"`
Headers []NameValueProbability `json:"headers"`

MaxFiles int `json:"max_files"`
MinFiles int `json:"min_files"`
Expand Down
34 changes: 16 additions & 18 deletions client/command/c2profiles/c2profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -292,6 +292,7 @@ func C2ConfigToJSON(profileName string, profile *clientpb.HTTPC2Config) (*assets
Name: header.Name,
Value: header.Value,
Probability: int(header.Probability),
Method: header.Method,
})
}
implantConfig.Headers = headers
Expand Down Expand Up @@ -358,6 +359,7 @@ func C2ConfigToJSON(profileName string, profile *clientpb.HTTPC2Config) (*assets
Name: header.Name,
Value: header.Value,
Probability: int(header.Probability),
Method: header.Method,
})
}

Expand Down Expand Up @@ -454,14 +456,12 @@ func C2ConfigToProtobuf(profileName string, config *assets.HTTPC2Config) *client
}

for _, clientHeader := range config.ImplantConfig.Headers {
for _, method := range clientHeader.Methods {
httpC2Headers = append(httpC2Headers, &clientpb.HTTPC2Header{
Method: method,
Name: clientHeader.Name,
Value: clientHeader.Value,
Probability: int32(clientHeader.Probability),
})
}
httpC2Headers = append(httpC2Headers, &clientpb.HTTPC2Header{
Method: clientHeader.Method,
Name: clientHeader.Name,
Value: clientHeader.Value,
Probability: int32(clientHeader.Probability),
})
}

implantConfig := &clientpb.HTTPC2ImplantConfig{
Expand All @@ -486,14 +486,12 @@ func C2ConfigToProtobuf(profileName string, config *assets.HTTPC2Config) *client
// Server Config
serverHeaders := []*clientpb.HTTPC2Header{}
for _, serverHeader := range config.ServerConfig.Headers {
for _, method := range serverHeader.Methods {
serverHeaders = append(serverHeaders, &clientpb.HTTPC2Header{
Method: method,
Name: serverHeader.Name,
Value: serverHeader.Value,
Probability: int32(serverHeader.Probability),
})
}
serverHeaders = append(serverHeaders, &clientpb.HTTPC2Header{
Method: serverHeader.Method,
Name: serverHeader.Name,
Value: serverHeader.Value,
Probability: int32(serverHeader.Probability),
})
}

serverCookies := []*clientpb.HTTPC2Cookie{}
Expand Down Expand Up @@ -536,7 +534,7 @@ func PrintC2Profiles(profile *clientpb.HTTPC2Config, con *console.SliverClient)

var serverHeaders []string
for _, header := range profile.ServerConfig.Headers {
serverHeaders = append(serverHeaders, header.Value)
serverHeaders = append(serverHeaders, header.Name)
}
tw.AppendRow(table.Row{
"Server Headers",
Expand All @@ -561,7 +559,7 @@ func PrintC2Profiles(profile *clientpb.HTTPC2Config, con *console.SliverClient)

var clientHeaders []string
for _, header := range profile.ImplantConfig.Headers {
clientHeaders = append(clientHeaders, header.Value)
clientHeaders = append(clientHeaders, header.Name)
}
tw.AppendRow(table.Row{
"Client Headers",
Expand Down
2 changes: 2 additions & 0 deletions server/configs/http-c2.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,6 +60,8 @@ var (
ErrDuplicateStageExt = errors.New("stager extension is already used in another C2 profile")
ErrDuplicateStartSessionExt = errors.New("start session extension is already used in another C2 profile")
ErrDuplicateC2ProfileName = errors.New("C2 Profile name is already in use")
ErrMissingC2ProfileName = errors.New("C2 Profile name is required")
ErrC2ProfileNotFound = errors.New("C2 Profile does not exist")
ErrUserAgentIllegalCharacters = errors.New("user agent cannot contain the ` character")

fileNameExp = regexp.MustCompile(`[^a-zA-Z0-9\\._-]+`)
Expand Down
2 changes: 1 addition & 1 deletion server/db/helpers.go
Original file line number Diff line number Diff line change
Expand Up @@ -471,7 +471,7 @@ func HTTPC2ConfigUpdate(newConf *clientpb.HTTPC2Config, oldConf *clientpb.HTTPC2
}

err = Session().Where(&models.HttpC2Header{
HttpC2ServerConfigID: &clientID,
HttpC2ImplantConfigID: &clientID,
}).Delete(&models.HttpC2Header{})
if err.Error != nil {
return err.Error
Expand Down
13 changes: 8 additions & 5 deletions server/rpc/rpc-c2profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -59,16 +59,15 @@ func (rpc *Server) SaveHTTPC2Profile(ctx context.Context, req *clientpb.HTTPC2Co
return nil, err
}

profileName := ""
if req.Overwrite {
profileName = req.C2Config.Name
if req.Overwrite && req.C2Config.Name == "" {
return nil, configs.ErrMissingC2ProfileName
}
err = db.SearchStageExtensions(req.C2Config.ImplantConfig.StagerFileExtension, profileName)
err = db.SearchStageExtensions(req.C2Config.ImplantConfig.StagerFileExtension, req.C2Config.Name)
if err != nil {
return nil, err
}

err = db.SearchStartSessionExtensions(req.C2Config.ImplantConfig.StartSessionFileExtension, profileName)
err = db.SearchStartSessionExtensions(req.C2Config.ImplantConfig.StartSessionFileExtension, req.C2Config.Name)
if err != nil {
return nil, err
}
Expand All @@ -81,6 +80,10 @@ func (rpc *Server) SaveHTTPC2Profile(ctx context.Context, req *clientpb.HTTPC2Co
return nil, configs.ErrDuplicateC2ProfileName
}

if httpC2Config.Name == "" {
return nil, configs.ErrC2ProfileNotFound
}

if req.Overwrite {
err = db.HTTPC2ConfigUpdate(req.C2Config, httpC2Config)
if err != nil {
Expand Down

0 comments on commit 9ecb68f

Please sign in to comment.