Adding support for global env variables

dev
mzack 2021-08-09 00:22:09 +02:00
parent ef7591d3c8
commit e17117c281
4 changed files with 26 additions and 0 deletions

View File

@ -95,6 +95,7 @@ on extensive configurability, massive extensibility and ease of use.`)
flagSet.StringVarP(&options.ResolversFile, "resolvers", "r", "", "file containing resolver list for nuclei"),
flagSet.BoolVar(&options.SystemResolvers, "system-resolvers", false, "use system DNS resolving as error fallback"),
flagSet.BoolVar(&options.OfflineHTTP, "passive", false, "enable passive HTTP response processing mode"),
flagSet.BoolVar(&options.EnvironmentVariables, "env-vars", false, "Enable environment variables support"),
)
createGroup(flagSet, "interactsh", "interactsh",

View File

@ -0,0 +1,18 @@
package generators
import (
"os"
"github.com/projectdiscovery/stringsutil"
)
// EnvVars returns a map with all environment variables into a map
func EnvVars() map[string]interface{} {
sliceEnvVars := os.Environ()
envVars := make(map[string]interface{}, len(sliceEnvVars))
for _, envVar := range sliceEnvVars {
key, val := stringsutil.Before(envVar, "="), stringsutil.After(envVar, "=")
envVars[key] = val
}
return envVars
}

View File

@ -62,6 +62,11 @@ func (r *requestGenerator) Make(baseURL string, dynamicValues map[string]interfa
parsedString := parsed.String()
values["BaseURL"] = parsedString
// merge with env vars
if r.options.Options.EnvironmentVariables {
values = generators.MergeMaps(values, generators.EnvVars())
}
// If data contains \n it's a raw request, process it like raw. Else
// continue with the template based request flow.
if isRawRequest {

View File

@ -143,4 +143,6 @@ type Options struct {
UpdateNuclei bool
// NoUpdateTemplates disables checking for nuclei templates updates
NoUpdateTemplates bool
// EnvironmentVariables enables support for environment variables
EnvironmentVariables bool
}