Skip to content

A comprehensive Python tool for SOC analysts to detect suspicious activities in system logs. Features brute-force detection, SSH analysis, threat assessment, and professional reporting. No external dependencies, production-ready, with full test coverage.

License

Notifications You must be signed in to change notification settings

aditya8Raj/cybersec-log-analyzer

Folders and files

NameName
Last commit message
Last commit date

Latest commit

Β 

History

4 Commits
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 
Β 

Repository files navigation

πŸ”’ Log Analyzer Tool for SOC Analysts

A comprehensive Python-based tool designed for Security Operations Center (SOC) analysts to detect and analyze suspicious activities in system logs, particularly SSH authentication logs.

🎯 Features

  • Brute-Force Detection: Automatically identifies IP addresses with multiple failed login attempts
  • Failed SSH Login Analysis: Parses and analyzes SSH authentication failures
  • Root Login Monitoring: Tracks unauthorized root access attempts
  • Successful Login Tracking: Monitors legitimate authentication events
  • IP Reputation Analysis: Provides threat level assessment for each IP address
  • Multiple Export Formats: Export results to CSV or JSON for further analysis
  • Command-Line Interface: Easy-to-use CLI with multiple options
  • Modular Design: Clean, maintainable code structure with separate utility functions

πŸ“ Project Structure

cybersec_project/
β”œβ”€β”€ logs/
β”‚   └── auth.log              # Sample log file
β”œβ”€β”€ analyzer.py               # Main analysis script
β”œβ”€β”€ utils.py                  # Utility functions
β”œβ”€β”€ README.md                 # This file
└── requirements.txt          # Dependencies (optional)

πŸš€ Quick Start

Basic Usage

# Analyze log file with default settings
python analyzer.py logs/auth.log

# Custom brute-force threshold (default is 5)
python analyzer.py logs/auth.log --threshold 10

# Export results to CSV
python analyzer.py logs/auth.log --export csv

# Export results to JSON with custom filename
python analyzer.py logs/auth.log --export json --output security_report.json

Advanced Usage

# Show top 10 attacking IPs
python analyzer.py logs/auth.log --top-attackers 10

# Check reputation for specific IP
python analyzer.py logs/auth.log --check-ip 192.168.1.10

# Quiet mode (minimal output)
python analyzer.py logs/auth.log --quiet --export csv

πŸ”§ Command-Line Options

Option Description Example
log_file Path to log file (required) logs/auth.log
--threshold, -t Brute-force detection threshold --threshold 10
--export, -e Export format (csv/json) --export csv
--output, -o Output file path --output results.csv
--top-attackers Show top N attacking IPs --top-attackers 5
--check-ip Check specific IP reputation --check-ip 1.2.3.4
--quiet, -q Suppress detailed output --quiet

πŸ“Š Sample Output

πŸ”’ Log Analyzer Tool for SOC Analysts
==================================================
πŸ“‚ Loading log file: logs/auth.log
βœ… Successfully loaded 30 log entries
πŸ” Analyzing logs for suspicious activities...
βœ… Log analysis completed successfully!

============================================================
          LOG ANALYSIS SECURITY REPORT
============================================================

πŸ“Š OVERVIEW:
Total log entries processed: 30
Total failed login attempts: 23
Total successful logins: 3
Unique IP addresses: 6

🚨 BRUTE FORCE ATTACKS DETECTED:
   β€’ 192.168.1.10 β†’ 8 failed attempts ❌
   β€’ 10.0.0.15 β†’ 7 failed attempts ❌
   β€’ 45.33.32.156 β†’ 7 failed attempts ❌

Total brute-force IPs: 3

⚠️  ROOT LOGIN ATTEMPTS:
   β€’ 192.168.1.10 β†’ 1 root login attempts
   β€’ 203.0.113.50 β†’ 3 root login attempts

πŸ” TOP ATTACKING IPs:
   β€’ 192.168.1.10 β†’ 8 attempts (🚨 BRUTE FORCE)
   β€’ 10.0.0.15 β†’ 7 attempts (🚨 BRUTE FORCE)
   β€’ 45.33.32.156 β†’ 7 attempts (🚨 BRUTE FORCE)
   β€’ 203.0.113.50 β†’ 3 attempts (⚠️  SUSPICIOUS)
   β€’ 198.51.100.10 β†’ 2 attempts (⚠️  SUSPICIOUS)

βœ… SUCCESSFUL LOGINS:
   β€’ 10.0.0.5 β†’ Users: john
   β€’ 192.168.1.100 β†’ Users: alice
   β€’ 172.16.0.10 β†’ Users: bob

============================================================
Report generated on: 2025-06-30 15:30:45
============================================================

πŸ” Detection Capabilities

1. Failed Login Detection

  • Identifies patterns like "Failed password"
  • Detects "Invalid user" attempts
  • Tracks authentication failures

2. Brute-Force Attack Detection

  • Configurable threshold (default: 5 failed attempts)
  • IP-based attack pattern recognition
  • Threat level assessment

3. Root Access Monitoring

  • Tracks root login attempts
  • Identifies privilege escalation attempts
  • Flags unauthorized administrative access

4. Successful Login Tracking

  • Monitors legitimate authentications
  • Tracks user activity patterns
  • Correlates with failed attempts

πŸ“ˆ Threat Level Classification

Level Criteria Description
CRITICAL Brute-force + Root attempts High-priority threat requiring immediate attention
HIGH Brute-force attacks Sustained attack pattern detected
MEDIUM 3+ failed attempts OR root attempts Suspicious activity requiring monitoring
LOW Minimal failed attempts Normal or low-risk activity

πŸ’Ύ Export Formats

CSV Export

Contains columns:

  • IP Address
  • Failed Attempts
  • Is Brute Force
  • Root Attempts
  • Successful Logins

JSON Export

Structured format with:

  • Summary statistics
  • Detailed IP analysis
  • Timestamp information
  • Raw data for integration

πŸ› οΈ Technical Details

Log Format Support

Currently supports standard syslog format for SSH authentication:

Jun 29 10:34:00 ubuntu sshd[1999]: Failed password for invalid user root from 192.168.1.10 port 445 ssh2

Regex Patterns

  • IP Address: \b(?:[0-9]{1,3}\.){3}[0-9]{1,3}\b
  • Failed Login: Failed password|Invalid user|authentication failure
  • Successful Login: Accepted password|session opened
  • Username: for (?:invalid user )?(\w+)

πŸ§ͺ Testing

Test the tool with the provided sample log file:

# Run basic analysis
python analyzer.py logs/auth.log

# Test with different thresholds
python analyzer.py logs/auth.log --threshold 3
python analyzer.py logs/auth.log --threshold 10

# Test export functionality
python analyzer.py logs/auth.log --export csv --output test_results.csv
python analyzer.py logs/auth.log --export json --output test_results.json

πŸ”§ Customization

Adding New Detection Patterns

Edit utils.py to add new regex patterns:

def is_custom_attack(log_line: str) -> bool:
    """Detect custom attack patterns"""
    custom_patterns = [
        r'your_custom_pattern',
        r'another_pattern'
    ]
    return any(re.search(pattern, log_line, re.IGNORECASE) for pattern in custom_patterns)

Extending Analysis

Add new analysis functions to the LogAnalyzer class in analyzer.py:

def custom_analysis(self) -> Dict:
    """Implement custom analysis logic"""
    # Your custom analysis code here
    pass

πŸ›‘οΈ Security Considerations

  • Log File Access: Ensure proper permissions for log file access
  • Data Privacy: Be mindful of sensitive information in logs
  • False Positives: Adjust thresholds based on your environment
  • Regular Updates: Keep detection patterns updated for new threats

🀝 Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Add tests for new functionality
  4. Submit a pull request

πŸ“‹ Requirements

  • Python 3.6+
  • Standard library modules only (no external dependencies required)
  • Read access to log files

πŸ†˜ Troubleshooting

Common Issues

  1. File Not Found Error

    python analyzer.py /correct/path/to/logfile.log
  2. Permission Denied

    sudo python analyzer.py /var/log/auth.log
  3. No Results Found

    • Check log file format
    • Verify log entries contain expected patterns
    • Try lowering the threshold

πŸ“ž Support

For issues or questions:

  • Check the troubleshooting section
  • Review the sample log format
  • Ensure proper file permissions

πŸ“„ License

This project is released under the MIT License. See LICENSE file for details.


Created for SOC Analysts by SOC Analysts πŸ›‘οΈ

Stay vigilant, stay secure!

About

A comprehensive Python tool for SOC analysts to detect suspicious activities in system logs. Features brute-force detection, SSH analysis, threat assessment, and professional reporting. No external dependencies, production-ready, with full test coverage.

Topics

Resources

License

Contributing

Security policy

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages