顯示具有 MikroTik 標籤的文章。 顯示所有文章
顯示具有 MikroTik 標籤的文章。 顯示所有文章

2017年6月5日 星期一

MikroTik RouterOS (Layer7 Protocol) 封鎖 Torrent、p2p 下載 Policy

總是會有人利用公司的網路下載 Torrent 載點,在試過下列的 Policy 之後效果還不錯。

有些 Torrent 連線是無法完全封鎖,但可以採用限制流量的方式,讓它慢.........................慢的下載。

/ip firewall layer7-protocol
add name=L7-Torrent regexp="^(\x13bittorrent protocol|azver\x01$|get /scrape\?info_hash=get /announce\?info_hash=|get /client/bitcomet/|GET /data\?fid=)|d1:ad2:id20:|\x08'7P\)[RP]"

/queue tree
add limit-at=32k max-limit=32k name=Torrent-Download packet-mark=Torrent-Conn parent=global priority=5 queue=default

/ip firewall filter
add action=add-src-to-address-list address-list=Torrent-Add address-list-timeout=2m chain=forward layer7-protocol=L7-Torrent
在 v6.39 後廠拿掉了對 p2p 阻擋的功能
add action=add-src-to-address-list address-list=Torrent-Add address-list-timeout=2m chain=forward p2p=all-p2p
add action=add-src-to-address-list address-list=Torrent-Add address-list-timeout=2m chain=forward p2p=bit-torrent

/ip firewall mangle
add action=mark-connection chain=prerouting comment=Torrent-Conn dst-port=!0-1024,8291,5900,5800,3389,14147,5222,59905 new-connection-mark=Torrent-Conn protocol=tcp src-address-list=Torrent-Add
add action=mark-connection chain=prerouting dst-port=!0-1024,8291,5900,5800,3389,14147,5222,59905 new-connection-mark=Torrent-Conn protocol=udp src-address-list=Torrent-Add
在 v6.39 後廠拿掉了對 p2p 阻擋的功能
add action=mark-connection chain=prerouting new-connection-mark=Torrent-Conn p2p=all-p2p src-address-list=Torrent-Add
add action=mark-connection chain=prerouting new-connection-mark=Torrent-Conn p2p=bit-torrent src-address-list=Torrent-Add

add action=mark-packet chain=prerouting connection-mark=Torrent-Conn new-packet-mark=Torrent-Conn passthrough=no


針對原廠拿掉封鎖 p2p 的功能,可以採用 Layer7 的方式加減擋掉一些連線:

/ip firewall layer7-protocol
add name=p2p_www regexp="^.*(get|GET).+(torrent|thepiratebay|isohunt|entertane|demonoid|btjunkie|mininova|flixflux|torrentz|vertor|h33t|btscene|bitunity|bittoxic|thunderbytes|entertane|zoozle|vcdq|bitnova|bitsoup|meganova|fulldls|btbot|flixflux|seedpeer|fenopy|gpirate|commonbits).*$"

add name=p2p_dns regexp="^.+(torrent|thepiratebay|isohunt|entertane|demonoid|btjunkie|mininova|flixflux|vertor|h33t|zoozle|bitnova|bitsoup|meg anova|fulldls|btbot|fenopy|gpirate|commonbits).*\$"

/ip firewall mangle
add action=mark-packet chain=prerouting comment="p2p download" disabled=no layer7-protocol=p2p_www new-packet-mark="p2p download" passthrough=no

add action=mark-packet chain=prerouting disabled=no layer7-protocol=p2p_dns new-packet-mark="p2p download" passthrough=no

/queue simple
add name="p2p download" target="" parent=none packet-marks="p2p download" priority=8/8  limit-at=0/0 max-limit=1k/1k burst-limit=0/0 burst-threshold=0/0 burst-time=0s/0s bucket-size=0.1/0.1 queue=default-small/default-small total-queue=default-small

備註:
這裡的 p2p download policy 是用 queue 方式,也可以在 filter 用 drop 方式試試:
add action=drop chain=forward comment="dropping p2p download" packet-mark="p2p download





2017年4月21日 星期五

MikroTik RouterOS RAW 設定

RouterOS 從 6.36 版後多了一個 RAW 功能,上網收集資料了解了解,順便整理起來。

(上圖是依網友的流程圖模仿重畫的)

firewall Raw 列表允許選擇性在 connection tracking 之前繞過或者丟棄封包,這樣能大大的降低 CPU 負載。
該功能非常有助於防御 DOS 攻擊,RAW 列表不能匹配連接狀態的追蹤,例如 connection-state 和 L7 協議。

Raw Policy 出現在 Prerouting chin 和 output chin,並在 connection-tracking 前執行。

Raw 目的是對指定的 IP 訪問可以不經過連接追蹤(connection-tracking),有助於減少 CPU 負載 ,
但對於私有網路做 NAT 轉換,connection-tracking 是必須的,Raw 又如何在實際網路應用中發揮作用。
例如遭到 DDoS 攻擊,可以通過 Raw 規則關閉掉攻擊來源 IP 的連接追蹤,不建立本地連接會話,不予回應,降低 CPU 負載 。

在 Raw 中有兩個連表,分別是 prerouting 和 output:
prerouting 用於處理任何進入路由器的封包
output 用於處理封包來自於路由器,並通過其中一個接口離開,即由路由器自身發出的封包

例如:
遭到 11.22.33.44 的 IP 通過 syn 的 DDoS 攻擊,可以拒絕對該 IP 做連接追蹤,減少 CPU 負載 :
/ip firewall raw
add chain=prerouting src-address=11.22.33.44 action=notrack


另一種情況, 如較大的網路環境,涉及內網和外網請求,在訪問外網時需要做 nat 轉換,而內網則不需要,
因此流量和對話增加的情況下,避免 CPU 負載過高,可以透過 Raw 關閉掉訪問內網的連接追蹤。

例如,在一個大型網絡,內網IP地址段是192.168.0.0/16,關閉掉內網的連接跟蹤,配置如下:
/ip firewall raw
add chain=prerouting dst-address=192.168.0.0/16 action=notrack

配置後,在 connection-tracking 列表將不會看到內網訪問 192.168.0.0/16 的連接訊息

其他 RAW policy:
/ip firewall raw
add action=drop chain=prerouting comment="Port scanners" protocol=tcp psd=21,3s,3,1
add action=drop chain=prerouting comment="Drop oversized unfragmented packets" packet-size=1492-65535 protocol=icmp
add action=drop chain=prerouting comment="SYN-FIN attack protection" protocol=tcp tcp-flags=fin,syn
add action=drop chain=prerouting comment="SYN-RST attack protection" protocol=tcp tcp-flags=syn,rst
add action=drop chain=prerouting comment="X-Mas attack protection" protocol=tcp tcp-flags=fin,psh,urg,!syn,!rst,!ack
add action=drop chain=prerouting comment="NMAP FIN attack protection" protocol=tcp tcp-flags=fin,!syn,!rst,!psh,!ack,!urg
add action=drop chain=prerouting comment="NMAP Push attack protection" protocol=tcp tcp-flags=fin,syn,rst,ack,urg,!psh
add action=drop chain=prerouting comment="NMAP FIN/PSH/URG attack protection" protocol=tcp tcp-flags=fin,psh,urg,!syn,!rst,!ack
add action=drop chain=prerouting comment="NULLflags attack protection" protocol=tcp tcp-flags=!fin,!syn,!rst,!psh,!ack,!urg
add action=drop chain=prerouting comment="ALLflags attack protection" protocol=tcp tcp-flags=fin,syn,rst,psh,ack,urg

add action=drop chain=prerouting comment="Drop udp DNS queries from WAN" dst-port=53 in-interface="WAN" protocol=udp
add action=drop chain=prerouting comment="Drop tcp DNS queries from WAN" dst-port=53 in-interface="WAN" protocol=tcp




資料來源:
http://www.rosjb.com/803.html
https://quchao.com/entry/basic-rules-of-raw-table-in-the-routeros-firewall/


2017年3月24日 星期五

MikroTik RouterOS block attack

以下的 Policy 是引用網路上網友的設定,微調符合自己的需求。
Policy 順序依 comment 欄位的說明。

/ip firewall filter
add chain=forward action=drop protocol=tcp src-address-list=login_blacklist dst-port=80 comment="drop login forcers 1"
add chain=input action=drop protocol=tcp src-address-list=login_blacklist dst-port=22 comment="drop login forcers 1"

add chain=forward action=jump jump-target=login_check connection-state=new protocol=tcp src-address-list=!Local_LAN dst-port=80 comment="drop login forcers 2"
add chain=input action=jump jump-target=login_check connection-state=new protocol=tcp src-address-list=!Local_LAN dst-port=22 comment="drop login forcers 2"

add chain=login_check action=add-src-to-address-list connection-state=new protocol=tcp src-address-list=login_stage3 address-list=login_blacklist address-list-timeout=1d dst-port=80,22 comment="drop login forcers 3"

add chain=login_check action=add-src-to-address-list connection-state=new protocol=tcp src-address-list=login_stage2 address-list=login_stage3 address-list-timeout=1m dst-port=80,22 comment="drop login forcers 4"

add chain=login_check action=add-src-to-address-list connection-state=new protocol=tcp src-address-list=login_stage1 address-list=login_stage2 address-list-timeout=1m dst-port=80,22 comment="drop login forcers 5"

add chain=login_check action=add-src-to-address-list connection-state=new protocol=tcp address-list=login_stage1 address-list-timeout=1m dst-port=80,22 comment="drop login forcers 6"

它的作法是限制來源 IP 在短時間建立多條連線。



2017年2月21日 星期二

MikroTik RouterOS L2TP over IPSec 連線設定

寫得太麻煩了,直接看圖

L2TP 設定:
IP >> Pool 新增一個給 L2TP 使用的 IP 網段(使用的 IP address: 192.168.125.100~192.168.125.200 )












PPP >> Profiles 按 新增一個 L2TP Profile























PPP >> Interface 啟用 L2TP Server














IPSec 設定:
IP >> IPSec >> Peer
新增一筆設定

IP >> IPSec >> Proposals 按 新增


新增使用者帳號:
PPP >> Secret 新增一個使用者帳號
























防火牆設定:
IP >> Firewall >> NAT 新增允許透過 VPN 上外網














IP >> Firewall >> Mangle 新增允許透過 VPN 內網













設定完成內、外網都可以連通。




CubeCOS 虛擬機刪除網路介面,且主機內沒有 virtio 驅動程式成為孤島主機時,進行 virtio iso 掛載流程

 # 當 CubeCOS 虛擬機刪除網路介面,且主機內沒有 virtio 驅動程式成為孤島主機時,進行 virtio iso 掛載流程。 # 步驟一:確認目標虛擬機的底層名稱 # 在 Compute Node(計算節點)上列出運行中的 instance,並反查對應的 OpenSt...