Try   HackMD

NASA Hw06 OPNSense

41173058h
鍾詠傑

ref

OPNsence防火牆manual

opnsense-vs-pfsense

lab6 mackmd

OPNsence alias

hping3

reporting_traffic

OPNSense Firewall Rules Explained (youtube)

Short Answers (20%)

1. (5%)

在 OPNSense 防火牆 rule 的設定中,對封包的處置有 Block 跟 Reject 可以選擇。請說明兩者的差別,還有各自在什麼情況下較適合使用。

在OPNsense防火牆中,"Block"和"Reject"都是用於處理封包的選項,它們有一些重要的差異:

  1. Block(封鎖)

    • 當防火牆接收到一個符合Block規則的封包時,它會將該封包丟棄,並不會向發送者發送任何回應。
    • Block通常用於阻止對來自不信任或有威脅的來源的封包的訪問,或者用於阻止某些通信端口的訪問,以確保不希望的流量無法進入網絡。
  2. Reject(拒絕)

    • 當防火牆接收到一個符合Reject規則的封包時,它會將該封包丟棄,並向發送者發送一個通知或拒絕訊息。這通常是一個ICMP錯誤訊息,告訴發送者封包被阻止。
    • Reject通常用於明確地告知發送者其封包已被阻止,這有助於節省網路資源,因為發送者在收到響應後通常會停止重試。

適合使用的情況取決於您的安全需求和網路策略:

  • Block的適用情況

    • 當您只需阻止特定封包進入網絡,而不希望通知發送者時,通常選擇Block。這可以讓攻擊者無法確定其攻擊是否成功,或是不存在該裝置或網域,增加了防禦的不可預測性。
    • 如果您對發送者的身份不太在意,只是想阻止封包,則使用Block。
  • Reject的適用情況

    • 當您希望明確地告知發送者其封包已被阻止時,通常選擇Reject。這對於合法用戶來說是一個良好的回饋,可以幫助他們迅速意識到問題並採取適當的措施。
    • 如果您希望發送者能夠清楚地知道其封包未被接受,並且希望他們停止重試或者嘗試與您的系統進行通信,則使用Reject。

2. (5%)

在 OPNSense 防火牆 rule 的設定中,Source 跟 Destination 選擇“interface net”和“interface address”的差別是什麼?

NET 會比對該子網路上的任何內容,且該位址僅符合指派給該子網路上 pfsense 的 IP 位址。

  1. Interface Net(介面網路)

    • 使用"interface net"選項時,您將規則應用到整個介面的IP地址範圍。這意味著規則將適用於介面上的所有IP地址,包括子網中的所有主機。
    • 這對於需要規則應用於特定介面的所有主機或子網的情況非常有用。
  2. Interface Address(介面地址)

    • 使用"interface address"選項時,您可以具體指定來源或目的地的IP地址。您可以輸入單個IP地址、CIDR表示的子網,或者甚至是一個地址範圍。
    • 這對於需要針對特定IP地址或特定IP地址範圍的情況非常有用,例如將規則應用於特定主機或一組主機。

3. (5%)

請說明什麼是“stateful firewall”以及“stateless firewall”。OPNSense 是屬於哪一種?
Ref: OPNsence防火牆manual

  1. Stateful Firewall(有狀態防火牆)

    • 有狀態防火牆能夠追蹤封包的狀態和連接狀態。當一個封包通過防火牆時,防火牆會記錄下相關的連接資訊,例如源IP地址、目的IP地址、源端口、目的端口等。
    • 一旦建立了初始的連接狀態,防火牆將根據先前建立的連接資訊來允許或阻止後續的封包。這樣可以實現對單個連接的跟蹤和管理,提高了安全性和效率。
    • Stateful Firewall通常能夠檢測和防止一些攻擊,如基於連接的攻擊(如SYN洪水攻擊)和特定連接的不正常行為。
  2. Stateless Firewall(無狀態防火牆)

    • 無狀態防火牆僅僅根據單個封包的內容進行過濾和判斷,而不關心連接的狀態。每個封包被視為獨立的事件,沒有考慮先前的封包或連接。
    • Stateless Firewall通常更加簡單和輕量,因為它們不需要維護連接狀態表,並且通常更快速地處理封包。
    • 但是,無狀態防火牆無法提供與連接相關的安全功能,也無法對一些進階攻擊進行有效的防範。

OPNsense,屬於有狀態防火牆。OPNsense使用狀態資訊來追蹤和管理封包的連接狀態,並根據先前建立的連接資訊來進行過濾和授權。

4. (5%)

目前系館防火牆是用 pfSense 架設。請簡單比較 pfSense 與 OPNSense 的差異,至少列舉兩樣?
Ref: opnsense-vs-pfsense

pfSense 和 OPNsense 都是基於 FreeBSD 的開源防火牆/路由器平台
OpnSense 專注於安全性和使用者友善性,而 pfSense 則提供靈活性和廣泛的插件。
這兩種解決方案都可以提供強大的防火牆保護並增強網路安全性。

  • pfSense 的用戶界面較為傳統,使用基於古老技術的WebGUI,功能上可能較為陽春,但已經穩定存在多年。
  • OPNsense 的用戶界面則更現代化和易於使用,具有更多的定製功能和視覺效果。它的WebGUI更加直觀和功能豐富,並且提供了更多的操作選項。
  • pfSense 和 OPNsense 都擁有活躍的開發社區,但兩者的開發模式和社區參與有所不同。
  • pfSense 的開發主要由商業公司 Netgate 領導,其核心代碼不是完全開源的,並且一些高級功能需要付費許可證。
  • OPNsense 的開發由一個開源社區主導,它強調透明度和開放性,所有功能都是完全開源的,並且在功能和安全方面積極進行發展和改進。

OPNSense (80%)

5. (10%)

設定 10.5.0.0/24, 10.8.0.0/24, 10.99.0.0/24 給 VLAN 5, VLAN 8, VLAN 99 三個網路介面。
以下所有大題中,下列關係是等價的
OPT 1=VLAN 5
OPT 2=VLAN 8
OPT 3=VLAN 99

請參考 lab 6 ,三台Client VM 與 OPNSense 作法完全如法炮製
lab6 hackmd
建立一台 FreeBsd64 並安裝 OPNSense
建立三台 alpine linux 並進行安裝 openssh vlan
各自建立 vlan 5, 8, 99

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

6. (10%) 設定以下 alias:

GOOGLE_DNS : 8.8.8.8, 8.8.4.4
ADMIN_PORTS : 22, 80, 443
CSIE_WORKSTATIONS : ws[1~5].csie.org

額外設定(後面會用到) :
PrivateRanges:
10.[5,8,99].0.0/24 + __lan_network

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

7. (10%)

打開 OPNSense 的 SSH 功能。設定只有 VLAN 99 的機器可以透過 ADMIN_PORTS 連到 OPNSense。VLAN 5 與 VLAN 8 皆不允許。

進入 System: Settings: Administration:Secure Shell
勾選以下所有

  • Enable Secure Shell yes
  • Permit root user login yes
  • Permit password login
  • SSH port 22
  • Listen Interfaces OPT3 (vlan99)

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

然後新增最上面的規則
允許Vlan99往防火牆 ADMIN_PORTS 的 TCP 連線

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

8. (10%) VLAN 99 的機器只能存取以下位址或機器:

• Google_DNS
• CSIE_WORKSTATIONS(請提供 traceroute CSIE_WORKSTATIONS 的截圖,若你是 windows 本機可以加參數 -I )
• 這台 OPNSense(請提供 ssh 到 OPNSense management interface 的截圖)

• Google_DNS 的解析規則(後四規則)請見下一題

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

9. (10%)

VLAN 5 的機器可以 ping 到 VLAN 8 的機器,反之則不行。

先在vlan 5 vlan 8 vlan 99 建立以下四個規則

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

PrivateRanges:
10.[5,8,99].0.0/24 + __lan_network

目的寫在 Description
綜合效果是所有vlan無法互相ping
但是都能透過 DNS 解析到外網。
PrivateRanges = vlan5 + vlan8 + vlan99 + lan
拒絕所有本服務內部的需求。
如果是ping Firewall 的服務就用 ICMP 啟用,
否則如果是DNS 請求就使用本地 GOOGLE_DNS 進行解析
最後預設通過所有需求(最低優先)

首先三台機器的DNS server 都做以下設定(這裡用OPT1舉例)
DNS servers = 8.8.8.8 , 8.8.4.4

Image Not Showing Possible Reasons
  • The image was uploaded to a note which you don't have access to
  • The note which the image was originally uploaded to has been deleted
Learn More →

接下來分別設定
VLAN5
在 OPT1 的防⽕牆加上優先規則(打勾的),允許將來⾃ OPT1 (VLAN5) 傳到 OPT2 (VLAN8) 通過

image

部分規則與知識參考這部影片
OPNSense Firewall Rules Explained (youtube)

10. (10%)

在 2024/03/14 整天,VLAN5 這個 interface 不能通過任何的封包。

前往 Firewall: Settings: Schedules
建立當天的時間規則
March 14 - 15 0:00-0:00

Schedules _ Settings _ Firewall _ OPNsense.localdomain - Google Chrome 2024_3_31 下午 09_19_30

然後特別 block Vlan5 (OPT1) 3/14 號無法通過任何封包 IPv4+6

image

11. (10%) 請使用 hping3 或其他指令,每秒分別發送 0.1 Mb, 1 Mb, 10 Mb, 50 Mb 給 OPNsense

server,觀察 reporting/traffic 中的 graph,試著分析圖形的變化。

可以看到隨著資料量擴大,該 Vlan 5 (OPT1) 所傳輸的流量也越大。
影片檔案 :
https://drive.google.com/drive/folders/1GkiqopiF7e9u0OQT1L5tkvgh8B3EDinN?usp=sharing

指令:

hping3 -c 10 -d 100 -S 10.0.2.15
hping3 -c 10 -d 1000 -S <OPNsense_IP>
hping3 -c 10 -d 10000 -S <OPNsense_IP>
hping3 -c 10 -d 50000 -S <OPNsense_IP>

12. (10%)

到 System > Configurations > Backups 中,下載 config.xml,將檔名依照你的學號改成如 b86506054.xml 的檔名,連同作業 PDF 一起繳交。