日誌是駭客留下的指紋。建立日誌收集 → 解析 → 特徵比對 → 告警 → 封鎖 完整鏈路:
| 伺服器 | 預設路徑 | 格式 | 關鍵欄位 |
|---|---|---|---|
| Apache | /var/log/httpd/access_log | Combined / CustomLog | %h %l %u %t "%r" %>s %b "%{Referer}i" "%{User-Agent}i" |
| IIS | C:\inetpub\logs\LogFiles\W3SVC1\u_exYYMMDD.log | W3C Extended | date time s-ip cs-method cs-uri-stem cs-uri-query s-port cs-username c-ip cs(User-Agent) cs(Referer) sc-status sc-substatus sc-win32-status time-taken |
| Nginx | /var/log/nginx/access.log | Combined (可自訂) | 同 Apache |
| 攻擊類型 | HTTP 方法/URI/參數特徵 | User-Agent 特徵 | 狀態碼 |
|---|---|---|---|
| SQL Injection | ' OR 1=1--, UNION SELECT, SLEEP(5), benchmark( | sqlmap, Havij, python-requests, curl | 200/500 |
| XSS | <script>, onerror=, javascript:, alert(1) | 同上 | 200/400 |
| 路徑遍歷 | ../../etc/passwd, ..%2f..%2f, %00 | 同上 | 404/200 |
| 命令注入 | ;id, |whoami, `cat /etc/passwd`, $(id) | 同上 | 200/500 |
| 掃描器/爬蟲 | 大量 404、/admin、/phpmyadmin、/.git、/backup.zip | Nikto, DirBuster, Gobuster, masscan, ZAP | 404/403 |
| 暴力破解 | 同一 IP 短時間大量 POST /login、/wp-login.php、/api/auth | 自動化工具特徵 | 200/401/403 |
| 惡意 Bot | 不遵守 robots.txt、高頻請求、空 User-Agent | -, python, go-http-client, okhttp | 200/403 |
# Logstash / Filebeat → Elasticsearch → Kibana
# 查詢範例 (KQL):
method:POST and (cs-uri-query:*' OR *UNION* OR *SELECT* OR *SLEEP*)
sc-status:404 and c-ip:* (terms aggregation top 20)
@timestamp > now-5m and sc-status:200 and cs-uri-stem:/login and method:POST (count by c-ip > 20)
iptables -A INPUT -s -j DROP / Cloudflare API 封鎖。limit_req_zone (Nginx) / AspNetCoreRateLimit / Spring Cloud Gateway RateLimiter。# 攻擊者
nc -nv 10.22.1.100 80
HEAD / HTTP/1.0
Host: target.com
# IIS 日誌片段
2024-01-15 06:31:00 10.22.1.100 HEAD / - 80 - 10.22.1.80 - - 200 0 0 12
# 識別點:HEAD 方法、無 User-Agent、單一請求、狀態 200 → 服務指紋偵察
hashchain / WORM / syslog-ng --sign 防竄改。日誌不是存著看的,是用來獵殺威脅的。建立自動化分析管線,讓駭客無處遁形。