mirror of
https://github.com/projectdiscovery/nuclei.git
synced 2025-12-18 18:35:26 +00:00
* feat: added initial live DAST server implementation * feat: more logging + misc additions * feat: auth file support enhancements for more complex scenarios + misc * feat: added io.Reader support to input providers for http * feat: added stats db to fuzzing + use sdk for dast server + misc * feat: more additions and enhancements * misc changes to live server * misc * use utils pprof server * feat: added simpler stats tracking system * feat: fixed analyzer timeout issue + missing case fix * misc changes fix * feat: changed the logics a bit + misc changes and additions * feat: re-added slope checks + misc * feat: added baseline measurements for time based checks * chore(server): fix typos Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix(templates): potential DOM XSS Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * fix(authx): potential NIL deref Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> * feat: misc review changes * removed debug logging * feat: remove existing cookies only * feat: lint fixes * misc * misc text update * request endpoint update * feat: added tracking for status code, waf-detection & grouped errors (#6028) * feat: added tracking for status code, waf-detection & grouped errors * lint error fixes * feat: review changes + moving to package + misc --------- Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com> * fix var dump (#5921) * fix var dump * fix dump test * Added filename length restriction for debug mode (-srd flag) (#5931) Co-authored-by: Andrey Matveenko <an.matveenko@vkteam.ru> * more updates * Update pkg/output/stats/waf/waf.go Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> --------- Co-authored-by: sandeep <8293321+ehsandeep@users.noreply.github.com> Co-authored-by: Dwi Siswanto <25837540+dwisiswant0@users.noreply.github.com> Co-authored-by: coderabbitai[bot] <136622811+coderabbitai[bot]@users.noreply.github.com> Co-authored-by: Dogan Can Bakir <65292895+dogancanbakir@users.noreply.github.com> Co-authored-by: 9flowers <51699499+Lercas@users.noreply.github.com> Co-authored-by: Andrey Matveenko <an.matveenko@vkteam.ru> Co-authored-by: Sandeep Singh <sandeep@projectdiscovery.io>
188 lines
5.3 KiB
Go
188 lines
5.3 KiB
Go
package authprovider
|
|
|
|
import (
|
|
"net"
|
|
"net/url"
|
|
"regexp"
|
|
"strings"
|
|
|
|
"github.com/projectdiscovery/nuclei/v3/pkg/authprovider/authx"
|
|
errorutil "github.com/projectdiscovery/utils/errors"
|
|
urlutil "github.com/projectdiscovery/utils/url"
|
|
)
|
|
|
|
// FileAuthProvider is an auth provider for file based auth
|
|
// it accepts a secrets file and returns its provider
|
|
type FileAuthProvider struct {
|
|
Path string
|
|
store *authx.Authx
|
|
compiled map[*regexp.Regexp][]authx.AuthStrategy
|
|
domains map[string][]authx.AuthStrategy
|
|
}
|
|
|
|
// NewFileAuthProvider creates a new file based auth provider
|
|
func NewFileAuthProvider(path string, callback authx.LazyFetchSecret) (AuthProvider, error) {
|
|
store, err := authx.GetAuthDataFromFile(path)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
if len(store.Secrets) == 0 && len(store.Dynamic) == 0 {
|
|
return nil, ErrNoSecrets
|
|
}
|
|
if len(store.Dynamic) > 0 && callback == nil {
|
|
return nil, errorutil.New("lazy fetch callback is required for dynamic secrets")
|
|
}
|
|
for _, secret := range store.Secrets {
|
|
if err := secret.Validate(); err != nil {
|
|
return nil, errorutil.NewWithErr(err).Msgf("invalid secret in file: %s", path)
|
|
}
|
|
}
|
|
for i, dynamic := range store.Dynamic {
|
|
if err := dynamic.Validate(); err != nil {
|
|
return nil, errorutil.NewWithErr(err).Msgf("invalid dynamic in file: %s", path)
|
|
}
|
|
dynamic.SetLazyFetchCallback(callback)
|
|
store.Dynamic[i] = dynamic
|
|
}
|
|
f := &FileAuthProvider{Path: path, store: store}
|
|
f.init()
|
|
return f, nil
|
|
}
|
|
|
|
// init initializes the file auth provider
|
|
func (f *FileAuthProvider) init() {
|
|
for _, _secret := range f.store.Secrets {
|
|
secret := _secret // allocate copy of pointer
|
|
if len(secret.DomainsRegex) > 0 {
|
|
for _, domain := range secret.DomainsRegex {
|
|
if f.compiled == nil {
|
|
f.compiled = make(map[*regexp.Regexp][]authx.AuthStrategy)
|
|
}
|
|
compiled, err := regexp.Compile(domain)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
|
|
if ss, ok := f.compiled[compiled]; ok {
|
|
f.compiled[compiled] = append(ss, secret.GetStrategy())
|
|
} else {
|
|
f.compiled[compiled] = []authx.AuthStrategy{secret.GetStrategy()}
|
|
}
|
|
}
|
|
}
|
|
for _, domain := range secret.Domains {
|
|
if f.domains == nil {
|
|
f.domains = make(map[string][]authx.AuthStrategy)
|
|
}
|
|
domain = strings.TrimSpace(domain)
|
|
domain = strings.TrimSuffix(domain, ":80")
|
|
domain = strings.TrimSuffix(domain, ":443")
|
|
if ss, ok := f.domains[domain]; ok {
|
|
f.domains[domain] = append(ss, secret.GetStrategy())
|
|
} else {
|
|
f.domains[domain] = []authx.AuthStrategy{secret.GetStrategy()}
|
|
}
|
|
}
|
|
}
|
|
for _, dynamic := range f.store.Dynamic {
|
|
domain, domainsRegex := dynamic.GetDomainAndDomainRegex()
|
|
|
|
if len(domainsRegex) > 0 {
|
|
for _, domain := range domainsRegex {
|
|
if f.compiled == nil {
|
|
f.compiled = make(map[*regexp.Regexp][]authx.AuthStrategy)
|
|
}
|
|
compiled, err := regexp.Compile(domain)
|
|
if err != nil {
|
|
continue
|
|
}
|
|
if ss, ok := f.compiled[compiled]; !ok {
|
|
f.compiled[compiled] = []authx.AuthStrategy{&authx.DynamicAuthStrategy{Dynamic: dynamic}}
|
|
} else {
|
|
f.compiled[compiled] = append(ss, &authx.DynamicAuthStrategy{Dynamic: dynamic})
|
|
}
|
|
}
|
|
}
|
|
for _, domain := range domain {
|
|
if f.domains == nil {
|
|
f.domains = make(map[string][]authx.AuthStrategy)
|
|
}
|
|
domain = strings.TrimSpace(domain)
|
|
domain = strings.TrimSuffix(domain, ":80")
|
|
domain = strings.TrimSuffix(domain, ":443")
|
|
|
|
if ss, ok := f.domains[domain]; !ok {
|
|
f.domains[domain] = []authx.AuthStrategy{&authx.DynamicAuthStrategy{Dynamic: dynamic}}
|
|
} else {
|
|
f.domains[domain] = append(ss, &authx.DynamicAuthStrategy{Dynamic: dynamic})
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
// LookupAddr looks up a given domain/address and returns appropriate auth strategy
|
|
func (f *FileAuthProvider) LookupAddr(addr string) []authx.AuthStrategy {
|
|
if strings.Contains(addr, ":") {
|
|
// default normalization for host:port
|
|
host, port, err := net.SplitHostPort(addr)
|
|
if err == nil && (port == "80" || port == "443") {
|
|
addr = host
|
|
}
|
|
}
|
|
for domain, strategy := range f.domains {
|
|
if strings.EqualFold(domain, addr) {
|
|
return strategy
|
|
}
|
|
}
|
|
for compiled, strategy := range f.compiled {
|
|
if compiled.MatchString(addr) {
|
|
return strategy
|
|
}
|
|
}
|
|
return nil
|
|
}
|
|
|
|
// LookupURL looks up a given URL and returns appropriate auth strategy
|
|
func (f *FileAuthProvider) LookupURL(u *url.URL) []authx.AuthStrategy {
|
|
return f.LookupAddr(u.Host)
|
|
}
|
|
|
|
// LookupURLX looks up a given URL and returns appropriate auth strategy
|
|
func (f *FileAuthProvider) LookupURLX(u *urlutil.URL) []authx.AuthStrategy {
|
|
return f.LookupAddr(u.Host)
|
|
}
|
|
|
|
// GetTemplatePaths returns the template path for the auth provider
|
|
func (f *FileAuthProvider) GetTemplatePaths() []string {
|
|
res := []string{}
|
|
for _, dynamic := range f.store.Dynamic {
|
|
if dynamic.TemplatePath != "" {
|
|
res = append(res, dynamic.TemplatePath)
|
|
}
|
|
}
|
|
return res
|
|
}
|
|
|
|
// PreFetchSecrets pre-fetches the secrets from the auth provider
|
|
func (f *FileAuthProvider) PreFetchSecrets() error {
|
|
for _, ss := range f.domains {
|
|
for _, s := range ss {
|
|
if val, ok := s.(*authx.DynamicAuthStrategy); ok {
|
|
if err := val.Dynamic.Fetch(false); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
for _, ss := range f.compiled {
|
|
for _, s := range ss {
|
|
if val, ok := s.(*authx.DynamicAuthStrategy); ok {
|
|
if err := val.Dynamic.Fetch(false); err != nil {
|
|
return err
|
|
}
|
|
}
|
|
}
|
|
}
|
|
return nil
|
|
}
|