پیکربندی فایروال میکروتیک

پیکربندی فایروال میکروتیک

میکروتیک دارای قسمت فایروال قدرتمندی می باشد که با تنظیم صحیح می توانید از آن به عنوان دیواره آتش در شبکه خود استفاده کنید. مبحث پیکربندی فایروال میکروتیک گسترده است و تسلط کامل بر آن نیاز به صرف زمان و مطالعه زیادی دارد. در صورتی که زمان کافی برای این قضیه ندارد ما در اینجا تنظیمات اولیه فایروال میکروتیک را برای شما آماده کرده ایم. با انجام همین تنظیمات شبکه شما به میزان زیادی ایمن می گردد.
مبحث فایروال میکروتیک شامل دو قسمت حفاظت از خود روتر و همچنین کلاینت های موجود در شبکه شما می باشد. در ادامه با ویپ لند باشید تا پیکربندی ابتدایی دیواره آتش را بررسی کنیم.

تنظیمات اولیه فایروال میکروتیک

پیکربندی فایروال برای روتر میکروتیک

در اینجا تنظیمات فایروال را برای حفاظت از خود روتر انجام می دهیم تا از اتصالات نا خواسته جلوگیری شود.

  • برای کاهش بار روتر با اتصالات جدید کار می کنیم.
  • یک لیست از IP های مجار که می توانند به روتر وصل شوند می سازیم. یک اسم مانند IT_Team به آن اختصاص می دهیم.
  • دسترسی ICMP برای پینگ را باز می کنیم.
  • ورود تمامی موارد دیگر را می بندیم. 192.168.10.0/24 رنج IP مجاز است.
/ip firewall address-list
add address=192.168.10.0/24 list=IT_Team
/ip firewall filter
add action=accept chain=input comment="default configuration" connection-state=established,related
add action=accept chain=input src-address-list=IT_Team
add action=accept chain=input protocol=icmp
add action=accept chain=input protocol=tcp dst-port=8291
add action=drop chain=input

پس از اجرای دستورات فوق و عدم دریافت پیغام خطا نتیجه را در winbox در دو قسمت می توانید ببیند. اگر خواستید از بیرون از مجموعه به میکروتیک وصل شوید پورت 8291 را باز می کنید که دستور آن آورده شده است.
از منوی سمت چپ IP > Firewall، در قسمت Filter Rules و Address List قابل مشاهده است.

تنظیمات فایروال برای کلاینت ها

برای توان عملیاتی سریع تر، پکت های مستقر و مرتبط Established/Related به fasttarck افزوده می شود، فایروال فقط با اتصالات جدید کار می کند.

  • اتصالات تا معتبر Invalid، قطع Drop می شوند و با پیشوند Inavlid لاگ می شوند.
  • رنج آی پی هایی که در اینترنت موجود نیستند اصطلاحا bogons نام دارند. اتصالات ورودی برای وصل شدن به این IP ها از شبکه داخلی قطع می شود. اینترفیس لوکال ما ether2 است. این آدرس ها را در لیست bogons قرار می دهیم و با public_from_Lan! لاگ می کنیم. “!” در میکروتیک یعنی به جز این.
  • بسته های ورودی که Nat نشده اند را قطع می کنیم. Ether5 در اینجا اینترفیس Public است. این اینترفیس می تواند PPPoE کانکشن باشد. با پیشوند !Nat لاگ می شوند.
  • بسته های ورودی که آدرس آی پی های Lan را ندارند قطع می کنیم. رنج آی پی لوکال ما 192.168.10.0/24 است.
/ip firewall address-list
add address=0.0.0.0/8 comment=RFC6890 list=bogons
add address=172.16.0.0/12 comment=RFC6890 list=bogons
add address=192.168.0.0/16 comment=RFC6890 list=bogons
add address=10.0.0.0/8 comment=RFC6890 list=bogons
add address=169.254.0.0/16 comment=RFC6890 list=bogons
add address=127.0.0.0/8 comment=RFC6890 list=bogons
add address=224.0.0.0/4 comment=Multicast list=bogons
add address=198.18.0.0/15 comment=RFC6890 list=bogons
add address=192.0.0.0/24 comment=RFC6890 list=bogons
add address=192.0.2.0/24 comment=RFC6890 list=bogons
add address=198.51.100.0/24 comment=RFC6890 list=bogons
add address=203.0.113.0/24 comment=RFC6890 list=bogons
add address=100.64.0.0/10 comment=RFC6890 list=bogons
add address=240.0.0.0/4 comment=RFC6890 list=bogons
add address=192.88.99.0/24 comment="6to4 relay Anycast [RFC 3068]" list=bogons

/ip firewall filter
add action=fasttrack-connection chain=forward comment=FastTrack connection-state=established,related
add action=accept chain=forward comment="Established, Related"  connection-state=established,related
add action=drop chain=forward comment="Drop invalid" connection-state=invalid log=yes log-prefix=invalid
add action=drop chain=forward comment="Drop tries to reach not public addresses from LAN" dst-address-list=bogons in-interface=ether2 log=yes log-prefix=!public_from_LAN out-interface=!ether2
add action=drop chain=forward comment="Drop incoming packets that are not NATted" connection-nat-state=!dstnat connection-state=new in-interface=ether1 log=yes log-prefix=!NAT
add action=drop chain=forward comment="Drop incoming from internet which is not public IP" in-interface=ether1 log=yes log-prefix=!public src-address-list=bogons
add action=drop chain=forward comment="Drop packets from LAN that do not have LAN IP" in-interface=ether2 log=yes log-prefix=LAN_!LAN src-address=!192.168.10.0/24

بستن سرویس های اتصال بدون استفاده

برای اتصال به میکروتیک روش های مختلفی وجود دارد. معمول ترین روش استفاده از winbox است. در صورتی که فقط از این روش استفاده می کنید بقیه سرویس ها را disable کنید. در اینجا ما همه سرویس ها را به جز winbox بسته ایم. اگر سرویس خاصی مثل SSH را استفاده می کنید آن را باز بگذارید.

/ip service
set api disabled=yes
set api-ssl disabled=yes
set ftp disabled=yes
set ssh disabled=yes
set www disabled=yes
set telnet disabled=yes
set www-ssl disabled=yes

تا اینجا یک فایروال ساده ولی کار آمد برای روتر خود نوشته ایم و آن را تبدیل به یک دیواره آتش کرده ایم. تنظیمات دیگری نیز وجود دارد که دیواره آتش ما را قدرتمند تر می کند.

تنظیمات تکمیلی برای پیکربندی فایروال میکروتیک

پیکربندی فایروال میکروتیک برای مقابله با ویروس ها

در این قسمت تنظیماتی برای جلوگیری از ویروس های شناخته شده انجام می دهیم. میتوانید با تحقیق آن را افزایش دهید. برای آگاهی از هر کدام کامنت آن را بخوانید.

/ip firewall filter

add chain=forward connection-state=established comment="allow established connections"  
add chain=forward connection-state=related comment="allow related connections"
add chain=forward connection-state=invalid action=drop comment="drop invalid connections"  
add chain=virus protocol=tcp dst-port=135-139 action=drop comment="Drop Blaster Worm"
add chain=virus protocol=udp dst-port=135-139 action=drop comment="Drop Messenger Worm"    
add chain=virus protocol=tcp dst-port=445 action=drop comment="Drop Blaster Worm"
add chain=virus protocol=udp dst-port=445 action=drop comment="Drop Blaster Worm"
add chain=virus protocol=tcp dst-port=593 action=drop comment="________"
add chain=virus protocol=tcp dst-port=1024-1030 action=drop comment="________"
add chain=virus protocol=tcp dst-port=1080 action=drop comment="Drop MyDoom"
add chain=virus protocol=tcp dst-port=1214 action=drop comment="________"
add chain=virus protocol=tcp dst-port=1363 action=drop comment="ndm requester"
add chain=virus protocol=tcp dst-port=1364 action=drop comment="ndm server"
add chain=virus protocol=tcp dst-port=1368 action=drop comment="screen cast"
add chain=virus protocol=tcp dst-port=1373 action=drop comment="hromgrafx"
add chain=virus protocol=tcp dst-port=1377 action=drop comment="cichlid"
add chain=virus protocol=tcp dst-port=1433-1434 action=drop comment="Worm"
add chain=virus protocol=tcp dst-port=2745 action=drop comment="Bagle Virus"
add chain=virus protocol=tcp dst-port=2283 action=drop comment="Drop Dumaru.Y"
add chain=virus protocol=tcp dst-port=2535 action=drop comment="Drop Beagle"
add chain=virus protocol=tcp dst-port=2745 action=drop comment="Drop Beagle.C-K"
add chain=virus protocol=tcp dst-port=3127-3128 action=drop comment="Drop MyDoom"
add chain=virus protocol=tcp dst-port=3410 action=drop comment="Drop Backdoor OptixPro"
add chain=virus protocol=tcp dst-port=4444 action=drop comment="Worm"
add chain=virus protocol=udp dst-port=4444 action=drop comment="Worm"
add chain=virus protocol=tcp dst-port=5554 action=drop comment="Drop Sasser"
add chain=virus protocol=tcp dst-port=8866 action=drop comment="Drop Beagle.B"
add chain=virus protocol=tcp dst-port=9898 action=drop comment="Drop Dabber.A-B"
add chain=virus protocol=tcp dst-port=10000 action=drop comment="Drop Dumaru.Y"
add chain=virus protocol=tcp dst-port=10080 action=drop comment="Drop MyDoom.B"
add chain=virus protocol=tcp dst-port=12345 action=drop comment="Drop NetBus"
add chain=virus protocol=tcp dst-port=17300 action=drop comment="Drop Kuang2"
add chain=virus protocol=tcp dst-port=27374 action=drop comment="Drop SubSeven"
add chain=virus protocol=tcp dst-port=65506 action=drop comment="Drop PhatBot, Agobot, Gaobot"
 
add chain=forward action=jump jump-target=virus comment="jump to the virus chain"

بستن پورت اسکنرها

هکر ها برای نفوذ ابتدا روتر شما را اسکن می کنند و بعد از پیدا کردن پورت های باز از آنجا نفوذ می کنند. با دستورات زیر آنها را به یک لیست فرستاده و بلاک می کنیم.

add chain=input protocol=tcp dst-port=22 src-address-list=ssh_blacklist action=drop \
comment="drop ssh brute forcers" disabled=no


add chain=input protocol=tcp psd=21,3s,3,1 action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="Port scanners  to list " disabled=no

/ip firewall filter
add chain=input protocol=tcp psd=21,3s,3,1 action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="Port scanners  to list " disabled=no
add chain=input protocol=tcp tcp-flags=fin,!syn,!rst,!psh,!ack,!urg action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="NMAP FIN Stealth scan"
add chain=input protocol=tcp tcp-flags=fin,syn action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="SYN/FIN scan"
add chain=input protocol=tcp tcp-flags=syn,rst action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="SYN/RST scan"
add chain=input protocol=tcp tcp-flags=fin,psh,urg,!syn,!rst,!ack action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="FIN/PSH/URG scan"
add chain=input protocol=tcp tcp-flags=fin,syn,rst,psh,ack,urg action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="ALL/ALL scan"
add chain=input protocol=tcp tcp-flags=!fin,!syn,!rst,!psh,!ack,!urg action=add-src-to-address-list address-list= "port scanners" \
address-list-timeout=2w comment="NMAP NULL scan"
add chain=input src-address-list="port scanners" action=drop comment="dropping port scanners" disabled=no

پیکر بندی فایروال میکروتیک برای جلوگیری از حملات Brute Force

# To stop SSH/FTP attacks on your router, follow this advice. #
# This configuration allows only 10 FTP login incorrect answers per minute #

add chain=input protocol=tcp dst-port=21 src-address-list=ftp_blacklist action=drop \
comment="drop ftp brute forcers"

add chain=output action=accept protocol=tcp content="530 Login incorrect" dst-limit=1/1m,9,dst-address/1m

add chain=output action=add-dst-to-address-list protocol=tcp content="530 Login incorrect" \
address-list=ftp_blacklist address-list-timeout=3h

# This will prevent a SSH brute forcer to be banned for 10 days after repetitive attempts. Change the timeouts as necessary.#

/ip firewall filter

add chain=input protocol=tcp dst-port=22 src-address-list=ssh_blacklist action=drop \
comment="drop ssh brute forcers" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new \
src-address-list=ssh_stage3 action=add-src-to-address-list address-list=ssh_blacklist \
address-list-timeout=10d comment="" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new \
src-address-list=ssh_stage2 action=add-src-to-address-list address-list=ssh_stage3 \
address-list-timeout=1m comment="" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new src-address-list=ssh_stage1 \
action=add-src-to-address-list address-list=ssh_stage2 address-list-timeout=1m comment="" disabled=no

add chain=input protocol=tcp dst-port=22 connection-state=new action=add-src-to-address-list \
address-list=ssh_stage1 address-list-timeout=1m comment="" disabled=no

# If you want to block downstream access as well, you need to block the with the forward chain:#

add chain=forward protocol=tcp dst-port=22 src-address-list=ssh_blacklist action=drop \
comment="drop ssh brute downstream" disabled=no

جلوگیری از حملات DDOS در پیکربندی فایروال میکروتیک

/ip firewall filter
add chain=forward connection-state=new action=jump jump-target=detect-ddos
add chain=detect-ddos dst-limit=32,32,src-and-dst-addresses/10s action=return
add chain=detect-ddos src-address=192.168.0.1 action=return
add chain=detect-ddos action=add-dst-to-address-list address-list=ddosed address-list-timeout=10m
add chain=detect-ddos action=add-src-to-address-list address-list=ddoser address-list-timeout=10m
add chain=forward connection-state=new src-address-list=ddoser dst-address-list=ddosed action=drop
پیمایش به بالا