This repository has been archived by the owner on Aug 17, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 13
/
main.go
73 lines (65 loc) · 1.61 KB
/
main.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
package main
import (
"bufio"
"io/ioutil"
"log"
"net/http"
"os"
"sync"
kingpin "gopkg.in/alecthomas/kingpin.v2"
"github.com/Sirupsen/logrus"
open "github.com/petermbenjamin/go-open"
)
var (
fileFlag = kingpin.Flag("file", "Path to file.").Short('f').String()
nameFlag = kingpin.Flag("name", "Bucket name.").Short('n').String()
openFlag = kingpin.Flag("open", "Open URL in default browser.").Short('o').Bool()
debugFlag = kingpin.Flag("debug", "Debug mode.").Short('d').Action(func(c *kingpin.ParseContext) error {
logrus.SetLevel(logrus.DebugLevel)
return nil
}).Bool()
)
func main() {
kingpin.Parse()
var wg sync.WaitGroup
if *fileFlag != "" {
file, err := os.Open(*fileFlag)
if err != nil {
log.Fatalf("could not open file: %+v", err)
}
defer file.Close()
scanner := bufio.NewScanner(file)
for scanner.Scan() {
wg.Add(1)
go fuzz(scanner.Text(), &wg)
}
if err := scanner.Err(); err != nil {
log.Fatalf("could not scan file: %+v", scanner.Err())
}
}
if *nameFlag != "" {
wg.Add(1)
go fuzz(*nameFlag, &wg)
}
wg.Wait()
}
func fuzz(name string, wg *sync.WaitGroup) {
defer wg.Done()
logrus.Debugf("checking %+v", name)
resp, err := http.Get("http://" + name + ".s3.amazonaws.com")
if err != nil {
logrus.Errorf("could not GET bucket: %+v", err)
}
defer resp.Body.Close()
_, err = ioutil.ReadAll(resp.Body)
if err != nil {
logrus.Errorf("could not read response body: %+v", err)
} else {
if resp.StatusCode == http.StatusOK {
logrus.Infof("Bucket found: %s.s3.amazonaws.com", name)
if *openFlag {
open.Open("http://" + name + ".s3.amazonaws.com")
}
}
}
}