Skip to content

Commit

Permalink
Merge pull request #248 from edoardottt/devel
Browse files Browse the repository at this point in the history
Add Proxy option
  • Loading branch information
edoardottt authored Jun 2, 2024
2 parents 578c57a + f3aab82 commit 106a7f2
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 10 deletions.
7 changes: 7 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ CONFIGURATIONS:
-c, -concurrency int Concurrency level (default 50)
-t, -timeout int Connection timeout in seconds (default 10)
-rl, -rate-limit int Set a rate limit (per second)
-px, -proxy string Set a proxy server (URL)

OUTPUT:
-o, -output string File to write output results
Expand Down Expand Up @@ -130,6 +131,12 @@ JSON Output
cat targets.txt | csprecon -j
```

Use a Proxy

```bash
cat targets.txt | csprecon -px http://127.0.0.1:8080
```

Changelog 📌
-------

Expand Down
23 changes: 19 additions & 4 deletions pkg/csprecon/csp.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,12 @@ import (
"log"
"net"
"net/http"
"net/url"
"regexp"
"time"

"github.com/PuerkitoBio/goquery"
"github.com/edoardottt/csprecon/pkg/input"
"github.com/edoardottt/golazy"
"github.com/projectdiscovery/gologger"
)
Expand Down Expand Up @@ -88,21 +90,34 @@ func ParseBodyCSP(body io.Reader, rCSP *regexp.Regexp) []string {
return result
}

func customClient(timeout int) *http.Client {
func customClient(options *input.Options) (*http.Client, error) {
transport := http.Transport{
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
Proxy: http.ProxyFromEnvironment,
Dial: (&net.Dialer{
Timeout: time.Duration(timeout) * time.Second,
Timeout: time.Duration(options.Timeout) * time.Second,
KeepAlive: KeepAlive * time.Second,
}).Dial,
TLSHandshakeTimeout: TLSHandshakeTimeout * time.Second,
}

if options.Proxy != "" {
u, err := url.Parse(options.Proxy)
if err != nil {
return nil, err
}

transport.Proxy = http.ProxyURL(u)

if options.Verbose {
gologger.Debug().Msgf("Using Proxy %s", options.Proxy)
}
}

client := http.Client{
Transport: &transport,
Timeout: time.Duration(timeout) * time.Second,
Timeout: time.Duration(options.Timeout) * time.Second,
}

return &client
return &client, nil
}
11 changes: 7 additions & 4 deletions pkg/csprecon/csprecon.go
Original file line number Diff line number Diff line change
Expand Up @@ -141,16 +141,19 @@ func execute(r *Runner) {
for value := range r.Input {
targetURL, err := PrepareURL(value)
if err != nil {
if r.Options.Verbose {
gologger.Error().Msgf("%s", err)
}
gologger.Error().Msgf("%s", err)

return
}

rl.Take()

client := customClient(r.Options.Timeout)
client, err := customClient(&r.Options)
if err != nil {
gologger.Error().Msgf("%s", err)

return
}

result, err := CheckCSP(targetURL, r.UserAgent, dregex, client)
if err != nil {
Expand Down
16 changes: 16 additions & 0 deletions pkg/input/check.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ package input
import (
"errors"
"fmt"
"net/url"

fileutil "github.com/projectdiscovery/utils/file"
)
Expand Down Expand Up @@ -38,5 +39,20 @@ func (options *Options) validateOptions() error {
return fmt.Errorf("rate limit: %w", ErrNegativeValue)
}

if options.Proxy != "" && !checkProxy(options.Proxy) {
_, err := url.Parse(options.Proxy)
return fmt.Errorf("proxy URL: %w", err)
}

return nil
}

func checkProxy(proxy string) bool {
if len(proxy) == 0 {
return false
}

_, err := url.Parse(proxy)

return err == nil
}
2 changes: 2 additions & 0 deletions pkg/input/flags.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ type Options struct {
Timeout int
Cidr bool
RateLimit int
Proxy string
}

// configureOutput configures the output on the screen.
Expand Down Expand Up @@ -66,6 +67,7 @@ func ParseOptions() *Options {
flagSet.IntVarP(&options.Concurrency, "concurrency", "c", DefaultConcurrency, `Concurrency level`),
flagSet.IntVarP(&options.Timeout, "timeout", "t", DefaultTimeout, `Connection timeout in seconds`),
flagSet.IntVarP(&options.RateLimit, "rate-limit", "rl", DefaultRateLimit, `Set a rate limit (per second)`),
flagSet.StringVarP(&options.Proxy, "proxy", "px", "", `Set a proxy server (URL)`),
)

// Output
Expand Down
2 changes: 1 addition & 1 deletion pkg/output/banner.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ import "github.com/projectdiscovery/gologger"
var printed = false

const (
Version = "v0.2.0"
Version = "v0.2.1"
banner = ` ______________ ________ _________ ____
/ ___/ ___/ __ \/ ___/ _ \/ ___/ __ \/ __ \
/ /__(__ ) /_/ / / / __/ /__/ /_/ / / / /
Expand Down
2 changes: 1 addition & 1 deletion snapcraft.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ summary: Discover new target domains using Content Security Policy
description: |
Take as input target URLs and probe them to retrieve their CSP (either from Head or Header)
and get new target domains.
version: 0.2.0
version: 0.2.1
grade: stable
base: core20

Expand Down

0 comments on commit 106a7f2

Please sign in to comment.