-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathmain.go
More file actions
184 lines (149 loc) · 4.94 KB
/
main.go
File metadata and controls
184 lines (149 loc) · 4.94 KB
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
package main
import (
"crypto/tls"
"encoding/json"
"flag"
"fmt"
"net"
"net/http"
"os"
"time"
)
type H1Response struct {
Data []Data `json:"data"`
Links Links `json:"links"`
}
type Data struct {
Id string `json:"id"`
Type string `json:"type"`
Attributes Attribute `json:"attributes"`
}
type Attribute struct {
Handle string `json:"handle"`
Name string `json:"name"`
Currency string `json:"currency"`
Policy string `json:"policy"`
Profile_picture string `json:"profile_picture"`
Submission_state string `json:"submission_state"`
Triage_active bool `json:"triage_active"`
State string `json:"state"`
Started_accepting_at string `json:"started_accepting_at"`
Number_of_reports_for_user int `json:"number_of_reports_for_user"`
Number_of_valid_reports_for_user int `json:"number_of_valid_reports_for_user"`
Bounty_earned_for_user float32 `json:"bounty_earned_for_user"`
Last_invitation_accepted_at_for_user string `json:"last_invitation_accepted_at_for_user"`
Bookmarked bool `json:"bookmarked"`
Allows_bounty_splitting bool `json:"allows_bounty_splitting"`
}
type ProgramDetails struct {
Attributes Attribute `json:"attributes"`
Relationships Relationships `json:"relationships"`
}
type Relationships struct {
StructedScopes StructedScopes `json:"structured_scopes"`
}
type StructedScopes struct {
Data []StructedScope `json:"data"`
}
type StructedScope struct {
Id string `json:"id"`
Type string `json:"string"`
Attributes StructedScopeAttribute `json:"attributes"`
}
type StructedScopeAttribute struct {
AssetType string `json:"asset_type"`
AssetIdentifier string `json:"asset_identifier"`
EligibleForBounty bool `json:"eligible_for_bounty"`
Instruction string `json:"instruction"`
MaxSeverity string `json:"max_severity"`
CreatedAt string `json:"created_at"`
UpdatedAt string `json:"updated_at"`
ConfidentialityRequirement string `json:"confidentiality_requirement"`
IntegrityRequirement string `json:"integrity_requirement"`
Availabilityrequirement string `json:"availibity_requirement"`
}
type Links struct {
Self string `json:"self"`
Next string `json:"next"`
Previous string `json:"previous"`
}
func main() {
username := flag.String("u", "", "Username for basic auth")
apiToken := flag.String("t", "", "API token for basic auth")
paidOnly := flag.Bool("paid", false, "Only include paid programs")
flag.Parse()
makeAPIRequest(*username, *apiToken, *paidOnly)
}
func makeAPIRequest(username string, token string, paidOnly bool) {
client := buildHttpClient()
var data H1Response
url := "https://api.hackerone.com/v1/hackers/programs?page[size]=100&page[number]=1"
for next := true; next; {
if data.Links.Self != "" {
url = data.Links.Next
}
req, err := http.NewRequest("GET", url, nil)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
req.SetBasicAuth(username, token)
resp, err := client.Do(req)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
defer resp.Body.Close()
if err := json.NewDecoder(resp.Body).Decode(&data); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
for _, details := range data.Data {
var programDetails ProgramDetails
detailReq, err := http.NewRequest("GET", "https://api.hackerone.com/v1/hackers/programs/"+details.Attributes.Handle, nil)
if err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
detailReq.SetBasicAuth(username, token)
detailResp, err := client.Do(detailReq)
if err != nil {
fmt.Fprintln(os.Stderr, err)
}
defer detailResp.Body.Close()
if err := json.NewDecoder(detailResp.Body).Decode(&programDetails); err != nil {
fmt.Fprintln(os.Stderr, err)
return
}
for _, scope := range programDetails.Relationships.StructedScopes.Data {
if scope.Attributes.AssetType == "URL" {
if !paidOnly || scope.Attributes.EligibleForBounty {
fmt.Println(scope.Attributes.AssetIdentifier)
}
}
}
}
next = data.Links.Next != data.Links.Self
}
}
func buildHttpClient() *http.Client {
var tr = &http.Transport{
MaxIdleConns: 30,
IdleConnTimeout: time.Second,
DisableKeepAlives: true,
TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
DialContext: (&net.Dialer{
Timeout: 10 * time.Second,
KeepAlive: time.Second,
}).DialContext,
}
re := func(req *http.Request, via []*http.Request) error {
return http.ErrUseLastResponse
}
client := &http.Client{
Transport: tr,
CheckRedirect: re,
Timeout: 10 * time.Second,
}
return client
}