Did you try to mark IPSec connection/packet in 'mangle', then allow/drop in 'filter'?MikroTik support says that the IPSec traffic is not identifiable in FW rules.
...and how would you go about identifying that traffic in the mangle rules?Did you try to mark IPSec connection/packet in 'mangle', then allow/drop in 'filter'?
Mangle/prerouting for ingress traffic, mangle/postrouting for egress traffic, set src-address and dst-address according to your IPSec policy addresses....and how would you go about identifying that traffic in the mangle rules?
but I'm unclear on how I can identify IPSec traffic
In case someone else has this question:
MikroTik support says that the IPSec traffic is not identifiable in FW rules.
If firewall/filter rules with src and dst addresses works, just use it.But if I'm selecting traffic based on the source and dest address, how is this better than what I can do in filter?
If you are affraid that attacker can break IPSec by setting remote subnet to value defined by your IPSec policy, that means you simply don't know how exactly IPSec works.[Assume the remote end of the IPSec tunnel is 10.0.1.0/24 and the local is 10.0.2.0/24]
filtering for src-addr=10.0.1.0/24 dest-addr=10.0.2.0/24 only means the packet CLAIMS to be from/to those source and destination addresses. There's no guarantee it actually IS.
If I could select traffic via some method like: "in-interface=ipsec1" then you could be sure the traffic ACTUALLY WAS from the ipsec interface, not that it just matched the source/dest addreses.
So, here's where we are:
1) You receive a packet on the WAN interface.
2) It claims to be from somewhere in 10.0.1.0/24 and destined for somewhere in 10.0.2.0/24.
3) You allow it, because those are addresses that are in the remote network and the local one, and if you don't, all your IPSec traffic will get black-holed.
Do you really think that packet with private network address (10.0.1.0/24 in this case) is received on WAN interface???So, what's to distinguish that packet from any other packet arriving at the WAN?
Can you be sure it came from the IPSec tunnel?
Answer: NO, you can't!
Everything described in mentioned article IS available in RouterOS, just RTFM.If you do some looking, you can use --pol ipsec to setup policy handling for IPSec traffic. [All about the iptables policy module]
See: http://twobit.us/blog/2010/11/managing- ... -iptables/
Evidently this is NOT available in ROS, and IMO, should be.
However, I used those addresses as an example - and I felt changing those "examples" in the middle of the thread would be confusing. The point is still the same.There's nothing to prevent spoofing of traffic should someone find a way to get traffic to the WAN side of the RB that has a source addy of 10.0.1.0/24 and dest of 10.0.2.0/24. [These examples are private IP ranges and input sanitization will help these cases some. But input sanitization won't help [I don't think] if the networks at either end of the ipsec tunnel are publicly routed ip ranges.]
Don't try to be sarcastic. When I'm reading sentences like this, I'm feeling that I'm wasting my time and you are unable to learn new things.[Should be easy, since it's in the effing manual, right?]
Fine by me.For me, EOT.
But I don't think this IS possible in MT. If it was, I could find someone talking about it, and showing it's possible.Everything described in mentioned article IS available in RouterOS, just RTFM.
I'll happily go into the sunset with that information. I'd even be glad to send you $20 just for the trouble. Paypal work?Everything described in mentioned article IS available in RouterOS, just RTFM.
If 1.0.1.10 and 1.0.2.10 are publicly routed addresses, than sending traffic from one host to another is just normal traffic. It doesn't have to route via an ipsec tunnel. Unless you're doing NAT, then it's a simple route from one to the other. Since it's simple routing, once the RB [or any firewall for that matter] see's a packet with valid source and destination ip addresses, if there isn't a default drop policy, it will simply route the packet.Traffic between clients (1.0.1.10 to 1.0.2.10) is only possible
when IPSec Security Associations between gateways (1.0.1.1 <-> 1.0.2.1) are established.
Ok, first rules:However, that doesn't resolve the proclamation that "Everything in that article is possible in ROS."
It just isn't possible - at least not in any way I've seen.
iptables --table filter --append INPUT \
--in-interface extif \
--proto udp \
--destination ${PUBLIC_IP} \
--dport 500 \
--source 0.0.0.0/ \
--sport 500 \
--jump ACCEPT
iptables --table filter --append INPUT \
--in-interface extif \
--proto udp \
--destination ${PUBLIC_IP} \
--dport 4500 \
--source 0.0.0.0/0 \
--sport 4500 \
--jump ACCEPT
iptables --table filter --append OUTPUT \
--out-interface extif \
--proto udp \
--destination 0.0.0.0/0 \
--dport 500 \
--source ${PUBLIC_IP} \
--sport 500 \
--jump ACCEPT
iptables --table filter --append OUTPUT \
--out-interface extif \
--proto udp \
--destination 0.0.0.0/0 \
--dport 4500 \
--source ${PUBLIC_IP} \
--sport 4500 \
--jump ACCEPT
}
/ip firewall filter
add action=accept chain=input comment=IKE&NAT-T disabled=no dst-port=500,4500 protocol=udp
add action=accept chain=output comment=IKE&NAT-T disabled=no dst-port=500,4500 protocol=udp
iptables -A FORWARD \
--in-interface extif \
--source 10.0.2.0/24 \
--out-interface wirif \
--destination 10.0.1.0/24 \
--jump ACCEPT
iptables -A FORWARD \
--in-interface wirif \
--source 10.0.1.0/24 \
--out-interface extif \
--destination 10.0.2.0/24 \
--jump ACCEPT
iptables --append FORWARD \
--match policy \
--dir in \
--pol ipsec \
--mode tunnel \
--tunnel-dst ${PUBLIC_IP} \
--tunnel-src 0.0.0.0/0 \
--in-interface extif \
--source 10.0.2.0/24 \
--out-interface wirif \
--destination 10.0.1.0/24 \
--jump ACCEPT
iptables --append FORWARD \
--match policy \
--dir out \
--pol ipsec \
--mode tunnel \
--tunnel-dst 0.0.0.0/0 \
--tunnel-src ${PUBLIC_IP} \
--in-interface wirif \
--source 10.0.1.0/24 \
--out-interface extif \
--destination 10.0.2.0/24 \
--jump ACCEPT
Did you mean non encrypted traffic from '10.0.2.0/24' and '10.0.1.0/24' subnets or the whole traffic incoming on WAN interface???drop the rest (non encrypted) traffic
iptables --policy INPUT DROP
iptables --policy OUTPUT DROP
iptables --policy FORWARD DROP
iptables --append FORWARD \
--match policy \
--dir in \
--pol ipsec \
--mode tunnel \
--tunnel-dst ${PUBLIC_IP} \
--tunnel-src 0.0.0.0/0 \
--in-interface extif \
--source 10.0.2.0/24 \
--out-interface wirif \
--destination 10.0.1.0/24 \
--jump ACCEPT
iptables --append FORWARD \
--match policy \
--dir out \
--pol ipsec \
--mode tunnel \
--tunnel-dst 0.0.0.0/0 \
--tunnel-src ${PUBLIC_IP} \
--in-interface wirif \
--source 10.0.1.0/24 \
--out-interface extif \
--destination 10.0.2.0/24 \
--jump ACCEPT
Without IPSec policy match, IPSec tunnel IS NOT established, thus there IS NO IPSec traffic flow.Without ipsec policy match, then spoofed traffic will very potentially flow through the filter-rules
Exactly! You're exactly right, but you're still missing the picture.Even if you send spoofed packet, with proper subnet src and dst addresses to gateway's public interface,
it'll be treated by gateway like every other packet on public/WAN interface (according to your firewall rules in 'input' chain), but not part of IPSec traffic.
So, the issue isn't compromising the VPN tunnel. The problem is the fact that the remote VPN ip/network address [or range] is "privileged" in our forward rules. We want to prevent anyone from exercising that privileged state unless we can be sure they're actually, verified members of that privileged network.These rules look pretty tight right? We’ve limited the the networks that can communicate and the interfaces on which the traffic should originate. We can do better though.
I’m particularly wary of the interface on the router that’s connected to the internet. The iptables rules above will allow the traffic we want to allow but it doesn’t require that the traffic from the 10.0.2.0/24 network arrive over the VPN! Theoretically an attacker that isn’t on the VPN could spoof traffic with the VPN IP and exchange packets with the protected 10.0.1.0/24 network. This is bad.
Yes, that is exactly what is happening.[More complete/expansive explanation:
Without being able to determine which traffic came through the ipsec tunnel [which ipsec policy matching does] you can't make any decisions about which traffic you see in the filter rules to drop or allow. ANY packet which has the apparent correct source and destination addresses will look the same, regardless of it's origin - ipsec tunnel or just the WAN interface.
You either drop all, or allow all. If you allow all, ipsec traffic will flow, but so will spoofed traffic. If you deny all, you will be protected against a spoof attack, but then all your ipsec traffic will get dropped or rejected - which obviously is a no-go.]
We're talking about traffic that arrives at the WAN interface vs traffic that arrives via IPSec.trust me, if you have an ipsec policy in place that traffic will either need to be successfully decrypted, or dropped. it will be dropped before it even hits the forward chain in the firewall if it didnt come thru the tunnel.
Since you can't distinguish IPSec traffic from regular WAN traffic, you have to pass traffic that has a src-address of the ip/network at the remote end of the ipsec tunnel, and the dst-address of the local network.So, the issue isn't compromising the VPN tunnel. The problem is the fact that the remote VPN ip/network address [or range] is "privileged" in our forward rules. We want to prevent anyone from exercising that privileged state unless we can be sure they're actually, verified members of that privileged network.
No, you should NEVER see traffic from that source anywhere in the routeros firewall UNLESS it has been processed by ipsec and actually came thru the tunnel. If its not part of the tunnel, meaning spoofed, arrived by magic, whatever - it will not be processed / routed / accepted.But if a packet with those same source and destination addresses can be passed to the WAN interface of your ROS device - even if it's not inside the ipsec tunnel, your ROS device will pass it into your privileged LAN - EVEN THOUGH IT DIDN'T COME FROM THE IPSEC TUNNEL.
When spoofed packet hits WAN interface, firstly is checked against 'prerouting' chain.router goes through the route in order to find a match to destination IP address of packet. When match is found - packet will be send out via corresponding port or to the router itself . In case of no match - packet will be discarded.
IPsec is a service as well. Read RFC4301 (http://tools.ietf.org/html/rfc4301). From that RFC:Internet Protocol security (IPSec) is a protocol, not a service, that provides encryption, integrity, and authentication services for IP-based network traffic
changeip is right, a packet, that matches your IPsec policy but arrives to your device unprotected must be discarded before it ever reaches your firewall chains. I'm not sure if ROS does it this way, but if it doesn't then it is a serious violation of the standards that exposes a major security problem and must be fixed ASAP.5.2. Processing Inbound IP Traffic (unprotected-to-protected)
....
IPsec MUST perform the following steps:
....
3b. If the packet is not addressed to the device or is addressed to
this device and is not AH or ESP, look up the packet header in
the (appropriate) SPD-I cache. If there is a match and the
packet is to be discarded or bypassed, do so. If there is no
cache match, look up the packet in the corresponding SPD-I and
create a cache entry as appropriate. (No SAs are created in
response to receipt of a packet that requires IPsec protection;
only BYPASS or DISCARD cache entries can be created this way.) If
there is no match, discard the traffic. This is an auditable
event. The audit log entry for this event SHOULD include the
current date/time, SPI if available, IPsec protocol if available,
source and destination of the packet, and any other selector
values of the packet that are available.
in my case the tunnel is not always up. will the packages also discarded when the tunnel is down ?RouterOS does exactly as it is written in RFC and what changeip said. If there is no match packets are discarded.
in my case the tunnel is not always up. will the packages also discarded when the tunnel is down ?RouterOS does exactly as it is written in RFC and what changeip said. If there is no match packets are discarded.
Mrz: See http://forum.mikrotik.com/viewtopic.php?f=2&t=74500This is not solution for Ipsec/L2TP setups, works only with ipsec in tunnel mode.
See this wiki article if anyone is interested:
http://wiki.mikrotik.com/wiki/IPSEC_bet ... ed_traffic
I gave up on it a while ago... I'll have to give it another test. ThanksI just copy pasted the same rules from wiki.. Works like a charm.
Probably you have misconfiguration somewhere. Contact support with attached supout files.
Well, I have checked and rechecked my configuration and it still fails to hit that mangle rule. I use tunnel-mode... I have asked the same question to the support department and they say it works. I can't find any reason what it's not working for me. This only works in tunnel-mode, or are supposed to work there at least, so if you're using transport mode there is no possibility to match it. Really bad!I gave up on it a while ago... I'll have to give it another test. ThanksI just copy pasted the same rules from wiki.. Works like a charm.
Probably you have misconfiguration somewhere. Contact support with attached supout files.
/ip ipsec policy
set 0 dst-address=192.168.7.0/24 src-address=0.0.0.0/0
/ip firewall filter
.....
add action=accept chain=input dst-port=500,4500 protocol=udp
add action=drop chain=input
0 T * group=default src-address=0.0.0.0/0 dst-address=192.168.7.0/24 protocol=all proposal=default template=yes
1 DA src-address=0.0.0.0/0 src-port=any dst-address=192.168.7.20/32 dst-port=any protocol=all action=encrypt level=unique ipsec-protocols=esp tunnel=yes
sa-src-address=1.1.1.1 sa-dst-address=2.2.2.2 proposal=default priority=2 ph2-count=1
/ip firewall filter add chain=input action=accept ipsec-policy=in,ipsec place-before=<last deny rule>
/ip firewall filter add chain=input action=accept protocol=ipsec-esp place-before=<last deny rule>