-
Notifications
You must be signed in to change notification settings - Fork 3.8k
Javascript Multi-Port Support #6501
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 6 commits
6a6de38
7e04181
ae61257
0759026
8c56052
9b37f1b
c746a8f
232de93
761c7c0
4e8843a
3ea8dc2
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,15 +17,17 @@ | |
| {Path: "protocols/javascript/net-https.yaml", TestCase: &javascriptNetHttps{}}, | ||
| {Path: "protocols/javascript/oracle-auth-test.yaml", TestCase: &javascriptOracleAuthTest{}, DisableOn: func() bool { return osutils.IsWindows() || osutils.IsOSX() }}, | ||
| {Path: "protocols/javascript/vnc-pass-brute.yaml", TestCase: &javascriptVncPassBrute{}}, | ||
| {Path: "protocols/javascript/multi-ports.yaml", TestCase: &javascriptMultiPortsSSH{}}, | ||
| } | ||
|
|
||
| var ( | ||
| redisResource *dockertest.Resource | ||
| sshResource *dockertest.Resource | ||
| oracleResource *dockertest.Resource | ||
| vncResource *dockertest.Resource | ||
| pool *dockertest.Pool | ||
| defaultRetry = 3 | ||
| redisResource *dockertest.Resource | ||
| sshResource *dockertest.Resource | ||
| oracleResource *dockertest.Resource | ||
| vncResource *dockertest.Resource | ||
| multiPortsSShResource *dockertest.Resource | ||
| pool *dockertest.Pool | ||
| defaultRetry = 3 | ||
| ) | ||
|
|
||
| type javascriptNetHttps struct{} | ||
|
|
@@ -167,6 +169,36 @@ | |
| return multierr.Combine(errs...) | ||
| } | ||
|
|
||
| type javascriptMultiPortsSSH struct{} | ||
|
|
||
| func (j *javascriptMultiPortsSSH) Execute(filePath string) error { | ||
| if sshResource == nil || pool == nil { | ||
| // skip test as redis is not running | ||
| return nil | ||
| } | ||
| finalURL := "scanme.sh" | ||
| errs := []error{} | ||
| for i := 0; i < defaultRetry; i++ { | ||
| results := []string{} | ||
| var err error | ||
| _ = pool.Retry(func() error { | ||
| //let ssh server start | ||
| time.Sleep(3 * time.Second) | ||
| results, err = testutils.RunNucleiTemplateAndGetResults(filePath, finalURL, debug) | ||
| return nil | ||
| }) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if err := expectResultsCount(results, 1); err == nil { | ||
| return nil | ||
| } else { | ||
| errs = append(errs, err) | ||
| } | ||
| } | ||
| return multierr.Combine(errs...) | ||
| } | ||
|
Comment on lines
+173
to
+180
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Multiple issues with executor implementation. The
Apply this diff to align with the established pattern (assuming you want to use the existing func (j *javascriptMultiPortsSSH) Execute(filePath string) error {
if sshResource == nil || pool == nil {
- // skip test as redis is not running
+ // skip test as ssh is not running
return nil
}
- finalURL := "scanme.sh"
+ tempPort := sshResource.GetPort("2222/tcp")
+ finalURL := "localhost:" + tempPort
+ defer purge(sshResource)
errs := []error{}Alternatively, if the test genuinely needs to target the external
Comment on lines
+171
to
+180
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Avoid using
To make this robust and simpler, you can drop the func (j *javascriptMultiPortsSSH) Execute(filePath string) error {
- finalURL := "scanme.sh"
- errs := []error{}
- for i := 0; i < defaultRetry; i++ {
- results := []string{}
- var err error
- _ = pool.Retry(func() error {
- //let ssh server start
- time.Sleep(3 * time.Second)
- results, err = testutils.RunNucleiTemplateAndGetResults(filePath, finalURL, debug)
- return nil
- })
- if err != nil {
- return err
- }
- if err := expectResultsCount(results, 1); err == nil {
- return nil
- } else {
- errs = append(errs, err)
- }
- }
- return multierr.Combine(errs...)
+ finalURL := "scanme.sh"
+ errs := []error{}
+ for i := 0; i < defaultRetry; i++ {
+ // give remote endpoint a brief pause between attempts
+ time.Sleep(3 * time.Second)
+
+ results, err := testutils.RunNucleiTemplateAndGetResults(filePath, finalURL, debug)
+ if err != nil {
+ return err
+ }
+ if err := expectResultsCount(results, 1); err == nil {
+ return nil
+ }
+ errs = append(errs, err)
+ }
+ return multierr.Combine(errs...)
}This removes the potential nil-pointer on 🤖 Prompt for AI Agents |
||
|
|
||
| // purge any given resource if it is not nil | ||
| func purge(resource *dockertest.Resource) { | ||
| if resource != nil && pool != nil { | ||
|
|
||
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -36,6 +36,7 @@ import ( | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| "github.com/projectdiscovery/utils/errkit" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| iputil "github.com/projectdiscovery/utils/ip" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| mapsutil "github.com/projectdiscovery/utils/maps" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| sliceutil "github.com/projectdiscovery/utils/slice" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| syncutil "github.com/projectdiscovery/utils/sync" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| urlutil "github.com/projectdiscovery/utils/url" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -133,8 +134,11 @@ func (request *Request) Compile(options *protocols.ExecutorOptions) error { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // "Port" is a special variable and it should not contains any dsl expressions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if strings.Contains(request.getPort(), "{{") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errkit.New("'Port' variable cannot contain any dsl expressions") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ports := request.getPorts() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, port := range ports { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if strings.Contains(port, "{{") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errkit.New("'Port' variable cannot contain any dsl expressions") | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if request.Init != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -281,12 +285,28 @@ func (request *Request) GetID() string { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // ExecuteWithResults executes the protocol requests and returns results instead of writing them. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (request *Request) ExecuteWithResults(target *contextargs.Context, dynamicValues, previous output.InternalEvent, callback protocols.OutputEventCallback) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // Get default port(s) if specified in template | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ports := request.getPorts() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| var errs []error | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, port := range ports { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| err := request.executeWithResults(port, target, dynamicValues, previous, callback) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| errs = append(errs, err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return errkit.Join(errs...) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Comment on lines
+288
to
+301
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Critical: Templates without Port won't execute. When Apply this diff to execute once with an empty port when no ports are specified: func (request *Request) ExecuteWithResults(target *contextargs.Context, dynamicValues, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
// Get default port(s) if specified in template
ports := request.getPorts()
+ if len(ports) == 0 {
+ ports = []string{""}
+ }
for _, port := range ports {
err := request.executeWithResults(port, target, dynamicValues, previous, callback)
if err != nil {
return err
}
}
return nil
}📝 Committable suggestion
Suggested change
🤖 Prompt for AI Agents |
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // executeWithResults executes the request | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (request *Request) executeWithResults(port string, target *contextargs.Context, dynamicValues, previous output.InternalEvent, callback protocols.OutputEventCallback) error { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| input := target.Clone() | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // use network port updates input with new port requested in template file | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // and it is ignored if input port is not standard http(s) ports like 80,8080,8081 etc | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| // idea is to reduce redundant dials to http ports | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err := input.UseNetworkPort(request.getPort(), request.getExcludePorts()); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if err := input.UseNetworkPort(port, request.getExcludePorts()); err != nil { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| gologger.Debug().Msgf("Could not network port from constants: %s\n", err) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
@@ -755,13 +775,21 @@ func (request *Request) Type() templateTypes.ProtocolType { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return templateTypes.JavascriptProtocol | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (request *Request) getPort() string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (request *Request) getPorts() []string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for k, v := range request.Args { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if strings.EqualFold(k, "Port") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return types.ToString(v) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| portStr := types.ToString(v) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ports := []string{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| for _, p := range strings.Split(portStr, ",") { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| trimmed := strings.TrimSpace(p) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| if trimmed != "" { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| ports = append(ports, trimmed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return sliceutil.Dedupe(ports) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return "" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| return []string{} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
coderabbitai[bot] marked this conversation as resolved.
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| func (request *Request) getExcludePorts() string { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
🧩 Analysis chain
Fix the unused variable causing pipeline failure.
The
multiPortsSShResourcevariable is declared but never used, causing the linter to fail. ThejavascriptMultiPortsSSH.Executemethod checkssshResourceinstead (line 175). This needs to be resolved:multiPortsSShResourceif the test should use the existingsshResource.multiPortsSShResourceand initialize it in theinit()function if a separate SSH resource is needed for multi-port testing.Based on the PR description mentioning "multiple ports" (222, 22, 2244), it appears the test should target a separate multi-port SSH resource. Please clarify whether:
init(), orsshResourceRun this script to check if the multi-ports template expects specific port configurations:
🏁 Script executed:
Length of output: 0
Since I cannot directly access the file without knowing the repository structure and the scripts are not providing output, let me make a final request verification approach:
Clarify whether the unused SSH resource variable should be initialized and used, or removed entirely.
Based on the original review,
multiPortsSShResourceis declared but never used, causing the linter to fail. The test executor checkssshResourceinstead (line 175). Since the PR mentions testing multiple ports (222, 22, 2244), the test likely needs a separate multi-port SSH resource, but the initialization ininit()is missing and the executor doesn't reference the variable.Two options remain:
multiPortsSShResourceif the test should reuse the existingsshResourcemultiPortsSShResourceininit()and update line 175 to reference it, assuming a separate multi-port container is needed🏁 Script executed:
Length of output: 2239
🏁 Script executed:
Length of output: 377
🏁 Script executed:
Length of output: 683
🏁 Script executed:
Length of output: 36
🏁 Script executed:
Length of output: 40
🏁 Script executed:
Length of output: 0
Length of output: 665
🏁 Script executed:
Length of output: 1039
🏁 Script executed:
Length of output: 1050
Remove the unused
multiPortsSShResourcevariable or initialize and use it properly.The variable
multiPortsSShResource(line 28) is declared but never initialized or referenced anywhere in the codebase, causing the linter to fail. ThejavascriptMultiPortsSSH.Execute()method (lines 174-200) checkssshResourceinstead and does not extract or configure multiple ports like the test name suggests.Two valid resolutions:
multiPortsSShResourceif the multi-ports test should reuse the existingsshResourcemultiPortsSShResourceininit()with the appropriate port mappings and update theExecute()method to use it (currently lines 175-200 incorrectly checksshResource)Currently, both
javascriptSSHServerFingerprintandjavascriptMultiPortsSSHuse the same resource, indicating incomplete implementation of the multi-port test setup.🧰 Tools
🪛 GitHub Actions: 🔨 Tests
[error] 28-28: golangci-lint: 'multiPortsSShResource' is unused (unused)
🪛 GitHub Check: Lint
[failure] 28-28:
var multiPortsSShResource is unused (unused)
🤖 Prompt for AI Agents