Tag Archives: Mikrotik

MikroTik – blokowanie programów p2p przy użyciu protokołów L7

Od wersji 6.39 RouterOS, protokoły P2P można zablokować wyłącznie używając wyrażeń regularnych (tzw. Regexp) w zakładce  Layer 7 Protocols (w Filter Rule -> General zniknęła funkcja P2P). Poniżej przedstawiona są restrykcyjne reguły, które bardzo skutecznie blokują ruch P2P (w skrypcie poniżej tylko BitTorrent).
Cała konfiguracja opiera się na 5 krokach.

Dodanie wpisów L7:

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

Markowanie ruchu BitTorrent:

/ip firewall mangle
add action=mark-connection chain=forward comment=mark_dw_connection in-interface=pppoe-out1 log-prefix=\
 all-connections new-connection-mark=mark_dw_connection passthrough=yes
add action=mark-packet chain=forward comment=mark_dw_packet connection-mark=mark_dw_connection new-packet-mark=\
 mark_dw_packet passthrough=yes

add action=mark-packet chain=forward comment=torrent_dw_pk layer7-protocol=bittorrent log-prefix=BitTorrent-log \
 new-packet-mark=torrent_dw_pk packet-mark=mark_dw_packet passthrough=no

Dodanie hostów do listy P2P-users, którym będą blokowane porty 0 – 1024. Komputery, które mają mieć pełen dostęp do internetu i mogą ściągać z BT można umieścić na liście, np o nazwie allow-p2p:

/ip firewall filter
add action=add-src-to-address-list address-list=P2P-Conn address-list-timeout=30m chain=forward comment=\
 "bittorrent - dodanie hostow na liste do blokowania portow" log=yes log-prefix=P2P-users packet-mark=\
 torrent_dw_pk src-address-list=!allow-p2p

Blokowanie portów komputerom, które korzystają z BitTorrent:

/ip firewall raw
add action=drop chain=prerouting comment="Blokowanie portow hostom korzystajacym z programow p2p" dst-port=!0-1024 \
 protocol=tcp src-address-list=P2P-Conn
add action=drop chain=prerouting dst-port=!0-1024 protocol=udp src-address-list=P2P-Conn

Jest to ostatnia reguła blokująca wcześniej zamarkowane pakiety – na wypadek gdy ruch przejdzie przez niezablokowany port z przedziału 0 – 1024.

/ip firewall filter
add action=drop chain=forward comment=\
 "BitTorrent - blokowanie pozostalego ruchu BitTorrent, przechodzacego przez niezablokowane porty: 0 - 1024" \
 packet-mark=torrent_dw_pk src-address-list=!allow-p2p

 

Poniżej przedstawione są filtry L7 (definicje Regexp), które blokują również inne protokoły (programy) p2p:

add name=chomikuj regexp="^.+(chomikuj.p).*\$"
add name=emule regexp="^[\\xc5\\xd4\\xe3-\\xe5].\?.\?.\?.\?([\\x01\\x02\\x05\\x14\\x15\\x16\\x18\\x19\\x1a\\x1b\\x1c\
 \\x20\\x21\\x32\\x33\\x34\\x35\\x36\\x38\\x40\\x41\\x42\\x43\\x46\\x47\\x48\\x49\\x4a\\x4b\\x4c\\x4d\\x4e\\x4f\\x\
 50\\x51\\x52\\x53\\x54\\x55\\x56\\x57\\x58[\\x60\\x81\\x82\\x90\\x91\\x93\\x96\\x97\\x98\\x99\\x9a\\x9b\\x9c\\x9e\
 \\xa0\\xa1\\xa2\\xa3\\xa4]|\\x59................\?[ -~]|\\x96....\$)"
add name=goboogy regexp=\
 "<peerplat>|^get /getfilebyhash\\.cgi\\\?|^get /queue_register\\.cgi\\\?|^get /getupdowninfo\\.cgi\\\?"
add name=soribada regexp="^GETMP3\r\
 \nFilename|^\01.\?.\?.\?(Q:\\+|Q2:)|^\10[\14-\16]\10[\15-\17].\?.\?.\?.\?\$"
add name=gnutella regexp="^(gnd[\01\02]\?.\?.\?\01|gnutella connect/[012]\\.[0-9]\r\
 \n|get /uri-res/n2r\\\?urn:sha1:|get /.*user-agent: (gtk-gnutella|bearshare|mactella|gnucleus|gnotella|limewire|i\
 mesh)|get /.*content-type: application/x-gnutella-packets|giv [0-9]*:[0-9a-f]*/|queue [0-9a-f]* [1-9][0-9]\?[0-9]\
 \?\\.[1-9][0-9]\?[0-9]\?\\.[1-9][0-9]\?[0-9]\?\\.[1-9][0-9]\?[0-9]\?:[1-9][0-9]\?[0-9]\?[0-9]\?|gnutella.*content\
 -type: application/x-gnutella|...................\?lime)"
add name=shoutcast regexp="icy [1-5][0-9][0-9] [\t-\r -~]*(content-type:audio|icy-)"
add name=bittorrent2 regexp=\
 "^(\13bittorrent protocol|azver\01\$|get/scrape\\\?info_hash=)|d1:ad2:id20:|\08'7P\\)[RP]"
add name=directconnect regexp="^(\\\$mynick |\\\$lock |\\\$key )"
add name=ares regexp="^\03[]Z].\?.\?\05\$"
add name=fasttrack regexp="^get (/.download/[ -~]*|/.supernode[ -~]|/.status[ -~]|/.network[ -~]*|/.files|/.hash=[0-9\
 a-f]*/[ -~]*) http/1.1|user-agent: kazaa|x-kazaa(-username|-network|-ip|-supernodeip|-xferid|-xferuid|tag)|^give \
 [0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9]\?[0-9]\?[0-9]\?"
add name=napster regexp="^(.[\02\06][!-~]+ [!-~]+ [0-9][0-9]\?[0-9]\?[0-9]\?[0-9]\? \"[\t-\r -~]+\" ([0-9]|10)|1(send\
 |get)[!-~]+ \"[\t-\r -~]+\")"
add name=soulseek regexp="^(\05..\?|.\01.[ -~]+\01F..\?.\?.\?.\?.\?.\?.\?)\$"
add name=imesh regexp="^(post[\t-\r -~]*<PasswordHash>................................</PasswordHash><ClientVer>|4\80\
 \?\r\?\FC\FF\04|get[\t-\r -~]*Host: imsh\\.download-prod\\.musicnet\\.com|\02(\01|\02)\83.\?.\?.\?.\?.\?.\?.\?.\?\
 .\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?.\?\02(\01|\02)\83)"
add name=mohaa regexp="^\FF\FF\FF\FFgetstatus\
 \n"
add name=tor regexp=TOR1.*<identity>
add name=bittorrent regexp="^(\\x13bittorrent protocol|azver\\x01\$|get /scrape\\\?info_hash=get /announce\\\?info_ha\
 sh=|get /client/bitcomet/|GET /data\\\?fid=)|d1:ad2:id20:|\\x08'7P\\)[RP]"
add name=bittorrent-sites regexp="^.+(|torrenty.org|thepiratebay|isohunt|entertane|demonoid|btjunkie|mininova|flixflu\
 x|torrentz|vertor|h33t|btscene|bitunity|bittoxic|thunderbytes|entertane|zoozle|vcdq|bitnova|bitsoup|meganova|full\
 dls|btbot|flixflux|seedpeer|fenopy|gpirate|commonbits|super-torrent|ex-torrenty-org|shadows-torrents|best-torrent\
 y|miliontorrent|mega-torrenty|torrent.top-100|polskitorrent).*\$"
add name="emule\?" regexp="\\xe3[\\x01-\\xff].\?.\?.\?\\x01.*\\xc5[\\x01-\\xff].\?.\?.\?\\x01.*\\xc5[\\x01-\\xff].\?.\
 \?.\?\\x02.\r\
 \n*\\xe3[\\x01-\\xff].\?.\?.\?\\x4c"