mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-23 11:35:28 +00:00
* feat: Improve DSL function UX #1295 Sort the output signatures * feat: Improve DSL function UX #1295 Sort the output signatures. Lint: simplified the sorting. * bug: fixed couple of bugs in the DSL functions Input number parameters are stored as float64 types, hence the type conversion should happen accordingly. Affected functions: * rand_int * wait_for * unix_time * rand_text_numeric Added tests for all functions. Related: #1261 * bug: fixed couple of bugs in the DSL functions Handle cases when the optional input character set is an empty string. Affected methods: * rand_char * rand_base * bug: fixed couple of bugs in the DSL functions Change rand_char to return a one character string, instead of the character code * refactor: Minor integration test changes to show the actual and expected result numbers * test: Added integration test for all existing DSL functions * test: Added integration test for all existing DSL functions Fixing linter issues. * feat: Add "repeat" DSL function * test: Add "repeat" DSL function
119 lines
2.5 KiB
Go
119 lines
2.5 KiB
Go
package main
|
|
|
|
import (
|
|
"net"
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/testutils"
|
|
)
|
|
|
|
var networkTestcases = map[string]testutils.TestCase{
|
|
"network/basic.yaml": &networkBasic{},
|
|
"network/hex.yaml": &networkBasic{},
|
|
"network/multi-step.yaml": &networkMultiStep{},
|
|
"network/self-contained.yaml": &networkRequestSelContained{},
|
|
}
|
|
|
|
const defaultStaticPort = 5431
|
|
|
|
type networkBasic struct{}
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
func (h *networkBasic) Execute(filePath string) error {
|
|
var routerErr error
|
|
|
|
ts := testutils.NewTCPServer(func(conn net.Conn) {
|
|
defer conn.Close()
|
|
|
|
data := make([]byte, 4)
|
|
if _, err := conn.Read(data); err != nil {
|
|
routerErr = err
|
|
return
|
|
}
|
|
if string(data) == "PING" {
|
|
_, _ = conn.Write([]byte("PONG"))
|
|
}
|
|
})
|
|
defer ts.Close()
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if routerErr != nil {
|
|
return routerErr
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
}
|
|
|
|
type networkMultiStep struct{}
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
func (h *networkMultiStep) Execute(filePath string) error {
|
|
var routerErr error
|
|
|
|
ts := testutils.NewTCPServer(func(conn net.Conn) {
|
|
defer conn.Close()
|
|
|
|
data := make([]byte, 5)
|
|
if _, err := conn.Read(data); err != nil {
|
|
routerErr = err
|
|
return
|
|
}
|
|
if string(data) == "FIRST" {
|
|
_, _ = conn.Write([]byte("PING"))
|
|
}
|
|
|
|
data = make([]byte, 6)
|
|
if _, err := conn.Read(data); err != nil {
|
|
routerErr = err
|
|
return
|
|
}
|
|
if string(data) == "SECOND" {
|
|
_, _ = conn.Write([]byte("PONG"))
|
|
}
|
|
_, _ = conn.Write([]byte("NUCLEI"))
|
|
})
|
|
defer ts.Close()
|
|
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, ts.URL, debug)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if routerErr != nil {
|
|
return routerErr
|
|
}
|
|
|
|
var expectedResultsSize int
|
|
if debug {
|
|
expectedResultsSize = 3
|
|
} else {
|
|
expectedResultsSize = 1
|
|
}
|
|
|
|
return expectResultsCount(results, expectedResultsSize)
|
|
}
|
|
|
|
type networkRequestSelContained struct{}
|
|
|
|
// Execute executes a test case and returns an error if occurred
|
|
func (h *networkRequestSelContained) Execute(filePath string) error {
|
|
var routerErr error
|
|
|
|
ts := testutils.NewTCPServer(func(conn net.Conn) {
|
|
defer conn.Close()
|
|
|
|
_, _ = conn.Write([]byte("Authentication successful"))
|
|
}, defaultStaticPort)
|
|
defer ts.Close()
|
|
results, err := testutils.RunNucleiTemplateAndGetResults(filePath, "", debug)
|
|
if err != nil {
|
|
return err
|
|
}
|
|
if routerErr != nil {
|
|
return routerErr
|
|
}
|
|
|
|
return expectResultsCount(results, 1)
|
|
}
|