Fortinet FortiGate 實戰課程

階段二:安全防護與連接 (Level 2) - 第 7 章:安全性設定檔

本章學習重點

FortiGate 的強大之處不僅在於阻擋連接埠 (Port),更在於能夠深入檢測封包內容。本章將帶領您深入了解三大核心防禦機制: 防毒與入侵防禦 (AV & IPS)網頁與 DNS 過濾 (Web & DNS Filter) 以及 應用程式控制 (App Control)

1. 防毒 (Antivirus) 與 入侵防禦 (IPS)

一、核心概念 (Concept)

一句話定義:

Antivirus (AV) 負責檢查檔案是否含有已知的惡意程式碼;IPS 則負責監控網路流量中是否有攻擊行為或漏洞利用的特徵。

生活化比喻:機場安檢

  • Antivirus (AV):就像「行李X光機」。它對照違禁品資料庫(病毒碼),掃描你的行李(檔案)裡有沒有槍枝或毒品(病毒)。它是針對「靜態」的物件進行檢查。
  • IPS:就像「航警與行為分析師」。即使你身上沒帶違禁品,但如果你試圖撬開管制區的門鎖(漏洞攻擊),或者在人群中異常奔跑尖叫(異常流量行為),航警會立刻將你制伏。它是針對「動態」的行為進行防禦。
二、運作原理 (Mechanism)

Antivirus 檢測模式

  • Flow-based (串流模式):效能高。封包一邊通過一邊掃描,不會完整重組檔案。適合大部分高速網路環境。
  • Proxy-based (代理模式):安全性最高。防火牆會先完整接收檔案,重組後進行詳細掃描,確認安全才放行給使用者。支援更多功能(如 CDR 檔案清洗)。

IPS 關鍵技術

  • Signatures (特徵碼):比對已知的攻擊模式 (如 SQL Injection 字串)。
  • Anomalies (異常檢測):偵測不符合協定標準的流量 (如 Malformed Packets)。
  • Rate Based (速率控制):防止 DoS 攻擊。
三、架構視覺化 (Visuals)

圖表說明:封包進入 FortiGate 後的內容檢測流程 (可左右捲動查看完整流程)

graph TD P_IN([封包進入 Ingress]) --> L3_Lookup[路由查表] L3_Lookup --> Policy[防火牆策略 Policy Check] Policy -- "Action: Deny" --> Drop([丟棄封包 Drop]) Policy -- "Action: Allow" --> SP_Check{是否啟用 Security Profiles?} SP_Check -- No --> Forward([轉發封包]) SP_Check -- Yes --> IPS_Engine[IPS 引擎分析] subgraph "Content Inspection (UTM)" IPS_Engine -- "發現攻擊特徵" --> Block_IPS([IPS 阻擋並紀錄]) IPS_Engine -- "流量正常" --> AV_Scan[Antivirus 掃描] AV_Scan -- "發現病毒" --> Block_AV([AV 阻擋並隔離]) AV_Scan -- "檔案安全" --> App_Ctrl[應用程式控制] end App_Ctrl --> Forward
四、實務應用場景 (Use Case)

情境:保護內部 Windows Server 伺服器區

需求:企業內部有一台網頁伺服器 (IIS) 開放給外部存取,為了防止駭客利用 OS 漏洞 (如 SMB 漏洞) 或上傳木馬檔案,需在 WAN 到 DMZ 的策略上啟用 IPS 與 AV。

GUI 設定重點:
  1. 前往 Security Profiles > Intrusion Prevention,建立 "Protect-Server-IPS"。
  2. 勾選 "Block Malicious URLs"。在 Signatures 篩選 Target 為 "Server" 且 OS 為 "Windows"。
  3. 前往 Security Profiles > Antivirus,建立 "Server-AV",啟用 HTTP/FTP/SMTP 掃描。
  4. 前往 Policy & Objects > Firewall Policy,編輯 WAN to DMZ 策略,啟用上述 Profile。
CLI 設定範例:
# 1. 設定 IPS Sensor
config ips sensor
    edit "Protect-Server-IPS"
        config entries
            edit 1
                set location server
                set os windows
                set action block
            next
        end
    next
end

# 2. 設定 AV Profile
config antivirus profile
    edit "Server-AV"
        set mode flow-based
        config http
            set options scan
        end
    next
end

# 3. 套用到 Firewall Policy
config firewall policy
    edit 1
        set name "WAN-to-DMZ-Web"
        set srcintf "wan1"
        set dstintf "dmz"
        set srcaddr "all"
        set dstaddr "Web-Server-VIP"
        set action accept
        set schedule "always"
        set service "HTTP" "HTTPS"
        set utm-status enable       <-- 啟用 UTM
        set av-profile "Server-AV"  <-- 套用 AV
        set ips-sensor "Protect-Server-IPS" <-- 套用 IPS
        set ssl-ssh-profile "certificate-inspection"
    next
end

2. 網頁過濾 (Web Filter) 與 DNS 過濾

一、核心概念 (Concept)

一句話定義:

管理使用者可以存取哪些網站。DNS Filter 在「查號台」階段阻擋;Web Filter 在「瀏覽內容」階段阻擋。

生活化比喻:電話簿與圖書館

  • DNS Filter:就像「撕掉電話簿的一頁」。你想打電話給賭場(惡意網站),但查號台(DNS Server)直接告訴你「查無此號」或給你警察局的電話(Redirect)。你連電話都撥不出去。
  • Web Filter:就像「圖書館管理員」。你已經到了圖書館(網站),但管理員看到你想拿《如何製造炸彈》(違規內容)這本書,立刻把書沒收並把你趕出去。這可以根據書名(URL)或內容分類(Category)來執行。
二、運作原理 (Mechanism)

關鍵差異:

DNS Filter 發生在 TCP 連線建立之前 (解析 IP 時);Web Filter 發生在 TCP 連線建立之後 (HTTP GET 時)。DNS Filter 更輕量、更隱密,但 Web Filter 能做到更精細的 URL 路徑控制。

三、架構視覺化 (Visuals)

圖表說明:使用者瀏覽網站時的兩道防線

sequenceDiagram participant User as 使用者電腦 participant FGT as FortiGate participant DNS as DNS Server participant Web as 網站伺服器 (Web Server) participant FG_Cloud as FortiGuard Cloud Note over User, FGT: 第一階段:DNS 查詢 User->>FGT: 查詢 www.gambling.com IP? (UDP/53) FGT->>FGT: 檢查 DNS Filter Profile alt 網站類別被阻擋 (Blocked) FGT-->>User: 回傳 Redirect IP (Block Page) User->>FGT: 顯示「禁止存取」頁面 else 網站類別允許 (Allowed) FGT->>DNS: 轉發 DNS 查詢 DNS-->>FGT: 回傳真實 IP (1.2.3.4) FGT-->>User: 回傳真實 IP end Note over User, Web: 第二階段:HTTP/HTTPS 連線 User->>FGT: 發送 HTTP GET 請求 (TCP/80 or 443) FGT->>FG_Cloud: 查詢 URL 分類 (即時查詢/快取) FG_Cloud-->>FGT: 回傳類別: Gambling FGT->>FGT: 檢查 Web Filter Profile alt Web Filter 設定為 Block FGT-->>User: 回傳 HTTP 403 / 取代頁面 else Web Filter 設定為 Allow FGT->>Web: 轉發請求 Web-->>User: 顯示網頁內容 end
四、實務應用場景 (Use Case)

情境:限制員工上班時間瀏覽社群網站與賭博網

需求:在 LAN to WAN 的策略中,完全阻擋「賭博 (Gambling)」類別,並針對「社群網路 (Social Networking)」類別設定在上班時間警告或阻擋。

GUI 設定重點:
  1. 前往 Security Profiles > Web Filter,建立 "Employee-Web-Policy"。
  2. 啟用 FortiGuard Category Based Filter
  3. 找到 "Gambling",動作設為 Block
  4. 找到 "Social Networking",動作設為 Monitor (僅紀錄) 或 Warning (跳出警告須點擊才可繼續)。
  5. 記得啟用 "Allow users to override blocked categories" (若需要主管授權)。
CLI 設定範例:
# 1. 設定 Web Filter Profile
config webfilter profile
    edit "Employee-Web-Policy"
        config ftgd-wf
            config filters
                edit 1
                    set category 2  <-- 假設 2 是 Gambling (ID依版本不同)
                    set action block
                next
                edit 2
                    set category 37 <-- 假設 37 是 Social Networking
                    set action warning
                next
            end
        end
        set log-all-url enable  <-- 紀錄所有瀏覽網址
    next
end

# 2. 設定 DNS Filter Profile (雙重保障)
config dnsfilter profile
    edit "Employee-DNS-Policy"
        config ftgd-dns
            config filters
                edit 1
                    set category 2
                    set action block
                next
            end
        end
    next
end

# 3. 套用到 Firewall Policy
config firewall policy
    edit 2
        set name "LAN-to-WAN-General"
        set srcintf "lan"
        set dstintf "wan1"
        set srcaddr "Internal_Subnet"
        set dstaddr "all"
        set action accept
        set schedule "work-hours"
        set service "ALL"
        set utm-status enable
        set webfilter-profile "Employee-Web-Policy"
        set dnsfilter-profile "Employee-DNS-Policy"
        set ssl-ssh-profile "certificate-inspection" <--- 必須啟用 SSL 檢測才能解析 HTTPS URL
        set nat enable
    next
end

3. 應用程式控制 (Application Control)

一、核心概念 (Concept)

一句話定義:

不只看 Port 號 (L4),而是識別封包內的實際應用程式 (L7),例如分辨出這是 Facebook 的「聊天」流量還是「影片」流量。

生活化比喻:透明包裹與貨車

  • 傳統防火牆 (L4):只看貨車大小 (Port)。只要是從「80號倉庫」出來的車,或是貼著「HTTP」標籤的箱子,全部放行。它不知道箱子裡裝的是炸彈還是糖果。
  • Application Control (L7):像是透視眼。它不管箱子外面貼什麼標籤,直接看內容物。它能發現這個標示為 HTTPS (Port 443) 的箱子,裡面其實裝的是 "BitTorrent" (P2P下載) 或者是 "Line Messenger"。它甚至能區分:「允許瀏覽 Facebook (看信件)」但「禁止 Facebook Game (玩玩具)」。
二、運作原理 (Mechanism)

FortiGate 使用 **IPS 引擎** 進行應用程式識別。它不依賴 Port 號,而是分析流量特徵 (Signatures)。

識別層級:

graph LR Raw_Traffic[原始流量 Port 443] --> Protocol_Decoder[協定解碼 HTTPS] Protocol_Decoder --> App_Signature[應用程式特徵比對] App_Signature --> Parent_App[應用程式: Facebook] Parent_App --> Child_Function[子功能: Facebook_Video] Child_Function --> Action[動作: Block]
四、實務應用場景 (Use Case)

情境:頻寬管理與生產力提升

需求:公司允許員工使用 YouTube 查找資料,但禁止使用 P2P 軟體 (BitTorrent) 佔用頻寬,並封鎖遠端控制軟體 (TeamViewer, AnyDesk) 以免資料外洩。

GUI 設定重點:
  1. 前往 Security Profiles > Application Control,建立 "Office-App-Control"。
  2. Categories 中,將 "P2P" 設為 Block。
  3. Application Overrides (例外清單) 中:
    • 搜尋 "TeamViewer",動作設為 Block。
    • 搜尋 "AnyDesk",動作設為 Block。
    • 搜尋 "YouTube",動作設為 Monitor (監控流量但不阻擋)。
CLI 設定範例:
# 1. 設定 Application Control List
config application list
    edit "Office-App-Control"
        set other-application-log enable
        config entries
            edit 1
                set category 8  <-- P2P Category ID
                set action block
            next
        end
        config entries
            edit 2
                set application 15832 <-- TeamViewer App ID (範例)
                set action block
            next
            edit 3
                set application 31256 <-- AnyDesk App ID (範例)
                set action block
            next
        end
    next
end

# 2. 套用到 Firewall Policy
config firewall policy
    edit 2
        # ... (前略: 來源/目的設定) ...
        set utm-status enable
        set application-list "Office-App-Control"
        set ssl-ssh-profile "deep-inspection" <-- 強烈建議:App Control 搭配 Deep Inspection 效果最佳
    next
end

大師提醒:

現代應用程式幾乎都走 HTTPS 加密。若只使用 "Certificate Inspection" (憑證檢測),FortiGate 只能看到這是 "Google" 的憑證,可能無法精準分辨是 Google Drive 上傳還是 Google Search。若要精準控制應用程式細部功能 (如阻擋 Facebook 上傳但允許瀏覽),必須啟用 **Deep Inspection (深度檢測)** 並在電腦端安裝 Fortinet CA 憑證。

五、隨堂測驗 (Quiz)