mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-20 05:25:27 +00:00
* Added fuzzing support for query params + var dump feature * Added query-fuzz integration test * Fixed payloads + added keys-regex fuzz parameter * Fixed interactsh not working + misc * Fixed evaluation + added global variables/dsl support to payloads * Misc fixes related to variables evaluations * Added http variables support to fuzz * misc * Misc * Added testing playground + misc renaming * Added support for path and raw request to fuzzing * Fixed fuzz integration test * Fixed variable unresolved issue * Add multiple parameter support with same name * Added parameter value as 'value' dsl variable for parts Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
54 lines
1.2 KiB
Go
54 lines
1.2 KiB
Go
package utils
|
|
|
|
import (
|
|
"fmt"
|
|
"net/url"
|
|
"path"
|
|
"strings"
|
|
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/common/generators"
|
|
"github.com/projectdiscovery/nuclei/v2/pkg/protocols/dns"
|
|
)
|
|
|
|
// GenerateVariables will create default variables after parsing a url
|
|
func GenerateVariables(parsed *url.URL, trailingSlash bool) map[string]interface{} {
|
|
domain := parsed.Host
|
|
if strings.Contains(parsed.Host, ":") {
|
|
domain = strings.Split(parsed.Host, ":")[0]
|
|
}
|
|
|
|
port := parsed.Port()
|
|
if port == "" {
|
|
if parsed.Scheme == "https" {
|
|
port = "443"
|
|
} else if parsed.Scheme == "http" {
|
|
port = "80"
|
|
}
|
|
}
|
|
|
|
if trailingSlash {
|
|
parsed.Path = strings.TrimSuffix(parsed.Path, "/")
|
|
}
|
|
|
|
escapedPath := parsed.EscapedPath()
|
|
directory := path.Dir(escapedPath)
|
|
if directory == "." {
|
|
directory = ""
|
|
}
|
|
base := path.Base(escapedPath)
|
|
if base == "." {
|
|
base = ""
|
|
}
|
|
httpVariables := map[string]interface{}{
|
|
"BaseURL": parsed.String(),
|
|
"RootURL": fmt.Sprintf("%s://%s", parsed.Scheme, parsed.Host),
|
|
"Hostname": parsed.Host,
|
|
"Host": domain,
|
|
"Port": port,
|
|
"Path": directory,
|
|
"File": base,
|
|
"Scheme": parsed.Scheme,
|
|
}
|
|
return generators.MergeMaps(httpVariables, dns.GenerateVariables(domain))
|
|
}
|