Skip to content

Commit

Permalink
adding in-template cookie reuse
Browse files Browse the repository at this point in the history
  • Loading branch information
Mzack9999 committed Jul 16, 2020
1 parent a4ac439 commit a256a56
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 2 deletions.
1 change: 1 addition & 0 deletions v2/internal/runner/runner.go
Original file line number Diff line number Diff line change
Expand Up @@ -259,6 +259,7 @@ func (r *Runner) processTemplateWithList(template *templates.Template, request i
ProxySocksURL: r.options.ProxySocksURL,
CustomHeaders: r.options.CustomHeaders,
JSON: r.options.JSON,
CookieReuse: value.CookieReuse,
})
}
if err != nil {
Expand Down
14 changes: 14 additions & 0 deletions v2/pkg/executer/executer_http.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io"
"io/ioutil"
"net/http"
"net/http/cookiejar"
"net/http/httputil"
"net/url"
"os"
Expand Down Expand Up @@ -36,6 +37,7 @@ type HTTPExecuter struct {
writer *bufio.Writer
outputMutex *sync.Mutex
customHeaders requests.CustomHeaders
CookieJar *cookiejar.Jar
}

// HTTPOptions contains configuration options for the HTTP executer.
Expand All @@ -50,6 +52,8 @@ type HTTPOptions struct {
Debug bool
JSON bool
CustomHeaders requests.CustomHeaders
CookieReuse bool
CookieJar *cookiejar.Jar
}

// NewHTTPExecuter creates a new HTTP executer from a template
Expand All @@ -68,6 +72,15 @@ func NewHTTPExecuter(options *HTTPOptions) (*HTTPExecuter, error) {
// Create the HTTP Client
client := makeHTTPClient(proxyURL, options)
client.CheckRetry = retryablehttp.HostSprayRetryPolicy()
if options.CookieJar != nil {
client.HTTPClient.Jar = options.CookieJar
} else if options.CookieReuse {
jar, err := cookiejar.New(nil)
if err != nil {
return nil, err
}
client.HTTPClient.Jar = jar
}

executer := &HTTPExecuter{
debug: options.Debug,
Expand All @@ -79,6 +92,7 @@ func NewHTTPExecuter(options *HTTPOptions) (*HTTPExecuter, error) {
outputMutex: &sync.Mutex{},
writer: options.Writer,
customHeaders: options.CustomHeaders,
CookieJar: options.CookieJar,
}
return executer, nil
}
Expand Down
2 changes: 2 additions & 0 deletions v2/pkg/requests/http-request.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,8 @@ type HTTPRequest struct {
Headers map[string]string `yaml:"headers,omitempty"`
// Body is an optional parameter which contains the request body for POST methods, etc
Body string `yaml:"body,omitempty"`
// CookieReuse is an optional setting that makes cookies shared within requests
CookieReuse bool `yaml:"cookie-reuse,omitempty"`
// Matchers contains the detection mechanism for the request to identify
// whether the request was successful
Matchers []*matchers.Matcher `yaml:"matchers,omitempty"`
Expand Down
4 changes: 2 additions & 2 deletions v2/pkg/workflows/var.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,12 @@ func (n *NucleiVar) Call(args ...tengo.Object) (ret tengo.Object, err error) {

// if external variables are specified and matches the template ones, these gets overwritten
if len(args) >= 1 {
headers = iterableToMapString(&args[0])
headers = iterableToMapString(args[0])
}

// if external variables are specified and matches the template ones, these gets overwritten
if len(args) >= 2 {
externalVars = iterableToMap(&args[1])
externalVars = iterableToMap(args[1])
}

var gotResult bool
Expand Down

0 comments on commit a256a56

Please sign in to comment.