講師導言
WAF 上線之後,工程師每天面對的是告警,而不是政策設定畫面。這一章要搞清楚幾件事:告警(Alert)和違規(Violation)差在哪裡、報表怎麼用、怎麼用 Action Set 把事件送到 Syslog / Splunk / SIEM、怎麼把地端告警匯出到雲端 Attack Analytics,以及怎麼用 REST API 自動化。 一句話總結重點:告警要送得出去、看得懂、能追到是誰改了設定。
Goals 本章學習目標
- 分辨 Violation、Alert、Audit,並說明
${Alert.dn}從 MX 與從 Gateway 送出時意義不同 - 說出 Action Set 與 Action Interface 的關係,以及常用 Action Interface 由誰送出
- 比較「MX 送 Syslog」與「Gateway 送 Syslog」,並列出各自需要開的防火牆
- 依步驟建立送往 Splunk 的 Action Set,並知道 placeholder 存不了檔時先查什麼
- 說出 Attack Analytics 匯出的前提
- 用 REST API 登入、登出,並知道 session 逾時與常見失敗代碼
一、Violation、Alert 與 Audit
用社區警衛室來想
每次有人違規,Gateway 都像巡邏警衛記下一張「違規單」;MX 像警衛室主管,把相似的違規單彙總成一則「告警」並累計次數。稽核記錄則像門禁刷卡紀錄,記下「誰來過」,不一定是壞人。
| 名詞 | 意義 | 實務上的差別 |
|---|---|---|
| Violation(違規) | 單一請求觸發政策規則 | Gateway 端產生,一次違規一筆 |
| Alert(告警) | MX 把相似違規彙總後的事件 | 有累計次數;MX 端的 ${Alert.dn} 是告警編號 |
| Audit(稽核記錄) | 依稽核政策記錄的存取資料 | 用於鑑識與合規,不一定是攻擊 |
官方說明可以佐證這個區分:同一個 placeholder ${Alert.dn},從 MX 送出時代表告警編號,從 Gateway 送出時代表違規 ID;${Alert.aggregationInfo.occurrences} 在 MX 是累計次數,在 Gateway 永遠是 1,因為 Gateway 不做彙總。
看告警的建議流程
- 1在 MX 的告警檢視(Monitor 類頁籤)依嚴重度與 Server Group 篩選【待實機確認】。
- 2打開告警看違規明細:哪條政策、哪個 URL / 參數、請求內容、來源 IP、使用者(若有開 User Tracking,見第 11 章)。
- 3判斷是攻擊還是誤報:同一 URL、大量不同正常使用者觸發,多半是誤報,回到 Web Profile 或政策調整(見第 8、9 章);少數來源、payload 明顯是攻擊字串,確認處置是否為阻擋,必要時加 IP Block。
- 4調整後記錄原因,留給第八節的系統事件記錄追蹤。
二、報表
| 報表 | 用途 | 版本 |
|---|---|---|
| 告警/違規統計類報表 | 週報、月報,看趨勢與熱點 | 各版皆有 |
| Web Profile – Web Application User Tracking | 檢查登入追蹤判斷是否正確(第 11 章) | 各版皆有 |
| OWASP Top 10 報表 | 依 OWASP Top 10 分類呈現告警 | v15.4 起,標示為 Controlled Availability |
| System Security Reference 合規報表 | 系統安全設定的合規檢查 | v15.5 起 |
- 報表可排程並用 Send an E-mail 的 Action Interface 寄出,預設附上報表檔;若要改寄連結,在 Admin > System Definitions > Report Settings 設定,同時要填入連結用的 URL。
- 升級前要另外備份已產生的報表檔(位置見第 13 章備份一節)。
三、Action Set 與 Action Interface
政策命中後要「做什麼」由 Action Set 決定;Action Set 裡的每一個動作叫 Action Interface。Action Interface 依情境出現(context sensitive),例如安全事件類的 Action Set 才會出現 Gateway 送 Syslog 的選項。
常用 Action Interface
節錄自官方 Configuring Action Interface Parameters。
| Action Interface | 由誰送出 | 重點參數與行為 |
|---|---|---|
| Send an E-mail | MX | SMTP Server Address/Port(常見 587)、Authentication Type(NO_AUTH、TLS、SSL)、To/CC、Email Format |
| Run a Shell Command | MX | 以 mxserver 使用者權限執行;可用來送 SNMP trap(例如 Gateway 斷線時)。Sealed 模式下不可用(第 13 章) |
| IP / User / Session Monitor | — | 在 Duration 期間持續記錄該 IP、使用者或 HTTP session 的所有活動 |
| IP Block / User Block / HTTP Session Block | Gateway | Duration(秒)、Trusted IPs(只有 IP Block 有);發現違規的 Gateway 立即封鎖,再經 MX 通知其他 Gateway |
| Server System Log > Log to System Log (syslog) | MX | Syslog Host(預設埠 514,其他埠寫成 host:port)、Log Level、Message、Facility |
| Server System Log(CEF 類) | MX | 以 CEF 格式送安全事件、系統事件給 ArcSight 類 SIEM |
| Gateway System Security Log | Gateway | Protocol(UDP/TCP)、Primary/Secondary Host 與 Port、Log Level、Message、Facility;每筆違規送一次 |
| SNMP Trap | MX | SNMP 位址、埠等 |
| Archive to SCP Location / Archive to Amazon S3 | MX | 只用於封存工作 |
Gateway System Security Log 可選格式
- Gateway Log - Security Event - System Log (syslog) - CEF Format (Extended)
- Gateway Log - Security Event - System Log (syslog) - JSON Format (Extended)
- Gateway Log security event / custom security event / network security event to System Log (syslog) using the CEF standard
- Gateway Log security event to RSA enVision
兩個容易忽略的細節
- 封鎖時間不精確:Block 動作是立即的,但解除是 Gateway 每 60 秒檢查一次。設 15 秒封鎖,實際可能封到 60 秒。
- Secondary 連線用 TCP:要設第二台 SIEM 收集器做備援時,官方要求 Protocol 用 TCP。
四、送到 Syslog / Splunk
先決定:由 MX 送,還是由 Gateway 送?
| 比較 | MX 送(Server System Log) | Gateway 送(Gateway System Security Log) |
|---|---|---|
| 單位 | 告警(有彙總) | 每筆違規 |
| 數量 | 少 | 多,需評估 SIEM 授權量 |
| 防火牆 | MX → Syslog | 每台 Gateway → Syslog |
| 適合 | 值班告警、工單 | SIEM 關聯分析、鑑識 |
Splunk 整合
官方以 Syslog 送出 Splunk 用的 placeholder 訊息;MX 提供預先定義的 Splunk Action Set。官方建議把預設訊息字串當範本,複製成自己的 Action Set 再修改,不要直接改預設那一份。官方同一頁一處寫 JSON 只用於稽核事件,另一處又列出安全事件的 JSON (Extended) Action Interface,兩者說法不一致,選用 JSON 前請在實機確認【待實機確認】。
設定步驟:Gateway 以 CEF Extended 送到 Splunk 10.0.30.50 TCP 514
- 1確認防火牆允許
gw01(10.0.30.11)、gw02(10.0.30.12)→10.0.30.50TCP 514;若同時由 MX 送,也要開mx01(10.0.30.10)→10.0.30.50。 - 2Splunk 端建立接收 TCP 514 的資料輸入,並規劃 index 與 sourcetype(Splunk 端設定不在本教材範圍)。
- 3在 MX 進入 Main > Policies > Action Sets,新增安全事件類的 Action Set,命名
AS-Splunk-GW(Policies > Action Sets 的位置見官方 AWS 備份說明;Main 工作區名稱【待實機確認】)。 - 4加入 Action Interface「Gateway Log - Security Event - System Log (syslog) - CEF Format (Extended)」,展開設定:Protocol
TCP;Primary Host10.0.30.50、Primary Port514;Syslog Log LevelInfo;Message 以預設 Splunk 訊息為範本,不要手打 placeholder;Facility 依公司規範。 - 5右上角 Save。
- 6到各安全政策(第 9 章)的 Followed Action 選擇
AS-Splunk-GW。 - 7用測試請求觸發一條低風險政策,在 Splunk 搜尋確認收到,並核對違規 ID 能對回 MX。
placeholder 驗證
Gateway 端的 Action Interface 加入 placeholder 時,系統會檢查 Gateway 能否取得該欄位,不能取得就不允許儲存。看到存檔失敗,先檢查是否用了只有 MX 才有的 placeholder。
五、動手玩:Syslog 訊息組合器
選擇由 MX 還是 Gateway 送,勾選要放進訊息的 placeholder,看看預覽訊息、實際取得的值,以及防火牆要開哪些路徑。可用的 placeholder 是本章前面提到的兩個;訊息範本與數值皆為教學範例,真正的預設 Splunk 訊息請以 MX 上的範本為準。
由誰送出?
選擇 placeholder
傳送設定
預覽
訊息範本(Message)
送出的訊息(範例值代入後)
六、Attack Analytics 匯出
Attack Analytics 是 Imperva 雲端服務,把大量告警依共同特徵分群成「資安事件(incident)」,也能和 Cloud WAF 的事件一起分析(見第 14 章)。
前提
官方 Attack Analytics 頁。
- 1MX 與 Gateway 都要能連網際網路。對應連線:Gateway →
ses-uploader.service.imperva.com:443(上傳告警)、MX → entitlement /auth.service.imperva.com:443(授權驗證)(埠表見第 3 章)。 - 2已購買 Attack Analytics;購買後至少等 30 分鐘再檢查 MX,並重新整理 SecureSphere 主畫面。
操作
- 1在 Main 工作區選 Attack Analytics,會開啟 my.imperva.com 上的 Attack Analytics 頁面。
- 2開關位置:Admin 工作區 > System Definitions > Cloud Settings > General Settings,切換 Attack Analytics。
- 3在 Attack Analytics 端的設定開啟「Export On-Premises WAF alerts」(依 Attack Analytics 文件)。
規劃提醒
告警會送到雲端,內容包含請求資訊。先跟法遵確認資料出境與保存規範;敏感欄位先用第 11 章的 Data Masking 遮罩。
七、REST API
登入流程
官方 Authentication、Login 頁。
- 1以 Basic Authentication 呼叫 Login,取得 session cookie(JSESSIONID)。
- 2之後每個請求在
Cookieheader 帶上 session。 - 3Session 閒置 30 分鐘逾時,或呼叫 Logout 結束。
| 動作 | Method | URL |
|---|---|---|
| Login | POST | https://{host:port}/SecureSphere/api/v1/auth/session |
| Logout | DELETE | 同上,header 帶 Cookie: {sessionId} |
範例:管理者電腦 10.0.30.100 對 mx01
# Login: credentials are read from environment variables, not typed on the command line curl -sk -X POST https://10.0.30.10:8083/SecureSphere/api/v1/auth/session \ -u "$MX_API_USER:$MX_API_PASS" # Response body: {"session-id": "JSESSIONID=0123456789ABCDEF..."} # Subsequent call (endpoint path below is illustrative) curl -sk https://10.0.30.10:8083/SecureSphere/api/v1/conf/sites \ -H "Cookie: JSESSIONID=0123456789ABCDEF..." # Logout curl -sk -X DELETE https://10.0.30.10:8083/SecureSphere/api/v1/auth/session \ -H "Cookie: JSESSIONID=0123456789ABCDEF..."
上例的登入、登出路徑出自官方文件;查詢 Sites 的路徑僅示意,實際 endpoint 請查 WAF API Reference Guide【待實機確認】。-k 只在 MX 仍用自簽憑證的實驗環境使用,正式環境應匯入 MX 憑證的 CA。
登入失敗代碼(節錄)
| IMP Code | 意義 |
|---|---|
| IMP-10063 | 未登入或帳密錯誤 |
| IMP-12300 | 憑證(密碼)已過期 |
| IMP-12301 | 使用者已停用 |
| IMP-12302 | 與驗證伺服器通訊失敗 |
| IMP-12303 | 帳號被鎖 |
| IMP-12304 / IMP-12305 | 此使用者 / 系統的 session 數已達上限 |
實務建議
API 用專屬帳號、最小權限;腳本結束一定呼叫 Logout,否則容易撞到 IMP-12304 的 session 上限。
八、系統事件記錄
- v15.0 起,系統事件記錄可追「誰在什麼時候改了什麼設定」。轉保護、調政策、改 Action Set 都應該能在這裡對到人與時間【待實機確認:GUI 位置】。
- 系統事件(例如 Gateway 斷線)也能透過 Server System Log 的系統事件 CEF Action Interface 送 SIEM,或用 Run a Shell Command 送 SNMP trap。
- 支援 SNMPv3(設定見 WAF Administration Guide 的 SNMPv3 章節)。
九、常見踩坑
只開 MX → Syslog 的防火牆
改用 Gateway System Security Log 後,訊息是從每台 Gateway 送出,防火牆沒開就整批收不到。
Gateway 送每筆違規,SIEM 授權量暴增
先估算違規量,或改由 MX 送彙總告警。
placeholder 存不了檔
在 Gateway 類 Action Interface 用了 Gateway 取不到的欄位。
把 ${Alert.dn} 當成同一種 ID
MX 送出的是告警編號,Gateway 送出的是違規 ID,SIEM 關聯規則要分開處理。
API session 用完不登出
累積到 session 上限,自動化腳本開始收到 401。
Attack Analytics 沒資料
Gateway 不能連 ses-uploader.service.imperva.com:443,或購買後未等授權生效。
十、新舊對照
舊簡報 vs 現行版本
下表左欄是舊簡報的說法,右欄是現行文件查到的現況。
| 舊簡報說法 | 現況 | 依據 |
|---|---|---|
| 共用平台提供 Management、Analytics、Reporting、Alerting(舊簡報 p.14),未談 SIEM 整合 | Action Interface 支援 Syslog、CEF / CEF Extended、JSON Extended、Splunk placeholder;Gateway 可直接送 Syslog | Configuring Action Interface Parameters、Splunk Placeholders |
| (無) | 地端告警可匯出到雲端 Attack Analytics,與 Cloud WAF 一起分析 | Attack Analytics(WAF User Guide) |
| (無) | MX REST API:Basic Auth 取得 JSESSIONID,閒置 30 分鐘逾時 | WAF API Reference Guide – Authentication |
| (無) | OWASP Top 10 報表(15.4 CA)、System Security Reference 報表(15.5)、系統事件「誰改了什麼」(15.0) | v15.5 Release Notes |
Quiz 隨堂測驗
請點選您認為正確的選項,系統將會顯示解析。