Linux Log Analysis & Attack Detection

Overview

This guide covers practical techniques for detecting, analysing, and defending against real-world attacks on Linux systems through log analysis. Each section provides log locations, detection patterns, investigation commands, and defensive recommendations.


Learning Workflow

Phase 1: Foundations — Log architecture, locations, and parsing basics Phase 2: Authentication Attacks — SSH brute-force, credential theft, lateral movement Phase 3: Application Attacks — Web server, database, and service exploitation Phase 4: Malware & Cryptominers — Detection of malicious software and resource abuse Phase 5: Privilege Escalation — Sudo abuse, SUID exploitation, kernel vulnerabilities Phase 6: Persistence & Evasion — Rootkits, backdoors, log tampering Phase 7: Network & Exfiltration — Data theft, C2 communication, lateral movement Phase 8: Container & Cloud — Escape attempts, misconfigurations, supply chain attacks


Phase 1: Linux Log Foundations

Critical Log Locations

Authentication & Access Logs

Log File
Distribution
Content

/var/log/auth.log

Debian/Ubuntu

Authentication events, sudo, SSH

/var/log/secure

RHEL/CentOS/Fedora

Authentication events, sudo, SSH

/var/log/faillog

All

Failed login attempts

/var/log/lastlog

All

Last login info per user

/var/log/btmp

All

Failed login attempts (binary)

/var/log/wtmp

All

Login/logout history (binary)

/var/run/utmp

All

Current logged-in users (binary)

System Logs

Log File
Content

/var/log/syslog

General system messages (Debian)

/var/log/messages

General system messages (RHEL)

/var/log/kern.log

Kernel messages

/var/log/dmesg

Boot and kernel ring buffer

/var/log/boot.log

Boot process logs

/var/log/cron

Cron job execution

Application Logs

Log File
Content

/var/log/apache2/

Apache web server

/var/log/nginx/

Nginx web server

/var/log/mysql/

MySQL database

/var/log/postgresql/

PostgreSQL database

/var/log/mail.log

Mail server

/var/log/cups/

Print services

Security & Audit Logs

Log File
Content

/var/log/audit/audit.log

Auditd events (SELinux, syscalls)

/var/log/fail2ban.log

Fail2ban actions

/var/log/ufw.log

UFW firewall

/var/log/firewalld

Firewalld logs

/var/log/snort/

Snort IDS

/var/log/suricata/

Suricata IDS

Container & Cloud Logs

Log File
Content

/var/log/docker.log

Docker daemon

/var/lib/docker/containers/<id>/

Container-specific logs

/var/log/containers/

Kubernetes container logs

/var/log/pods/

Kubernetes pod logs

/var/log/cloud-init.log

Cloud instance initialization

/var/log/amazon/

AWS-specific logs

Essential Log Analysis Commands

Basic Parsing

Journalctl (systemd)

Binary Log Analysis

Auditd Analysis


Phase 2: SSH Brute-Force Detection

Attack Overview

SSH brute-force attacks involve automated attempts to guess valid username/password combinations. Variants include:

  • Traditional brute-force: Many passwords against one user

  • Password spraying: One password against many users

  • Credential stuffing: Known credential pairs from breaches

  • Dictionary attacks: Common passwords/usernames

Log Indicators

Failed Authentication Patterns

Successful Attack Indicators

Detection Commands

Basic Brute-Force Detection

Successful Login Analysis

Advanced Detection

Geolocation & Enrichment

Investigation Workflow

Real-Time Detection Script

Defensive Recommendations


Phase 3: Web Server Attack Detection

Attack Types

Category
Examples

Injection

SQL injection, command injection, LDAP injection

XSS

Reflected, stored, DOM-based cross-site scripting

Path Traversal

Directory traversal, LFI, RFI

Brute-Force

Login attacks, directory enumeration

Exploitation

Known CVEs, web shells, RCE

DoS

Slowloris, request flooding

Scanning

Vulnerability scanners, bots

Log Locations

Detection Patterns

SQL Injection

Cross-Site Scripting (XSS)

Path Traversal & LFI/RFI

Command Injection

Web Shell Detection

Scanner & Bot Detection

Response Code Analysis

Comprehensive Analysis Commands

Investigation Workflow

Modsecurity/WAF Log Analysis

Defensive Recommendations


Phase 4: Cryptocurrency Miner Detection

Attack Overview

Cryptominers consume CPU/GPU resources to mine cryptocurrency. They may be:

  • Deployed through exploited vulnerabilities

  • Installed via malicious packages

  • Running as unauthorized containers

  • Embedded in compromised applications

Detection Indicators

Process-Based Detection

Network-Based Detection

System Log Detection

File System Analysis

Container-Based Mining

Comprehensive Detection Script

Known Mining Pool Indicators

Pool Type
Domains/IPs

Monero (XMR)

pool.minexmr.com, xmr.pool.minergate.com

Nanopool

*.nanopool.org

F2Pool

*.f2pool.com

NiceHash

*.nicehash.com

Generic

Connections to ports 3333, 4444, 5555, 14433

Defensive Recommendations


Phase 5: Privilege Escalation Detection

Attack Categories

Category
Examples

Sudo Abuse

Sudo misconfig, sudo caching, sudoers modification

SUID/SGID

SUID binary exploitation, capability abuse

Kernel Exploits

Dirty COW, Dirty Pipe, kernel module loading

Cron/Service

Writable cron jobs, service hijacking

Path Hijacking

PATH manipulation, library preloading

Credentials

Password files, SSH keys, environment variables

Log Locations

Sudo Abuse Detection

SUID/SGID Detection

Kernel Exploit Detection

User/Group Modification Detection

File Permission Changes

Cron/Service Hijacking

Environment Hijacking

Auditd Rules for Privilege Escalation

Privilege Escalation Investigation Workflow


Phase 6: Rootkit & Kernel Attack Detection

Attack Types

Type
Description

User-space Rootkits

LD_PRELOAD, modified binaries, library replacement

Kernel Rootkits

LKM rootkits, modified syscalls, hidden processes

Bootkit

Modified bootloader, initramfs

Memory-only

Fileless, inject into running processes

Detection Techniques

Process Hiding Detection

File Hiding Detection

Kernel Module Detection

Syscall Hooking Detection

Library Preload Detection

Binary Integrity Verification

Network Hiding Detection

Rootkit Scanning Tools

Memory Analysis

Rootkit Detection Workflow


Phase 7: Data Exfiltration Detection

Exfiltration Methods

Method
Description

Network

Direct TCP/UDP, DNS, ICMP, HTTP/S

Cloud

S3, Azure Blob, GDrive, Dropbox

Email

SMTP, webmail

USB

External storage devices

Encrypted Channels

VPN, Tor, stunnel

Steganography

Hidden data in images

Network-Based Exfiltration

Outbound Traffic Analysis

DNS Exfiltration

HTTP/HTTPS Exfiltration

Encrypted Channel Detection

File System Exfiltration

Sensitive File Access

USB/Removable Media

Email Exfiltration

Exfiltration Investigation Workflow


Phase 8: Network Attack & Firewall Detection

Attack Types

Attack
Description

Port Scanning

Service discovery, nmap, masscan

DDoS

Volume-based, protocol, application layer

MITM

ARP spoofing, DNS spoofing

Lateral Movement

Internal pivoting, SSH tunnels

Firewall Bypass

Port hopping, tunneling

Log Locations

Port Scanning Detection

Firewall Log Analysis

UFW

iptables Logging

Netfilter Connection Tracking

DDoS Detection

ARP/MITM Detection

Lateral Movement Detection

Network Attack Investigation


Phase 9: Container Escape Detection

Attack Vectors

Vector
Description

Privileged Containers

Full host access

Sensitive Mounts

/etc, /var/run/docker.sock

Kernel Exploits

Container breakout CVEs

Capability Abuse

CAP_SYS_ADMIN, etc.

Misconfigured Seccomp

Allowed dangerous syscalls

Log Locations

Container Security Analysis

Privileged Container Detection

Sensitive Mount Detection

Container Process Monitoring

Kubernetes Security

Container Escape Indicators

Runtime Security Logs

Container Security Script


Phase 10: Supply Chain Attack Detection

Attack Vectors

Vector
Description

Package Managers

Malicious npm, pip, gem packages

Repository Compromise

Tainted mirrors, hijacked repos

Build Pipeline

CI/CD poisoning

Dependency Confusion

Internal vs public package naming

Typosquatting

Similar package names

Detection Techniques

Package Manager Monitoring

Python/Pip Monitoring

Node.js/NPM Monitoring

Build Pipeline Security

Container Image Verification

Integrity Monitoring

Supply Chain Attack Script


Additional Attack Detection

Backdoor Detection

Webshell Detection

Log Tampering Detection


Quick Reference Card

Essential Commands

Task
Command

Failed SSH logins

grep "Failed password" /var/log/auth.log

Successful SSH logins

grep "Accepted" /var/log/auth.log

Sudo commands

grep "sudo:" /var/log/auth.log | grep "COMMAND="

User additions

grep -E "useradd|adduser" /var/log/auth.log

High CPU processes

ps aux --sort=-%cpu | head

Network connections

ss -tunapl

Firewall blocks

grep "UFW BLOCK" /var/log/ufw.log

SUID files

find / -perm -4000 -type f

Recent file changes

find / -mtime -1 -type f

Kernel modules

lsmod

Docker containers

docker ps -a

Package integrity

dpkg -V or rpm -Va

Audit search

ausearch -m <message_type>

Journal logs

journalctl -u <service>

Real-time logs

tail -f /var/log/syslog

Log Locations Summary

Category
Debian/Ubuntu
RHEL/CentOS

Auth

/var/log/auth.log

/var/log/secure

System

/var/log/syslog

/var/log/messages

Kernel

/var/log/kern.log

/var/log/messages

Audit

/var/log/audit/audit.log

/var/log/audit/audit.log

Boot

/var/log/boot.log

/var/log/boot.log

Cron

/var/log/cron.log

/var/log/cron

Apache

/var/log/apache2/

/var/log/httpd/

Nginx

/var/log/nginx/

/var/log/nginx/

Critical Detection Patterns

Attack
Key Indicator

SSH Brute-Force

Multiple "Failed password" from same IP

Privilege Escalation

Unusual sudo, SUID changes, kernel exploits

Webshell

eval/system/exec in web files

Cryptominer

High CPU, connections to pool ports

Rootkit

Process/file hiding, binary modifications

Data Exfil

Large outbound transfers, DNS tunneling

Container Escape

Privileged containers, host mounts

Supply Chain

Unauthorized packages, modified binaries


Defensive Baseline

Last updated