This repository has been archived by the owner on Apr 14, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
126 lines (112 loc) Β· 3.62 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
package main
import (
"bufio"
"encoding/json"
"html/template"
"io/ioutil"
"log"
"os"
"sort"
"strings"
)
// Leak sturct represents a slice of bucket leaks in yas3bl.json file
type Leak struct {
Count string `json:"count"`
Data string `json:"data"`
Organization string `json:"organization"`
URL string `json:"url"`
}
const tmpl = `# YAS3BL (Yet Another S3 Bucket Leak)
> π Enumerating all the AWS S3 bucket leaks that have been discovered to date.
| Company | Link | Records Exposed | Data |
| ------- | ---- | --------------- | ---- |
{{range .}}| <h4>{{.Organization}}</h4> | [π]({{.URL}}) | {{.Count}} | {{.Data}} |
{{end}}
`
const htmlTmpl = `
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>YAS3BL</title>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/css/bootstrap.min.css" integrity="sha384-/Y6pD6FV/Vv2HJnA6t+vslU6fwYXjCFtcEpHbNJ0lyAFsXTsjBbfaDjzALeQsN6M" crossorigin="anonymous">
</head>
<style>
td {
font-family: monospace;
}
a {
text-decoration: none;
}
</style>
<body>
<div class="container">
<div class="header clearfix">
<h1 class="text-muted text-center"><a href="https://github.com/petermbenjamin/yas3bl/">Yet Another S3 Bucket Leak</a></h1>
</div>
<table class="table table-striped">
<thead>
<tr>
<th>Organization</th>
<th>Count</th>
<th>Data</th>
</tr>
</thead>
<tbody>
{{range .}}<tr>
<td><a href="{{.URL}}">{{.Organization}}</a></td>
<td>{{.Count}}</td>
<td>{{.Data}}</td>
</tr>
{{end}}
</tbody>
</table>
</div>
<footer class="footer fixed-bottom">
<div class="container-fluid"><span class="text-muted">MIT © 2017 <a href="https://github.com/petermbenjamin/YAS3BL">Peter Benjamin</a></span></div>
</footer>
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.11.0/umd/popper.min.js" integrity="sha384-b/U6ypiBEHpOf/4+1nzFpr53nxSS+GLCkfwBdFNTxtclqqenISfwAzpKaMNFNmj4" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0-beta/js/bootstrap.min.js" integrity="sha384-h0AbiXch4ZDo7tp9hKZ4TsHbi047NrKGLO3SEJAg45jXxnGIfYzk4Si90RDIqNm1" crossorigin="anonymous"></script>
</body>
</html>
`
func main() {
jsonBytes, err := ioutil.ReadFile("yas3bl.json")
if err != nil {
log.Fatalf("could not read file: %+v\n", err)
}
var bucketsLeaked []Leak
err = json.Unmarshal(jsonBytes, &bucketsLeaked)
if err != nil {
log.Fatalf("could not unmarshal JSON: %+v\n", err)
}
sort.Slice(bucketsLeaked, func(i, j int) bool {
return strings.ToUpper(bucketsLeaked[i].Organization) < strings.ToUpper(bucketsLeaked[j].Organization)
})
f, err := os.Create("README.md")
if err != nil {
log.Fatalf("could not create README.md file: %+v\n", err)
}
defer f.Close()
w := bufio.NewWriter(f)
t := template.Must(template.New("tmpl").Parse(tmpl))
err = t.Execute(w, bucketsLeaked)
if err != nil {
log.Fatalf("could not merge data from JSON into README.md: %+v\n", err)
}
w.Flush()
hf, err := os.Create("docs/index.html")
if err != nil {
log.Fatalf("could not create index.html file: %+v\n", err)
}
defer hf.Close()
hw := bufio.NewWriter(hf)
ht := template.Must(template.New("tmpl").Parse(htmlTmpl))
err = ht.Execute(hw, bucketsLeaked)
if err != nil {
log.Fatalf("could not merge data from JSON into index.html: %+v\n", err)
}
hw.Flush()
}