-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathrun.py
More file actions
109 lines (92 loc) · 3.74 KB
/
run.py
File metadata and controls
109 lines (92 loc) · 3.74 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
#!/usr/bin/env python3
"""
Run script for Cobalt Strike Web Client
"""
import os
import sys
import logging
from pathlib import Path
# Add the current directory to Python path
current_dir = Path(__file__).parent
sys.path.insert(0, str(current_dir))
def setup_logging():
"""Setup logging configuration"""
log_dir = current_dir / 'logs'
log_dir.mkdir(exist_ok=True)
logging.basicConfig(
level=logging.INFO,
format='%(asctime)s - %(name)s - %(levelname)s - %(message)s',
handlers=[
logging.FileHandler(log_dir / 'app.log'),
logging.StreamHandler(sys.stdout)
]
)
def main():
"""Main entry point"""
try:
setup_logging()
logger = logging.getLogger(__name__)
logger.info("Starting Cobalt Strike Web Client...")
# Change to the application directory
os.chdir(current_dir)
# Import Flask app
sys.path.insert(0, str(current_dir / 'cobalt_web_client'))
from app import app
# Configuration
host = os.environ.get('HOST', '127.0.0.1')
port = int(os.environ.get('PORT', 5000))
debug = os.environ.get('FLASK_DEBUG', 'False').lower() == 'true'
use_ssl = os.environ.get('USE_SSL', 'false').lower() == 'true' # Default to HTTP for easier testing
logger.info(f"Server starting on {host}:{port}")
logger.info(f"Debug mode: {debug}")
logger.info(f"SSL enabled: {use_ssl}")
# SSL configuration
ssl_context = None
if use_ssl:
try:
# Try to use custom certificates first
cert_file = current_dir / 'certs' / 'cert.pem'
key_file = current_dir / 'certs' / 'key.pem'
if cert_file.exists() and key_file.exists():
ssl_context = (str(cert_file), str(key_file))
logger.info("Using custom SSL certificates")
else:
# Fall back to ad-hoc certificates
try:
ssl_context = 'adhoc'
logger.info("Using ad-hoc SSL certificates")
except ImportError:
logger.warning("Cryptography library not available, falling back to HTTP")
ssl_context = None
use_ssl = False
except Exception as e:
logger.warning(f"SSL setup failed: {e}, falling back to HTTP")
ssl_context = None
use_ssl = False
if not use_ssl:
logger.info("Running in HTTP mode")
print(f"\n🌐 Application starting at: http://{host}:{port}")
print("📝 To enable HTTPS, set USE_SSL=true in environment or .env file")
else:
print(f"\n🔒 Application starting at: https://{host}:{port}")
print("\n⚠️ Security Notice:")
print("This application connects to Cobalt Strike. Ensure proper authorization.")
print("All activities are logged and monitored.")
print("\n🚀 Starting server...\n")
# Run the application
app.run(
host=host,
port=port,
debug=debug,
ssl_context=ssl_context
)
except Exception as e:
logger.error(f"Failed to start application: {str(e)}")
print(f"\n❌ Error: {str(e)}")
print("\n💡 Troubleshooting tips:")
print("1. Ensure you're in the virtual environment: venv\\Scripts\\activate")
print("2. Install dependencies: pip install -r requirements.txt")
print("3. Check if port 5000 is available")
sys.exit(1)
if __name__ == '__main__':
main()