Skip to content

Conversation

@terrorbyte
Copy link
Collaborator

@terrorbyte terrorbyte commented Jan 28, 2025

Adds ApplyTemplate which will take a string and apply the Go text/template string format to the string with the config.Config struct.

This allows for the following sort of invocation:

conf := config.NewRemoteExploit(
	config.ImplementedFeatures{AssetDetection: true, VersionScanning: true, Exploitation: true},
	config.CodeExecution, []c2.Impl{}, "Apache", []string{"OFBiz"},
	[]string{"cpe:2.3:a:apache:ofbiz"}, "CVE-2024-45507", "HTTP", 80)

conf.CreateStringFlag("teststring2", "default!", "string usage")
conf.CreateUintFlag("testuint2", 99, "uint usage")
conf.CreateIntFlag("testint2", 300, "int usage")
conf.CreateBoolFlag("testbool2", true, "bool usage")

s := conf.ApplyTemplate("{{.CVE}} {{.StringFlagsMap.teststring2}} {{.UintFlagsMap.testuint2}} {{.IntFlagsMap.testint2}} {{.BoolFlagsMap.testbool2}}")

if s != "CVE-2024-45507 default! 99 300 true" {
	t.Errorf("'%s' unexpected", s)
}

My only real question or thought is that we have generally avoided having trickle up of error values and have masked some of the errors in the framework to keep calls to just be simple return values. Would it be worth doing this as well? Changing the function signature to:

func (conf *Config) ApplyTemplate(name string) string

would allow for really simple inline usage and application without error checking. The only real downside to that imo would be not having clear error reporting, but that would most likely only bubble up during initial development if say a variable was mistyped.

@terrorbyte terrorbyte added the enhancement New feature or request label Jan 28, 2025
@terrorbyte terrorbyte requested review from j-baines and wvu January 28, 2025 17:28
@terrorbyte terrorbyte self-assigned this Jan 28, 2025
@terrorbyte terrorbyte mentioned this pull request Jan 29, 2025
@terrorbyte terrorbyte merged commit 2d7ebe0 into main Jan 30, 2025
3 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

enhancement New feature or request

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants