• Earn real money by being active: Hello Guest, earn real money by simply being active on the forum — post quality content, get reactions, and help the community. Once you reach the minimum credit amount, you’ll be able to withdraw your balance directly. Learn how it works.

Identifying Attacks and Breaches

  • Views: 50

Web-Server-Log-Analysis-Identifying-Attacks-and-Breaches.webp

Web Server Log Analysis: Identifying Attacks and Breaches

Table of Contents

  1. Introduction
  2. Understanding Web Server Logs
    • Apache Logs
    • Nginx Logs
    • Cloudflare Logs
  3. Common Attack Patterns in Logs
    • Brute Force Attacks
    • SQL Injection Attempts
    • Cross-Site Scripting (XSS)
    • Directory Traversal & LFI/RFI
    • DDoS & Rate Limiting
  4. Tools for Log Analysis
    • GoAccess (Real-time log analyzer)
    • ELK Stack (Elasticsearch, Logstash, Kibana)
    • Graylog (Centralized log management)
    • AWStats (Web analytics)
    • Fail2Ban (Automated intrusion prevention)
  5. Automated Detection with Scripts
    • Python Script for Suspicious IP Detection
    • Bash Script for High-Frequency Requests
  6. Case Study: Analyzing a Real-World Breach
  7. Best Practices for Log Monitoring
  8. Resources & References
  9. Disclaimer

1. Introduction

Web server logs are a goldmine for cybersecurity professionals. They record every request made to a server, including malicious attempts. By analyzing logs from Apache, Nginx, and Cloudflare, security teams can detect attacks early, investigate breaches, and harden defenses.

This guide covers:

  • How to read and interpret logs
  • Common attack signatures
  • Tools for automated analysis
  • Scripts to detect intrusions

2. Understanding Web Server Logs

Apache Logs

Apache logs are typically found in:

  • /var/log/apache2/access.log (standard requests)
  • /var/log/apache2/error.log (errors, including attack attempts)
Sample Apache Access Log Entry:
Bash:
192.168.1.100 - - [28/Apr/2025:14:30:22 +0000] "GET /admin.php HTTP/1.1" 200 4325 "-" "Mozilla/5.0 (X11; Linux x86_64) AppleWebKit/537.36"
  • 192.168.1.100 → Attacker’s IP
  • GET /admin.php → Suspicious access to admin panel
  • 200 → HTTP success (may indicate unauthorized access)

Nginx Logs

Nginx logs are usually in:

  • /var/log/nginx/access.log
  • /var/log/nginx/error.log
Sample Nginx Log Entry:
Bash:
203.0.113.45 - - [28/Apr/2025:14:35:12 +0000] "POST /wp-login.php HTTP/1.1" 404 153 "-" "python-requests/2.25.1"
  • POST /wp-login.php → Possible brute force attempt
  • 404 → Failed request (may indicate probing)

Cloudflare Logs

Cloudflare provides enhanced logs (Enterprise plan) with:

  • HTTP request details
  • Security flags (e.g., WAF blocks, bot detection)
Sample Cloudflare Log Entry (via Logpull API):
JSON:
{
  "ClientIP": "198.51.100.3",
  "RequestMethod": "GET",
  "RequestURI": "/?id=1' OR 1=1--",
  "UserAgent": "sqlmap/1.6#stable",
  "EdgeResponseStatus": 403,
  "WAFAction": "block"
}

  • SQL Injection attempt (1' OR 1=1--)
  • Blocked by WAF (403)



3. Common Attack Patterns in Logs

Brute Force Attacks

  • Pattern: Repeated POST /wp-login.php or /admin requests
  • Detection:
Bash:
grep "POST /wp-login.php" /var/log/nginx/access.log | awk '{print $1}' | sort | uniq -c | sort -nr

SQL Injection Attempts

  • Pattern: Queries with ' OR 1=1, UNION SELECT, --
  • Detection:
Bash:
grep -E "'.*OR.*1=1|UNION SELECT|\-\-" /var/log/apache2/access.log

Cross-Site Scripting (XSS)

  • Pattern: <script>, alert(, javascript: in URLs
  • Detection:
Bash:
grep -iE "<script>|alert\(|javascript:" /var/log/nginx/access.log

Directory Traversal & LFI/RFI

  • Pattern: ../, /etc/passwd, ?file=http://evil.com/shell.php
  • Detection:
Bash:
grep -E "\.\./|/etc/passwd|\?file=http" /var/log/apache2/access.log

DDoS & Rate Limiting

  • Pattern: Too many requests from a single IP
  • Detection with [/CODE]netstat[/ICODE]:
Bash:
netstat -ntu | awk '{print $5}' | cut -d: -f1 | sort | uniq -c | sort -n



4. Tools for Log Analysis



ToolPurposeLink
GoAccessReal-time log visualization
This link is hidden for visitors. Please Log in or register now.
ELK StackLog aggregation & dashboards
This link is hidden for visitors. Please Log in or register now.
GraylogCentralized log management
This link is hidden for visitors. Please Log in or register now.
AWStatsWeb traffic analytics
This link is hidden for visitors. Please Log in or register now.
Fail2BanBan malicious IPs automatically
This link is hidden for visitors. Please Log in or register now.



5. Automated Detection with Scripts

Python Script to Detect Suspicious IPs

Python:
import re
from collections import Counter

log_file = "/var/log/nginx/access.log"
suspicious_ips = []

with open(log_file, "r") as f:
    for line in f:
        if re.search(r"(union select|\.\./|1=1|script>)", line, re.I):
            ip = line.split()[0]
            suspicious_ips.append(ip)

print("Suspicious IPs:", Counter(suspicious_ips).most_common(10))

Bash Script for High-Frequency Requests

Python:
#!/bin/bash
LOG="/var/log/apache2/access.log"
THRESHOLD=100

echo "IPs with too many requests:"
awk '{print $1}' $LOG | sort | uniq -c | sort -nr | while read count ip; do
    if [ $count -gt $THRESHOLD ]; then
        echo "$ip: $count requests"
    fi
done



6. Case Study: Analyzing a Real-World Breach

Scenario: A WordPress site was compromised via a plugin vulnerability.

Log Findings:

  • Multiple POST /wp-admin/admin-ajax.php requests with long parameters.
  • SQL errors in error.log indicating database manipulation.
  • A sudden spike in traffic from a single IP.
Remediation:

  • Blocked the attacker’s IP via .htaccess.
  • Updated plugins and enabled WAF rules.



7. Best Practices for Log Monitoring

✅ Enable detailed logging (Apache: LogLevel debug, Nginx: error_log /var/log/nginx/error.log warn;)
✅ Centralize logs (Use ELK or Graylog)
✅ Automate alerts (Fail2Ban, custom scripts)
✅ Regularly audit logs (Daily checks for anomalies)


8. Resources & References


9. Disclaimer

This article is for educational purposes only. Always ensure you have proper authorization before analyzing logs on systems you do not own. The author is not responsible for any misuse of the techniques discussed.


By mastering log analysis, cybersecurity professionals can detect attacks early, respond faster, and secure web applications more effectively. 🚀

Latest comments

‎7 Years of Service‎
dEEpEst made a new blog post:

Identifying Attacks and Breaches

Web-Server-Log-Analysis-Identifying-Attacks-and-Breaches.webp

Web Server Log Analysis: Identifying Attacks and Breaches

Table of Contents

  1. Introduction
  2. Understanding Web Server Logs
    • Apache Logs
    • Nginx Logs
    • Cloudflare Logs
  3. Common Attack Patterns in Logs
    • Brute Force Attacks
    • SQL Injection...

Read the full blog post here...
Back
Top