mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 04:45:27 +00:00
Misc
This commit is contained in:
parent
17d0b34e61
commit
d16102f955
@ -15,6 +15,7 @@ func TestEvaluate(t *testing.T) {
|
||||
{input: "{{hex_encode('PING')}}", expected: "50494e47", extra: map[string]interface{}{}},
|
||||
{input: "test", expected: "test", extra: map[string]interface{}{}},
|
||||
{input: "{{hex_encode(Item)}}", expected: "50494e47", extra: map[string]interface{}{"Item": "PING"}},
|
||||
{input: "{{hex_encode(Item)}}\r\n", expected: "50494e47\r\n", extra: map[string]interface{}{"Item": "PING"}},
|
||||
}
|
||||
for _, item := range items {
|
||||
value, err := Evaluate(item.input, item.extra)
|
||||
|
||||
@ -94,7 +94,7 @@ func (r *Request) responseToDSLMap(resp *http.Response, host, matched, rawReq, r
|
||||
data[strings.ToLower(cookie.Name)] = cookie.Value
|
||||
}
|
||||
for k, v := range resp.Header {
|
||||
k = strings.ToLower(strings.TrimSpace(k))
|
||||
k = strings.ToLower(strings.Replace(strings.TrimSpace(k), "-", "_", -1))
|
||||
data[k] = strings.Join(v, " ")
|
||||
}
|
||||
data["all_headers"] = headers
|
||||
|
||||
@ -140,7 +140,7 @@ func TestHTTPOperatorExtract(t *testing.T) {
|
||||
event := request.responseToDSLMap(resp, host, matched, exampleRawRequest, exampleRawResponse, exampleResponseBody, exampleResponseHeader, 1*time.Second, map[string]interface{}{})
|
||||
require.Len(t, event, 12, "could not get correct number of items in dsl map")
|
||||
require.Equal(t, exampleRawResponse, event["response"], "could not get correct resp")
|
||||
require.Equal(t, "Test-Response", event["test-header"], "could not get correct resp for header")
|
||||
require.Equal(t, "Test-Response", event["test_header"], "could not get correct resp for header")
|
||||
|
||||
t.Run("extract", func(t *testing.T) {
|
||||
extractor := &extractors.Extractor{
|
||||
@ -159,7 +159,7 @@ func TestHTTPOperatorExtract(t *testing.T) {
|
||||
t.Run("kval", func(t *testing.T) {
|
||||
extractor := &extractors.Extractor{
|
||||
Type: "kval",
|
||||
KVal: []string{"test-header"},
|
||||
KVal: []string{"test_header"},
|
||||
}
|
||||
err = extractor.CompileExtractors()
|
||||
require.Nil(t, err, "could not compile kval extractor")
|
||||
|
||||
@ -48,6 +48,8 @@ type Input struct {
|
||||
Type string `yaml:"type"`
|
||||
// Read is the number of bytes to read from socket
|
||||
Read int `yaml:"read"`
|
||||
// Name is the optional name of the input to provide matching on
|
||||
Name string `yaml:"name"`
|
||||
}
|
||||
|
||||
// GetID returns the unique ID of the request if any.
|
||||
|
||||
@ -80,6 +80,7 @@ func (r *Request) executeAddress(actualAddress, address, input string, shouldUse
|
||||
responseBuilder := &strings.Builder{}
|
||||
reqBuilder := &strings.Builder{}
|
||||
|
||||
inputEvents := make(map[string]interface{})
|
||||
for _, input := range r.Inputs {
|
||||
var data []byte
|
||||
|
||||
@ -108,6 +109,9 @@ func (r *Request) executeAddress(actualAddress, address, input string, shouldUse
|
||||
buffer := make([]byte, r.ReadSize)
|
||||
n, _ := conn.Read(buffer)
|
||||
responseBuilder.Write(buffer[:n])
|
||||
if input.Name != "" {
|
||||
inputEvents[input.Name] = string(buffer[:n])
|
||||
}
|
||||
}
|
||||
r.options.Progress.IncrementRequests()
|
||||
}
|
||||
@ -147,6 +151,9 @@ func (r *Request) executeAddress(actualAddress, address, input string, shouldUse
|
||||
for k, v := range previous {
|
||||
outputEvent[k] = v
|
||||
}
|
||||
for k, v := range inputEvents {
|
||||
outputEvent[k] = v
|
||||
}
|
||||
|
||||
event := &output.InternalWrappedEvent{InternalEvent: outputEvent}
|
||||
if r.CompiledOperators != nil {
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user