Pendahuluan
Log access webserver adalah rekaman forensik dari semua aktivitas HTTP/HTTPS yang masuk ke server (Nginx, Apache, IIS). Dalam dunia sysadmin dan cybersecurity, log analysis adalah keterampilan wajib untuk troubleshooting, auditing, dan hardening server.
Artikel ini akan membongkar teknik analisis log secara mendalam menggunakan command-line tools (grep, awk, sed) dan real-world case study.
Struktur Log Access
Format standar (Nginx/Apache Combined Log Format):
192.168.1.1 - - [20/Oct/2023:14:30:45 +0700] "GET /index.php?page=1 HTTP/1.1" 200 1432 "https://example.com/referrer" "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/117.0.0.0 Safari/537.36"
Field Kritis:
-
$remote_addr
: IP client (penting untuk identifikasi serangan). -
$time_local
: Timestamp (analisis temporal). -
$request
: Method + URL + query string (deteksi SQLi/XSS). -
$status
: HTTP status code (404 = not found, 500 = server error). -
$body_bytes_sent
: Ukuran response (optimasi bandwidth). -
$http_referer
: Sumber traffic (analisis referral). -
$http_user_agent
: Browser/OS client (device fingerprinting).
Teknik Analisis dengan Command-Line
1. Filtering dengan grep
-
Cari request POST ke login page (indikasi brute force):
grep "POST /wp-login.php" access.log | awk '{print $1}' | sort | uniq -c | sort -nr
Output: Hitungan percobaan login per IP.
-
Deteksi SQL Injection (pola khas
' OR 1=1 --
):grep -Ei "(union.*select|%27%20OR%201=1)" access.log
2. Parsing Lanjut dengan awk
-
Hitung bandwidth per endpoint (descending):
awk '{bytes[$7]+=$10} END {for (url in bytes) print bytes[url], url}' access.log | sort -nr | head -20
Output: URL dengan konsumsi bandwidth tertinggi.
-
Extract query string dari URL (untuk analisis parameter):
awk -F'[ ?]' '{print $7}' access.log | grep -oP '\?.*' | sort | uniq -c
3. Analisis Temporal dengan sed
-
Request per jam (time-series analysis):
sed -n 's/.*\[\(.*\):.*\].*/\1/p' access.log | cut -d: -f1,2 | uniq -c
Output: Distribusi traffic per jam (berguna untuk deteksi DDoS).
Studi Kasus: Deteksi Serangan Web Skriping
Gejala:
-
Banyak request ke path
/uploads/.php
dengan user-agent tidak wajar.
Investigasi:
-
Filter request mencurigakan:
grep -E "(\.php|\.asp|\.jsp)" access.log | grep -v "200" | awk '{print $1,$7,$9}'
-
Cek IP penyerang:
awk '{if ($7 ~ /\.php/ && $9 != 200) print $1}' access.log | sort | uniq -c | sort -nr
-
Blok IP dengan
iptables
:sudo iptables -A INPUT -s 123.456.789.0/24 -j DROP
Optimasi Performa
-
Identifikasi slow request (response time > 5 detik):
awk '{if ($10 > 5000000) print $7,$10}' access.log | sort -k2 -nr
Keterangan: $10 adalah
request_time
dalam microseconds (format khusus Nginx). -
Caching policy berdasarkan frekuensi akses:
awk '{print $7}' access.log | sort | uniq -c | sort -nr | head -30
Visualisasi dengan GoAccess
Untuk analisis real-time:
-
Install GoAccess:
sudo apt install goaccess # Debian/Ubuntu
-
Generate HTML report:
goaccess access.log --log-format=COMBINED --output=report.html
Fitur: Geolocation, HTTP status, user-agent breakdown.
Kesimpulan
Analisis log access adalah tulang punggung server management. Dengan teknik di atas, Anda bisa:
-
🛡️ Deteksi serangan (brute force, SQLi, XSS).
-
🚀 Optimasi performa (identifikasi slow request).
-
📊 Audit traffic (referral spam, bot traffic).
Tips Advanced:
-
Gunakan
rsyslog
untuk centralisasi log. -
Implementasi
fail2ban
untuk auto-block IP mencurigakan.
Referensi Teknis:
#SysAdmin #CyberSecurity #DevOps