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 injection4version: '1.0'5author: mahipal (vendored by SOCIS)6license: Apache-2.07platforms:8- linux9- macos10- windows11category: security12metadata:13 source: https://skillmd.com/skills/socisio/analyzing-web-server-logs-for-intrusion14 socis:15 tags:16 - web-log-analysis17 - apache-logs18 - nginx-logs19 - sql-injection-detection20 - lfi-detection21 - directory-traversal22 - intrusion-detection23 subdomain: security-operations24 upstream: mukul975/Anthropic-Cybersecurity-Skills25 nist_csf:26 - DE.CM-0127 - RS.MA-0128 - GV.OV-0129 - DE.AE-0230 mitre_attack:31 - T119032 - T1059.00733 - T111034 - T1595.00235 - T1505.00336---37383940# Analyzing Web Server Logs for Intrusion414243## When to Use4445- When investigating security incidents that require analyzing web server logs for intrusion46- When building detection rules or threat hunting queries for this domain47- When SOC analysts need structured procedures for this analysis type48- When validating security monitoring coverage for related attack techniques4950## Prerequisites5152- Familiarity with security operations concepts and tools53- Access to a test or lab environment for safe execution54- Python 3.8+ with required dependencies installed55- Appropriate authorization for any testing activities5657## Instructions58591. Install dependencies: `pip install geoip2 user-agents`602. Collect web server access logs in Combined Log Format (Apache) or Nginx default format.613. Parse each log entry extracting: IP, timestamp, method, URI, status code, response size, user-agent, referer.624. Apply detection rules:63 - SQL injection: `UNION SELECT`, `OR 1=1`, `' OR '`, hex encoding patterns64 - LFI/Path traversal: `../`, `/etc/passwd`, `/proc/self`, `php://filter`65 - XSS: `<script>`, `javascript:`, `onerror=`, `onload=`66 - Scanner signatures: nikto, sqlmap, dirbuster, gobuster, wfuzz user-agents67 - Brute force: >50 POST requests to login endpoints from same IP in 5 minutes685. Enrich with GeoIP data and generate a prioritized findings report.6970```bash71python scripts/agent.py --log-file /var/log/nginx/access.log --geoip-db GeoLite2-City.mmdb --output web_intrusion_report.json72```7374## Examples7576### Detect SQLi in URI77```78192.168.1.100 - - [15/Jan/2024:10:30:45 +0000] "GET /products?id=1' UNION SELECT username,password FROM users-- HTTP/1.1" 200 453279```8081### Scanner User-Agent Detection82```83Nikto/2.1.6, sqlmap/1.7, DirBuster-1.0-RC1, gobuster/3.1.084```