Skip to content

Commit 746a05d

Browse files
authored
fix(javascript): restore exec for templates w/o Port arg (#6709)
Restore backwards compat for JavaScript protocol templates that omit the `Port` argument. Regression was introduced in f4f2e9f, which removed the fallback for empty `Port` in `(*Request).ExecuteWithResults`, causing templates without `Port` to be silently skipped. Now, if no `Port` is specified, the engine executes the JavaScript block using the target URL's port. Fixes #6708. Signed-off-by: Dwi Siswanto <[email protected]>
1 parent b370607 commit 746a05d

File tree

3 files changed

+37
-0
lines changed

3 files changed

+37
-0
lines changed

cmd/integration-test/javascript.go

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@ var jsTestcases = []TestCaseInfo{
1818
{Path: "protocols/javascript/oracle-auth-test.yaml", TestCase: &javascriptOracleAuthTest{}, DisableOn: func() bool { return osutils.IsWindows() || osutils.IsOSX() }},
1919
{Path: "protocols/javascript/vnc-pass-brute.yaml", TestCase: &javascriptVncPassBrute{}},
2020
{Path: "protocols/javascript/multi-ports.yaml", TestCase: &javascriptMultiPortsSSH{}},
21+
{Path: "protocols/javascript/no-port-args.yaml", TestCase: &javascriptNoPortArgs{}},
2122
}
2223

2324
var (
@@ -179,6 +180,16 @@ func (j *javascriptMultiPortsSSH) Execute(filePath string) error {
179180
return expectResultsCount(results, 1)
180181
}
181182

183+
type javascriptNoPortArgs struct{}
184+
185+
func (j *javascriptNoPortArgs) Execute(filePath string) error {
186+
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "yo.dawg", debug)
187+
if err != nil {
188+
return err
189+
}
190+
return expectResultsCount(results, 1)
191+
}
192+
182193
// purge any given resource if it is not nil
183194
func purge(resource *dockertest.Resource) {
184195
if resource != nil && pool != nil {
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
id: javascript-no-port-args
2+
3+
info:
4+
name: JavaScript Template Without Port Args
5+
author: dwisiswant0
6+
severity: info
7+
description: |
8+
Test backwards compatibility for JavaScript templates without Port in args.
9+
Templates should execute even when Port arg is not explicitly specified.
10+
11+
javascript:
12+
- code: |
13+
// Simple JavaScript code that does not require Port
14+
let result = "executed";
15+
Export(result);
16+
17+
args:
18+
TestArg: "test-value"
19+
20+
matchers:
21+
- type: dsl
22+
dsl:
23+
- success == true

pkg/protocols/javascript/js.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -287,6 +287,9 @@ func (request *Request) GetID() string {
287287
func (request *Request) ExecuteWithResults(target *contextargs.Context, dynamicValues, previous output.InternalEvent, callback protocols.OutputEventCallback) error {
288288
// Get default port(s) if specified in template
289289
ports := request.getPorts()
290+
if len(ports) == 0 {
291+
return request.executeWithResults("", target, dynamicValues, previous, callback)
292+
}
290293

291294
var errs []error
292295

0 commit comments

Comments
 (0)