Skip to content

Stavin13/Threat-lens

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

12 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

ThreatLens - AI-Powered Security Log Analysis

ThreatLens is a comprehensive security log analysis platform that provides real-time threat detection, AI-powered analysis, and intuitive visualization of security events.

πŸš€ Features

  • Real-time Log Processing: Monitor security logs in real-time
  • AI-Powered Analysis: Advanced threat detection using machine learning
  • macOS Console Integration: Native support for macOS Console logs
  • Web Dashboard: Modern React-based user interface
  • WebSocket API: Real-time updates and notifications
  • Multi-format Support: Parse various log formats (syslog, Console, custom)
  • Threat Categorization: Automatic event classification
  • Historical Analysis: Search and analyze historical security events

πŸ“ Project Structure

threatlens/
β”œβ”€β”€ frontend/              # React TypeScript frontend
β”‚   β”œβ”€β”€ src/
β”‚   β”‚   β”œβ”€β”€ components/    # React components
β”‚   β”‚   β”œβ”€β”€ hooks/         # Custom React hooks
β”‚   β”‚   β”œβ”€β”€ services/      # API services
β”‚   β”‚   └── types/         # TypeScript definitions
β”‚   β”œβ”€β”€ public/            # Static assets
β”‚   └── package.json       # Frontend dependencies
β”‚
β”œβ”€β”€ backend/               # FastAPI Python backend
β”‚   β”œβ”€β”€ app/               # Main application code
β”‚   β”‚   β”œβ”€β”€ realtime/      # Real-time processing
β”‚   β”‚   β”œβ”€β”€ migrations/    # Database migrations
β”‚   β”‚   └── ...            # Core modules
β”‚   β”œβ”€β”€ tests/             # Backend tests
β”‚   β”œβ”€β”€ data/              # Sample data
β”‚   β”œβ”€β”€ scripts/           # Utility scripts
β”‚   β”œβ”€β”€ main.py            # API server entry point
β”‚   └── requirements.txt   # Python dependencies
β”‚
β”œβ”€β”€ docs/                  # Documentation
β”œβ”€β”€ docker-compose.yml     # Docker configuration
└── README.md              # This file

πŸ› οΈ Quick Start

Prerequisites

  • Node.js 16+ and npm (for frontend)
  • Python 3.8+ (for backend)
  • Docker (optional, for containerized deployment)

1. Backend Setup

cd backend

# Create virtual environment
python -m venv venv
source venv/bin/activate  # On Windows: venv\Scripts\activate

# Install dependencies
pip install -r requirements.txt

# Set up environment
python setup_env.py

# Start the backend server
python main.py

Backend will be available at: http://localhost:8000

2. Frontend Setup

cd frontend

# Install dependencies
npm install

# Start development server
npm run dev

Frontend will be available at: http://localhost:3000

3. Docker Setup (Alternative)

# Start both frontend and backend
docker-compose up -d

# View logs
docker-compose logs -f

πŸ”§ Configuration

Backend Configuration

Copy backend/.env.example to backend/.env and configure:

# Database
DATABASE_URL=sqlite:///./threatlens.db

# Security
SECRET_KEY=your-secret-key

# API Settings
DEBUG=true
LOG_LEVEL=INFO

Frontend Configuration

The frontend automatically connects to the backend API. For custom configurations, check frontend/src/services/api.ts.

πŸ“Š Usage

1. Log Ingestion

Web Interface:

  1. Navigate to http://localhost:3000/ingest
  2. Upload log files or paste log content
  3. Click "Analyze" to process

API:

# Upload file
curl -X POST -F "file=@logfile.log" http://localhost:8000/api/ingest/file

# Submit text
curl -X POST -H "Content-Type: application/json" \
  -d '{"content":"log content","source":"test"}' \
  http://localhost:8000/api/ingest/text

2. macOS Console Integration

cd backend

# Analyze recent Console logs
python scripts/console_integration.py

# Security-focused monitoring
python scripts/console_integration.py --mode security --hours 24

# Monitor specific process
python scripts/console_integration.py --mode process --process sshd

3. Real-time Monitoring

The system supports real-time log monitoring through WebSocket connections. Connect to ws://localhost:8000/ws for live updates.

πŸ§ͺ Testing

Backend Tests

cd backend
pytest                    # Run all tests
pytest --cov=app         # Run with coverage
pytest tests/test_parser.py  # Run specific test

Frontend Tests

cd frontend
npm test                  # Run tests
npm run test:coverage    # Run with coverage

πŸ” API Documentation

Once the backend is running, visit:

πŸš€ Deployment

Production Deployment

  1. Backend: Use Gunicorn with Uvicorn workers
  2. Frontend: Build and serve with nginx
  3. Database: Consider PostgreSQL for production
  4. Monitoring: Set up logging and health checks

See DEPLOYMENT.md for detailed deployment instructions.

Docker Production

# Build and deploy
docker-compose -f docker-compose.prod.yml up -d

πŸ›‘οΈ Security Features

  • Authentication: JWT-based user authentication
  • Input Validation: Comprehensive input sanitization
  • Rate Limiting: API rate limiting and abuse prevention
  • CORS: Configurable cross-origin resource sharing
  • Audit Logging: Complete audit trail of all actions

πŸ“ˆ Performance

  • Concurrent Processing: Multi-threaded log processing
  • WebSocket Scaling: Efficient real-time communication
  • Database Optimization: Indexed queries and connection pooling
  • Caching: In-memory caching for frequently accessed data

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch (git checkout -b feature/amazing-feature)
  3. Commit your changes (git commit -m 'Add amazing feature')
  4. Push to the branch (git push origin feature/amazing-feature)
  5. Open a Pull Request

πŸ“ License

This project is licensed under the MIT License - see the LICENSE file for details.

πŸ†˜ Support

  • Documentation: Check the docs/ directory
  • Issues: Report bugs and request features via GitHub Issues
  • Discussions: Join community discussions

πŸ”„ Recent Updates

  • βœ… macOS Console Integration: Full support for Console log format
  • βœ… Real-time Processing: WebSocket-based live monitoring
  • βœ… Enhanced UI: Modern React dashboard with real-time updates
  • βœ… Security Hardening: Comprehensive security measures
  • βœ… Performance Optimization: Improved processing speed and scalability

ThreatLens - Making security log analysis intelligent and accessible.

About

AI-Powered macOS Log Intelligence

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published