-
-
Notifications
You must be signed in to change notification settings - Fork 119
/
hackerone.py
211 lines (198 loc) · 8.45 KB
/
hackerone.py
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
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
import requests
import re
import json
import itertools
query_url = "https://hackerone.com/programs/search?query=type:hackerone&sort=published_at:descending&page={page}"
policy_scope_query = """
query PolicySearchStructuredScopesQuery($handle: String!) {
team(handle: $handle) {
structured_scopes_search {
nodes {
... on StructuredScopeDocument {
identifier
eligible_for_bounty
eligible_for_submission
display_name
instruction
}
}
}
}
}
"""
scope_query = """
query TeamAssets($handle: String!) {
team(handle: $handle) {
in_scope_assets: structured_scopes(
archived: false
eligible_for_submission: true
) {
edges {
node {
asset_identifier
asset_type
eligible_for_bounty
}
}
}
}
}
"""
def hackerone_to_list():
targets = {
"domains": [],
"with_bounty": [],
"source_code": [],
"source_code_with_bounty": [],
}
csv = [["handle", "domain", "eligible_for_bounty"]]
csv_source_code = [["handle", "source_code", "eligible_for_bounty"]]
page = 1
with requests.Session() as session:
while True:
r = session.get(query_url.format(page=page))
page += 1
if r.status_code != 200:
break
resp = json.loads(r.text)
for program in resp["results"]:
r = session.get(
"https://hackerone.com{program}".format(program=program["url"]),
headers={"Accept": "application/json"},
)
if r.status_code != 200:
print("unable to retreive %s", program["name"])
continue
resp = json.loads(r.text)
# new scope
query = json.dumps(
{
"query": policy_scope_query,
"variables": {"handle": resp["handle"]},
}
)
r = session.post(
"https://hackerone.com/graphql",
data=query,
headers={"content-type": "application/json"},
)
policy_scope_resp = json.loads(r.text)
for e in policy_scope_resp["data"]["team"]["structured_scopes_search"][
"nodes"
]:
if (
e["display_name"] == "Domain" and e["eligible_for_submission"]
) or (
e["eligible_for_submission"] and e["identifier"].startswith("*")
):
identifier = e["identifier"]
for i in identifier.split(","):
if i in targets["domains"]:
continue
targets["domains"].append(i)
bounty = e["eligible_for_bounty"]
if bounty is None:
bounty = False
if bounty is True:
targets["with_bounty"].append(i)
csv.append([resp["handle"], i, str(bounty)])
if (
e["display_name"] == "SourceCode"
and e["eligible_for_submission"]
):
identifier = e["identifier"]
for id in identifier.split(","):
if (
id.startswith("https://")
or id.startswith("http://")
or id.startswith("git")
or id.startswith("www")
or re.match(r".*\/.*", id)
):
if id.startswith("git") or id.startswith("www"):
id = "https://" + id
if not id.startswith("http"):
id = "https://github.com/" + id
if id in targets["source_code"]:
continue
targets["source_code"].append(id)
bounty = e["eligible_for_bounty"]
if bounty is None:
bounty = False
if bounty is True:
targets["source_code_with_bounty"].append(id)
csv_source_code.append(
[resp["handle"], id, str(bounty)]
)
# old scope
query = json.dumps(
{"query": scope_query, "variables": {"handle": resp["handle"]}}
)
# 'variables': {'handle': 'malwarebytes'}})
r = session.post(
"https://hackerone.com/graphql",
data=query,
headers={"content-type": "application/json"},
)
scope_resp = json.loads(r.text)
for e in scope_resp["data"]["team"]["in_scope_assets"]["edges"]:
node = e["node"]
if (
node["asset_type"] == "Domain"
or node["asset_identifier"].startswith("*")
or node["asset_type"] == "URL"
):
identifier = node["asset_identifier"]
for i in identifier.split(","):
targets["domains"].append(i)
bounty = node["eligible_for_bounty"]
if bounty is None:
bounty = False
if bounty is True:
targets["with_bounty"].append(i)
csv.append([resp["handle"], i, str(bounty)])
if node["asset_type"] == "SOURCE_CODE":
identifier = node["asset_identifier"]
for id in identifier.split(","):
if (
id.startswith("https://")
or id.startswith("http://")
or id.startswith("git")
or id.startswith("www")
or re.match(r".*\/.*", id)
):
if id.startswith("git") or id.startswith("www"):
id = "https://" + id
if not id.startswith("http"):
id = "https://github.com/" + id
if id in targets["source_code"]:
continue
targets["source_code"].append(id)
bounty = node["eligible_for_bounty"]
if bounty is None:
bounty = False
if bounty is True:
targets["source_code_with_bounty"].append(id)
csv_source_code.append(
[resp["handle"], id, str(bounty)]
)
# dedupe
targets["domains"] = list(set(targets["domains"]))
targets["with_bounty"] = list(set(targets["with_bounty"]))
targets["source_code"] = list(set(targets["source_code"]))
targets["source_code_with_bounty"] = list(set(targets["source_code_with_bounty"]))
return targets, csv, csv_source_code
if __name__ == "__main__":
targets, csv, csv_source_code = hackerone_to_list()
with open("domains.txt", "w") as f:
f.write("\n".join(targets["domains"]))
with open("domains_with_bounties.txt", "w") as f:
f.write("\n".join(targets["with_bounty"]))
with open("domains.csv", "w") as f:
f.write("\n".join([",".join(e) for e in csv]))
with open("source_code.csv", "w") as f:
f.write("\n".join([",".join(e) for e in csv_source_code]))
with open("source_code.txt", "w") as f:
f.write("\n".join(targets["source_code"]))
with open("source_code_with_bounties.txt", "w") as f:
f.write("\n".join(targets["source_code_with_bounty"]))