-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathopen_redirect.py
72 lines (60 loc) · 2.64 KB
/
open_redirect.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
import requests
from hints import *
from vulnerability_class import VulnerabilityClass
import fuzz
class OpenRedirect(VulnerabilityClass):
fuzz=None
testURL='https://www.ciao.com'
def __init__(self, fuzz):
self.fuzz = fuzz
def estimate_effort(self):
total=0
for request in self.fuzz.requests:
for param in self.fuzz.GET_hints[request['requestId']]:
if OpenRedirect.hasToBeTested(self.fuzz.GET_hints[request['requestId']][param]):
total+=self.fuzz.lenNecessaryRequests
for param in self.fuzz.POST_hints[request['requestId']]:
if OpenRedirect.hasToBeTested(self.fuzz.POST_hints[request['requestId']][param]):
total+=self.fuzz.lenNecessaryRequests #count open redirect
print str(total)+" requests required to test for open-redirects"
return total
def get_payload(self):
return OpenRedirect.testURL
@staticmethod
def verify(response):
if len(response.history)>0:
if self.get_payload() in response.url:
print "FOUND OPEN REDIRECT"
exit()
def testOpenRedirect(self, url, param, method, requestId, actualMethod=None, post_=None):
assert not (method=='GET' and actualMethod==None)
#test for Open-redirect
s=requests.Session()
self.fuzz.catchUp(s)
if method=='GET':
newUrl = fuzz.Fuzz.substParam(url,param,self.get_payload())
response = self.fuzz.send_req(requestId, s, newUrl, actualMethod)
elif method=='POST':
newPost=copy.deepcopy(post_)
newPost['formData'][param]=self.get_payload()
response = self.fuzz.send_req(requestId, s, url, 'POST')
else:
raise ValueError('method: '+method+' yet unsupported')
OpenRedirect.verify(response)
self.fuzz.tillTheEnd(s) #follow the remaining requests to check for the redirect
@staticmethod
def hasToBeTested(hint):
if hint&Hints.URL:
print "FOUND URL"
return True
return False
def test(self, method, url, requestId, param, postData=None, actualMethod=None):
s = requests.Session()
if method=='GET':
if not OpenRedirect.hasToBeTested(self.fuzz.GET_hints[requestId][param]):
return
self.testOpenRedirect(url, param, 'GET', requestId, actualMethod, postData)
elif method=='POST':
if not OpenRedirect.hasToBeTested(self.fuzz.POST_hints[requestId][param]):
return
self.testOpenRedirect(url, param, 'POST', requestId, post_=postData)