This repository has been archived by the owner on Feb 26, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 19
/
h1-search.go
103 lines (81 loc) · 2.14 KB
/
h1-search.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
package main
import (
"encoding/json"
"html/template"
"io/ioutil"
"log"
"net/http"
"os"
"time"
)
// TemplateData : Prepares the template with the reports from HackerOne
type TemplateData struct {
Target string
Reports []Report
}
// Report : The structure of the report taken from a HackerOne report
type Report struct {
Title string
Url string
SeverityRating string
}
// Response : Grab the number of reports, pages and the reports from HackerOne
type Response struct {
Count int
Pages int
Reports []Report
}
func main() {
var templateData TemplateData
var hacktivity *hacktivity
var response Response
log.Println("::: Loading h1-search.go...")
log.Println("::: by @dsopas and @pauloasilva_com")
log.Println(":::::::::::::::::::::::::::::::::::.")
templateData = TemplateData{Target: os.Args[1]}
hacktivity = NewHacktivity(os.Args[1])
res, err := http.Get(hacktivity.String())
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
jsonErr := json.Unmarshal(body, &response)
if jsonErr != nil {
log.Fatal(jsonErr)
}
log.Println("::: Creating template file...")
tmpl := template.Must(template.ParseFiles("./layout.html"))
log.Println("::: Getting results from HackerOne...")
for p := 1; p <= response.Pages; p++ {
res, err := http.Get(hacktivity.NextPage().String())
if err != nil {
log.Fatal(err)
}
body, err := ioutil.ReadAll(res.Body)
if err != nil {
log.Fatal(err)
}
jsonErr := json.Unmarshal(body, &response)
if jsonErr != nil {
log.Fatal(jsonErr)
}
log.Printf("::: Getting page %d of %d...\n", p, response.Pages)
for _, r := range response.Reports {
report := Report{
Title: r.Title,
SeverityRating: r.SeverityRating,
Url: r.Url}
templateData.Reports = append(templateData.Reports, report)
}
time.Sleep(time.Millisecond * 500)
}
http.HandleFunc("/", func(w http.ResponseWriter, r *http.Request) {
tmpl.Execute(w, templateData)
})
log.Println("::: File is ready...")
log.Println("::: Click to view the results: http://localhost:3000/")
http.ListenAndServe(":3000", nil)
}