Community discussions

MikroTik App
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Good lock down firewall rules for a home AP router

Mon Jul 28, 2014 1:05 pm

I went crazy, because I wanted to see examples of how to have decent security. My config file works fine and everything but I'm not sure if everything works the way its supposed to as the Access Control Lists (ACLs aka firewall rules) maybe in the wrong order and stuff like that? Its all just mushed together (there are probably duplicate rules). I guess I want everything on its own seperate vlan too.
My router resources are still low but I have a good router for my situation :)
Please help me fix and consolidate this config with your experience, Thanks!

My MikroTik is 192.168.88.1 (GW) it connects to my ISP router (GW) 192.168.254.254
My PC is 192.168.88.254
Last edited by ezrollin on Fri Aug 22, 2014 10:59 pm, edited 1 time in total.
 
Rudios
Forum Veteran
Forum Veteran
Posts: 977
Joined: Mon Mar 11, 2013 12:58 pm
Location: The Netherlands

Re: Good lock down firewall rules for a home AP router

Tue Jul 29, 2014 11:09 am

There are a LOT of duplicate entries.
Also I'm wondering what you want to achieve.

Just some basic rules could look like this

ros code

/ip firewall filter
add action=drop chain=input comment="Drop invalid connections" connection-state=invalid
add chain=input comment="Accept established connections" connection-state=established
add chain=input comment="Accept related connections" connection-state=related
add chain=input comment="Allow access from local network" in-interface=br-PrivateNetwork src-address=192.168.25.0/24
add action=log chain=input comment="Log everything else" disabled=yes log-prefix="IPv4 Drop input RR:"
add action=drop chain=input comment="Drop everything else"
add action=drop chain=forward comment="Drop invalid connections" connection-state=invalid
add chain=forward comment="Accept established connections" connection-state=established
add chain=forward comment="Accept related connections" connection-state=related
add chain=forward comment="Allow traffic from Local network" in-interface=br-PrivateNetwork src-address=192.168.25.0/24
add action=log chain=forward comment="Log everything else" disabled=yes log-prefix="IPv4 Drop forward RR:"
add action=drop chain=forward comment="Drop everything else"
Only allow established/related traffic and inside initiated, rest will be blocked.
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Tue Jul 29, 2014 12:21 pm

My first sentence says: I wanted to see examples of how to have decent security. I want to learn the syntax. I want to learn how to create IDS/IPS systems. Just diving in head first trying to learn this stuff. I like the CLI but dont understand these chains yet. I will revise it soon.

I really enjoy the freeware program called PeerBlock.. I wish I had a hardware version to protect my whole network like at the inside local area (my wan interface)
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Tue Aug 05, 2014 1:32 pm

anyone up for this, want to help me consolidate for a good home wifi AP security? If not I will eventually get around to learning the syntax and config it how i want. thanks
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Fri Aug 15, 2014 12:19 pm

I see a few duplicates in the default config.
Do these rules go from top -> down like in Cisco's ACLs?
If so, is there an implicit deny all at the end?

Ex: in your post, you have a "drop everything else" in the middle of the settings... how does the processor know when to "drop everything else", if the timing is not specified?
Last edited by ezrollin on Fri Aug 22, 2014 11:00 pm, edited 1 time in total.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Good lock down firewall rules for a home AP router

Fri Aug 15, 2014 12:43 pm

it is really important to understand what you are doing and where before you delve deep into the firewall.

here is manual for filter section to start with:
http://wiki.mikrotik.com/wiki/Manual:IP/Firewall/Filter

here is link to packet flow in RouterOS:
http://wiki.mikrotik.com/wiki/Packet_Flow

Really important stuff that you have to understand regarding firewall in RouterOS are chains, you have to know TCP and UDP protocol, have some insight into ICMP. And then there is IPv6.

here you can see how default configuration should look like:
http://wiki.mikrotik.com/wiki/Manual:De ... igurations

p.s. default home/soho router configuration is locked down. Everything you add most probably will make it less secure as nothing beats chain=input action=drop interface=<external>
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Fri Aug 15, 2014 1:08 pm

I cut it down to what I think it should've been as "basic" without duplicates:
/ip firewall filter
add chain=input comment="default configuration" protocol=icmp
add chain=input comment="default configuration" connection-state=established
add chain=input comment="default configuration" connection-state=related
add action=drop chain=input comment="default configuration" in-interface=ether1-gateway
add chain=forward comment="default configuration" connection-state=established
add chain=forward comment="default configuration" connection-state=related
add action=drop chain=forward comment="default configuration" connection-state=invalid
add chain=forward comment="default configuration" connection-state=established
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Good lock down firewall rules for a home AP router

Fri Aug 15, 2014 3:09 pm

by the way, default action is accept, so if there are no rules that are dropping packet, it will be accepted when passed through all the rules.
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Sat Aug 16, 2014 8:10 am

p.s. default home/soho router configuration is locked down. Everything you add most probably will make it less secure as nothing beats chain=input action=drop interface=<external>
So are you saying that rule is a "tcp established" type of rule?
OR is that rule meant to be at the very last (after the allow rules)?
If not, please break it down for me thanks
 
User avatar
Etz
Member Candidate
Member Candidate
Posts: 178
Joined: Thu Mar 27, 2014 10:09 am
Location: Estonia

Re: Good lock down firewall rules for a home AP router

Sat Aug 16, 2014 8:19 am

Final Drop rule should be last...

This is my "simple firewall" example:

ros code

/ip firewall filter
add action=drop chain=input comment="Drop invalid connections" connection-state=invalid
add chain=input comment="Permit established connections" connection-state=established
add chain=input comment="Permit related connections" connection-state=related
add action=log chain=input comment="Log everything else, except LAN" in-interface=!ether01 log-prefix="ip filter input:"

add action=drop chain=input comment="Drop everything else not specified, except LAN" in-interface=!ether01

add action=drop chain=forward comment="Drop invalid connections" connection-state=invalid
add chain=forward comment="Permit established connections" connection-state=established
add chain=forward comment="Permit related connections" connection-state=related
add action=log chain=forward comment="Log everything else, except LAN" in-interface=!ether01 log-prefix="ip filter forward:"

add action=drop chain=forward comment="Drop everything else not specified, except LAN" in-interface=!ether01
If it is first, everything gets instantly dropped and nothing passes trough.

Routers process Access-lists and Firewall statements, line by line beginning from top, untill first match is found.
If match is found, no further rules will be processed for that packet.
 
Rudios
Forum Veteran
Forum Veteran
Posts: 977
Joined: Mon Mar 11, 2013 12:58 pm
Location: The Netherlands

Re: Good lock down firewall rules for a home AP router

Sat Aug 16, 2014 3:30 pm

I prefer putting an allowance rule from the interface I trust (master-port or bridge) and then block all other traffic

ros code

/ip firewall filter
add action=drop chain=input comment="Drop invalid connections" connection-state=invalid
add chain=input comment="Permit established connections" connection-state=established
add chain=input comment="Permit related connections" connection-state=related
add chain=input in-interface=bridge-local src-address=<local lan IP segment>
add action=log chain=input comment="Log everything else" log-prefix="ip filter input:"
add action=drop chain=input comment="Drop everything else" 

add action=drop chain=forward comment="Drop invalid connections" connection-state=invalid
add chain=forward comment="Permit established connections" connection-state=established
add chain=forward comment="Permit related connections" connection-state=related
add chain=forward in-interface=bridge-local src-address=<local lan IP segment>
add action=log chain=forward comment="Log everything else" log-prefix="ip filter forward:"
add action=drop chain=forward comment="Drop everything else"
 
User avatar
Etz
Member Candidate
Member Candidate
Posts: 178
Joined: Thu Mar 27, 2014 10:09 am
Location: Estonia

Re: Good lock down firewall rules for a home AP router

Sat Aug 16, 2014 5:09 pm

I prefer putting an allowance rule from the interface I trust (master-port or bridge) and then block all other traffic.
Well, it all depends...

How many interfaces you have, how much of those are "trusted" and how many are "untrusted" also different approaches exist ;)
For example I have multiple "untrusted" uplink interfaces, hence it makes more sense to block all others except one "trusted" one via single line.
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Wed Aug 20, 2014 1:02 am

Rudios, those "log everything else statements" seems to be crashing my router EVERY TIME I put it in... its logging everything
 
Rudios
Forum Veteran
Forum Veteran
Posts: 977
Joined: Mon Mar 11, 2013 12:58 pm
Location: The Netherlands

Re: Good lock down firewall rules for a home AP router

Wed Aug 20, 2014 8:13 am

Rudios, those "log everything else statements" seems to be crashing my router EVERY TIME I put it in... its logging everything
It will log what will get blocked. It depends on the packets arriving at the router and the rules what is allowed.
If there are many packets send to the router from outside without the request of an internal device it probably is unwanted traffic and it will be blocked.
The log rules are not always necessary though. It is more for debugging if the firewall is not behaving as wanted.
 
User avatar
janisk
MikroTik Support
MikroTik Support
Posts: 6263
Joined: Tue Feb 14, 2006 9:46 am
Location: Riga, Latvia

Re: Good lock down firewall rules for a home AP router

Wed Aug 20, 2014 12:44 pm

use logging only if you really want to see what you are dropping. Else that is just a resource hog that does nothing.
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Wed Aug 20, 2014 2:41 pm

Another problem was like what Etz was saying.. very first rule cant be DROP INPUT or everythings denied!
 
Rudios
Forum Veteran
Forum Veteran
Posts: 977
Joined: Mon Mar 11, 2013 12:58 pm
Location: The Netherlands

Re: Good lock down firewall rules for a home AP router

Wed Aug 20, 2014 7:58 pm

Another problem was like what Etz was saying.. very first rule cant be DROP INPUT or everythings denied!
The first line only drops invalid packets.
 
User avatar
Etz
Member Candidate
Member Candidate
Posts: 178
Joined: Thu Mar 27, 2014 10:09 am
Location: Estonia

Re: Good lock down firewall rules for a home AP router

Wed Aug 20, 2014 8:44 pm

Another problem was like what Etz was saying.. very first rule cant be DROP INPUT or everythings denied!
The first line only drops invalid packets.
He probably meaned:

ros code

add action=drop chain=input
cannot be first, yours is correct implementation...
Also I talked about "final drop rule", not dropping only invalid packets.
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Thu Aug 21, 2014 11:51 pm

I finally went with this one:
http://wiki.mikrotik.com/wiki/Basic_uni ... all_script
I've actually started figuring out how I can edit and and fix things the way I want!
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Fri Aug 22, 2014 11:06 pm

What is the ! in "!ether1"?

Using this firewall list:
http://wiki.mikrotik.com/wiki/Basic_uni ... all_script

ros code

add action=add-src-to-address-list address-list=Port_Scanner address-list-timeout=1w chain=input comment="Port Scanner Detect"\
disabled=no protocol=tcp psd=21,3s,3,1
add action=drop chain=input comment="Drop to port scan list" disabled=no src-address-list=Port_Scanner
Why is it now, always thinking that I am a port scanner?
I see I have a lot of TCP 6 connections but I dont know what that port is?
It didnt do this before and I dont know what changed?
I am in the support user list. Thanks!
 
Rudios
Forum Veteran
Forum Veteran
Posts: 977
Joined: Mon Mar 11, 2013 12:58 pm
Location: The Netherlands

Re: Good lock down firewall rules for a home AP router

Fri Aug 22, 2014 11:22 pm

What is the ! in "!ether1"?

[...]
The exclamation mark indicates 'not' so in your example, not ether1
 
bvandenbremt
newbie
Posts: 27
Joined: Sat Jul 27, 2013 11:34 am

Re: Good lock down firewall rules for a home AP router

Sun Aug 24, 2014 9:12 pm

Protocol 6 stands for TCP
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Tue Aug 26, 2014 7:52 am

I'm getting an way too many logs of 443 (HTTPS) logs in my "log everything else" (false positives)
I bet its just reflexive(aka established) connections and the firewall is not grouping them into the filter #14 (accept established) since its 443 and its accidentally overlooking this.
How can I fix this? thanks

Here is my log and my filters:
443 overload.png
You do not have the required permissions to view the files attached to this post.
 
Rudios
Forum Veteran
Forum Veteran
Posts: 977
Joined: Mon Mar 11, 2013 12:58 pm
Location: The Netherlands

Re: Good lock down firewall rules for a home AP router

Tue Aug 26, 2014 8:04 am

I guess you are wrong in the chain assignment.
The rule you highlighted is on the input chain, traffic destined for the router itself.
Are these all your rules or are there more.
For easy reading I advise to group them per chain, so it is clear in one view what rules will be applied to which packet.
 
User avatar
MadEngineer
Member Candidate
Member Candidate
Posts: 141
Joined: Mon May 02, 2011 10:47 am
Location: New Zealand

Re: Good lock down firewall rules for a home AP router

Mon Sep 01, 2014 11:50 am

I actually prefer what is provided in the book "RouterOS by Example":it has the usual dropping invalid and accepting input from trusted networks then it accepts established, then only accepts NEW forwards from the trusted network, then related forwards then established forwards, finally dropping all other inputs and forwards. This works perfectly. From this I also add in accepted ports for services I want accessible to the world while listing and banning those that make repeated blocked attempts as a means to protect those open ports.

The default firewall rules as set up by the quickset option probably works the same as above but only using the input chain (as per v6.19): first rule is to blindly accept all ICMP, then accept established, then related, rules for vpn go here if enabled, then drop everything on the wan interface.

...
Ex: in your post, you have a "drop everything else" in the middle of the settings... how does the processor know when to "drop everything else", if the timing is not specified?
to directly answer this and to add to the answer already provided, you have to realise that there are multiple ways that data is handled by the router. Yes, the rules are from top down but you might have a few input rules at the top, followed by a deny all input rule, followed by your rules for the forwarded data, followed by say a chain created for icmp that's jumped to prior to the drop all.

Also, muchas gracias for the log option on rules now :)
Last edited by MadEngineer on Tue Sep 02, 2014 11:54 am, edited 2 times in total.
 
ezrollin
Frequent Visitor
Frequent Visitor
Topic Author
Posts: 52
Joined: Mon Jul 28, 2014 8:04 am

Re: Good lock down firewall rules for a home AP router

Tue Sep 02, 2014 9:57 am

MadEngineer, do you have an example of this firewall? a link to the writeup?
I understood the timing.
I like my new firewall, but I'm definately missing something!

anyone know what PeerBlock is?
I would love it if I could implement something like that into a hardware appliance (like a switch or router or ASA)
(allows or denies host IPs based on community defined hosts lists of bad or good hosts)
 
User avatar
MadEngineer
Member Candidate
Member Candidate
Posts: 141
Joined: Mon May 02, 2011 10:47 am
Location: New Zealand

Re: Good lock down firewall rules for a home AP router

Tue Sep 02, 2014 11:49 am

If you can't work it out from my post, buy the book :)