Analyzing Web Server Logs for Intrusion
When to Use
- When investigating security incidents that require analyzing web server logs for intrusion
- When building detection rules or threat hunting queries for this domain
- When SOC analysts need structured procedures for this analysis type
- When validating security monitoring coverage for related attack techniques
Prerequisites
- Familiarity with security operations concepts and tools
- Access to a test or lab environment for safe execution
- Python 3.8+ with required dependencies installed
- Appropriate authorization for any testing activities
Instructions
- Install dependencies:
pip install geoip2 user-agents
- Collect web server access logs in Combined Log Format (Apache) or Nginx default format.
- Parse each log entry extracting: IP, timestamp, method, URI, status code, response size, user-agent, referer.
- Apply detection rules:
- SQL injection:
UNION SELECT, OR 1=1, ' OR ', hex encoding patterns
- LFI/Path traversal:
../, /etc/passwd, /proc/self, php://filter
- XSS:
<script>, javascript:, onerror=, onload=
- Scanner signatures: nikto, sqlmap, dirbuster, gobuster, wfuzz user-agents
- Brute force: >50 POST requests to login endpoints from same IP in 5 minutes
- Enrich with GeoIP data and generate a prioritized findings report.
python scripts/agent.py --log-file /var/log/nginx/access.log --geoip-db GeoLite2-City.mmdb --output web_intrusion_report.json
Examples
Detect SQLi in URI
192.168.1.100 - - [15/Jan/2024:10:30:45 +0000] "GET /products?id=1' UNION SELECT username,password FROM users-- HTTP/1.1" 200 4532
Scanner User-Agent Detection
Nikto/2.1.6, sqlmap/1.7, DirBuster-1.0-RC1, gobuster/3.1.0
1---2name: analyzing-web-server-logs-for-intrusion3description: Parse Apache and Nginx access logs to detect SQL injection attempts,4 local file inclusion, directory traversal, web scanner fingerprints, and brute-force5 patterns. Uses regex-based pattern matching against OWASP attack signatures, GeoIP6 enrichment for source attribution, and statistical anomaly detection for request7 frequency and response size outliers.8domain: cybersecurity9subdomain: security-operations10tags:11- web-log-analysis12- apache-logs13- nginx-logs14- sql-injection-detection15- lfi-detection16- directory-traversal17- intrusion-detection18version: '1.0'19author: mahipal20license: Apache-2.021nist_csf:22- DE.CM-0123- RS.MA-0124- GV.OV-0125- DE.AE-0226mitre_attack:27- T119028- T1059.00729- T111030- T1595.00231- T1505.00332metadata:33 source: https://skillmd.com/skills/mukul975/analyzing-web-server-logs-for-intrusion34---353637# Analyzing Web Server Logs for Intrusion383940## When to Use4142- When investigating security incidents that require analyzing web server logs for intrusion43- When building detection rules or threat hunting queries for this domain44- When SOC analysts need structured procedures for this analysis type45- When validating security monitoring coverage for related attack techniques4647## Prerequisites4849- Familiarity with security operations concepts and tools50- Access to a test or lab environment for safe execution51- Python 3.8+ with required dependencies installed52- Appropriate authorization for any testing activities5354## Instructions55561. Install dependencies: `pip install geoip2 user-agents`572. Collect web server access logs in Combined Log Format (Apache) or Nginx default format.583. Parse each log entry extracting: IP, timestamp, method, URI, status code, response size, user-agent, referer.594. Apply detection rules:60 - SQL injection: `UNION SELECT`, `OR 1=1`, `' OR '`, hex encoding patterns61 - LFI/Path traversal: `../`, `/etc/passwd`, `/proc/self`, `php://filter`62 - XSS: `<script>`, `javascript:`, `onerror=`, `onload=`63 - Scanner signatures: nikto, sqlmap, dirbuster, gobuster, wfuzz user-agents64 - Brute force: >50 POST requests to login endpoints from same IP in 5 minutes655. Enrich with GeoIP data and generate a prioritized findings report.6667```bash68python scripts/agent.py --log-file /var/log/nginx/access.log --geoip-db GeoLite2-City.mmdb --output web_intrusion_report.json69```7071## Examples7273### Detect SQLi in URI74```75192.168.1.100 - - [15/Jan/2024:10:30:45 +0000] "GET /products?id=1' UNION SELECT username,password FROM users-- HTTP/1.1" 200 453276```7778### Scanner User-Agent Detection79```80Nikto/2.1.6, sqlmap/1.7, DirBuster-1.0-RC1, gobuster/3.1.081```