forked from ethicalhackingplayground/Bug-Bounty-Tools
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathredir.py
201 lines (151 loc) · 9.88 KB
/
redir.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
#!/usr/bin/env python
import json
import requests
import sys
import time
import os
import argparse
import urlparse
from bs4 import BeautifulSoup
from colorama import Style,Fore
common_params = ["/", "next", "url", "target", "rurl", "dest", "destination",
"redir", "redirect_url", "redirect_uri", "redirect", "redirect.cgi?", "/out/",
"view", "/login/?to", "image_url", "go", "return", "returnTo", "return_to", "checkout_url",
"continue", "return_path", "returnUrl", "goto", "continue_to", "redirect"]
top = Style.BRIGHT + Fore.BLUE + """
########################################
# #
# _ #
# |_) _ _| o ._ _ _ _|_ #
# | \ (/_ (_| | | (/_ (_ |_ #
# #
# #
# @z0idex #
########################################
""" + Style.RESET_ALL
def main():
os.system('clear')
print(top)
parser = argparse.ArgumentParser()
parser.add_argument('-w', help='path to file of domain list', nargs=1, dest='domain', required=True)
parser.add_argument('-p', help='payload wordlist', nargs=1, dest='payload', required=True)
parser.add_argument('-d', help="destination host", nargs=1, dest='destination', required=True)
parser.add_argument('-s', help="spider through sites", nargs=1, dest='spider', required=True)
parser.add_argument('-o', help='output to file', nargs=1, dest='output', required=True)
args = parser.parse_args()
spider = args.spider[0]
# first argument - file with subdomains
file = args.domain[0]
# second argument - payload string
payloads = args.payload[0]
# The final destination
dest = str(args.destination[0])
# Output file
output = str(args.output[0])
#open file with subdomains and iterates
with open(file) as f:
print ""
print Style.BRIGHT + Fore.MAGENTA + "Searching for open redirects, prayz to the lordz.."
print "\n"
time.sleep(4)
redirects = list()
# loop for find the trace of all requests (303 is an open redirect) see the final destination
if spider == '0':
for host in f:
with open(payloads) as p:
for payload in p:
# strip some stuff
url = host.strip()
payload = payload.strip()
# replace the wildcard with the destination
payload = payload.replace("*", str(dest))
# find the parameters in the url
params = urlparse.parse_qs(urlparse.urlparse(url).query)
if len(params) == 0:
url = url + payload
else:
for p in params:
if p in common_params:
print Fore.WHITE + "--------------------------"
print Fore.GREEN + "Potential VULN Parameter %s" %p
print Fore.WHITE + "--------------------------"
p=url.replace(p,("%s=%s" % (p, dest)))
url=p
try:
print Style.BRIGHT + Fore.WHITE + "[ " + Fore.YELLOW + "CHECKING" + Fore.WHITE + " ] " + Fore.WHITE + url
response = requests.get(url, allow_redirects=True)
# check the status code
if len(response.history) != 0:
# check to see if there is an open redirect
d1 = "https://" + dest
s2 = "http://" + dest
if response.url == d1 or response.url == d2:
print Style.BRIGHT + Fore.WHITE + "[ " + Fore.GREEN + "FOUND" + Fore.WHITE + " ] " + Fore.YELLOW + "Open Redirect, Request was redirected"
print Style.BRIGHT + Fore.CYAN + "[Dest] " + Fore.WHITE + response.url
os.system("echo %s >> %s" % (url, output))
except:
pass
print Style.BRIGHT + Fore.GREEN + "\n --------------------------- RESULTS ------------------------\n"
if os.path.isfile(output):
results = open(output, 'r')
for result in results.readlines():
print Fore.GREEN + result
else:
print Fore.RED + "No Results.."
else:
print Style.BRIGHT + Fore.CYAN + "\nStarting Spider...\n"
for host in f:
# strip some stuff
host = host.strip()
try:
r = requests.get(host)
data = r.text
soup = BeautifulSoup(data, "lxml")
payloadFile = open(payloads).readlines()
crawled_urls = []
for link in soup.find_all('a'):
ref = link.get('href')
if "https://" in ref or "http://" in ref:
crawled_urls.append(ref)
for url in crawled_urls:
payloadFile = open(payloads)
for payload in payloadFile.readlines():
payload = payload.strip()
# replace the wildcard with the destination
payload = payload.replace("*", str(dest))
# find the parameters in the url
params = urlparse.parse_qs(urlparse.urlparse(url).query)
if len(params) == 0:
website = url + payload
else:
for p in params:
if p in common_params:
print Fore.WHITE + "--------------------------"
print Fore.GREEN + "Potential VULN Parameter %s" %p
print Fore.WHITE + "--------------------------"
p=website.replace(p,("%s=%s" % (p, dest)))
website=p
try:
print Style.BRIGHT + Fore.WHITE + "[ " + Fore.YELLOW + "CHECKING" + Fore.WHITE + " ] " + Fore.WHITE + website
response = requests.get(website, allow_redirects=True)
# check the status code
if len(response.history) != 0:
# check to see if there is an open redirect
d1 = "https://" + dest
d2 = "http://" + dest
if response.url == d1 or response.url == d2:
print Style.BRIGHT + Fore.WHITE + "[ " + Fore.GREEN + "FOUND" + Fore.WHITE + " ] " + Fore.YELLOW + "Open Redirect, Request was redirected"
print Style.BRIGHT + Fore.CYAN + "[Dest] " + Fore.WHITE + response.url
os.system("echo %s >> %s" % (url, output))
except:
pass
except:
pass
print Style.BRIGHT + Fore.GREEN + "\n --------------------------- RESULTS ------------------------\n"
if os.path.isfile(output):
results = open(output, 'r')
for result in results.readlines():
print Fore.GREEN + result
else:
print Fore.RED + "No Results.."
main()