-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathtest_modules.py
More file actions
408 lines (322 loc) · 14 KB
/
Copy pathtest_modules.py
File metadata and controls
408 lines (322 loc) · 14 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
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
#!/usr/bin/env python3
"""
Comprehensive Module Testing Script
Tests each component of the forensic scanner to ensure functionality
"""
import sys
import os
# Color codes for output
GREEN = '\033[92m'
RED = '\033[91m'
YELLOW = '\033[93m'
BLUE = '\033[94m'
RESET = '\033[0m'
def print_test(test_name, status, message=""):
"""Print test result"""
symbol = "✅" if status else "❌"
color = GREEN if status else RED
print(f"{symbol} {color}{test_name}{RESET}", end="")
if message:
print(f" - {message}")
else:
print()
def print_section(title):
"""Print section header"""
print(f"\n{BLUE}{'='*60}")
print(f" {title}")
print(f"{'='*60}{RESET}\n")
def test_imports():
"""Test if ext.py imports work"""
print_section("Testing Imports")
try:
import ext
print_test("Import ext module", True)
return True
except Exception as e:
print_test("Import ext module", False, str(e))
return False
def test_api_config():
"""Test API Configuration"""
print_section("Testing API Configuration")
try:
from ext import APIConfig
# Test instantiation
api_config = APIConfig()
print_test("APIConfig instantiation", True)
# Test endpoints
eth_endpoint = api_config.get_endpoint('ETH')
has_endpoint = eth_endpoint is not None
print_test("Get ETH endpoint", has_endpoint, eth_endpoint if has_endpoint else "None")
btc_endpoint = api_config.get_endpoint('BTC')
has_btc = btc_endpoint is not None
print_test("Get BTC endpoint", has_btc, btc_endpoint if has_btc else "None")
# Test save/load
save_result = api_config.save()
print_test("Save API config", save_result)
return True
except Exception as e:
print_test("APIConfig test", False, str(e))
return False
def test_crypto_utils():
"""Test Crypto Utilities"""
print_section("Testing Crypto Utilities")
try:
from ext import EnhancedCryptoUtils
# Test instantiation
crypto = EnhancedCryptoUtils()
print_test("EnhancedCryptoUtils instantiation", True)
# Test seed phrase validation (valid 12-word seed)
test_seed = "abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about"
is_valid = crypto.validate_seed_phrase(test_seed)
print_test("Validate valid seed phrase", is_valid)
# Test invalid seed
invalid_seed = "invalid seed phrase test"
is_invalid = not crypto.validate_seed_phrase(invalid_seed)
print_test("Reject invalid seed phrase", is_invalid)
# Test private key validation
valid_key = "0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
is_valid_key = crypto.is_valid_private_key(valid_key)
print_test("Validate private key format", is_valid_key, f"{valid_key[:16]}...")
# Test address generation
test_key = "1234567890abcdef1234567890abcdef1234567890abcdef1234567890abcdef"
eth_address = crypto.private_key_to_address(test_key, "ETH")
has_address = eth_address is not None and eth_address.startswith('0x')
print_test("Generate ETH address from key", has_address, eth_address[:20] + "..." if has_address else "None")
# Test seed extraction from text
text_with_seed = "Here is my seed: abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon abandon about and some other text"
found_seeds = crypto.extract_seed_phrases_from_text(text_with_seed)
print_test("Extract seed from text", len(found_seeds) > 0, f"Found {len(found_seeds)} seed(s)")
# Test private key extraction
text_with_key = "Private key: 0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef"
found_keys = crypto.extract_private_keys_from_text(text_with_key)
print_test("Extract private key from text", len(found_keys) > 0, f"Found {len(found_keys)} key(s)")
return True
except Exception as e:
print_test("Crypto utilities test", False, str(e))
import traceback
traceback.print_exc()
return False
def test_balance_checker():
"""Test Balance Checker"""
print_section("Testing Balance Checker")
try:
from ext import AdvancedBalanceChecker, APIConfig
api_config = APIConfig()
balance_checker = AdvancedBalanceChecker(api_config)
print_test("AdvancedBalanceChecker instantiation", True)
# Test price fetching (should work without API key)
eth_price = balance_checker.get_usd_price('ETH')
has_price = eth_price > 0
print_test("Get ETH USD price", has_price, f"${eth_price:.2f}" if has_price else "Failed")
btc_price = balance_checker.get_usd_price('BTC')
has_btc_price = btc_price > 0
print_test("Get BTC USD price", has_btc_price, f"${btc_price:.2f}" if has_btc_price else "Failed")
# Note: Balance checking requires valid addresses and may hit rate limits
print_test("Balance checker ready", True, "Note: Address checks require valid API keys")
return True
except Exception as e:
print_test("Balance checker test", False, str(e))
return False
def test_database():
"""Test Database Manager"""
print_section("Testing Database Manager")
try:
from ext import EnhancedDatabaseManager
# Test instantiation (creates DB)
db = EnhancedDatabaseManager()
print_test("EnhancedDatabaseManager instantiation", True)
# Test adding wallet
test_wallet = {
'address': '0x742d35Cc6634C0532925a3b844Bc9e7595f0bEb',
'crypto_type': 'ETH',
'balance': 0.0,
'wallet_source': 'test'
}
add_result = db.add_wallet(test_wallet)
print_test("Add wallet to database", add_result)
# Test getting statistics
stats = db.get_statistics()
has_stats = stats is not None and 'total_wallets' in stats
print_test("Get database statistics", has_stats, f"Total wallets: {stats.get('total_wallets', 0)}")
# Test adding credential
test_cred = {
'email': 'test@example.com',
'password': 'testpass123',
'category': 'test',
'source_file': 'test.txt'
}
cred_result = db.add_credential(test_cred)
print_test("Add credential to database", cred_result)
return True
except Exception as e:
print_test("Database test", False, str(e))
import traceback
traceback.print_exc()
return False
def test_email_validator():
"""Test Email Validator"""
print_section("Testing Email Validator")
try:
from ext import EmailValidator
validator = EmailValidator()
print_test("EmailValidator instantiation", True)
# Test SMTP server detection
smtp_server = validator.get_smtp_server('test@gmail.com')
has_smtp = smtp_server is not None
print_test("Detect Gmail SMTP server", has_smtp, f"{smtp_server[0]}:{smtp_server[1]}" if has_smtp else "None")
# Test premium email detection
is_premium = validator.is_premium_email('test@comcast.net')
print_test("Detect premium email", is_premium, "comcast.net is premium")
# Test SMS gateway detection
has_sms = validator.has_sms_gateway('test@att.net')
print_test("Detect SMS gateway", has_sms, "att.net has SMS gateway")
print_test("Email validator ready", True, "Note: Actual validation requires valid credentials")
return True
except Exception as e:
print_test("Email validator test", False, str(e))
return False
def test_extractors():
"""Test Data Extractors"""
print_section("Testing Data Extractors")
try:
from ext import (
ComprehensivePrivateKeyExtractor,
SensitiveDataDetector,
EnhancedCryptoUtils,
AdvancedBalanceChecker,
APIConfig,
EnhancedDatabaseManager
)
# Setup dependencies
crypto = EnhancedCryptoUtils()
api_config = APIConfig()
balance_checker = AdvancedBalanceChecker(api_config)
db = EnhancedDatabaseManager()
def dummy_callback(msg, type="info"):
pass
# Test Private Key Extractor
pk_extractor = ComprehensivePrivateKeyExtractor(crypto, balance_checker, dummy_callback)
print_test("ComprehensivePrivateKeyExtractor instantiation", True)
# Test pattern recognition
test_content = """
Some text with a private key:
0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef
And more text
"""
# Create temp file for testing
import tempfile
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(test_content)
temp_file = f.name
pk_extractor.extract_all_key_formats(temp_file)
summary = pk_extractor.get_summary()
found_keys = summary['total_keys_found'] > 0
print_test("Extract private key from file", found_keys, f"Found {summary['total_keys_found']} key(s)")
# Cleanup
os.unlink(temp_file)
# Test Sensitive Data Detector
sensitive_detector = SensitiveDataDetector(db, dummy_callback)
print_test("SensitiveDataDetector instantiation", True)
# Test pattern detection (obfuscated for security)
test_sensitive = """
AWS_ACCESS_KEY_ID=AKIA0000000000000000
payment_api_key=test_key_placeholder_only
"""
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(test_sensitive)
temp_file2 = f.name
sensitive_detector.scan_file_for_sensitive_data(temp_file2)
found_sensitive = len(sensitive_detector.found_data) > 0
print_test("Detect sensitive data patterns", found_sensitive, f"Found {len(sensitive_detector.found_data)} item(s)")
os.unlink(temp_file2)
return True
except Exception as e:
print_test("Extractors test", False, str(e))
import traceback
traceback.print_exc()
return False
def test_sms_detector():
"""Test SMS API Detector"""
print_section("Testing SMS API Detector")
try:
from ext import SMSAPIDetector
detector = SMSAPIDetector()
print_test("SMSAPIDetector instantiation", True)
# Test pattern detection
test_content = """
TWILIO_ACCOUNT_SID=AC1234567890abcdef1234567890abcd
TWILIO_AUTH_TOKEN=1234567890abcdef1234567890abcdef
"""
import tempfile
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(test_content)
temp_file = f.name
found_apis = detector.scan_file_for_apis(temp_file)
has_found = len(found_apis) > 0
print_test("Detect Twilio credentials", has_found, f"Found {len(found_apis)} API(s)")
os.unlink(temp_file)
return True
except Exception as e:
print_test("SMS detector test", False, str(e))
return False
def test_hosting_detector():
"""Test Hosting Service Detector"""
print_section("Testing Hosting Service Detector")
try:
from ext import HostingServiceDetector
detector = HostingServiceDetector()
print_test("HostingServiceDetector instantiation", True)
# Test pattern detection
test_content = """
AWS_ACCESS_KEY_ID=AKIAIOSFODNN7EXAMPLE
cpanel_user=admin
cpanel_password=secretpass123
"""
import tempfile
with tempfile.NamedTemporaryFile(mode='w', suffix='.txt', delete=False) as f:
f.write(test_content)
temp_file = f.name
found_services = detector.scan_file_for_hosting(temp_file)
has_found = len(found_services) > 0
print_test("Detect hosting credentials", has_found, f"Found {len(found_services)} service(s)")
os.unlink(temp_file)
return True
except Exception as e:
print_test("Hosting detector test", False, str(e))
return False
def main():
"""Run all tests"""
print(f"\n{BLUE}{'='*60}")
print(" 🧪 LULZSEC FORENSIC SCANNER - MODULE TESTING")
print(f"{'='*60}{RESET}\n")
results = {}
# Run tests
results['imports'] = test_imports()
if not results['imports']:
print(f"\n{RED}❌ Import test failed. Cannot continue.{RESET}")
return False
results['api_config'] = test_api_config()
results['crypto'] = test_crypto_utils()
results['balance'] = test_balance_checker()
results['database'] = test_database()
results['email'] = test_email_validator()
results['extractors'] = test_extractors()
results['sms'] = test_sms_detector()
results['hosting'] = test_hosting_detector()
# Summary
print_section("Test Summary")
passed = sum(1 for v in results.values() if v)
total = len(results)
for test_name, result in results.items():
status = "✅ PASS" if result else "❌ FAIL"
color = GREEN if result else RED
print(f"{color}{status}{RESET} - {test_name}")
print(f"\n{BLUE}{'='*60}")
percentage = (passed / total * 100) if total > 0 else 0
color = GREEN if percentage >= 80 else YELLOW if percentage >= 60 else RED
print(f"{color}Results: {passed}/{total} tests passed ({percentage:.1f}%){RESET}")
print(f"{BLUE}{'='*60}{RESET}\n")
return passed == total
if __name__ == '__main__':
success = main()
sys.exit(0 if success else 1)