Skip to content

Commit 66e5bb3

Browse files
committed
Add config oriented URL helper.
1 parent 86d4ee5 commit 66e5bb3

File tree

2 files changed

+27
-0
lines changed

2 files changed

+27
-0
lines changed

config/config.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import (
1010
"github.com/vulncheck-oss/go-exploit/c2"
1111
"github.com/vulncheck-oss/go-exploit/c2/shelltunnel"
1212
"github.com/vulncheck-oss/go-exploit/output"
13+
"github.com/vulncheck-oss/go-exploit/protocol"
1314
)
1415

1516
type ExploitType int
@@ -370,6 +371,13 @@ func (conf *Config) ApplyTemplate(name string) string {
370371
return buf.String()
371372
}
372373

374+
// Generate a URL from a path from the current configuration. This is a
375+
// way of invoking protocol.GenerateURL for developer ergonomics during
376+
// exploit development.
377+
func (conf *Config) GenerateURL(path string) string {
378+
return protocol.GenerateURL(conf.Rhost, conf.Rport, conf.SSL, path)
379+
}
380+
373381
// Disable automatic start of c2 servers. Manually starting is required after
374382
// this function is called. This is useful when you have an exploit that
375383
// may have multiple stages and you are guaranteed to not need the C2

config/config_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package config_test
22

33
import (
4+
"strings"
45
"testing"
56

67
"github.com/vulncheck-oss/go-exploit/c2"
@@ -97,3 +98,21 @@ func TestApplyTemplate(t *testing.T) {
9798
t.Errorf("'%s' unexpected", s)
9899
}
99100
}
101+
102+
func TestGenerateURL(t *testing.T) {
103+
conf := config.NewRemoteExploit(
104+
config.ImplementedFeatures{AssetDetection: true, VersionScanning: true, Exploitation: true},
105+
config.CodeExecution, []c2.Impl{}, "Apache", []string{"OFBiz"},
106+
[]string{"cpe:2.3:a:apache:ofbiz"}, "CVE-2024-45507", "HTTP", 80)
107+
conf.Rhost = "127.13.37.1"
108+
conf.Rport = 31337
109+
conf.SSL = true
110+
111+
if strings.Compare(conf.GenerateURL("/vulncheck"), `https://127.13.37.1:31337/vulncheck`) != 0 {
112+
t.Errorf("GenerateURL did not generate expected HTTPS URL: `%s` != `%s`", conf.GenerateURL("/vulncheck"), `https://127.13.37.1:31337/vulncheck`)
113+
}
114+
conf.SSL = false
115+
if strings.Compare(conf.GenerateURL("/vulncheck"), `http://127.13.37.1:31337/vulncheck`) != 0 {
116+
t.Errorf("GenerateURL did not generate expected HTTP URL: `%s` != `%s`", conf.GenerateURL("/vulncheck"), `http://127.13.37.1:31337/vulncheck`)
117+
}
118+
}

0 commit comments

Comments
 (0)