2026年4月30日 星期四

Lab : Setting up a FortiGate VPN Client (OPNsense) with OTP

 

 使用軟體 opnsense

 https://opnsense.org/


先前導讀相關 Blog  

https://xrcd2.blogspot.com/2025/05/pfsense-fortigate.html

https://xrcd2.blogspot.com/2025/04/freeradius-google-authenticator-2fa.html


下載 ISO 用它開機後,使用 帳/密:  installer / opnsense 進入安裝模式,如有使用二張網卡,預設 WAN port 會使用 DHCP 取得IP/GW/DNS等相關資訊,LAN port IP 預設則為 192..168.1.1/24 可以透過 browser 連入 OPNsense,可使用 帳/密:  root / opnsense 登入OPNsense管理頁面.

接下來可以安裝  os-freeradius / os-net-snmp / os-net-snmp 等外掛,在安裝及設定完成後可以移除不使用的 WAN port ,以下這台OPNsense僅做 RADIUS 伺服器使用.


以下運用情境為 FortiGate VPN Client 透過 RADIUS 做 OTP 登入認證.


運作機制說明:使用者輸入密碼再加上 Google Authenticator APP 產生的 6 碼動態驗證碼(TOTP 協定)。[OTP 碼直接在密碼後面接者輸入即可.]

FortiGate 收到後將驗證請求轉發至後端的 RADIUS 伺服器(FreeRADIUS ).RADIUS 伺服器與綁定 Google Authenticator (OTP) 演算法的驗證比對後回傳驗證成功.


簡要架構說明:


FortiGate VPN Client ===>(密碼加OTP)===> Fortigate Firewall ===> RADIUS (OPNsense Plugin) ===>  OPNsense 登入認證 (user id/pwd/otp) 


重點一.必需將 OPNsense \System\  Access \ Servers 新增一個 OTP-Server 

          Type 為 Local + Timebased One Time Password


重點二. 必需將 OPNsense \System\  Access \ Users \ 新增一個使用者並

         設定上密碼 及使用 OTP (這些資訊是用來提供 VPN 登入認證使用) 


重點三. 不使用 OPNsense \ Services \ FreeRADIUS \ Users 這個功能.


Demo










2026年4月12日 星期日

守護網路安全的瑞士刀:Security Onion 簡介

 

守護網路安全的瑞士刀:Security Onion 簡介

在網路安全的世界裡,如果你想要監控流量、偵測威脅並進行入侵分析,通常需要安裝一大堆工具。但 Security Onion (SO) 的出現,讓這一切變得簡單許多。

什麼是 Security Onion?

Security Onion 是一個自由且開源的 Linux 發行版,專門用於 威脅狩獵 (Threat Hunting)企業安全監控 (Enterprise Security Monitoring, ESM) 以及 日誌管理

簡單來說,它就像是一個「安全工具大禮包」,幫你把業界最強大的開源安全軟體全部整合在一起,並預先配置好,讓你開箱即用。


Security Onion 的核心三部曲

Security Onion 的強大來自於它整合了三種主要功能:

  1. 全數據包捕獲 (Full Packet Capture): 就像錄影機一樣,記錄下網路上發生的一切細節。

  2. 入侵偵測系統 (IDS): 包含主機端 (HIDS) 與網路端 (NIDS),當發現可疑行為時會立即發出警報。

  3. 分析工具 (Analysis Tools): 提供直觀的圖表與介面,讓分析師能快速從海量數據中抓出「害群之馬」。


內建的神級工具陣容

Security Onion 整合了多款重量級工具,形成了一個完整的防禦體系:

  • 流量分析: Zeek (舊稱 Bro) 與 Suricata。

  • 日誌處理: 著名的 ELK Stack (Elasticsearch, Logstash, Kibana),現在也支持 Elastic Fleet

  • 分析介面: * Security Onion Console (SOC): 自家的管理中心。

    • CyberChef: 萬能的資料轉換工具。

    • TheHive: 專為事件響應設計的案例管理平台。


為什麼你應該嘗試 Security Onion?

1. 節省大量的部署時間

手動整合 Elasticsearch、Suricata、Zeek 等工具是一個地獄級的任務。Security Onion 透過簡單的安裝程序,幾分鐘內就能幫你搭建好一個專業級的 SOC 中心。

2. 強大的可視化

透過 Kibana 儀表板,你可以一眼看出當前網路的流量分佈、哪些 IP 正在嘗試攻擊你的伺服器,甚至追蹤惡意程式的連線行為。

3. 學習與實戰的絕佳平台

如果你是資安新手,Security Onion 是學習「藍隊 (Blue Teaming)」技能的最佳起點。它能讓你真實體驗到分析師在處理警報時的完整工作流。


以上內容撰寫: gemini ai

線上手冊: https://docs.securityonion.net/






2026年4月11日 星期六

Lab: Building a Network IDS with Active Response via Wazuh and Suricata




 Wazuh 整合 Suricata 達成網路入侵偵測與自動回應實驗

Wazuh Server 安裝  (192.168.100.10)

https://documentation.wazuh.com/current/quickstart.html

curl -sO https://packages.wazuh.com/4.14/wazuh-install.sh && sudo bash ./wazuh-install.sh -a

Wazuh Agent  安裝

 ( client interface ens160 192.168.100.20/24  / suricata monitor interface ens224  192.168.100.30/32)

curl -o wazuh-agent-4.14.4-1.x86_64.rpm https://packages.wazuh.com/4.x/yum/wazuh-agent-4.14.4-1.x86_64.rpm && sudo WAZUH_MANAGER='192.168.100.10' rpm -ihv wazuh-agent-4.14.4-1.x86_64.rpm


https://documentation.wazuh.com/current/proof-of-concept-guide/integrate-network-ids-suricata.html


[root@Wazuh-Client01 suricata]# ip add | grep ens

2: ens160: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

    inet 192.168.100.20/24 brd 192.168.100.255 scope global noprefixroute ens160

3: ens224: <BROADCAST,MULTICAST,UP,LOWER_UP> mtu 1500 qdisc mq state UP group default qlen 1000

    inet 192.168.100.30/32 scope global noprefixroute ens224


參考 URL

Suricata 安裝 

https://docs.suricata.io/en/suricata-7.0.15/install.html#rpm-packages

https://copr.fedorainfracloud.org/coprs/g/oisf/suricata-7.0/


Suricata Rule 

https://rules.emergingthreats.net/open/suricata-7.0.15/

https://rules.emergingthreats.net/open/suricata-7.0.15/rules/


Suricata 重要設定

vi /etc/sysconfig/suricata

OPTIONS="-i eth0" -->  OPTIONS="-i ens224" 

vi /etc/suricata/suricata.yaml

interface: eth0 ---> interface: ens224

可以用

sed -i 's/interface: eth0/interface: ens224/g' /etc/suricata/suricata.yaml


運行 rule 宣告 
vi /etc/suricata/suricata.yaml

## Configure Suricata to load Suricata-Update managed rules.
default-rule-path: /var/lib/suricata/rules
rule-files:
  - suricata.rules


觸發log檢查

[root@Wazuh-Client01 rules]# cat /var/log/suricata/fast.log
04/11/2026-20:01:05.711058  [**] [1:2100498:7] GPL ATTACK_RESPONSE id check returned root [**] [Classification: Potentially Bad Traffic] [Priority: 2] {TCP} 217.160.0.187:80 -> 192.168.100.20:59428
04/11/2026-20:07:12.072266  [**] [1:2039584:2] ET FILE_SHARING Observed DNS Query to Filesharing Service (mega .co .nz) [**] [Classification: Misc activity] [Priority: 3] {UDP} 192.168.100.99:52525 -> 8.8.8.8:53
04/11/2026-20:07:12.072339  [**] [1:2039584:2] ET FILE_SHARING Observed DNS Query to Filesharing Service (mega .co .nz) [**] [Classification: Misc activity] [Priority: 3] {UDP} 192.168.100.99:52525 -> 8.8.8.8:53
04/11/2026-20:07:13.250532  [**] [1:2039584:2] ET FILE_SHARING Observed DNS Query to Filesharing Service (mega .co .nz) [**] [Classification: Misc activity] [Priority: 3] {UDP} 192.168.100.99:52525 -> 8.8.8.8:53
04/11/2026-20:07:13.250583  [**] [1:2039584:2] ET FILE_SHARING Observed DNS Query to Filesharing Service (mega .co .nz) [**] [Classification: Misc activity] [Priority: 3] {UDP} 192.168.100.99:52525 -> 8.8.8.8:53
04/11/2026-20:15:53.248125  [**] [1:2047866:4] ET INFO Observed Google DNS over HTTPS Domain (dns .google in TLS SNI) [**] [Classification: Misc activity] [Priority: 3] {TCP} 192.168.100.99:53705 -> 8.8.8.8:443
04/11/2026-20:16:25.147099  [**] [1:2039584:2] ET FILE_SHARING Observed DNS Query to Filesharing Service (mega .co .nz) [**] [Classification: Misc activity] [Priority: 3] {UDP} 192.168.100.99:52525 -> 8.8.8.8:53
04/11/2026-20:16:25.147133  [**] [1:2039584:2] ET FILE_SHARING Observed DNS Query to Filesharing Service (mega .co .nz) [**] [Classification: Misc activity] [Priority: 3] {UDP} 192.168.100.99:52525 -> 8.8.8.8:53
04/11/2026-20:16:25.741758  [**] [1:2062715:1] ET INFO Observed UA-CPU Header [**] [Classification: Misc activity] [Priority: 3] {TCP} 192.168.100.99:53720 -> 66.203.127.11:80
04/11/2026-20:19:40.406579  [**] [1:2027695:5] ET INFO Observed Cloudflare DNS over HTTPS Domain (cloudflare-dns .com in TLS SNI) [**] [Classification: Misc activity] [Priority: 3] {TCP} 192.168.100.99:52061 -> 104.16.248.249:443
04/11/2026-21:08:39.787225  [**] [1:1000001:1] DEBUG SQL Injection Attempt [**] [Classification: (null)] [Priority: 3] {TCP} 192.168.100.10:51566 -> 192.168.100.30:80

 

Demo







Client 端自我測試

curl http://testmyids.com

在 Server 端發向 Client 端的 SQL Injection 測試. 

echo "UNION SELECT 1,2,3" | nc -w 1 192.168.100.30 80


SQL Injection rules

cat /var/lib/suricata/rules/local.rules

alert tcp any any -> any any (msg:"DEBUG SQL Injection Attempt"; content:"UNION SELECT"; nocase; sid:1000001; rev:1;)