Thu Jun 03, 2021 8:49 am
I find this set of firewall rules and layer 7 works well with encrypted torrents. Tested with Deluge full encryption and Flud on Android full encryption.
/ip firewall layer7-protocol
add comment="Mikrotik Block Torrent" name=layer7-bittorrent-expp 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]"
/ip firewall filter
add action=jump chain=forward comment="Torrent Blocker" jump-target=forward-torrents-non-allowed-devices out-interface-list=WAN src-address-list=!torrents-allowed-devices
add action=add-src-to-address-list address-list=torrent-connections address-list-timeout=1w chain=forward-torrents-non-allowed-devices comment="Torrent Blocker" layer7-protocol=layer7-bittorrent-expp
add action=add-src-to-address-list address-list=torrent-connections address-list-timeout=1w chain=forward-torrents-non-allowed-devices comment="Torrent Blocker" content=tracker
add action=add-src-to-address-list address-list=torrent-connections address-list-timeout=1w chain=forward-torrents-non-allowed-devices comment="Torrent Blocker" content=info_hash
add action=add-src-to-address-list address-list=torrent-connections address-list-timeout=1w chain=forward-torrents-non-allowed-devices comment="Torrent Blocker" content=annonce_peers
add action=add-src-to-address-list address-list=torrent-connections address-list-timeout=1w chain=forward-torrents-non-allowed-devices comment="Torrent Blocker" content=getpeers
add action=add-src-to-address-list address-list=torrent-connections address-list-timeout=1w chain=forward-torrents-non-allowed-devices comment="Torrent Blocker" content=torrent
add action=return chain=forward-torrents-non-allowed-devices comment="Torrent Blocker"
add action=drop chain=forward comment="Torrent Blocker" dst-port=!53,80,443,110,143,993,995,465,587,8080,8291,3389 protocol=tcp src-address-list=torrent-connections
add action=drop chain=forward comment="Torrent Blocker" dst-port=!53,80,443,110,143,993,995,465,587,8080,8291,3389 protocol=udp src-address-list=torrent-connections
Make sure UPnP is not enabled on the the subnet you wish to block torrents or selectively enabled per IP.
I found that increasing the timeout on src-address-list entries helped alot as some torrent client apps did not trigger/reset the original 2m timeout on the address addition.
You can also add these rules above est-rel connections in addition to the others.
/ip firewall filter
add action=drop chain=forward comment="Torrent Blocker" dst-port=!53,80,443,110,143,993,995,465,587,8080,8291,3389 protocol=tcp src-address-list=torrent-connections
add action=drop chain=forward comment="Torrent Blocker" dst-port=!53,80,443,110,143,993,995,465,587,8080,8291,3389 protocol=udp src-address-list=torrent-connections
Helps to catch already running torrent connections.