Sustained attack! Port 5061

Morning,

I have a sustained attack on port 5061 which is open for Sangoma Connect Mobile access, the firewall shows:-

171176 [2022-05-17 07:41:05] NOTICE[154162] res_pjsip/pjsip_distributor.c: Request ‘REGISTER’ from ‘sip:[email protected]’ failed for ‘69.76.43.169:8345’ (callid: e5f4a146065662e4f7a) - Failed to authenticate

for several different IP’s and extensions (that don’t exist).

Do I:-

Trust in the firewall and fail to ban (which currently has a long blacklist due to this)

Do something else? Suggestions please!

Thanks in advance.

Alan

It would be easier if you can explain how you have configured your system. It looks as if your PBX is connected directly to the internet. In case it is not, it’s actually a bit simpler as you could configure the edge router.

I don’t know why an IP like 69.76.43.169 can talk to your FreePBX. I guess it is a configuration issue. I personally never use Fail2Ban, or I leave it in the default configuration, but I don’t really rely on it. But I do have a personal black list for telephony (and other) services.

At the level of iptables/nftables I maintain blacklists, where entire countries and “bad players” are blocked. The “bad players” come from analyzing my log files at various locations and there are typically about 500-600 entries. The entries are actually subnets, which you can easily get from Maxmind’s GeoIP databases. In your case the 69.76.43.169 (assuming that you have not changed the IP) is an older Spectrum address and it is (more or less generally) known that there are a couple compromised Spectrum routers with technically pretty good internet connections out there. I generally block all Spectrum (and other Charter Communications) IPs for European servers. There are a couple of other providers (internet and cloud) that should be treated similarly. I am not saying that these are bad companies, but you do get a lot of dubious traffic from some of their IPs. This ansatz filters more than 99% of the unwanted traffic.

BTW, the “bad players” list depends on the country. In the US you need to block different nets than in Europe.

Why do you have something other than TLS on 5061?

I use PFSense and NAT port 5061 to the PBX, I have used a blacklist firewall rule to block the bad players but they keep coming Thanks for your advise jgttgns I have just checked the IP’s against ipapi - Bulk IP Lookup Tool | Locate IP Address on a Map and the location is all over the globe. Not sure how to proceed.

Bad Players
23.148.145.240
23.148.145.229
185.16.38.123
51.15.158.146
193.46.255.14
217.182.198.219
141.98.10.43
51.159.0.76
51.159.0.63
185.16.38.140
5.39.66.199
163.172.14.15
23.148.145.236
195.154.134.96
62.210.187.86
193.46.255.44
62.210.100.149
173.212.245.245
188.161.154.206
37.187.148.124
5.135.143.184
141.138.140.103
5.135.143.170
23.237.134.170
217.182.45.107
47.104.199.253
37.187.145.49
193.46.255.44
74.121.191.146
92.83.237.249
92.85.187.153
116.47.24.139
94.92.182.70
20.127.75.172
40.71.114.18
189.29.119.234
20.69.93.91
213.6.173.118
20.122.172.118
52.170.185.199
45.134.144.137
193.107.216.90
173.247.232.10
45.227.254.26
194.165.16.71
94.232.43.32
193.107.216.101
20.111.32.201
193.107.216.144
20.118.162.20
20.205.100.78
20.232.108.204
20.70.26.176
20.213.142.148
20.203.209.201
20.119.33.15
141.98.10.121
13.88.20.54
193.107.216.92
20.228.222.192
141.98.11.91
66.169.129.184
68.93.187.61
68.98.208.196
213.6.168.212
47.181.68.29
198.52.50.244
98.212.178.193
69.76.43.169
24.193.160.140
24.227.222.4
97.81.164.33
100.6.135.231
166.70.71.129
74.112.114.210
47.151.16.166
97.95.33.127
24.90.226.59
71.9.116.239
198.167.172.159
68.145.15.97
24.226.121.157
209.204.213.247
64.18.181.210
135.19.253.187
68.69.155.184
107.190.13.64
72.47.167.209
208.58.65.200
72.210.61.13
24.126.216.59
71.47.26.165
206.15.68.157
76.100.49.43
70.112.76.229
63.73.214.18
47.149.33.169
54.174.153.54
54.67.55.229
68.229.213.107
213.6.168.212

5061 is too similar to 5060 not to get heavily attacked.

Do you actually need extensions to access you from random networks? If not set your firewall to only pass 5061 from networks used by you extensions and your ITSP.

If possible switch to TLS.

If possible change the port number to something completely different from 5060.

I’m using 5061 soley for the sangoma connect service, I don’t think I can customise this port. Please correct me if I’m wrong.

Well, I always use pfSense or opnSense myself. I am basically using URL aliases in the firewall section for ipv4 and separately for ipv6 (not much traffic yet). I am using a larger URL list to block ingress traffic from China, Russia and a few more, but I collect everything in a single list. pfBlockerNG would also work, but I don’t want to use complex tools for simple things.

For example, let’s look at 195.154.134.96, which belongs to poneytelecom.eu in Paris and the associated subnet is 195.154.134.0/24 (Maxmind geoip). So I would block 195.154.134.0/24. The background is that you very frequently get attacks from the same subnet and/or service provider.

You seem to get a lot of attacks from Poland, France and Romania, but not much from Germany. I guess you are in Europe yourself, probably in the UK (if the initial address is right and based on the attack pattern). If you were in the US you’d see a lot more traffic from German servers, btw.

I hear what you’re saying. The users of sangoma connect are going to be from UK telco’s so perhaps I should have a UK whitelist followed by a deny all.

Can you or someone else explain what Sangoma Connect does in terms of net connections? I am not using it myself.

You may not need to have your PBX open to the world, they ask to allow certain IP addresses:

107.170.65.67
107.170.123.70
107.170.151.176
159.65.186.176
159.65.251.173
159.65.252.186
159.65.253.49
162.243.35.55
162.243.66.221
162.243.226.67
162.243.226.164
165.227.184.188
167.99.48.91
167.99.119.203
167.99.119.244
192.241.179.113

Source: Technical Details - Sangoma Connect - Documentation

1 Like

Whitelisting those IP is in addition to a proper path from Public WAN to PJSIP transport port…Sangoma Connrct uses TCP by default but you can change it to TCP, UDP or TLS… so if youre behind a NAT router…you need to forward that transport port to your PBX…

I use TLS for Sangoma Connect…

Yes I am using TLS which runs over TCP it seems. Once a call is placed to a mobile device the push notification wakes up the mobile which them contacts the PBX directly on port 5061. So it must be open.

I think perhaps a block of al countries exect UK is the way forward. I may get a performance hit on the firewall though.

The attack continues and fail2ban has been very active!!

Or you could use a default deny config (default setup for incoming traffic on pfSense) and then allow UK, possibly with some exceptions. Blocking is a lot cheaper than going into some protocol negotiations.

It is very unlikely that your attackers are using TCP. I think you have 5061/UDP enabled, for which I see no useful purpose.

Confirmed TCP only opened to 5061.
The attack continues and fail2ban has send me about 150 emails today with no two IP’s the same!
I can watch the asterisk logs files every few seconds another attempt made against it.

Should I be worried, the firewall and fail2ban is working!

IDK what is going on, but I also have seen a TON of attacks and Fail2ban emails on 5061 the last 24hours… I maybe saw 1 fail2ban email a month for the past few years. I wonder what changed/happened…

If you have exposed any signaling port to untrusted traffic, you will get fail2ban notices when intruders are banned. It’s working as expected. If you would prefer to get a few ban notifications a year instead of a minute, change the signaling port to some high random number in the 50k range. It’s not securing anything, but it will make the logs quieter.

Blacklists are pretty worthless IMO, but if you want to go that route suggest using something dynamic like APIBan.

1 Like

So I do use high random number 50k range signaling ports for everything but TLS… I was under the impression after working with support on my D80 that due to the D80 having to use FQDN and TLS that you had to use 5061?? Maybe I misunderstood that and you just had to use TLS but can change TLS transport to any port you want?? Same for Sangoma Connect TLS/SRTP??? That is the ONLY reason I have 5061 open in my firewall…All other ports are not open…

Asterisk isn’t normally configured to check the common name of the certificate, so it is possible that TLS is no longer a safe option, as the real point of certificates is to confirm that you are talking to the owner of a particular common name. The encryption only really protects against local wire tapping attacks.

Although people don’t seem to like “self signed” certificates, which often means really having a private CA, rather than actually self signing the working certificates, either that, or verifying common names are the only ways to really use TLS to prevent a SIP request getting through.

Nothing an stop attacks other than having no internet presence; it is just a question of at what point you detect and presumably, log them. You’d still be under a sustained attack, even if your router is catching them all. All you can do is reduce the number that get a chance to test a user password combination, or a source IP address.

Given that Freepbx WILL (by default ) “verify server”

https://you.com/admin/config.php?display=sipsettings

Can you expound on your position?

More expansively, you could likely use self signed certs for your TLS phones (not wild cards) , but if you use the same self signed cert for your gooey, it probably won’t work so well

There is no technical reason to use the same cert for all your TLS services, and adding strict SNI checking to your various DNS names can pretty well deny DNS leaks on a preliminary HTTP 1 to your public URL thus any IP based connections to your PBX server or indeed to the ‘public’ https server, which uses another cert for VOIP’s TLS service would be unsuccessful