forked from errorfiathck/IDOR-Forge
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathIDOR-Forge.py
358 lines (317 loc) · 14 KB
/
IDOR-Forge.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
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
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
import argparse
import requests
from urllib.parse import urlparse, parse_qs
import time
import json
import concurrent.futures
import csv
import sys
from typing import Dict, List, Optional, Union
from tkinter import Tk, Label, Entry, Button, Text, Scrollbar, END, messagebox, ttk
import threading
from bs4 import BeautifulSoup
from core.banner import banner
import random
import string
class IDORChecker:
def __init__(
self,
url: str,
delay: float = 1,
headers: Optional[Dict] = None,
proxy: Optional[Dict] = None,
verbose: bool = False,
sensitive_keywords: Optional[List[str]] = None,
):
"""
Initialize the IDORChecker with the target URL, delay between requests, custom headers, proxy, verbose mode, and sensitive keywords.
"""
self.url = url
self.base_url, self.params = self._parse_url(url)
self.delay = delay # Delay between requests to avoid rate limiting
self.headers = headers or {} # Custom headers for requests
self.proxy = proxy # Proxy configuration
self.verbose = verbose # Verbose mode for detailed output
self.sensitive_keywords = sensitive_keywords or [
"password",
"email",
"token",
"ssn",
"credit_card",
] # Sensitive keywords to detect
self.session = requests.Session() # Use a session for persistent connections
self.rate_limit_detected = False # Flag to detect rate limiting
def _parse_url(self, url: str) -> tuple:
"""
Parse the URL into base URL and query parameters.
"""
try:
parsed_url = urlparse(url)
if not parsed_url.scheme or not parsed_url.netloc:
raise ValueError("Invalid URL format")
base_url = f"{parsed_url.scheme}://{parsed_url.netloc}{parsed_url.path}"
params = parse_qs(parsed_url.query)
return base_url, params
except Exception as e:
print(f"Error parsing URL: {e}")
raise
def _generate_payloads(self, param: str, values: List[str]) -> List[Dict]:
"""
Generate dynamic payloads by replacing the specified parameter with the given values.
Includes advanced payloads like random strings, numbers, and special characters.
"""
payloads = []
for value in values:
# Basic payload
new_params = self.params.copy()
new_params[param] = value
payloads.append(new_params)
# Advanced payloads
payloads.append({**new_params, "random_str": self._generate_random_string(10)}) # Add random string
payloads.append({**new_params, "random_num": random.randint(1000, 9999)}) # Add random number
payloads.append({**new_params, "special_chars": "!@#$%^&*()"}) # Add special characters
return payloads
def _generate_random_string(self, length: int) -> str:
"""
Generate a random string of the specified length.
"""
return "".join(random.choices(string.ascii_letters + string.digits, k=length))
def _send_request(self, params: Dict, method: str = "GET") -> Optional[requests.Response]:
"""
Send a request with the given parameters and HTTP method.
"""
try:
request_args = {
"headers": self.headers,
"proxies": self.proxy,
"timeout": 10, # Timeout for requests
}
if method.upper() == "GET":
response = self.session.get(self.base_url, params=params, **request_args)
elif method.upper() == "POST":
response = self.session.post(self.base_url, data=params, **request_args)
elif method.upper() == "PUT":
response = self.session.put(self.base_url, data=params, **request_args)
elif method.upper() == "DELETE":
response = self.session.delete(self.base_url, data=params, **request_args)
else:
raise ValueError(f"Unsupported HTTP method: {method}")
return response
except requests.RequestException as e:
print(f"Request failed: {e}")
return None
def _detect_sensitive_data(self, response_text: str) -> bool:
"""
Detect sensitive data in the response text.
"""
for keyword in self.sensitive_keywords:
if keyword in response_text.lower():
return True
return False
def _detect_rate_limiting(self, response: requests.Response) -> bool:
"""
Detect rate limiting based on response status code and headers.
"""
if response.status_code == 429: # Too Many Requests
return True
if "Retry-After" in response.headers: # Retry-After header
return True
return False
def _test_payload(self, payload: Dict, method: str) -> Dict:
"""
Test a single payload and return the result.
"""
if self.verbose:
print(f"Testing payload: {payload}")
response = self._send_request(payload, method)
if response is None:
return {}
# Detect rate limiting
if self._detect_rate_limiting(response):
self.rate_limit_detected = True
print("Rate limiting detected. Adjusting delay...")
time.sleep(self.delay * 2) # Increase delay to avoid further rate limiting
result = {
"payload": payload,
"status_code": response.status_code,
"response_content": response.text[:200], # Save first 200 chars of response
"sensitive_data_detected": self._detect_sensitive_data(response.text),
}
if self.verbose:
print(f"Status Code: {response.status_code}")
print(f"Response Content: {result['response_content']}...")
if result["sensitive_data_detected"]:
print("Sensitive data detected!")
print("-" * 40)
# Delay between requests to avoid rate limiting
time.sleep(self.delay)
return result
def check_idor(
self,
param: str,
test_values: List[str],
method: str = "GET",
output_file: Optional[str] = None,
output_format: str = "txt",
):
"""
Check for IDOR vulnerabilities by testing different values for the specified parameter.
"""
payloads = self._generate_payloads(param, test_values)
results = []
# Use threading for concurrent scanning
with concurrent.futures.ThreadPoolExecutor() as executor:
futures = [executor.submit(self._test_payload, payload, method) for payload in payloads]
for future in concurrent.futures.as_completed(futures):
result = future.result()
if result:
results.append(result)
# Save results to file if output file is provided
if output_file:
if output_format == "csv":
self._save_results_csv(results, output_file)
else:
self._save_results_txt(results, output_file)
print(f"Results saved to {output_file}")
def _save_results_txt(self, results: List[Dict], output_file: str):
"""
Save results to a text file.
"""
with open(output_file, "w") as f:
for result in results:
f.write(f"Payload: {result['payload']}\n")
f.write(f"Status Code: {result['status_code']}\n")
f.write(f"Response Content: {result['response_content']}\n")
f.write(f"Sensitive Data Detected: {result['sensitive_data_detected']}\n")
f.write("-" * 40 + "\n")
def _save_results_csv(self, results: List[Dict], output_file: str):
"""
Save results to a CSV file.
"""
with open(output_file, "w", newline="") as f:
writer = csv.writer(f)
writer.writerow(["Payload", "Status Code", "Response Content", "Sensitive Data Detected"])
for result in results:
writer.writerow(
[
result["payload"],
result["status_code"],
result["response_content"],
result["sensitive_data_detected"],
]
)
def interactive_mode():
"""
Launch an interactive GUI for IDOR testing.
"""
root = Tk()
root.title("IDOR Vulnerability Scanner")
Label(root, text="Target URL:").grid(row=0, column=0, padx=10, pady=10)
url_entry = Entry(root, width=50)
url_entry.grid(row=0, column=1, padx=10, pady=10)
Label(root, text="Test Values (comma-separated):").grid(row=1, column=0, padx=10, pady=10)
test_values_entry = Entry(root, width=50)
test_values_entry.grid(row=1, column=1, padx=10, pady=10)
Label(root, text="Output File:").grid(row=2, column=0, padx=10, pady=10)
output_file_entry = Entry(root, width=50)
output_file_entry.grid(row=2, column=1, padx=10, pady=10)
output_text = Text(root, height=20, width=80)
output_text.grid(row=3, column=0, columnspan=2, padx=10, pady=10)
scrollbar = Scrollbar(root, command=output_text.yview)
scrollbar.grid(row=3, column=2, sticky="ns")
output_text.config(yscrollcommand=scrollbar.set)
progress = ttk.Progressbar(root, orient="horizontal", length=400, mode="determinate")
progress.grid(row=4, column=0, columnspan=2, pady=10)
def run_scan():
url = url_entry.get()
test_values = test_values_entry.get().split(",")
output_file = output_file_entry.get()
if not url or not test_values:
messagebox.showerror("Error", "Please provide a URL and test values.")
return
checker = IDORChecker(url, verbose=True)
output_text.insert(END, f"Scanning URL: {url}\n")
output_text.insert(END, f"Test Values: {test_values}\n")
output_text.insert(END, "-" * 40 + "\n")
progress["maximum"] = len(checker.params.keys()) * len(test_values)
progress["value"] = 0
for param in checker.params.keys():
output_text.insert(END, f"Scanning parameter: {param}\n")
checker.check_idor(param, test_values, output_file=output_file)
progress["value"] += len(test_values)
root.update_idletasks()
output_text.insert(END, "-" * 40 + "\n")
output_text.insert(END, "Scan complete!\n")
Button(root, text="Run Scan", command=run_scan).grid(row=5, column=0, columnspan=2, pady=10)
root.mainloop()
def main():
banner()
# Set up argument parser
parser = argparse.ArgumentParser(description="Ultimate IDOR Vulnerability Checker")
parser.add_argument("-u", "--url", help="Target URL to test for IDOR vulnerabilities")
parser.add_argument("-p", "--parameters", action="store_true", help="Scan all parameters in the URL")
parser.add_argument("-m", "--method", default="GET", help="HTTP method to use (GET, POST, PUT, DELETE)")
parser.add_argument("-d", "--delay", type=float, default=1, help="Delay between requests (in seconds)")
parser.add_argument("-o", "--output", help="Output file to save results")
parser.add_argument("--output-format", choices=["txt", "csv"], default="txt", help="Output file format (txt or csv)")
parser.add_argument("--headers", help="Custom headers in JSON format (e.g., '{\"Authorization\": \"Bearer token\"}')")
parser.add_argument("--proxy", help="Proxy URL (e.g., 'http://127.0.0.1:8080')")
parser.add_argument("-v", "--verbose", action="store_true", help="Enable verbose mode for detailed output")
parser.add_argument("--test-values", help="Custom test values in JSON format (e.g., '[1, 2, 3, 4, 5]')")
parser.add_argument("--sensitive-keywords", help="Custom sensitive keywords in JSON format (e.g., '[\"password\", \"email\"]')")
parser.add_argument("--interactive", action="store_true", help="Launch interactive GUI mode")
args = parser.parse_args()
if args.interactive:
interactive_mode()
return
# Parse custom headers
headers = {}
if args.headers:
try:
headers = json.loads(args.headers) # Convert JSON string to dictionary
except json.JSONDecodeError as e:
print(f"Error parsing headers: {e}")
return
# Parse proxy configuration
proxy = None
if args.proxy:
proxy = {
"http": args.proxy,
"https": args.proxy,
}
# Parse custom test values
test_values = [1, 2, 3, 4, 5] # Default test values
if args.test_values:
try:
test_values = json.loads(args.test_values) # Convert JSON string to list
except json.JSONDecodeError as e:
print(f"Error parsing test values: {e}")
return
# Parse custom sensitive keywords
sensitive_keywords = None
if args.sensitive_keywords:
try:
sensitive_keywords = json.loads(args.sensitive_keywords) # Convert JSON string to list
except json.JSONDecodeError as e:
print(f"Error parsing sensitive keywords: {e}")
return
# Initialize IDORChecker
checker = IDORChecker(
args.url,
delay=args.delay,
headers=headers,
proxy=proxy,
verbose=args.verbose,
sensitive_keywords=sensitive_keywords,
)
# If -p switch is used, scan all parameters in the URL
if args.parameters:
for param in checker.params.keys():
print(f"Scanning parameter: {param}")
checker.check_idor(param, test_values, method=args.method, output_file=args.output, output_format=args.output_format)
else:
# If -p is not used, test a single parameter (e.g., 'id')
param_to_test = "id" # Default parameter to test
checker.check_idor(param_to_test, test_values, method=args.method, output_file=args.output, output_format=args.output_format)
if __name__ == "__main__":
main()