-
-
Notifications
You must be signed in to change notification settings - Fork 170
Expand file tree
/
Copy pathhackgpt_v2.py
More file actions
1029 lines (878 loc) · 42.6 KB
/
hackgpt_v2.py
File metadata and controls
1029 lines (878 loc) · 42.6 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
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
#!/usr/bin/env python3
"""
HackGPT - Enterprise AI-Powered Penetration Testing Platform
Author: HackGPT Team
Version: 2.0.0 (Production-Ready)
Description: Enterprise-grade pentesting automation platform with advanced AI, microservices architecture,
and cloud-native capabilities for professional security assessments.
Features:
- Advanced AI Engine with ML pattern recognition
- Enterprise authentication and RBAC
- Real-time analytics and reporting
- Microservices architecture with Docker/Kubernetes support
- Performance optimization with caching and parallel processing
- Database persistence with PostgreSQL
- Compliance framework integration (OWASP, NIST, ISO27001, SOC2)
- Zero-day detection with behavioral analysis
"""
import os
import sys
import json
import time
import asyncio
import argparse
import logging
import configparser
import subprocess
from datetime import datetime, timedelta
from pathlib import Path
import threading
import queue
import hashlib
import uuid
from typing import Dict, List, Any, Optional, Union
# Load environment variables
try:
from dotenv import load_dotenv
load_dotenv()
except ImportError:
pass
# Core imports with fallback handling
def safe_import(module_name, package=None):
"""Safely import modules with error handling"""
try:
if package:
return __import__(package, fromlist=[module_name])
else:
return __import__(module_name)
except ImportError:
return None
# Essential imports
from rich.console import Console
from rich.table import Table
from rich.panel import Panel
from rich.progress import Progress, SpinnerColumn, TextColumn, BarColumn
from rich.prompt import Prompt, Confirm
from rich.markdown import Markdown
# Optional imports
requests = safe_import('requests')
openai = safe_import('openai')
flask = safe_import('flask')
redis = safe_import('redis')
psycopg2 = safe_import('psycopg2')
sqlalchemy = safe_import('sqlalchemy')
docker = safe_import('docker')
consul = safe_import('consul')
jwt = safe_import('jwt')
bcrypt = safe_import('bcrypt')
sr = safe_import('speech_recognition')
pyttsx3 = safe_import('pyttsx3')
numpy = safe_import('numpy')
pandas = safe_import('pandas')
# Import our custom modules
try:
from database import get_db_manager, PentestSession, Vulnerability, User, AuditLog
from ai_engine import get_advanced_ai_engine
from security import EnterpriseAuth, ComplianceFrameworkMapper
from exploitation import AdvancedExploitationEngine, ZeroDayDetector
from reporting import DynamicReportGenerator, get_realtime_dashboard
from cloud import DockerManager, KubernetesManager, ServiceRegistry
from performance import get_cache_manager, get_parallel_processor
MODULES_AVAILABLE = True
except ImportError as e:
print(f"Warning: Some modules not available: {e}")
MODULES_AVAILABLE = False
# Initialize Rich Console
console = Console()
# Configuration
class Config:
"""Application configuration manager"""
def __init__(self, config_file: str = "config.ini"):
self.config = configparser.ConfigParser()
self.config_file = config_file
self.load_config()
# Environment variables override config file
self.DATABASE_URL = os.getenv("DATABASE_URL", self.config.get("database", "url", fallback="postgresql://hackgpt:hackgpt123@localhost:5432/hackgpt"))
self.REDIS_URL = os.getenv("REDIS_URL", self.config.get("cache", "redis_url", fallback="redis://localhost:6379/0"))
self.OPENAI_API_KEY = os.getenv("OPENAI_API_KEY", self.config.get("ai", "openai_api_key", fallback=""))
self.SECRET_KEY = os.getenv("SECRET_KEY", self.config.get("security", "secret_key", fallback=str(uuid.uuid4())))
self.LDAP_SERVER = os.getenv("LDAP_SERVER", self.config.get("ldap", "server", fallback=""))
self.LDAP_BIND_DN = os.getenv("LDAP_BIND_DN", self.config.get("ldap", "bind_dn", fallback=""))
self.LDAP_BIND_PASSWORD = os.getenv("LDAP_BIND_PASSWORD", self.config.get("ldap", "bind_password", fallback=""))
# Application settings
self.DEBUG = self.config.getboolean("app", "debug", fallback=False)
self.LOG_LEVEL = self.config.get("app", "log_level", fallback="INFO")
self.MAX_WORKERS = self.config.getint("performance", "max_workers", fallback=10)
self.ENABLE_VOICE = self.config.getboolean("features", "enable_voice", fallback=True)
self.ENABLE_WEB_DASHBOARD = self.config.getboolean("features", "enable_web_dashboard", fallback=True)
self.ENABLE_REALTIME_DASHBOARD = self.config.getboolean("features", "enable_realtime_dashboard", fallback=True)
# Cloud settings
self.DOCKER_HOST = os.getenv("DOCKER_HOST", self.config.get("cloud", "docker_host", fallback="unix:///var/run/docker.sock"))
self.KUBERNETES_CONFIG = os.getenv("KUBECONFIG", self.config.get("cloud", "kubernetes_config", fallback=""))
self.SERVICE_REGISTRY_BACKEND = self.config.get("cloud", "service_registry_backend", fallback="memory")
def load_config(self):
"""Load configuration from file"""
if os.path.exists(self.config_file):
self.config.read(self.config_file)
else:
self.create_default_config()
def create_default_config(self):
"""Create default configuration file"""
sections = {
"app": {"debug": "false", "log_level": "INFO"},
"database": {"url": "postgresql://hackgpt:hackgpt123@localhost:5432/hackgpt"},
"cache": {"redis_url": "redis://localhost:6379/0"},
"ai": {"openai_api_key": "", "local_model": "llama2:7b"},
"security": {"secret_key": str(uuid.uuid4()), "jwt_algorithm": "HS256", "jwt_expiry": "3600"},
"ldap": {"server": "", "bind_dn": "", "bind_password": ""},
"performance": {"max_workers": "10", "cache_ttl": "3600"},
"features": {"enable_voice": "true", "enable_web_dashboard": "true", "enable_realtime_dashboard": "true"},
"cloud": {"docker_host": "unix:///var/run/docker.sock", "kubernetes_config": "", "service_registry_backend": "memory"}
}
for section_name, options in sections.items():
self.config.add_section(section_name)
for option, value in options.items():
self.config.set(section_name, option, value)
with open(self.config_file, 'w') as f:
self.config.write(f)
# Initialize configuration
config = Config()
# Setup logging
log_dir = Path("/var/log")
if not log_dir.exists() or not os.access(log_dir, os.W_OK):
log_dir = Path.cwd() / "logs"
log_dir.mkdir(exist_ok=True)
logging.basicConfig(
level=getattr(logging, config.LOG_LEVEL),
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_dir / 'hackgpt.log'),
logging.StreamHandler()
]
)
logger = logging.getLogger('hackgpt')
# ASCII Banner
BANNER = """
[bold red]
██╗ ██╗ █████╗ ██████╗██╗ ██╗ ██████╗ ██████╗ ████████╗
██║ ██║██╔══██╗██╔════╝██║ ██╔╝██╔════╝ ██╔══██╗╚══██╔══╝
███████║███████║██║ █████╔╝ ██║ ███╗██████╔╝ ██║
██╔══██║██╔══██║██║ ██╔═██╗ ██║ ██║██╔═══╝ ██║
██║ ██║██║ ██║╚██████╗██║ ██╗╚██████╔╝██║ ██║
╚═╝ ╚═╝╚═╝ ╚═╝ ╚═════╝╚═╝ ╚═╝ ╚═════╝ ╚═╝ ╚═╝
[/bold red]
[bold cyan] Enterprise AI-Powered Penetration Testing Platform v2.0[/bold cyan]
[bold green] Production-Ready | Cloud-Native | AI-Enhanced[/bold green]
[dim] Advanced Security Assessment Platform[/dim]
"""
class EnterpriseHackGPT:
"""Main HackGPT Enterprise Application"""
def __init__(self):
self.config = config
self.console = Console()
self.logger = logging.getLogger('hackgpt.main')
# Initialize components
self.initialize_components()
# Initialize services
self.initialize_services()
# Setup signal handlers
self.setup_signal_handlers()
def initialize_components(self):
"""Initialize core components"""
# Initialize all attributes first with fallback values
self.auth = None
self.cache = None
self.processor = None
self.compliance = None
self.db = None
try:
# Database
if MODULES_AVAILABLE:
self.db = get_db_manager()
self.console.print("[green]✓[/green] Database connection initialized")
else:
self.db = None
self.console.print("[yellow]⚠[/yellow] Database not available")
# AI Engine
if MODULES_AVAILABLE and (config.OPENAI_API_KEY or self.check_local_llm()):
self.ai_engine = get_advanced_ai_engine()
self.console.print("[green]✓[/green] Advanced AI Engine initialized")
else:
self.ai_engine = self.create_fallback_ai()
self.console.print("[yellow]⚠[/yellow] Using fallback AI engine")
# Authentication
if MODULES_AVAILABLE:
try:
self.auth = EnterpriseAuth()
self.console.print("[green]✓[/green] Enterprise authentication initialized")
except Exception as e:
self.auth = None
self.console.print(f"[yellow]⚠[/yellow] Authentication not available: {str(e)}")
else:
self.auth = None
self.console.print("[yellow]⚠[/yellow] Authentication not available")
# Cache Manager
if MODULES_AVAILABLE:
try:
self.cache = get_cache_manager()
self.console.print("[green]✓[/green] Cache manager initialized")
except Exception as e:
self.cache = None
self.console.print(f"[yellow]⚠[/yellow] Cache not available: {str(e)}")
else:
self.cache = None
self.console.print("[yellow]⚠[/yellow] Cache not available")
# Parallel Processor
if MODULES_AVAILABLE:
try:
self.processor = get_parallel_processor()
self.console.print("[green]✓[/green] Parallel processor initialized")
except Exception as e:
self.processor = None
self.console.print(f"[yellow]⚠[/yellow] Parallel processing not available: {str(e)}")
else:
self.processor = None
self.console.print("[yellow]⚠[/yellow] Parallel processing not available")
# Tool Manager
self.tool_manager = EnterpriseToolManager()
self.console.print("[green]✓[/green] Enterprise tool manager initialized")
# Compliance Framework
if MODULES_AVAILABLE:
self.compliance = ComplianceFrameworkMapper()
self.console.print("[green]✓[/green] Compliance framework initialized")
else:
self.compliance = None
self.console.print("[yellow]⚠[/yellow] Compliance framework not available")
# Exploitation Engine
if MODULES_AVAILABLE:
self.exploitation = AdvancedExploitationEngine()
self.zero_day_detector = ZeroDayDetector()
self.console.print("[green]✓[/green] Advanced exploitation engine initialized")
else:
self.exploitation = None
self.zero_day_detector = None
self.console.print("[yellow]⚠[/yellow] Advanced exploitation not available")
# Reporting
if MODULES_AVAILABLE:
self.report_generator = DynamicReportGenerator()
self.console.print("[green]✓[/green] Dynamic report generator initialized")
else:
self.report_generator = BasicReportGenerator()
self.console.print("[yellow]⚠[/yellow] Using basic report generator")
except Exception as e:
self.logger.error(f"Error initializing components: {e}")
self.console.print(f"[red]Error initializing components: {e}[/red]")
def initialize_services(self):
"""Initialize enterprise services"""
try:
# Cloud services
if MODULES_AVAILABLE and docker:
self.docker_manager = DockerManager()
self.console.print("[green]✓[/green] Docker manager initialized")
else:
self.docker_manager = None
self.console.print("[yellow]⚠[/yellow] Docker not available")
if MODULES_AVAILABLE:
self.k8s_manager = KubernetesManager()
self.service_registry = ServiceRegistry(backend=config.SERVICE_REGISTRY_BACKEND)
self.console.print("[green]✓[/green] Cloud services initialized")
else:
self.k8s_manager = None
self.service_registry = None
self.console.print("[yellow]⚠[/yellow] Cloud services not available")
# Voice interface
if config.ENABLE_VOICE and sr and pyttsx3:
self.voice_interface = EnterpriseVoiceInterface()
self.console.print("[green]✓[/green] Voice interface initialized")
else:
self.voice_interface = None
self.console.print("[yellow]⚠[/yellow] Voice interface not available")
# Web dashboard
if config.ENABLE_WEB_DASHBOARD and flask:
self.web_dashboard = EnterpriseWebDashboard(self)
self.console.print("[green]✓[/green] Web dashboard initialized")
else:
self.web_dashboard = None
self.console.print("[yellow]⚠[/yellow] Web dashboard not available")
# Real-time dashboard
if config.ENABLE_REALTIME_DASHBOARD and MODULES_AVAILABLE:
self.realtime_dashboard = get_realtime_dashboard()
self.console.print("[green]✓[/green] Real-time dashboard initialized")
else:
self.realtime_dashboard = None
self.console.print("[yellow]⚠[/yellow] Real-time dashboard not available")
except Exception as e:
self.logger.error(f"Error initializing services: {e}")
self.console.print(f"[red]Error initializing services: {e}[/red]")
def check_local_llm(self):
"""Check if local LLM is available"""
try:
result = subprocess.run(['which', 'ollama'], capture_output=True, text=True)
return result.returncode == 0
except Exception:
return False
def create_fallback_ai(self):
"""Create fallback AI engine"""
class FallbackAI:
def __init__(self):
self.console = Console()
def analyze(self, context, data, phase="general"):
return f"[Fallback AI Analysis]\nContext: {context}\nPhase: {phase}\nRecommendation: Please configure AI engine for detailed analysis."
def correlate_vulnerabilities(self, vulnerabilities):
return {"correlation": "basic", "risk_score": 5.0}
def generate_exploit_suggestions(self, vulnerability_data):
return ["Manual verification recommended", "Check CVE database", "Test with standard tools"]
def detect_anomalies(self, data):
return {"anomalies": [], "confidence": 0.0}
return FallbackAI()
def setup_signal_handlers(self):
"""Setup graceful shutdown signal handlers"""
import signal
def signal_handler(signum, frame):
self.logger.info(f"Received signal {signum}, shutting down gracefully...")
self.shutdown()
sys.exit(0)
signal.signal(signal.SIGINT, signal_handler)
signal.signal(signal.SIGTERM, signal_handler)
def show_banner(self):
"""Display the HackGPT banner with system status"""
self.console.print(BANNER)
# System status
status_table = Table(title="System Status", show_header=True)
status_table.add_column("Component", style="cyan")
status_table.add_column("Status", style="green")
status_table.add_column("Version", style="yellow")
components = [
("Database", "✓ Connected" if self.db else "⚠ Not Available", "PostgreSQL"),
("AI Engine", "✓ Advanced" if MODULES_AVAILABLE else "⚠ Fallback", "ML-Enhanced"),
("Authentication", "✓ Enterprise" if self.auth else "⚠ Basic", "RBAC+LDAP"),
("Cache", "✓ Multi-Layer" if self.cache else "⚠ None", "Redis+Memory"),
("Parallel Processing", "✓ Available" if self.processor else "⚠ Sequential", f"{config.MAX_WORKERS} workers"),
("Cloud Services", "✓ Ready" if self.docker_manager else "⚠ Not Available", "Docker+K8s"),
("Compliance", "✓ Integrated" if self.compliance else "⚠ Manual", "OWASP+NIST"),
("Real-time Dashboard", "✓ Active" if self.realtime_dashboard else "⚠ Disabled", "WebSocket")
]
for name, status, version in components:
status_table.add_row(name, status, version)
self.console.print(status_table)
def show_main_menu(self):
"""Display enhanced main menu"""
menu_table = Table(title="HackGPT Enterprise Main Menu", show_header=True)
menu_table.add_column("Option", style="cyan", width=8)
menu_table.add_column("Category", style="magenta", width=20)
menu_table.add_column("Description", style="white")
menu_options = [
("1", "Assessment", "Full Enterprise Pentest (All 6 Phases)"),
("2", "Assessment", "Run Specific Phase"),
("3", "Assessment", "Custom Assessment Workflow"),
("4", "Reporting", "View Reports & Analytics"),
("5", "Reporting", "Generate Executive Summary"),
("6", "Reporting", "Real-time Dashboard"),
("7", "Administration", "User & Permission Management"),
("8", "Administration", "System Configuration"),
("9", "Administration", "Compliance Management"),
("10", "Cloud", "Cloud & Container Management"),
("11", "AI", "AI Engine Configuration"),
("12", "Tools", "Tool Management & Updates"),
("13", "API", "Start API Server"),
("14", "Voice", "Voice Command Mode"),
("15", "Web", "Launch Web Dashboard"),
("0", "System", "Exit Application")
]
for option, category, description in menu_options:
menu_table.add_row(option, category, description)
self.console.print(menu_table)
def get_target_info(self):
"""Get comprehensive target information"""
self.console.print(Panel("[bold cyan]Target Information Collection[/bold cyan]"))
target = Prompt.ask("[cyan]Enter target (IP/domain/CIDR)[/cyan]")
scope = Prompt.ask("[cyan]Enter scope description[/cyan]")
# Assessment type
assessment_types = ["black-box", "white-box", "gray-box"]
assessment_type = Prompt.ask(
"[cyan]Assessment type[/cyan]",
choices=assessment_types,
default="black-box"
)
# Compliance frameworks
if self.compliance:
frameworks = ["OWASP", "NIST", "ISO27001", "SOC2", "PCI-DSS"]
compliance_framework = Prompt.ask(
"[cyan]Compliance framework[/cyan]",
choices=frameworks,
default="OWASP"
)
else:
compliance_framework = "OWASP"
# Authorization
auth_key = Prompt.ask("[cyan]Enter authorization key[/cyan]", password=True)
# Additional options
parallel_execution = Confirm.ask("[cyan]Enable parallel execution?[/cyan]", default=True)
ai_enhanced = Confirm.ask("[cyan]Enable AI-enhanced analysis?[/cyan]", default=True)
return {
"target": target,
"scope": scope,
"assessment_type": assessment_type,
"compliance_framework": compliance_framework,
"auth_key": auth_key,
"parallel_execution": parallel_execution,
"ai_enhanced": ai_enhanced,
"timestamp": datetime.utcnow()
}
def run_full_enterprise_pentest(self, target_info=None):
"""Run comprehensive enterprise penetration test"""
if not target_info:
target_info = self.get_target_info()
if not target_info["target"]:
return
self.console.print(f"[green]Starting Enterprise Pentest: {target_info['target']}[/green]")
# Create session in database
if self.db:
session = self.db.create_pentest_session(
target=target_info["target"],
scope=target_info["scope"],
assessment_type=target_info["assessment_type"],
compliance_framework=target_info["compliance_framework"]
)
session_id = session.session_id
else:
session_id = str(uuid.uuid4())
# Initialize enterprise pentesting phases
phases = EnterprisePentestingPhases(
session_id=session_id,
ai_engine=self.ai_engine,
tool_manager=self.tool_manager,
target_info=target_info,
db=self.db,
cache=self.cache,
processor=self.processor,
exploitation=self.exploitation,
zero_day_detector=self.zero_day_detector,
compliance=self.compliance,
report_generator=self.report_generator
)
try:
with Progress(
SpinnerColumn(),
TextColumn("[progress.description]{task.description}"),
BarColumn(),
TextColumn("[progress.percentage]{task.percentage:>3.0f}%"),
console=self.console
) as progress:
# Execute all phases
phase_tasks = [
("Phase 1: Intelligence Gathering & Reconnaissance", phases.phase1_reconnaissance),
("Phase 2: Advanced Scanning & Enumeration", phases.phase2_scanning_enumeration),
("Phase 3: Vulnerability Assessment", phases.phase3_vulnerability_assessment),
("Phase 4: Exploitation & Post-Exploitation", phases.phase4_exploitation),
("Phase 5: Enterprise Reporting & Analytics", phases.phase5_reporting),
("Phase 6: Verification & Retesting", phases.phase6_retesting)
]
for phase_name, phase_method in phase_tasks:
task = progress.add_task(phase_name, total=100)
progress.update(task, advance=10)
result = phase_method()
progress.update(task, completed=100)
if not result.get("success", True):
self.console.print(f"[red]Phase failed: {phase_name}[/red]")
break
self.console.print("[bold green]Enterprise Pentest Completed Successfully![/bold green]")
if self.db:
session.status = "completed"
session.completed_at = datetime.utcnow()
self.db.update_session(session)
# Show summary
self.show_pentest_summary(session_id, phases.results)
except KeyboardInterrupt:
self.console.print("[yellow]Pentest interrupted by user[/yellow]")
if self.db and session:
session.status = "cancelled"
self.db.update_session(session)
except Exception as e:
self.logger.error(f"Error during pentest: {e}")
self.console.print(f"[red]Error during pentest: {e}[/red]")
if self.db and session:
session.status = "failed"
session.error_message = str(e)
self.db.update_session(session)
def show_pentest_summary(self, session_id: str, results: Dict):
"""Show pentest summary"""
summary_table = Table(title=f"Pentest Summary - Session {session_id[:8]}")
summary_table.add_column("Phase", style="cyan")
summary_table.add_column("Status", style="green")
summary_table.add_column("Findings", style="yellow")
summary_table.add_column("Risk Score", style="red")
for phase_name, phase_results in results.items():
status = "✓ Complete" if phase_results.get("success") else "✗ Failed"
findings_count = len(phase_results.get("vulnerabilities", []))
risk_score = phase_results.get("risk_score", 0.0)
summary_table.add_row(
phase_name.replace("_", " ").title(),
status,
str(findings_count),
f"{risk_score:.1f}"
)
self.console.print(summary_table)
def manage_cloud_services(self):
"""Manage cloud and container services"""
if not self.docker_manager:
self.console.print("[red]Cloud services not available[/red]")
return
cloud_menu = Table(title="Cloud & Container Management")
cloud_menu.add_column("Option", style="cyan")
cloud_menu.add_column("Description", style="white")
cloud_options = [
("1", "View Docker Containers"),
("2", "Deploy HackGPT Stack"),
("3", "Kubernetes Management"),
("4", "Service Registry Status"),
("5", "Scale Services"),
("0", "Return to Main Menu")
]
for option, description in cloud_options:
cloud_menu.add_row(option, description)
self.console.print(cloud_menu)
choice = Prompt.ask("[cyan]Select option[/cyan]",
choices=[opt[0] for opt in cloud_options])
if choice == "1":
self.show_docker_status()
elif choice == "2":
self.deploy_hackgpt_stack()
elif choice == "3":
self.manage_kubernetes()
elif choice == "4":
self.show_service_registry_status()
elif choice == "5":
self.scale_services()
def show_docker_status(self):
"""Show Docker container status"""
try:
if self.docker_manager.is_docker_available():
containers = self.docker_manager.client.containers.list(all=True)
if containers:
container_table = Table(title="Docker Containers")
container_table.add_column("Name", style="cyan")
container_table.add_column("Image", style="yellow")
container_table.add_column("Status", style="green")
container_table.add_column("Ports", style="blue")
for container in containers:
ports = ", ".join([f"{p['HostPort']}:{p['PrivatePort']}"
for p in container.attrs['NetworkSettings']['Ports'].values()
if p]) if container.attrs['NetworkSettings']['Ports'] else "None"
container_table.add_row(
container.name,
container.image.tags[0] if container.image.tags else "Unknown",
container.status,
ports
)
self.console.print(container_table)
else:
self.console.print("[yellow]No Docker containers found[/yellow]")
else:
self.console.print("[red]Docker not available[/red]")
except Exception as e:
self.console.print(f"[red]Error accessing Docker: {e}[/red]")
def deploy_hackgpt_stack(self):
"""Deploy HackGPT microservices stack"""
if not self.docker_manager:
return
self.console.print("[cyan]Deploying HackGPT Enterprise Stack...[/cyan]")
# Create services configuration
from cloud.docker_manager import ServiceDefinition, ContainerConfig
services = [
ServiceDefinition(
service_name="hackgpt-api",
container_config=ContainerConfig(
name="hackgpt-api",
image="hackgpt/api:latest",
ports={"8000": 8000},
environment={"DATABASE_URL": config.DATABASE_URL, "REDIS_URL": config.REDIS_URL},
volumes={"/app/logs": "/var/log/hackgpt"}
),
dependencies=[],
health_check={"test": ["CMD", "curl", "-f", "http://localhost:8000/health"]},
scaling={"min_replicas": 1, "max_replicas": 5}
),
ServiceDefinition(
service_name="hackgpt-worker",
container_config=ContainerConfig(
name="hackgpt-worker",
image="hackgpt/worker:latest",
environment={"DATABASE_URL": config.DATABASE_URL, "REDIS_URL": config.REDIS_URL}
),
dependencies=["hackgpt-database", "hackgpt-redis"],
health_check={"test": ["CMD", "python", "-c", "import sys; sys.exit(0)"]},
scaling={"min_replicas": 2, "max_replicas": 10}
)
]
# Generate docker-compose file
compose_content = self.docker_manager.generate_docker_compose(services)
# Deploy stack
success = self.docker_manager.deploy_stack(compose_content, "hackgpt-enterprise")
if success:
self.console.print("[green]✓ HackGPT Enterprise Stack deployed successfully[/green]")
else:
self.console.print("[red]✗ Failed to deploy HackGPT Enterprise Stack[/red]")
def start_api_server(self):
"""Start HackGPT API server"""
if not flask:
self.console.print("[red]Flask not available for API server[/red]")
return
from flask import Flask, request, jsonify
from flask_cors import CORS
app = Flask(__name__)
CORS(app)
app.secret_key = config.SECRET_KEY
@app.route('/api/health', methods=['GET'])
def health_check():
return jsonify({
"status": "healthy",
"version": "2.0.0",
"timestamp": datetime.utcnow().isoformat()
})
@app.route('/api/pentest/start', methods=['POST'])
def start_pentest():
try:
data = request.json
target_info = {
"target": data.get("target"),
"scope": data.get("scope"),
"assessment_type": data.get("assessment_type", "black-box"),
"compliance_framework": data.get("compliance_framework", "OWASP"),
"auth_key": data.get("auth_key"),
"parallel_execution": data.get("parallel_execution", True),
"ai_enhanced": data.get("ai_enhanced", True)
}
# Start pentest in background
thread = threading.Thread(
target=self.run_full_enterprise_pentest,
args=(target_info,)
)
thread.start()
return jsonify({
"status": "started",
"message": "Enterprise pentest initiated"
})
except Exception as e:
return jsonify({
"status": "error",
"message": str(e)
}), 500
@app.route('/api/sessions', methods=['GET'])
def get_sessions():
if not self.db:
return jsonify({"error": "Database not available"}), 503
sessions = self.db.get_recent_sessions(limit=50)
return jsonify([{
"session_id": s.session_id,
"target": s.target,
"status": s.status,
"created_at": s.created_at.isoformat(),
"completed_at": s.completed_at.isoformat() if s.completed_at else None
} for s in sessions])
self.console.print("[cyan]Starting HackGPT API Server on http://0.0.0.0:8000[/cyan]")
app.run(host='0.0.0.0', port=8000, debug=config.DEBUG)
def run(self):
"""Main application loop"""
self.show_banner()
while True:
try:
self.show_main_menu()
choice = Prompt.ask("[cyan]Select option[/cyan]",
choices=[str(i) for i in range(16)])
if choice == "0":
self.console.print("[green]Shutting down HackGPT Enterprise...[/green]")
self.shutdown()
break
elif choice == "1":
self.run_full_enterprise_pentest()
elif choice == "2":
self.run_specific_phase()
elif choice == "3":
self.run_custom_workflow()
elif choice == "4":
self.view_reports_analytics()
elif choice == "5":
self.generate_executive_summary()
elif choice == "6":
self.start_realtime_dashboard()
elif choice == "7":
self.manage_users_permissions()
elif choice == "8":
self.system_configuration()
elif choice == "9":
self.compliance_management()
elif choice == "10":
self.manage_cloud_services()
elif choice == "11":
self.configure_ai_engine()
elif choice == "12":
self.manage_tools()
elif choice == "13":
self.start_api_server()
elif choice == "14":
self.voice_command_mode()
elif choice == "15":
self.launch_web_dashboard()
except KeyboardInterrupt:
self.console.print("\n[yellow]Use option 0 to exit properly[/yellow]")
except Exception as e:
self.logger.error(f"Application error: {e}")
self.console.print(f"[red]Error: {e}[/red]")
def shutdown(self):
"""Graceful shutdown of all services"""
self.console.print("[cyan]Shutting down services...[/cyan]")
try:
if self.processor:
self.processor.stop()
if self.service_registry:
self.service_registry.stop()
if self.realtime_dashboard:
self.realtime_dashboard.running = False
self.console.print("[green]All services shut down successfully[/green]")
except Exception as e:
self.logger.error(f"Error during shutdown: {e}")
# Placeholder classes for missing components
class EnterpriseToolManager:
"""Enterprise tool manager with advanced features"""
def __init__(self):
self.console = Console()
self.installed_tools = set()
self.tool_versions = {}
def ensure_tools(self, tools):
"""Ensure tools are installed"""
missing = [t for t in tools if not self.check_tool(t)]
if missing:
self.console.print(f"[yellow]Missing tools: {', '.join(missing)}[/yellow]")
for tool in missing:
self.install_tool(tool)
return True
def check_tool(self, tool_name):
"""Check if tool is available"""
try:
result = subprocess.run(['which', tool_name], capture_output=True)
return result.returncode == 0
except Exception:
return False
def install_tool(self, tool_name):
"""Install a tool"""
try:
subprocess.run(['sudo', 'apt', 'install', '-y', tool_name], check=True)
self.installed_tools.add(tool_name)
return True
except Exception:
return False
class EnterprisePentestingPhases:
"""Enterprise pentesting phases with advanced features"""
def __init__(self, session_id, ai_engine, tool_manager, target_info, db, cache, processor, exploitation, zero_day_detector, compliance, report_generator):
self.session_id = session_id
self.ai_engine = ai_engine
self.tool_manager = tool_manager
self.target_info = target_info
self.db = db
self.cache = cache
self.processor = processor
self.exploitation = exploitation
self.zero_day_detector = zero_day_detector
self.compliance = compliance
self.report_generator = report_generator
self.results = {}
def phase1_reconnaissance(self):
"""Phase 1: Intelligence Gathering & Reconnaissance"""
console.print(Panel("[bold blue]Phase 1: Intelligence Gathering & Reconnaissance[/bold blue]"))
result = {"success": True, "vulnerabilities": [], "risk_score": 1.0}
self.results["phase1_reconnaissance"] = result
return result
def phase2_scanning_enumeration(self):
"""Phase 2: Advanced Scanning & Enumeration"""
console.print(Panel("[bold blue]Phase 2: Advanced Scanning & Enumeration[/bold blue]"))
result = {"success": True, "vulnerabilities": [], "risk_score": 3.0}
self.results["phase2_scanning_enumeration"] = result
return result
def phase3_vulnerability_assessment(self):
"""Phase 3: Vulnerability Assessment"""
console.print(Panel("[bold blue]Phase 3: Vulnerability Assessment[/bold blue]"))
result = {"success": True, "vulnerabilities": [], "risk_score": 5.0}
self.results["phase3_vulnerability_assessment"] = result
return result
def phase4_exploitation(self):
"""Phase 4: Exploitation & Post-Exploitation"""
console.print(Panel("[bold red]Phase 4: Exploitation & Post-Exploitation[/bold red]"))
result = {"success": True, "vulnerabilities": [], "risk_score": 8.0}
self.results["phase4_exploitation"] = result
return result
def phase5_reporting(self):
"""Phase 5: Enterprise Reporting & Analytics"""
console.print(Panel("[bold blue]Phase 5: Enterprise Reporting & Analytics[/bold blue]"))
result = {"success": True, "vulnerabilities": [], "risk_score": 0.0}
self.results["phase5_reporting"] = result
return result
def phase6_retesting(self):
"""Phase 6: Verification & Retesting"""
console.print(Panel("[bold blue]Phase 6: Verification & Retesting[/bold blue]"))
result = {"success": True, "vulnerabilities": [], "risk_score": 0.0}
self.results["phase6_retesting"] = result
return result
class EnterpriseVoiceInterface:
"""Enterprise voice interface"""
def __init__(self):
self.console = Console()
def listen_for_command(self):
return None
def speak(self, text):
pass
class EnterpriseWebDashboard:
"""Enterprise web dashboard"""
def __init__(self, hackgpt_instance):
self.hackgpt = hackgpt_instance
def run(self):
pass
class BasicReportGenerator:
"""Basic report generator fallback"""
def __init__(self):
pass
def generate_report(self, session_id, results):
return {"report": "Basic report generated"}
def main():
"""Entry point for HackGPT Enterprise"""
parser = argparse.ArgumentParser(description="HackGPT Enterprise - AI-Powered Penetration Testing Platform")
parser.add_argument('--target', help='Target IP or domain')
parser.add_argument('--scope', help='Scope description')
parser.add_argument('--auth-key', help='Authorization key')
parser.add_argument('--assessment-type', choices=['black-box', 'white-box', 'gray-box'], default='black-box')
parser.add_argument('--compliance', choices=['OWASP', 'NIST', 'ISO27001', 'SOC2'], default='OWASP')
parser.add_argument('--api', action='store_true', help='Start API server only')
parser.add_argument('--web', action='store_true', help='Start web dashboard only')
parser.add_argument('--realtime', action='store_true', help='Start real-time dashboard only')
parser.add_argument('--config', default='config.ini', help='Configuration file path')
args = parser.parse_args()
# Update config file path if specified
if args.config != 'config.ini':
global config
config = Config(args.config)