From 70a2c3c3783cb056e31e0a05af80b4a3dfe05661 Mon Sep 17 00:00:00 2001 From: Gwyn Hannay Date: Sun, 5 Jul 2020 00:43:58 +0000 Subject: [PATCH] Adds dr flag for discarding responses with specific string --- README.mkd | 10 ++++++++++ args.go | 12 ++++++++++-- main.go | 4 ++++ 3 files changed, 24 insertions(+), 2 deletions(-) mode change 100644 => 100755 README.mkd diff --git a/README.mkd b/README.mkd old mode 100644 new mode 100755 index 5f182b3..23e39b4 --- a/README.mkd +++ b/README.mkd @@ -137,6 +137,7 @@ Usage: Options: -c, --concurrency Set the concurrency level (defaut: 20) -d, --delay Milliseconds between requests to the same host (default: 5000) + -dr, --discresp Discard responses containing specific string -H, --header
Send a custom HTTP header -r, --rawhttp Use the rawhttp library for requests (experimental) -s, --savestatus Save only responses with specific status code @@ -243,6 +244,15 @@ use the `-sr` or `--saveresp` option: ▶ meg --saveresp '": "v1"' /robots.txt ``` +### Discarding Certain Response Strings + +Alternatively, if you don't want to save results that contained a certain string, you can +use the `-dr` or `--discresp` option: + +``` +▶ meg --discresp '": "v1"' /robots.txt +``` + ### Specifying The Method You can specify which HTTP method to use with the `-X` or `--method` option: diff --git a/args.go b/args.go index b0b633d..efe7e7a 100755 --- a/args.go +++ b/args.go @@ -44,6 +44,7 @@ type config struct { body string concurrency int delay int + discResp string headers headerArgs followLocation bool method string @@ -77,6 +78,11 @@ func processArgs() config { flag.IntVar(&delay, "delay", 5000, "") flag.IntVar(&delay, "d", 5000, "") + // discResp params + discResp := "" + flag.StringVar(&discResp, "discresp", "", "") + flag.StringVar(&discResp, "dr", "", "") + // headers params var headers headerArgs flag.Var(&headers, "header", "") @@ -99,7 +105,7 @@ func processArgs() config { // saveResp params saveResp := "" - flag.StringVar(&saveResp, "saveResp", "", "") + flag.StringVar(&saveResp, "saveresp", "", "") flag.StringVar(&saveResp, "sr", "", "") // timeout param @@ -151,6 +157,7 @@ func processArgs() config { body: body, concurrency: concurrency, delay: delay, + discResp: discResp, headers: headers, followLocation: followLocation, method: method, @@ -177,11 +184,12 @@ func init() { h += " -b, --body Set the request body\n" h += " -c, --concurrency Set the concurrency level (default: 20)\n" h += " -d, --delay Milliseconds between requests to the same host (default: 5000)\n" + h += " -dr, --discresp Discard responses containing specific string\n" h += " -H, --header
Send a custom HTTP header\n" h += " -L, --location Follow redirects / location header\n" h += " -r, --rawhttp Use the rawhttp library for requests (experimental)\n" h += " -s, --savestatus Save only responses with specific status code\n" - h += " -sr, --saveresp Save only responses containing specific string\n" + h += " -sr, --saveresp Save only responses containing specific string\n" h += " -t, --timeout Set the HTTP timeout (default: 10000)\n" h += " -v, --verbose Verbose mode\n" h += " -X, --method HTTP method (default: GET)\n\n" diff --git a/main.go b/main.go index 12542da..488b305 100755 --- a/main.go +++ b/main.go @@ -93,6 +93,10 @@ func main() { continue } + if len(c.discResp) > 0 && (strings.Contains(strings.Join(res.headers, ""), c.discResp) || (strings.Contains(string(res.body), c.discResp))) { + continue + } + if res.err != nil { fmt.Fprintf(os.Stderr, "request failed: %s\n", res.err) continue