← All lessons Stage 5 · Lesson 2
20 min

Reading Linux and web server logs

Stage 5 · Lesson 2 · 20 minutes · Requires Stage 1 Lessons 1, 4 and 6


The one-line answer

Logs are not read line by line — they are read by pattern, and the three patterns that matter most are repetition, a change in outcome, and regularity where there should be none.


Why you should care

In Stage 1 you learned grep, cut, sort and uniq. This lesson is what they are actually for.

A production web server generates hundreds of thousands of log lines a day. Nobody reads them. What an analyst does is collapse them — turn a million lines into twenty counts, look at the shape, and then zoom in on the one line that breaks it.

That is a learnable technique, and it works the same way on an SSH log, an Nginx access log, a proxy log or a firewall log. Learn it once here and the rest of Stage 5 is pattern-matching.


How it actually works

The anatomy of a log line

Nearly every log line is the same five things in some order:

WHEN          WHO/WHERE        WHAT              OUTCOME      DETAIL
Mar 14 02:11  203.0.113.44     Failed password   failure      for root

Once you see that shape, an unfamiliar log format stops being intimidating. Find the timestamp, find the source, find the outcome. The rest is detail.

Pattern 1 — repetition, and the line that breaks it

Here is an SSH authentication log:

Mar 14 02:11:03 web01 sshd[2841]: Failed password for root from 203.0.113.44 port 51022
Mar 14 02:11:05 web01 sshd[2843]: Failed password for root from 203.0.113.44 port 51024
Mar 14 02:11:07 web01 sshd[2845]: Failed password for root from 203.0.113.44 port 51026
Mar 14 02:11:09 web01 sshd[2847]: Failed password for root from 203.0.113.44 port 51028
Mar 14 02:11:12 web01 sshd[2851]: Accepted password for root from 203.0.113.44 port 51033

Four failures then one success, nine seconds apart, from one address.

The failures are not the finding. Any internet-facing SSH server receives thousands of these a day; it is weather, not an event. If you alert on failed SSH logins you will drown.

The last line is the entire incident. Accepted means the guessing worked and someone now holds a root shell on web01. Everything changes at 02:11:12, and your next question is no longer "who is attacking us" but "what did they do after that timestamp".

This is the single most important habit in log reading: look for the change in outcome, not the volume of attempts.

# The failures — background noise
grep "Failed password" /var/log/auth.log | wc -l

# The successes — the part that matters
grep "Accepted" /var/log/auth.log

Pattern 2 — the same attack, shaped differently

Two attacks produce completely different log shapes, and confusing them means looking in the wrong place.

Brute force — many passwords against one account:

Failed password for admin from 203.0.113.44
Failed password for admin from 203.0.113.44
Failed password for admin from 203.0.113.44     ← 200 more of these

Loud. Usually trips an account lockout. Easy to detect by counting failures per account.

Password spray — one or two common passwords against many accounts:

Failed password for rkumar  from 198.51.100.9
Failed password for spatel  from 198.51.100.9
Failed password for amenon  from 198.51.100.9
Failed password for dsingh  from 198.51.100.9

Three failures per account, deliberately under the lockout threshold. If you count failures per account, this is invisible — every account looks fine.

You only see spraying when you count by source, or by time window across all accounts.

# Failures per account — catches brute force
grep "Failed password" auth.log | awk '{print $9}' | sort | uniq -c | sort -rn

# Failures per source IP — catches spraying
grep "Failed password" auth.log | awk '{print $11}' | sort | uniq -c | sort -rn

Two commands, two different attacks. Run both.

Pattern 3 — reading web server logs

A typical access log line:

203.0.113.9 - - [14/Mar/2026:03:02:12] "GET /.git/config HTTP/1.1" 200 418
└── source ──┘   └──── when ─────┘  └──── request ────┘ └┬┘ └┬┘
                                                      status  bytes

Scanners hit every site constantly, so a stream of 404s is noise. The signal is the status code changing:

203.0.113.9 "GET /admin"          404    ← noise
203.0.113.9 "GET /administrator"  404    ← noise
203.0.113.9 "GET /wp-admin"       404    ← noise
203.0.113.9 "GET /.git/config"    200    ← the scanner found something
203.0.113.9 "GET /backup.zip"     404    ← noise

Four misses and one hit. That 200 means an exposed .git directory, which can leak the entire source history — including credentials that were committed once and "removed" later.

# What did this scanner actually find?
grep "203.0.113.9" access.log | awk '$9 != 404'

Status code summary first, always:

awk '{print $9}' access.log | sort | uniq -c | sort -rn

A sudden rise in 500s means your application is breaking on someone's input. A rise in 401s or 403s means someone is testing access. A rise in 200s on paths nobody links to means someone found something.

Pattern 4 — regularity where there should be none

Humans are irregular. Machines are not.

11:00:04  10.2.14.9 → 198.51.100.7   412 bytes
11:01:04  10.2.14.9 → 198.51.100.7   404 bytes
11:02:04  10.2.14.9 → 198.51.100.7   418 bytes
11:03:04  10.2.14.9 → 198.51.100.7   409 bytes

Every 60 seconds, a few hundred bytes, the same destination, around the clock. That is beaconing — the signature of an implant checking in with a command and control server for instructions.

No human browses like that. Legitimate software does poll on schedules, so this is not proof of anything by itself — but the question "what application on that host is supposed to be doing this?" has to have an answer.

The giveaway is not volume. It is regularity, over a long period, with small transfers.

The commands that do most of the work

# Top sources
awk '{print $1}' access.log | sort | uniq -c | sort -rn | head -20

# Everything in a time window
awk '$4 >= "[14/Mar/2026:02:00" && $4 <= "[14/Mar/2026:03:00"' access.log

# One source, full story
grep "203.0.113.44" access.log

# Count by hour — find the 03:00 spike
awk '{print substr($4,14,2)}' access.log | sort | uniq -c

Four commands cover most first-pass triage. Collapse, look at the shape, zoom in.


See it yourself

On any Linux machine:

# 1. How many authentication failures, and from where?
sudo grep "Failed password" /var/log/auth.log \
  | awk '{print $(NF-3)}' | sort | uniq -c | sort -rn | head

# 2. Did any of them succeed?
sudo grep "Accepted" /var/log/auth.log

# 3. What accounts were targeted?
sudo grep "Failed password" /var/log/auth.log \
  | grep -oP 'for \K\w+' | sort | uniq -c | sort -rn

Run these on a VPS with a public IP and you will see real attack traffic within minutes. Run them on your laptop and you will mostly see your own sudo typos — which is still useful, because you learn what normal looks like.

Compare the output of 1 and 3. If one IP dominates with many accounts, that is spray-shaped. If one account dominates, that is brute-force-shaped.


How attackers abuse this

They keep failures below the threshold. Spraying exists specifically to stay under lockout and per-account alerting. Three attempts per account looks like forgetfulness.

They come from many addresses. A botnet spreads the same attack over hundreds of IPs, so counting by source fails too. Then you have to count by behaviour — the same four usernames tried in the same order from unrelated addresses.

They move to a legitimate channel immediately. Once a password works, the attacker stops failing and starts succeeding. Their activity now looks exactly like a normal user's, because it is a normal user's account. This is why the Accepted line matters so much more than the failures.

They blend beacons into real traffic. Beaconing over port 443 to a cloud hosting provider looks like software calling home — because that is precisely what it is imitating. Some implants add random jitter to break the regular interval.

Impossible travel. A user logs in from Mumbai at 09:14 and Berlin at 09:41. Nobody travels between them in 27 minutes, so one of those sessions is not the user. This is one of the most reliable identity detections precisely because the reasoning is physical rather than statistical. The usual innocent explanation is a VPN or a roaming mobile — which is why it is investigated, not auto-blocked.


Common mistakes

Alerting on failed logins. You will generate thousands of alerts a day and learn nothing. Alert on success after repeated failure, on spray patterns, on logins from new countries.

Counting only one way. Per-account counts miss spraying. Per-source counts miss botnets. Run both and know what each one is blind to.

Reading chronologically. Starting at line one of a million-line file is how a shift disappears. Collapse first with uniq -c, then zoom.

Trusting the log's own time zone. Web servers, databases and domain controllers frequently disagree. Check before you build a timeline across them.

Assuming a 200 is fine. 200 means the server answered successfully. Whether it should have is a different question entirely — and on /.git/config, the answer is no.

Forgetting logs rotate. auth.log.1, auth.log.2.gz hold yesterday and last week. Use zgrep on the compressed ones. Evidence you need is often one rotation old, and sometimes already gone.


Check yourself

  1. You see 2,000 Failed password entries for root from one IP overnight, and no Accepted line at all. A colleague wants to declare an incident. What do you tell them?
  2. An IP makes 60 requests, all returning 404, except one /config.bak that returns 200. Which line do you investigate, and what do you check next?
  3. A workstation connects to the same external address every 300 seconds, transferring about 2 KB each time, for six days. The destination is a well-known cloud provider. Is this malicious?
Answers
  1. That it is noise, not an incident. Any internet-facing SSH server sees this constantly; it means someone ran a tool, not that anything happened. The finding would be an Accepted line, and there isn't one. Worth doing: confirm root SSH login is disabled and key authentication is enforced, so the attempts stay pointless. Worth not doing: spending the shift on it.
  1. The 200 on /config.bak. The 404s tell you a scanner ran; the 200 tells you it succeeded. Next: retrieve that file yourself to see what it exposes — credentials, connection strings, internal hostnames — then check whether that same IP returned to use anything it found, and whether any other source has requested the same path.
  1. Unknown on this evidence, and that is the correct answer. The pattern is textbook beaconing — fixed interval, small payload, long duration — but legitimate software polls on schedules too, and a reputable cloud provider is exactly where both real services and modern C2 infrastructure live. The deciding question is which process on that host is making the connection, and is it supposed to. That requires endpoint telemetry, not network logs — which is Lesson 4.

Your lab

Challenge 09 — Log file investigation

A log file and a question. Use the collapse-then-zoom technique rather than reading top to bottom.

→ Open Stage 1 labs


Summary in your language

हिन्दी सारांश (Hindi summary)

Linux और web server logs पढ़ना

Logs लाइन-दर-लाइन नहीं पढ़े जाते। उन्हें pattern से पढ़ा जाता है।

हर log line में पाँच चीज़ें: कब · कौन/कहाँ से · क्या · नतीजा · विवरण

Pattern 1 — दोहराव, और उसे तोड़ने वाली लाइन

02:11:03  Failed password for root from 203.0.113.44
02:11:05  Failed password for root from 203.0.113.44
02:11:07  Failed password for root from 203.0.113.44
02:11:12  Accepted password for root from 203.0.113.44   ← असली घटना

Failures finding नहीं हैं — हर public SSH server पर रोज़ हज़ारों आते हैं। Accepted लाइन पूरी घटना है।

सबसे ज़रूरी आदत: attempts की संख्या नहीं, नतीजे का बदलाव देखिए।

Pattern 2 — एक ही हमला, दो आकार

  • Brute force — एक account पर कई passwords। शोरगुल वाला, lockout चालू हो जाता है।
  • Password spray — कई accounts पर एक-दो आम passwords। हर account पर सिर्फ़ 3 कोशिशें, lockout से नीचे।

अगर आप per-account गिनते हैं तो spray दिखेगा ही नहीं। Source IP से भी गिनिए।

# Brute force के लिए — account से
grep "Failed password" auth.log | awk '{print $9}' | sort | uniq -c | sort -rn

# Spray के लिए — IP से
grep "Failed password" auth.log | awk '{print $11}' | sort | uniq -c | sort -rn

Pattern 3 — Web server logs में status code

"GET /admin"         404   ← शोर
"GET /.git/config"   200   ← scanner को कुछ मिल गया

चार 404 और एक 200 — वही 200 finding है।

Pattern 4 — जहाँ नियमितता नहीं होनी चाहिए

हर 60 सेकंड, कुछ सौ bytes, वही destination, पूरे दिन — यह beaconing है, यानी malware अपने C2 server से निर्देश ले रहा हो सकता है।

इंसान ऐसे browse नहीं करता। पर कुछ software भी schedule पर चलते हैं — इसलिए यह अकेले सबूत नहीं, जाँच का कारण है।

Impossible travel: सुबह 9:14 मुंबई से login, 9:41 बर्लिन से। 27 मिनट में यह सफ़र असंभव है — तो एक session असली user का नहीं।

मुख्य गलतियाँ:

  • Failed logins पर alert लगाना — हज़ारों बेकार alerts
  • सिर्फ़ एक तरीक़े से गिनना — spray या botnet छूट जाएगा
  • शुरू से क्रम में पढ़ना — पहले uniq -c से छोटा कीजिए
  • यह भूलना कि logs rotate होते हैं — auth.log.1, .gz फ़ाइलों के लिए zgrep
தமிழ் சுருக்கம் (Tamil summary)

Linux மற்றும் web server logs படிப்பது

Logs வரி வரியாகப் படிக்கப்படுவதில்லை. அவை pattern மூலம் படிக்கப்படுகின்றன.

ஒவ்வொரு log வரியிலும் ஐந்து விஷயங்கள்: எப்போது · யார்/எங்கிருந்து · என்ன · முடிவு · விவரம்

Pattern 1 — மீண்டும் மீண்டும், அதை உடைக்கும் வரி

02:11:03  Failed password for root from 203.0.113.44
02:11:07  Failed password for root from 203.0.113.44
02:11:12  Accepted password for root from 203.0.113.44   ← உண்மையான நிகழ்வு

Failures கண்டுபிடிப்பு அல்ல — பொது SSH server-களில் தினமும் ஆயிரக்கணக்கில் வரும். Accepted வரிதான் முழு நிகழ்வு.

மிக முக்கியமான பழக்கம்: முயற்சிகளின் எண்ணிக்கை அல்ல, முடிவின் மாற்றத்தைப் பாருங்கள்.

Pattern 2 — ஒரே தாக்குதல், இரு வடிவங்கள்

  • Brute force — ஒரு account-க்கு பல passwords. சத்தமானது, lockout ஆகும்.
  • Password spray — பல accounts-க்கு ஒன்றிரண்டு பொதுவான passwords. ஒவ்வொரு account-க்கும் 3 முயற்சிகள் மட்டும்.

Per-account எண்ணினால் spray தெரியவே தெரியாது. Source IP வாரியாகவும் எண்ணுங்கள்.

Pattern 3 — Web logs-இல் status code

"GET /admin"         404   ← சத்தம்
"GET /.git/config"   200   ← scanner ஒன்றைக் கண்டுபிடித்தது

நான்கு 404, ஒரு 200 — அந்த 200 தான் கண்டுபிடிப்பு.

Pattern 4 — ஒழுங்கு இருக்கக் கூடாத இடத்தில் ஒழுங்கு

ஒவ்வொரு 60 வினாடிக்கும், சில நூறு bytes, அதே destination, நாள் முழுவதும் — இது beaconing, malware தன் C2 server-ஐத் தொடர்புகொள்வதாக இருக்கலாம்.

மனிதர்கள் இப்படி browse செய்வதில்லை. ஆனால் சில software-உம் அட்டவணைப்படி இயங்கும் — எனவே இது ஆதாரம் அல்ல, விசாரணைக்கான காரணம்.

Impossible travel: காலை 9:14 மும்பையிலிருந்து login, 9:41 பெர்லினிலிருந்து. 27 நிமிடத்தில் இது சாத்தியமில்லை — ஒரு session உண்மையான user-உடையது அல்ல.

முக்கியத் தவறுகள்:

  • Failed logins-க்கு alert வைப்பது — ஆயிரக்கணக்கான பயனற்ற alerts
  • ஒரே வழியில் எண்ணுவது — spray அல்லது botnet தப்பிவிடும்
  • தொடக்கத்திலிருந்து வரிசையாகப் படிப்பது — முதலில் uniq -c மூலம் சுருக்குங்கள்
  • Logs rotate ஆகும் என்பதை மறப்பது — .gz கோப்புகளுக்கு zgrep

Want this summary in Malayalam, Telugu, Kannada or another language? Tell us — the most requested languages get added next.


What's next

Linux logs are half the estate. Most corporate environments run on Windows, and Windows records things in its own language — numbered events, with meanings worth memorising.

→ Lesson 3: Windows event IDs that matter