-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathwitnessthefitness.py
More file actions
272 lines (232 loc) · 8.89 KB
/
witnessthefitness.py
File metadata and controls
272 lines (232 loc) · 8.89 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
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
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
from fire import FireProx
import datetime
import argparse
import json
def main(args):
if args.command == "create":
if args.urls == None or args.outfile == None:
print("Eyewitness file creation requires url and outfile inputs")
return
elif args.command == "delete":
if args.api_id == None:
print("Delete command requires API ID input")
return
else:
pass
if args.config != None:
print("[+] Loading AWS configuration details from file: {}".format(args.config))
aws_dict = json.loads(open(args.config).read())
access_key = aws_dict['access_key']
secret_access_key = aws_dict['secret_access_key']
else:
access_key = args.access_key
secret_access_key = args.secret_access_key
if access_key == None or secret_access_key == None:
print("Please input access key and secret access key for AWS authentication")
return
if args.command != "create":
fp_command(access_key, secret_access_key, "", "", args.region, args.command, args.api_id)
return
version_date = f'{datetime.datetime.now():%Y-%m-%dT%XZ}'
title = 'fireprox_wtf'
template = '''
{
"swagger": "2.0",
"info": {
"version": "{{version_date}}",
"title": "{{title}}"
},
"basePath": "/",
"schemes": [
"https"
],
"paths": {
"/": {
"get": {
"parameters": [
{
"name": "proxy",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "X-My-X-Forwarded-For",
"in": "header",
"required": false,
"type": "string"
}
],
"responses": {},
"x-amazon-apigateway-integration": {
"uri": "https://github.com/knavesec/EyeWitnessTheFitness",
"responses": {
"default": {
"statusCode": "200"
}
},
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy",
"integration.request.header.X-Forwarded-For": "method.request.header.X-My-X-Forwarded-For"
},
"passthroughBehavior": "when_no_match",
"httpMethod": "ANY",
"cacheNamespace": "irx7tm",
"cacheKeyParameters": [
"method.request.path.proxy"
],
"type": "http_proxy"
}
}
}
{{template_additions}}
}
}
'''
template_add = '''
"/{{url}}/": {
"x-amazon-apigateway-any-method": {
"produces": [
"application/json"
],
"parameters": [
{
"name": "proxy",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "X-My-X-Forwarded-For",
"in": "header",
"required": false,
"type": "string"
}
],
"responses": {},
"x-amazon-apigateway-integration": {
"uri": "{{url_full}}/{proxy}",
"responses": {
"default": {
"statusCode": "200"
}
},
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy",
"integration.request.header.X-Forwarded-For": "method.request.header.X-My-X-Forwarded-For"
},
"passthroughBehavior": "when_no_match",
"httpMethod": "ANY",
"cacheNamespace": "irx7tm",
"cacheKeyParameters": [
"method.request.path.proxy"
],
"type": "http_proxy"
}
}
},
"/{{url}}/{proxy+}": {
"x-amazon-apigateway-any-method": {
"produces": [
"application/json"
],
"parameters": [
{
"name": "proxy",
"in": "path",
"required": true,
"type": "string"
},
{
"name": "X-My-X-Forwarded-For",
"in": "header",
"required": false,
"type": "string"
}
],
"responses": {},
"x-amazon-apigateway-integration": {
"uri": "{{url_full}}/{proxy}",
"responses": {
"default": {
"statusCode": "200"
}
},
"requestParameters": {
"integration.request.path.proxy": "method.request.path.proxy",
"integration.request.header.X-Forwarded-For": "method.request.header.X-My-X-Forwarded-For"
},
"passthroughBehavior": "when_no_match",
"httpMethod": "ANY",
"cacheNamespace": "irx7tm",
"cacheKeyParameters": [
"method.request.path.proxy"
],
"type": "http_proxy"
}
}
}
'''
urls = open(args.urls,'r').readlines()
print("[+] {} URLs read from file: {}".format(len(urls),args.urls))
template_additions = ''
short_urls = []
print("[+] Generating template")
for url in urls:
url_full = url.strip()
url_split = url_full.split("/")[2]
short_urls.append(url_split)
template_addition = template_add
template_addition = template_addition.replace("{{url}}", url_split)
template_addition = template_addition.replace("{{url_full}}", url_full)
template_additions = template_additions + ',' + template_addition
template = template.replace("{{template_additions}}", template_additions)
template = template.replace("{{title}}", title)
template = template.replace("{{version_date}}", version_date)
print("[+] Creating API")
vars = create_api(access_key, secret_access_key, "", "", args.region, template)
print("[+] API Created: {}".format(vars['proxy_url']))
print("[+] Writing EyeWitness web URL file at {}".format(args.outfile))
f = open(args.outfile,'a')
for url in short_urls:
f.write(vars['proxy_url'] + url + '/')
f.write('\n')
f.close()
print("[+] Done")
print("[+] Now run: python3 Eyewitness.py --web -f {} [other inputs]".format(args.outfile))
def get_fireprox_args(access_key, secret_access_key, profile_name, session_token, command, region):
args = {}
args["access_key"] = access_key
args["secret_access_key"] = secret_access_key
args["url"] = ""
args["command"] = command
args["region"] = region
args["api_id"] = ""
args["profile_name"] = profile_name
args["session_token"] = session_token
help_str = "Fireprox errored and catches so much that there is no detail. Common error is system time being off by 5+ minutes"
return args, help_str
def create_api(access_key, secret_access_key, profile_name, session_token, region, template):
args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, "create", region)
fp = FireProx(args, help_str)
resource_id, proxy_url = fp.create_api(template)
return { "api_gateway_id" : resource_id, "proxy_url" : proxy_url }
def fp_command(access_key, secret_access_key, profile_name, session_token, region, command, api_id):
args, help_str = get_fireprox_args(access_key, secret_access_key, profile_name, session_token, command, region)
fp = FireProx(args, help_str)
if command == "list":
fp.list_api()
else:
fp.delete_api(api_id)
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('-u', '--urls', type=str, default=None, required=False, help="List of target HTTP/S hosts (must have http:// or https:// prepended on every line)")
parser.add_argument('-o', '--outfile', type=str, default=None, required=False, help="Desired output file")
parser.add_argument('--region', type=str, default="us-east-2", required=True, help="Region to create API in (default: us-east-2)")
parser.add_argument('--command', type=str, default="create", required=False, choices=["list", "delete", "create"], help="FireProx command input other than default list create [list, delete]")
parser.add_argument('--api_id', type=str, default=None, required=False, help="API ID, used to delete an API")
parser.add_argument('--access_key', type=str, default=None, help='AWS Access Key')
parser.add_argument('--secret_access_key', type=str, default=None, help='AWS Secret Access Key')
parser.add_argument('--config', type=str, default=None, help='Authenticate to AWS using config file aws.config')
args = parser.parse_args()
main(args)