PAYPAL CASH REWARD!! Filter to block rouge SIP registration

Argh, no wonder you all kept asking about this ruleset. I found one MAJOR error, but I am still not getting the results I want. The major error is that you should not be blocking dst but the src

10 chain=output action=add-src-to-address-list protocol=udp address-list=sip_blacklist address-list-timeout=4w2d dst-port=5060-5099

Either way, in psudo here is what I think we are trying to accomplish:

  1. If address is in sip_blacklist BAN AND BURN IP COMPLETELY
  2. If traffic is to port 5060-5099 and source IP is in sip-allow; accept
  3. If traffic is to port 5060-5099 and connections/second under X; accept
  4. If traffic is to port 5060-5099 and connections/second is over X; add source of traffic to sip_blacklist

I keep getting good ips added to the ban list even ones in the white list, so I have disabled rule 0 for now. Does the accept rule not skip subsequent rules?

Ok I changed the rules a bit and now I am not flagging safe addresses. But I am still flagging customers

Export

add action=drop chain=forward disabled=yes src-address-list=sip_blacklist
add chain=forward src-address-list=sip-safe
add chain=forward dst-limit=1,120,dst-address/1m dst-port=5060-5099 protocol=udp
add action=add-src-to-address-list address-list=sip_blacklist address-list-timeout=4w2d chain=forward dst-port=5060-5099 limit=0,0 protocol=udp

Print

78 X chain=forward action=drop src-address-list=sip_blacklist 
79   chain=forward action=accept src-address-list=sip-safe 
80   chain=forward action=accept protocol=udp dst-port=5060-5099 dst-limit=1,120,dst-address/1m 
81   chain=forward action=add-src-to-address-list protocol=udp address-list=sip_blacklist address-list-timeout=4w2d dst-port=5060-5099 limit=0,0

sip scanners still not getting listed in the black list:
ip firewall connections
sip-scan.png

Take a look at SecAst (http://www.telium.ca?secast). It watches for a variety of SIP attacks, can block based on geographic source of IP, watch for unusual calling patterns, etc. And best of all, it can talk to a MikroTik router to manage a list of blocked IP’s.

It’s Asterisk specific (but based on the error messages you posted you’re running Asterisk)


EDIT: Note URL changed to www.telium.ca for this vendor.

Thanks for this link but this thing is too expensive! Mostly, those who use asterisk are NOT willing to pay 5000 USD for it.

Best Regards.

We’ve installed SecAst on call center and healthcare Asterisk servers (large scale installations). If you’re targetting home/small office then FREE is certainly the way to go…

According to their official data, free SecAst won’t communicate with mikrotik.

I’m not sure if it would be possible to block these SIP messages using the router alone, even at layer 7.

Standard Registration is →

REGISTER →
← 401 Unauthorized
REGISTER (With authentication) →
← 200 OK

INVITE →
← 401 Unauthorized
INVITE (With authentication) →
← 200 OK

401’s are a normal part of the SIP dialogue.

The real danger is a customer with several SIP phones behind a single NAT. This would easily exceed the threshold

I would probably opt to use fail2ban on the Asterisk box itself.
If the Asterisk box has iptables installed, just firewall it right there.
If not, a “knock” packet would be easily done as well. - Just make fail2ban send a “strange” packet
of a certain size with a certain source - say UDP SrcAddr = 6.6.6.6 srcPort = 666 and Dst IP=(offender), Dst Port = 5060
Pad the packet to a recognizable size (666bytes? haha). Match these in the router and add dst-addr to ban list.

I am trying to make fail2ban work with mikrotik by adding the problematic addresses to the list. If I succeed, I will make a post with a detailed description. I started from here http://wiki.mikrotik.com/wiki/Use_Mikrotik_as_Fail2ban_firewall but this will not work as it is described on the link… It needs modifications.

That solution you linked to is for a no-password ssh session to log into the MT and executing commands.

You don’t really need all of that - if you can make a bash script that sends an unusual packet from a packet generation utility, (e.g. sendip) then you’re good to go. In my example, you could send a UDP packet with very specific values e.g.
src-IP = 7.7.7.7
src-port = 777
dst-IP =
dst-port = 666

You should never receive such a packet from your ISP as the destination is not in your network, but if you want more security, you could make the contents of the packet have some sort of security phrase/hash to match against in the Mikrotik with the contents check in addtion to the stuff below. (Also a good idea if you’re an ISP and have users behind this router able to send such packets maliciously)

Next you make a rule in forward chain that matches such packets, and adds dst-ip to the BANLIST
e.g.:
/ip firewall filter add chain=forward in-interface= src-address=7.7.7.7 protocol=udp src-port=777 dst-port=666 dst-address-list=!UnBannable action=add-dst-to-address-list address-list=BANLIST address-list-timeout=2d

If you use the dst-address-list=!UnBannable criteria, then you can exempt addresses/networks from being banned by adding them to the UnBannable list.

Now you put two rules into the forward chain:
/ip firewall filter add chain=forward src-address-list=BANLIST action=drop
/ip firewall filter add chain=forward dst-address-list=BANLIST action=drop

Make sure the positioning of these rules in your forward chain makes sense.

All your base are belong to them
I gave up and l2tp every customer with VPBX and let the core SIP proxy run fail2ban