Skip to content

Commit

Permalink
Allow auth option to parse string input as api key (projectdiscovery#…
Browse files Browse the repository at this point in the history
  • Loading branch information
RamanaReddy0M authored Feb 18, 2024
1 parent 0bd4478 commit 95f8bd7
Showing 1 changed file with 13 additions and 3 deletions.
16 changes: 13 additions & 3 deletions cmd/nuclei/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import (
"time"

"github.com/projectdiscovery/utils/auth/pdcp"
"github.com/projectdiscovery/utils/env"
_ "github.com/projectdiscovery/utils/pprof"

"github.com/projectdiscovery/goflags"
Expand Down Expand Up @@ -180,7 +181,7 @@ func readConfig() *goflags.FlagSet {

// when true updates nuclei binary to latest version
var updateNucleiBinary bool
var pdcpauth bool
var pdcpauth string

flagSet := goflags.NewFlagSet()
flagSet.CaseSensitive = true
Expand Down Expand Up @@ -386,7 +387,7 @@ on extensive configurability, massive extensibility and ease of use.`)
)

flagSet.CreateGroup("cloud", "Cloud",
flagSet.BoolVar(&pdcpauth, "auth", false, "configure projectdiscovery cloud (pdcp) api key"),
flagSet.DynamicVar(&pdcpauth, "auth", "true", "configure projectdiscovery cloud (pdcp) api key"),
flagSet.BoolVarP(&options.EnableCloudUpload, "cloud-upload", "cup", false, "upload scan results to pdcp dashboard"),
flagSet.StringVarP(&options.ScanID, "scan-id", "sid", "", "upload scan results to given scan id"),
)
Expand Down Expand Up @@ -417,8 +418,17 @@ Additional documentation is available at: https://docs.nuclei.sh/getting-started
goflags.DisableAutoConfigMigration = true
_ = flagSet.Parse()

if pdcpauth {
// api key hierarchy: cli flag > env var > .pdcp/credential file
if pdcpauth == "true" {
runner.AuthWithPDCP()
} else if len(pdcpauth) == 36 {
ph := pdcp.PDCPCredHandler{}
if _, err := ph.GetCreds(); err == pdcp.ErrNoCreds {
apiServer := env.GetEnvOrDefault("PDCP_API_SERVER", pdcp.DefaultApiServer)
if validatedCreds, err := ph.ValidateAPIKey(pdcpauth, apiServer, config.BinaryName); err == nil {
_ = ph.SaveCreds(validatedCreds)
}
}
}

gologger.DefaultLogger.SetTimestamp(options.Timestamp, levels.LevelDebug)
Expand Down

0 comments on commit 95f8bd7

Please sign in to comment.