Skip to content

Commit

Permalink
Add cert authentication to crawl (#713)
Browse files Browse the repository at this point in the history
* Add cert authentication to crawl

* Update CONTRIBUTORS.md

* Update CONTRIBUTORS.md
  • Loading branch information
Serizao committed Sep 12, 2023
1 parent ca2224c commit 301968c
Show file tree
Hide file tree
Showing 5 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions CONTRIBUTORS.md
Expand Up @@ -41,6 +41,7 @@
* [putsi](https://github.com/putsi)
* [SakiiR](https://github.com/SakiiR)
* [seblw](https://github.com/seblw)
* [Serizao](https://github.com/Serizao)
* [Shaked](https://github.com/Shaked)
* [Skyehopper](https://github.com/Skyehopper)
* [SolomonSklash](https://github.com/SolomonSklash)
Expand Down
2 changes: 2 additions & 0 deletions main.go
Expand Up @@ -89,6 +89,8 @@ func ParseFlags(opts *ffuf.ConfigOptions) *ffuf.ConfigOptions {
flag.IntVar(&opts.HTTP.Timeout, "timeout", opts.HTTP.Timeout, "HTTP request timeout in seconds.")
flag.IntVar(&opts.Input.InputNum, "input-num", opts.Input.InputNum, "Number of inputs to test. Used in conjunction with --input-cmd.")
flag.StringVar(&opts.General.AutoCalibrationKeyword, "ack", opts.General.AutoCalibrationKeyword, "Autocalibration keyword")
flag.StringVar(&opts.HTTP.ClientCert, "cc", "", "Client cert to auth must be define with client key too")
flag.StringVar(&opts.HTTP.ClientKey, "ck", "", "Client key to auth must be define with client cert too")
flag.StringVar(&opts.General.AutoCalibrationStrategy, "acs", opts.General.AutoCalibrationStrategy, "Autocalibration strategy: \"basic\" or \"advanced\"")
flag.StringVar(&opts.General.ConfigFile, "config", "", "Load configuration from a file")
flag.StringVar(&opts.General.ScraperFile, "scraperfile", "", "Custom scraper file path")
Expand Down
2 changes: 2 additions & 0 deletions pkg/ffuf/config.go
Expand Up @@ -64,6 +64,8 @@ type Config struct {
Verbose bool `json:"verbose"`
Wordlists []string `json:"wordlists"`
Http2 bool `json:"http2"`
ClientCert string `json:"client-cert"`
ClientKey string `json:"client-key"`
}

type InputProviderConfig struct {
Expand Down
11 changes: 11 additions & 0 deletions pkg/ffuf/optionsparser.go
Expand Up @@ -41,6 +41,8 @@ type HTTPOptions struct {
Timeout int `json:"timeout"`
URL string `json:"url"`
Http2 bool `json:"http2"`
ClientCert string `json:"client-cert"`
ClientKey string `json:"client-key"`
}

type GeneralOptions struct {
Expand Down Expand Up @@ -361,6 +363,15 @@ func ConfigFromOptions(parseOpts *ConfigOptions, ctx context.Context, cancel con
conf.SNI = parseOpts.HTTP.SNI
}

// prepare cert
if parseOpts.HTTP.ClientCert != "" {
conf.ClientCert = parseOpts.HTTP.ClientCert
}
if parseOpts.HTTP.ClientKey != "" {
conf.ClientKey = parseOpts.HTTP.ClientKey
}


//Prepare headers and make canonical
for _, v := range parseOpts.HTTP.Headers {
hs := strings.SplitN(v, ":", 2)
Expand Down
8 changes: 8 additions & 0 deletions pkg/runner/simple.go
Expand Up @@ -43,6 +43,13 @@ func NewSimpleRunner(conf *ffuf.Config, replay bool) ffuf.RunnerProvider {
proxyURL = http.ProxyURL(pu)
}
}
cert := []tls.Certificate{}

if conf.ClientCert != "" && conf.ClientKey != "" {
tmp, _ := tls.LoadX509KeyPair(conf.ClientCert, conf.ClientKey)
cert = []tls.Certificate{tmp}
}

simplerunner.config = conf
simplerunner.client = &http.Client{
CheckRedirect: func(req *http.Request, via []*http.Request) error { return http.ErrUseLastResponse },
Expand All @@ -62,6 +69,7 @@ func NewSimpleRunner(conf *ffuf.Config, replay bool) ffuf.RunnerProvider {
MinVersion: tls.VersionTLS10,
Renegotiation: tls.RenegotiateOnceAsClient,
ServerName: conf.SNI,
Certificates: cert,
},
}}

Expand Down

0 comments on commit 301968c

Please sign in to comment.