Skip to content

Commit

Permalink
Blocking backticks from user agent strings in the config so that we c…
Browse files Browse the repository at this point in the history
…an support other characters that would normally need to be escaped.
  • Loading branch information
RafBishopFox committed Nov 2, 2023
1 parent d46e43d commit c1d1bf7
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 1 deletion.
2 changes: 1 addition & 1 deletion implant/sliver/transports/httpclient/httpclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ import (
var (
goHTTPDriver = "go"

userAgent = {{printf "%q" GenerateUserAgent}}
userAgent = `{{GenerateUserAgent}}`
nonceQueryArgs = "{{.HTTPC2ImplantConfig.NonceQueryArgs}}" // "abcdefghijklmnopqrstuvwxyz"

ErrClosed = errors.New("http session closed")
Expand Down
13 changes: 13 additions & 0 deletions server/configs/http-c2.go
Original file line number Diff line number Diff line change
Expand Up @@ -394,6 +394,7 @@ var (
ErrTooFewSessionFiles = errors.New("implant config must specify at least one session_files value")
ErrNonuniqueFileExt = errors.New("implant config must specify unique file extensions")
ErrQueryParamNameLen = errors.New("implant config url query parameter names must be 3 or more characters")
ErrUserAgentIllegalCharacters = errors.New("user agent cannot contain the ` character")

fileNameExp = regexp.MustCompile(`[^a-zA-Z0-9\\._-]+`)
)
Expand Down Expand Up @@ -536,5 +537,17 @@ func checkImplantConfig(config *HTTPC2ImplantConfig) error {
}
}

/*
User agent
Do not allow backticks in user agents because that breaks compilation of the
implant.
*/
if strings.Index(config.UserAgent, "`") != -1 {
// Blank out the user agent so that a default one will be filled in later
config.UserAgent = ""
return ErrUserAgentIllegalCharacters
}

return nil
}

0 comments on commit c1d1bf7

Please sign in to comment.