Cyberlium

Linux › Module 5 › Lesson 4

BeginnerModule 5Lesson 4/5

Lab — Hunt Through Logs

Practice grep and pipes on a sample auth log

25 min+24 XP3 quiz
Module progress4 of 5

Opening

Be the analyst for five minutes

You have practiced pipes, grep, and find in isolation. This lab puts them on one fake auth.log — a file you create under $HOME/cyberlium-lab so you never touch production logs. Your job: count Failed password lines, list Accepted logins, and save a short report. That is the first five minutes of many real investigations, minus the stress and the legal risk. You will not wipe /var/log, and you will not grep a server you do not administer.

1. Why a fake log is the right classroom

Real /var/log/auth.log (or /var/log/secure) belongs to the operating system. Reading it on a machine you administer is normal. Rewriting it, deleting it, or grepping a server you do not own is not a lab — it is an incident or unauthorized access. A practice file with the same English phrases (Failed password, Accepted password) trains your eyes without harming evidence.

Synthetic lines also let you control the signal. You plant three failures and two accepts, then prove your pipeline finds them. If you only ever practice on a quiet home laptop's empty auth.log, you learn "grep returned nothing" instead of "here is the count." Controlled data teaches measurement.

Chain of custody mindset still applies: do not alter the only copy of real logs; work on copies. Here the original is fake by design, but you still write a report file separately (auth-hunt-report.txt) so raw and findings stay distinct — a habit that transfers to real IR.

2. What "good" looks like in an auth hunt

Good is specific: grep -c "Failed password" sample-auth.log gives a number you can defend. grep "Accepted" sample-auth.log lists successes you can skim. Piping to tee or redirecting >> report.txt preserves the work. Vague is scrolling the whole file in nano and saying "there were some fails." Numbers and saved output beat vibes.

Case and spacing matter. Auth logs are usually consistent, but -i can help when formats differ. Quote patterns so the shell does not eat spaces. Prefer fixed strings first; jump to fancy regex only when the simple pattern misses. Analysts escalate complexity on purpose, not for sport.

wc -l on the sample tells you total volume; comparing fail count to total is a tiny triage ratio. head and tail spot-check that your sample file looks like a log (timestamps, sshd, messages) before you trust counts. Garbage in, confident nonsense out — verify the artifact first.

3. Building the sample and the report pipeline

mkdir -p $HOME/cyberlium-lab/logs. Create sample-auth.log with several lines you type or paste — include at least Failed password and Accepted password (or Accepted publickey). Keep it short: ten to twenty lines is enough. Then run counted greps and append results to auth-hunt-report.txt with echo headers and date/whoami.

Example mental pipeline: echo "=== fails ===" >> report; grep -c "Failed password" sample >> report; echo "=== accepts ===" >> report; grep "Accepted" sample >> report. Read the report with less. If counts are zero, fix your sample — do not invent sudo or touch /var/log/auth.log to "get real data" on a machine where that is out of scope or unauthorized.

Ethics: do not upload real production logs with user IPs and usernames into a public chat to ask for homework help. This lab's fake lines avoid that leak. If you later analyze real logs at work, follow your org's handling rules. Cyberlium practice stays under your home lab folder.

4. Wrong vs right: hunt without contaminating evidence

Failure mode — "I practiced IR" by vandalizing logs. Right uses a copy you created:

  • Wrong

    sudo truncate -s 0 /var/log/auth.log to "make a clean lab." grep another student's server over SSH without permission. Paste real user log lines into Discord. Or run destructive find -delete while hunting. Or claim zero failures without saving any command output you can re-check.

  • Right

    Create sample-auth.log under $HOME/cyberlium-lab/logs with planted Failed/Accepted lines. Use grep -c, grep, and redirections to build auth-hunt-report.txt including date and whoami. Re-run counts to confirm. Leave system logs alone unless you administer the box and are doing approved work — not this homework.

5. Practical: plant, hunt, report

Run the block below on your VM/WSL. Adjust planted lines if you like, but keep the Failed password and Accepted phrases so patterns match. End by reading your report aloud once — if you cannot explain a number, the hunt is incomplete.

Command guide

Safe auth hunt on a fake log under cyberlium-lab

YOUR VM / WSL / spare machine only

Command — copy this

mkdir -p "$HOME/cyberlium-lab/logs"
cd "$HOME/cyberlium-lab/logs" || exit 1

Command — copy this

cat > sample-auth.log << 'EOF'
Jan 10 09:01:01 lab sshd[1001]: Failed password for invalid user admin from 203.0.113.10 port 51234 ssh2
Jan 10 09:01:04 lab sshd[1001]: Failed password for invalid user admin from 203.0.113.10 port 51234 ssh2
Jan 10 09:01:08 lab sshd[1001]: Failed password for root from 203.0.113.10 port 51235 ssh2
Jan 10 09:15:22 lab sshd[1002]: Accepted password for sam from 198.51.100.8 port 4242 ssh2
Jan 10 10:02:11 lab sshd[1003]: Failed password for sam from 203.0.113.44 port 60001 ssh2
Jan 10 10:44:01 lab sshd[1004]: Accepted publickey for sam from 198.51.100.8 port 4243 ssh2
EOF

Command — copy this

REPORT="$HOME/cyberlium-lab/auth-hunt-report.txt"
{
  echo "date: $(date)"
  echo "whoami: $(whoami)"
  echo "total lines: $(wc -l < sample-auth.log)"
  echo "failed_count: $(grep -c 'Failed password' sample-auth.log)"
  echo "=== Accepted lines ==="
  grep 'Accepted' sample-auth.log
} > "$REPORT"

Command — copy this

cat "$REPORT"

Do NOT for this lab:

Optional command

sudo rm /var/log/auth.log
grep other people's servers without permission

Mission: counts you can defend

1) Create sample-auth.log under $HOME/cyberlium-lab/logs with multiple Failed password and at least one Accepted line. 2) Write auth-hunt-report.txt with date, whoami, failed count (grep -c), and Accepted matches. 3) Re-run grep -c once to confirm the number matches the report. 4) One sentence: why this lab used a fake file instead of wiping /var/log.

Stuck? Ask Cyberlium AI Mentor

If grep -c returns 0 but you swear the line is there, ask Cyberlium AI Mentor for a hint — not the full report. Try: "Hint only: grep -c found 0 for Failed password — what should I check about quoting, spelling, and the file path?" No spoilers; re-open the sample with cat yourself.

You now have a miniature IR loop: controlled evidence, grep counts, saved report, verification. That is how log work stays honest. Next up — Quiz — Pipes & Search — checks whether you can choose grep, head/tail, and find without a scrollback crutch.

Knowledge Check

1

APPLY: Your report says failed_count: 3 but a teammate's eyes saw four "Failed" lines. Best next step?

Multiple choice

Knowledge Check

2

APPLY: You administer nothing at school but want "real" auth lines for homework. Best choice?

Multiple choice

Knowledge Check

3

APPLY: True or False: Saving grep output to auth-hunt-report.txt is optional fluff; scrolling the terminal once is enough for a professional investigation record.

True or False

← Previous

Answer all 3 knowledge checks to continue. (0/3 answered)