Skip to content

Commit da1ced9

Browse files
committed
add option to hide responses of a certain content-length
1 parent 6add9c2 commit da1ced9

File tree

3 files changed

+27
-1
lines changed

3 files changed

+27
-1
lines changed

cmd/scout/url.go

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ var filename string
2222
var headers []string
2323
var extensions = []string{"php", "htm", "html", "txt"}
2424
var enableSpidering bool
25+
var ignoredLengths []int
2526

2627
var urlCmd = &cobra.Command{
2728
Use: "url [url]",
@@ -80,6 +81,7 @@ var urlCmd = &cobra.Command{
8081

8182
options := []scan.URLOption{
8283
scan.WithPositiveStatusCodes(intStatusCodes),
84+
scan.WithNegativeLengths(ignoredLengths),
8385
scan.WithTargetURL(*parsedURL),
8486
scan.WithResultChan(resultChan),
8587
scan.WithBusyChan(busyChan),
@@ -124,7 +126,7 @@ var urlCmd = &cobra.Command{
124126

125127
go func() {
126128
for result := range resultChan {
127-
importantOutputChan <- tml.Sprintf("<blue>[</blue><yellow>%d</yellow><blue>]</blue> %s\n", result.StatusCode, result.URL.String())
129+
importantOutputChan <- tml.Sprintf("<blue>[</blue><yellow>%d</yellow><blue>]</blue> <blue>[</blue><yellow>%d</yellow><blue>]</blue> %s\n", result.StatusCode, result.Size, result.URL.String())
128130
}
129131
close(waitChan)
130132
}()
@@ -197,6 +199,7 @@ func init() {
197199
urlCmd.Flags().StringSliceVarP(&extensions, "extensions", "x", extensions, "File extensions to detect.")
198200
urlCmd.Flags().StringSliceVarP(&headers, "header", "H", headers, "Extra header to send with requests (can be specified multiple times).")
199201
urlCmd.Flags().BoolVarP(&enableSpidering, "spider", "s", enableSpidering, "Spider links within page content")
202+
urlCmd.Flags().IntSliceVarP(&ignoredLengths, "hide-lengths", "l", ignoredLengths, "Hide results with these content lengths")
200203

201204
rootCmd.AddCommand(urlCmd)
202205
}

pkg/scan/url_options.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,13 @@ func WithPositiveStatusCodes(codes []int) URLOption {
3131
}
3232
}
3333

34+
// WithNegativeLengths provides lengths which should be ignored
35+
func WithNegativeLengths(lengths []int) URLOption {
36+
return func(s *URLScanner) {
37+
s.negativeLengths = lengths
38+
}
39+
}
40+
3441
func WithTimeout(timeout time.Duration) URLOption {
3542
return func(s *URLScanner) {
3643
s.timeout = timeout
@@ -104,4 +111,5 @@ func WithMethod(method string) URLOption {
104111
type URLResult struct {
105112
URL url.URL
106113
StatusCode int
114+
Size int
107115
}

pkg/scan/url_scanner.go

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ import (
88
"io/ioutil"
99
"net/http"
1010
"net/url"
11+
"strconv"
1112
"strings"
1213
"sync"
1314
"sync/atomic"
@@ -43,6 +44,7 @@ type URLScanner struct {
4344
jobsLoaded int32
4445
proxy *url.URL
4546
method string
47+
negativeLengths []int
4648
}
4749

4850
type URLJob struct {
@@ -334,9 +336,22 @@ func (scanner *URLScanner) checkURL(job URLJob) *URLResult {
334336
_, _ = io.Copy(ioutil.Discard, resp.Body)
335337
}
336338

339+
var size int
340+
contentLength := resp.Header.Get("Content-Length")
341+
if contentLength != "" {
342+
size, _ = strconv.Atoi(contentLength)
343+
}
344+
345+
for _, length := range scanner.negativeLengths {
346+
if length == size {
347+
return nil
348+
}
349+
}
350+
337351
result = &URLResult{
338352
StatusCode: code,
339353
URL: *parsedURL,
354+
Size: size,
340355
}
341356

342357
break

0 commit comments

Comments
 (0)