nuclei/v2/pkg/protocols/http/matchers.go

33 lines
836 B
Go
Raw Normal View History

package http
import (
"net/http"
"net/http/httputil"
"strings"
"time"
)
// responseToDSLMap converts a HTTP response to a map for use in DSL matching
func responseToDSLMap(resp *http.Response, body, headers string, duration time.Duration, extra map[string]interface{}) map[string]interface{} {
data := make(map[string]interface{}, len(extra)+6+len(resp.Header))
for k, v := range extra {
data[k] = v
}
data["content_length"] = resp.ContentLength
data["status_code"] = resp.StatusCode
2020-12-24 01:42:04 +05:30
data["body"] = body
for k, v := range resp.Header {
k = strings.ToLower(strings.TrimSpace(strings.ReplaceAll(k, "-", "_")))
data[k] = strings.Join(v, " ")
}
2020-12-24 01:42:04 +05:30
data["headers"] = headers
if r, err := httputil.DumpResponse(resp, true); err == nil {
data["raw"] = string(r)
}
data["duration"] = duration.Seconds()
return data
}