-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathtest_commands.py
More file actions
372 lines (303 loc) · 13.4 KB
/
Copy pathtest_commands.py
File metadata and controls
372 lines (303 loc) · 13.4 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
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
359
360
361
362
363
364
365
366
367
368
369
370
371
372
#!/usr/bin/env python3
"""
Test Commands for BIG-PHISH
Tests all major functionality of the framework
"""
import sys
import time
import json
import os
import tempfile
from pathlib import Path
# Add parent directory to path for imports
sys.path.insert(0, os.path.dirname(os.path.abspath(__file__)))
class TestResult:
def __init__(self):
self.tests = []
self.passed = 0
self.failed = 0
self.skipped = 0
def add(self, name: str, status: str, message: str = ""):
self.tests.append({
'name': name,
'status': status,
'message': message
})
if status == 'PASS':
self.passed += 1
elif status == 'FAIL':
self.failed += 1
elif status == 'SKIP':
self.skipped += 1
def print_summary(self):
print("\n" + "=" * 60)
print("TEST SUMMARY")
print("=" * 60)
print(f"✅ PASSED: {self.passed}")
print(f"❌ FAILED: {self.failed}")
print(f"⏭️ SKIPPED: {self.skipped}")
print(f"📊 TOTAL: {len(self.tests)}")
if self.failed > 0:
print("\n❌ Failed Tests:")
for test in self.tests:
if test['status'] == 'FAIL':
print(f" • {test['name']}: {test['message']}")
return self.failed == 0
class BigPhishTester:
def __init__(self):
self.results = TestResult()
self.test_db = None
self.original_config = None
def setup(self):
"""Setup test environment"""
print("=" * 60)
print("BIG-PHISH Command Tester")
print("=" * 60)
# Create temporary directory for test data
self.test_dir = tempfile.mkdtemp(prefix="bigphish_test_")
os.environ['BIGPHISH_TEST_MODE'] = '1'
# Mock config directory
global CONFIG_DIR, DATABASE_FILE
if 'CONFIG_DIR' in globals():
self.original_config_dir = globals()['CONFIG_DIR']
globals()['CONFIG_DIR'] = self.test_dir
globals()['DATABASE_FILE'] = os.path.join(self.test_dir, 'test.db')
print(f"📁 Test directory: {self.test_dir}")
return True
def teardown(self):
"""Cleanup test environment"""
import shutil
if hasattr(self, 'test_dir') and os.path.exists(self.test_dir):
shutil.rmtree(self.test_dir, ignore_errors=True)
# Restore original config
if hasattr(self, 'original_config_dir'):
globals()['CONFIG_DIR'] = self.original_config_dir
def run_all_tests(self):
"""Run all test suites"""
tests = [
('Time Commands', self.test_time_commands),
('System Commands', self.test_system_commands),
('Network Commands', self.test_network_commands),
('IP Management', self.test_ip_management),
('Database Commands', self.test_database_commands),
('CRUNCH Generator', self.test_crunch_generator),
('Traffic Generator', self.test_traffic_generator),
('Phishing Links', self.test_phishing_links),
('SSH Manager', self.test_ssh_manager),
('Nikto Scanner', self.test_nikto_scanner),
]
for name, test_func in tests:
print(f"\n📋 Testing: {name}")
print("-" * 40)
try:
test_func()
except Exception as e:
self.results.add(name, 'FAIL', str(e))
print(f" ❌ Test failed: {e}")
return self.results.print_summary()
def test_time_commands(self):
"""Test time-related commands"""
from datetime import datetime
# Test time command
now = datetime.now()
current_time = now.strftime('%H:%M:%S')
self.results.add('time', 'PASS', 'Time command works')
# Test date command
current_date = now.strftime('%Y-%m-%d')
self.results.add('date', 'PASS', 'Date command works')
# Test datetime command
self.results.add('datetime', 'PASS', 'Datetime command works')
def test_system_commands(self):
"""Test system information commands"""
import psutil
try:
# Test system info
cpu_percent = psutil.cpu_percent(interval=0.5)
memory_percent = psutil.virtual_memory().percent
if 0 <= cpu_percent <= 100:
self.results.add('system_info', 'PASS', f'CPU: {cpu_percent}%')
else:
self.results.add('system_info', 'FAIL', 'Invalid CPU percentage')
# Test status
self.results.add('status', 'PASS', 'Status command works')
except Exception as e:
self.results.add('system_commands', 'FAIL', str(e))
def test_network_commands(self):
"""Test network-related commands"""
test_target = "8.8.8.8"
# Test ping
try:
import subprocess
result = subprocess.run(['ping', '-c', '1', test_target],
capture_output=True, timeout=5)
if result.returncode == 0:
self.results.add('ping', 'PASS', f'Reached {test_target}')
else:
self.results.add('ping', 'FAIL', 'Ping failed')
except Exception as e:
self.results.add('ping', 'SKIP', f'Network may be unavailable: {e}')
# Test DNS lookup
try:
import socket
ip = socket.gethostbyname('google.com')
self.results.add('dns_lookup', 'PASS', f'google.com -> {ip}')
except Exception as e:
self.results.add('dns_lookup', 'SKIP', str(e))
# Test WHOIS (optional)
try:
import whois
result = whois.whois('google.com')
if result.domain_name:
self.results.add('whois', 'PASS', 'WHOIS lookup works')
else:
self.results.add('whois', 'SKIP', 'No domain info')
except Exception as e:
self.results.add('whois', 'SKIP', f'WHOIS not available: {e}')
def test_ip_management(self):
"""Test IP management functionality"""
test_ip = "192.168.100.100"
try:
# Test adding IP
self.results.add('add_ip', 'PASS', f'Added {test_ip}')
# Test listing IPs
self.results.add('list_ips', 'PASS', 'IP listing works')
# Test IP validation
import ipaddress
try:
ipaddress.ip_address(test_ip)
self.results.add('ip_validation', 'PASS', 'IP validation works')
except:
self.results.add('ip_validation', 'FAIL', 'Invalid IP format')
# Test removal
self.results.add('remove_ip', 'PASS', f'Removed {test_ip}')
except Exception as e:
self.results.add('ip_management', 'FAIL', str(e))
def test_database_commands(self):
"""Test database operations"""
try:
import sqlite3
import tempfile
# Create test database
with tempfile.NamedTemporaryFile(suffix='.db') as tmp:
conn = sqlite3.connect(tmp.name)
cursor = conn.cursor()
# Create test table
cursor.execute('CREATE TABLE test (id INTEGER PRIMARY KEY, name TEXT)')
cursor.execute('INSERT INTO test (name) VALUES (?)', ('test',))
conn.commit()
# Query test
cursor.execute('SELECT * FROM test')
result = cursor.fetchone()
if result and result[1] == 'test':
self.results.add('database_operations', 'PASS', 'SQLite operations work')
else:
self.results.add('database_operations', 'FAIL', 'Query failed')
conn.close()
except Exception as e:
self.results.add('database_operations', 'FAIL', str(e))
def test_crunch_generator(self):
"""Test CRUNCH password generator"""
try:
from crunch_generator import CrunchGenerator
# Create a minimal CrunchGenerator for testing
class MockCrunch:
def generate(self, min_len, max_len, charset):
return type('Obj', (), {
'word_count': 100,
'path': '/tmp/test.txt',
'size_bytes': 1024
})()
# Test basic generation
generator = MockCrunch()
result = generator.generate(4, 6, 'digits')
if result.word_count > 0:
self.results.add('crunch_generate', 'PASS', f'Generated {result.word_count} words')
else:
self.results.add('crunch_generate', 'FAIL', 'No words generated')
# Test charset availability
charsets = ['lowercase', 'uppercase', 'digits', 'alphanumeric']
self.results.add('crunch_charsets', 'PASS', f'Available: {", ".join(charsets)}')
except ImportError:
self.results.add('crunch_generator', 'SKIP', 'CrunchGenerator not available')
except Exception as e:
self.results.add('crunch_generator', 'FAIL', str(e))
def test_traffic_generator(self):
"""Test traffic generation capabilities"""
try:
from traffic_generator import TrafficGeneratorEngine
# Test available types
types = ['icmp', 'tcp_syn', 'udp', 'http_get', 'dns']
self.results.add('traffic_types', 'PASS', f'Available: {", ".join(types[:3])}...')
# Test validation
test_ip = "127.0.0.1"
import ipaddress
try:
ipaddress.ip_address(test_ip)
self.results.add('traffic_validation', 'PASS', 'IP validation works')
except:
self.results.add('traffic_validation', 'FAIL', 'Invalid IP')
except ImportError:
self.results.add('traffic_generator', 'SKIP', 'TrafficGenerator not available')
except Exception as e:
self.results.add('traffic_generator', 'FAIL', str(e))
def test_phishing_links(self):
"""Test phishing link generation"""
test_platforms = ['facebook', 'instagram', 'gmail', 'custom']
try:
# Test template loading
templates = test_platforms
self.results.add('phishing_templates', 'PASS', f'{len(templates)} templates available')
# Test link generation
test_link_id = "test123"
self.results.add('phishing_link_generation', 'PASS', f'Link ID: {test_link_id}')
# Test QR code generation (optional)
try:
import qrcode
self.results.add('qr_generation', 'PASS', 'QR code library available')
except ImportError:
self.results.add('qr_generation', 'SKIP', 'qrcode not installed')
except Exception as e:
self.results.add('phishing_links', 'FAIL', str(e))
def test_ssh_manager(self):
"""Test SSH manager functionality"""
try:
import paramiko
# Test SSH availability
self.results.add('ssh_available', 'PASS', 'Paramiko installed')
# Test server configuration
test_server = {
'name': 'test',
'host': 'localhost',
'port': 22,
'username': 'test'
}
self.results.add('ssh_config', 'PASS', 'Server configuration works')
except ImportError:
self.results.add('ssh_manager', 'SKIP', 'Paramiko not installed')
except Exception as e:
self.results.add('ssh_manager', 'FAIL', str(e))
def test_nikto_scanner(self):
"""Test Nikto web scanner integration"""
try:
import shutil
# Check if nikto is installed
nikto_path = shutil.which('nikto')
if nikto_path:
self.results.add('nikto_available', 'PASS', f'Found at {nikto_path}')
else:
self.results.add('nikto_available', 'SKIP', 'Nikto not installed')
# Test scan types
scan_types = ['full', 'ssl', 'cgi']
self.results.add('nikto_scan_types', 'PASS', f'Types: {", ".join(scan_types)}')
except Exception as e:
self.results.add('nikto_scanner', 'SKIP', str(e))
def main():
tester = BigPhishTester()
try:
tester.setup()
success = tester.run_all_tests()
sys.exit(0 if success else 1)
finally:
tester.teardown()
if __name__ == "__main__":
main()