#!/bin/bash
# ===============================================
# NoctisAI Startup Script
# ===============================================
#
# This script starts all NoctisAI services for
# malware development and threat intelligence.
#
# Usage: ./start_noctis.sh
#
# ===============================================
# Change to the script's directory (NoctisAI root)
SCRIPT_DIR="$(cd "$(dirname "${BASH_SOURCE[0]}")" && pwd)"
PROJECT_ROOT="$(dirname "$SCRIPT_DIR")"
cd "$PROJECT_ROOT"
echo "🌙 NoctisAI - Malware Development & Threat Intelligence MCP"
echo "=========================================================="
echo ""
# Colors for output
RED='\033[0;31m'
GREEN='\033[0;32m'
YELLOW='\033[1;33m'
BLUE='\033[0;34m'
NC='\033[0m' # No Color
# Function to print colored output
print_status() {
echo -e "${BLUE}[INFO]${NC} $1"
}
print_success() {
echo -e "${GREEN}[SUCCESS]${NC} $1"
}
print_warning() {
echo -e "${YELLOW}[WARNING]${NC} $1"
}
print_error() {
echo -e "${RED}[ERROR]${NC} $1"
}
# Function to check if port is in use
check_port() {
local port=$1
if netstat -tlnp 2>/dev/null | grep -q ":$port "; then
return 0 # Port is in use
else
return 1 # Port is free
fi
}
# Function to check if virtual environment exists
check_venv() {
if [ ! -d "noctis-env" ]; then
print_error "Virtual environment not found. Please run setup first."
print_status "Run: ./scripts/setup_noctis.sh"
exit 1
fi
}
# Function to check Python dependencies
check_dependencies() {
print_status "Checking Python dependencies..."
source noctis-env/bin/activate
# Check if required packages are installed
python -c "
import sys
try:
import mcp
import fastapi
import requests
import yara
print('✅ Core dependencies available')
except ImportError as e:
print(f'❌ Missing dependency: {e}')
sys.exit(1)
"
if [ $? -ne 0 ]; then
print_error "Missing dependencies. Please run setup first."
exit 1
fi
print_success "All dependencies available"
}
# Function to start NoctisAI MCP server
start_mcp_server() {
print_status "Starting NoctisAI MCP server..."
# Check if port 8081 is available
if check_port 8081; then
print_warning "Port 8081 is already in use. NoctisAI MCP server may already be running."
return 0
fi
# Start MCP server in background
source noctis-env/bin/activate
python src/noctis_ai/mcp/noctis_mcp.py --debug > logs/noctis_mcp.log 2>&1 &
MCP_PID=$!
echo $MCP_PID > logs/noctis_mcp.pid
print_success "NoctisAI MCP server started with PID: $MCP_PID"
# Wait for server to be ready
print_status "Waiting for MCP server to be ready..."
for i in {1..10}; do
if curl -s http://localhost:8081/health > /dev/null 2>&1; then
print_success "NoctisAI MCP server is ready!"
break
fi
sleep 1
echo -n "."
done
echo
}
# Function to start NoctisAI services
start_services() {
print_status "Starting NoctisAI services..."
# Create logs directory if it doesn't exist
mkdir -p logs
# Start MCP server
start_mcp_server
print_success "All NoctisAI services started"
}
# Function to display service information
display_service_info() {
echo ""
echo "🌙 NoctisAI Services Status"
echo "=========================="
echo ""
# Check MCP server
if check_port 8081; then
print_success "NoctisAI MCP Server: Running (Port 8081)"
else
print_error "NoctisAI MCP Server: Not running"
fi
# Check Villager AI integration
if check_port 37695; then
print_success "Villager AI Integration: Available (Port 37695)"
else
print_warning "Villager AI Integration: Not available (Port 37695)"
fi
# Check HexStrike AI integration
if check_port 8000; then
print_success "HexStrike AI Integration: Available (Port 8000)"
else
print_warning "HexStrike AI Integration: Not available (Port 8000)"
fi
echo ""
echo "🔗 Service URLs:"
echo " • NoctisAI MCP Server: http://localhost:8081"
echo " • Villager AI: http://localhost:37695"
echo " • HexStrike AI: http://localhost:8000"
echo ""
echo "🛠️ Available NoctisAI Tools:"
echo " • Malware Development (Python, C/C++, Rust, Assembly)"
echo " • Threat Intelligence (IOC analysis, MITRE ATT&CK)"
echo " • OSINT & Reconnaissance (Domain intel, social engineering)"
echo " • Forensic Analysis (Memory, disk, network forensics)"
echo " • TheSilencer Integration (Enhanced C/C++ malware framework)"
echo ""
echo "📋 MCP Configuration:"
echo " Add the following to your MCP configuration:"
echo ""
cat noctis-mcp.json
echo ""
echo "🔧 Troubleshooting:"
echo " • Check logs: tail -f logs/noctis_mcp.log"
echo " • Restart services: ./scripts/start_noctis.sh"
echo " • Stop services: ./scripts/stop_noctis.sh"
echo ""
}
# Function to stop services
stop_services() {
print_status "Stopping NoctisAI services..."
# Stop MCP server
if [ -f "logs/noctis_mcp.pid" ]; then
MCP_PID=$(cat logs/noctis_mcp.pid)
if kill -0 $MCP_PID 2>/dev/null; then
kill $MCP_PID
print_success "NoctisAI MCP server stopped (PID: $MCP_PID)"
else
print_warning "NoctisAI MCP server was not running"
fi
rm -f logs/noctis_mcp.pid
else
print_warning "No PID file found for MCP server"
fi
print_success "All NoctisAI services stopped"
}
# Main execution
main() {
# Check if stop command was given
if [ "$1" = "stop" ]; then
stop_services
exit 0
fi
# Pre-flight checks
check_venv
check_dependencies
# Start services
start_services
# Display service information
display_service_info
print_success "🌙 NoctisAI is ready for malware development and threat intelligence!"
}
# Run main function
main "$@"