Skip to content

Commit 465a558

Browse files
committed
Adds a few tweaks to mirror
1 parent 99d82c0 commit 465a558

File tree

1 file changed

+18
-8
lines changed

1 file changed

+18
-8
lines changed

mirror/main.go

+18-8
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ func main() {
1818

1919
var input io.Reader
2020
input = strings.NewReader(strings.Join(flag.Args(), "\n"))
21-
if flag.Arg(0) == "" {
21+
if flag.NArg() == 0 {
2222
input = os.Stdin
2323
}
2424

@@ -27,29 +27,39 @@ func main() {
2727
for sc.Scan() {
2828
u, err := url.Parse(sc.Text())
2929
if err != nil {
30-
fmt.Println(err)
31-
return
30+
fmt.Fprintln(os.Stderr, err)
31+
continue
3232
}
3333

3434
resp, err := http.Get(u.String())
3535
if err != nil {
36-
fmt.Println(err)
37-
return
36+
fmt.Fprintln(os.Stderr, err)
37+
continue
3838
}
3939

4040
defer resp.Body.Close()
4141

4242
b, err := ioutil.ReadAll(resp.Body)
4343
if err != nil {
44-
fmt.Println(err)
45-
return
44+
fmt.Fprintln(os.Stderr, err)
45+
continue
4646
}
4747
body := string(b)
4848

4949
for k, vv := range u.Query() {
5050
for _, v := range vv {
5151

52+
// short strings are so likely to show up in the response
53+
// that it's best just to skip over them to avoid too many
54+
// false positives. There should be a flag to control this.
55+
if len(v) < 4 {
56+
continue
57+
}
58+
5259
// a fairly shonky way to get a few chars of context either side of the match
60+
// but it helps avoid trying to find the locations of all the matches in the
61+
// body, and then getting the context on either side, with all the bounds
62+
// checking etc that would need to be done for that.
5363
re, err := regexp.Compile("(.{0,6}" + regexp.QuoteMeta(v) + ".{0,6})")
5464
if err != nil {
5565
fmt.Fprintf(os.Stderr, "regexp compile error: %s", err)
@@ -58,7 +68,7 @@ func main() {
5868
matches := re.FindAllStringSubmatch(body, -1)
5969

6070
for _, m := range matches {
61-
fmt.Printf("%s: query string key '%s' with value '%s' reflected in response body (...%s...)\n", u, k, v, m[0])
71+
fmt.Printf("%s: '%s=%s' reflected in response body (...%s...)\n", u, k, v, m[0])
6272
}
6373
}
6474

0 commit comments

Comments
 (0)