Skip to content

Commit 4ee4134

Browse files
committed
Enhance logging in C2 server with Rich library and update requirements
- Added 'rich' to requirements.txt for improved logging capabilities. - Refactored logging setup in c2_server_alt.py to utilize Rich for better formatting and readability. - Updated log messages to include color and formatting enhancements for clarity.
1 parent c289cc4 commit 4ee4134

File tree

2 files changed

+15
-12
lines changed

2 files changed

+15
-12
lines changed

c2_server/c2_server_alt.py

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,30 +12,33 @@
1212
import time
1313
from datetime import datetime
1414
import logging
15+
from rich.logging import RichHandler
1516

1617
# -----------------
1718
# LOGGING SETUP
1819
# -----------------
1920
def setup_logging():
20-
"""Setup logging for C2 server activities"""
21+
"""Setup rich logging for C2 server activities"""
2122
if not os.path.exists('logs'):
2223
os.makedirs('logs')
2324
timestamp = datetime.now().strftime("%Y%m%d_%H%M%S")
2425
log_filename = f'logs/c2_server_alt_{timestamp}.log'
26+
FORMAT = "[%(asctime)s] %(levelname)-8s %(message)s"
2527
logging.basicConfig(
26-
level=logging.INFO,
27-
format='%(asctime)s - %(levelname)s - %(message)s',
28+
level="INFO",
29+
format=FORMAT,
30+
datefmt="%Y-%m-%d %H:%M:%S",
2831
handlers=[
29-
logging.FileHandler(log_filename, encoding='utf-8'),
30-
logging.StreamHandler()
32+
RichHandler(rich_tracebacks=True, markup=True, show_time=False, show_level=True, show_path=False),
33+
logging.FileHandler(log_filename, encoding='utf-8')
3134
]
3235
)
33-
logger = logging.getLogger(__name__)
34-
logger.info("=" * 60)
35-
logger.info("C2 SERVER (ALT, HTTP POST) STARTED")
36-
logger.info("=" * 60)
37-
logger.info(f"Log file: {log_filename}")
38-
logger.info(f"Timestamp: {datetime.now().strftime('%Y-%m-%d %H:%M:%S')}")
36+
logger = logging.getLogger("rich")
37+
logger.info("[bold green]========================================[/bold green]")
38+
logger.info("[bold cyan]C2 SERVER (ALT, HTTP POST) STARTED[/bold cyan]")
39+
logger.info("[bold green]========================================[/bold green]")
40+
logger.info(f"Log file: [bold yellow]{log_filename}[/bold yellow]")
41+
logger.info(f"Timestamp: [bold magenta]{datetime.now().strftime('%Y-%m-%d %H:%M:%S')}[/bold magenta]")
3942
return logger
4043

4144
# -----------------

requirements.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,6 @@ pytest-qt
99
# tkinter (system package, e.g. python3-tk)
1010
pydantic-settings
1111
Flask
12-
12+
rich
1313
# For GUI
1414
# (tkinter is included with standard Python installations)

0 commit comments

Comments
 (0)