Tip: type a SIP code like 488, or a problem like one-way audio. Use ↑ ↓ and Enter.

Security

How to Protect Your PBX From Toll Fraud and SIP Attacks

On this page
  1. How toll fraud happens
  2. Keep SIP off the open internet
  3. Strong secrets and no anonymous calls
  4. fail2ban for Asterisk
  5. Restrict what can be dialled
  6. Limits at the provider
  7. Encrypt, patch and lock down the GUI
  8. Monitor call records and alert
  9. What to do if you are hit
  10. Hardening checklist

Toll fraud happens when someone gains the ability to make calls through your PBX or SIP trunk and uses it to call expensive destinations, usually international or premium-rate numbers that pay them a share of the revenue. You prevent it by keeping SIP and the admin interface off the open internet, using strong random credentials, restricting what can be dialled, capping spend with your provider, and watching call records so an attack is caught in minutes rather than days.

How toll fraud happens

The usual scheme is International Revenue Share Fraud (IRSF): the fraudster obtains high-cost international or premium numbers that pay out per minute, then pushes as many calls as possible to them through someone else's phone system, typically at night, over weekends or on public holidays. The ways in are well known:

  • SIP scanning and brute force. Scanners sweep the internet for anything answering on the SIP ports. Tools in the SIPVicious family (svmap finds SIP devices, svwar enumerates extensions, svcrack guesses passwords) and their imitators send OPTIONS and REGISTER requests at high rates; a user agent such as friendly-scanner in your logs is a classic sign. An extension whose password is 1234 or its own number falls quickly.
  • Exposed admin GUI. A web interface reachable from the internet invites password guessing and exploitation. In 2025, Sangoma warned of an actively exploited vulnerability in the FreePBX administrator interface that put systems with an internet-exposed admin panel at risk.
  • Voicemail and DISA. DISA gives outside callers a dial tone, so a weak PIN is an open line. Voicemail with dial-out or callback enabled (dialout and callback in Asterisk's voicemail.conf), or remotely changeable call forwarding, lets an attacker forward your number abroad and then call it.
  • Phones and provisioning. Phone web interfaces on default passwords can reveal SIP credentials, and public provisioning servers may hand out config files named after MAC addresses to anyone who guesses the name.
  • Leaked trunk credentials. These can be used from anywhere, bypassing your PBX entirely, unless the provider only accepts your IP address.
Why it gets expensive. High-cost destinations can cost many times more per minute than a local call, and attackers run many simultaneous channels. On a post-paid trunk with no spend cap, the only limit is how long it takes someone to notice, which over a long weekend can be days.

Keep SIP off the open internet

The most effective control is to refuse SIP from addresses that have no reason to send it. Do not expose 5060 and 5061 to the whole internet unless you must.

  • Allowlist your provider's signalling IPs, including backup SBCs, and drop everything else on the SIP ports.
  • Bring remote phones in over a VPN, or through an SBC built to face the internet.
  • If remote phones must register directly, allowlist their static IPs. FreePBX's Responsive Firewall option rate-limits SIP from unknown addresses and trusts those that register successfully.
# Allow SIP only from the provider's networks, then drop the rest.
# These rules must come before any rule that accepts all traffic.
iptables -A INPUT -p udp --dport 5060 -s 198.51.100.0/24 -j ACCEPT
iptables -A INPUT -p udp --dport 5060 -s 203.0.113.64/27 -j ACCEPT
iptables -A INPUT -p udp --dport 5060 -j DROP

Adapt this to your firewall and cover TCP and TLS ports if you use them. Moving SIP to a non-standard port cuts the volume of automated scanning in your logs, but it is not a security control: a port scan finds it, and it does nothing against a targeted attacker. Treat it as noise reduction on top of an allowlist, never instead of one.

Strong secrets and no anonymous calls

  • Random SIP secrets. Nobody needs to remember one, because it lives in the phone's configuration. openssl rand -hex 16 gives 32 hex characters that almost every phone accepts. Keep the long random secrets FreePBX generates.
  • Voicemail PINs. Not the extension number, not 0000 or 1234, and longer than four digits where allowed.
  • Admin passwords. Change every default: PBX GUI, user portal, phone web interfaces, SSH and database.
  • Per-extension ACLs. Limit each extension to the networks it should register from with deny and permit on PJSIP endpoints, or the Permit and Deny fields on FreePBX extensions.

Disable anonymous and guest calls, which arrive without authentication:

  • Asterisk PJSIP: requests that match no endpoint are rejected unless an endpoint named anonymous exists; if it does, its context must only reach inbound destinations.
  • chan_sip (older systems): allowguest=no, plus alwaysauthreject=yes so failed logins do not reveal valid usernames.
  • FreePBX: under Settings → Asterisk SIP Settings, set Allow Anonymous Inbound SIP Calls and Allow SIP Guests to No.

fail2ban for Asterisk

fail2ban watches the Asterisk log, counts failed authentications per IP and bans repeat offenders. Enable its shipped asterisk jail rather than writing your own: it bans both UDP and TCP, while a home-made jail with a single default action may only ban TCP, leaving SIP over UDP open. In /etc/fail2ban/jail.local:

[asterisk]
enabled  = true
logpath  = /var/log/asterisk/messages
maxretry = 5
findtime = 600
bantime  = 86400

Point logpath at the file your logger.conf writes notices to; the name varies by version. Apply with fail2ban-client reload and check with fail2ban-client status asterisk. On FreePBX, use its built-in intrusion detection rather than editing fail2ban by hand. fail2ban is a backstop: slow attacks spread across many IPs stay under the threshold. If legitimate phones get banned, the SIP registration troubleshooting checklist shows how to lift the ban.

Restrict what can be dialled

Each extension and trunk lands in a dial plan context that should allow only what that caller needs. Above all, calls arriving from a trunk must never reach your outbound routes.

  • Allowlist patterns. Build outbound routes from explicit number formats, not a catch-all such as X. or ..
  • Separate international. Give it its own route, limited to the extensions that need it and protected with a PIN (FreePBX PIN Sets), or block it if nobody calls abroad.
  • Block premium-rate ranges. Ask your provider which prefixes are premium-rate in your numbering plan.
  • Restrict after hours. Use time-based rules (FreePBX time groups, or GotoIfTime in Asterisk), or ask the provider to bar international calls outside business hours.
  • Keep emergency numbers working. Test them after every change.
[from-internal-restricted]
; national numbers in a 10-digit plan such as South Africa's
exten => _0[1-8]XXXXXXXX,1,Dial(PJSIP/${EXTEN}@mytrunk)
; international (00 prefix): refuse
exten => _00.,1,Hangup()

This illustrates the approach only; emergency numbers and short codes need their own patterns.

Limits at the provider

Controls at the provider still work when the PBX itself is compromised, so ask for:

  • International barring if you do not need it, or a list of allowed countries if you do.
  • A daily or monthly spend cap, or a prepaid balance.
  • A concurrent channel limit that matches your real peak, not the maximum the trunk allows.
  • IP locking, so the trunk only accepts traffic from your public addresses.
  • Usage or fraud alerts by email or SMS.

On the PBX, the FreePBX trunk setting Maximum Channels, or GROUP() and GROUP_COUNT() in an Asterisk dial plan, caps concurrent outbound calls.

Encrypt, patch and lock down the GUI

  • TLS and SRTP stop eavesdropping on signalling and audio, including digest responses that could be cracked offline. They do not stop brute force.
  • Patch. Follow the Asterisk security advisories, update FreePBX modules (fwconsole ma updateall then fwconsole reload), the operating system and phone firmware.
  • Admin access only via VPN or allowlisted IPs: PBX GUI, user portal, phone web interfaces, provisioning and SSH.

Monitor call records and alert

Review call detail records daily (on FreePBX, Reports → CDR Reports) and automate alerts. FreePBX stores CDRs in asteriskcdrdb.cdr, so a cron job can run a query like this and email any rows:

mysql -e "SELECT calldate, src, dst, billsec, channel
  FROM asteriskcdrdb.cdr
  WHERE calldate > NOW() - INTERVAL 1 HOUR
    AND (dst LIKE '00%' OR dst LIKE '+%')
  ORDER BY calldate DESC;"

Adjust the prefixes to your dial plan (011 is the international prefix in North America). Also alert on unusual concurrent calls (asterisk -rx "core show channels count"), after-hours calls, bursts of short calls to sequential numbers, registrations from unfamiliar IPs, and spikes of failed authentications, which show as streams of 401 or 403 responses.

What to do if you are hit

  1. Stop the calls. Disable the trunk or outbound routes, hang up active calls with asterisk -rx "channel request hangup all", and block the attacking IPs.
  2. Phone your provider, do not just email. Ask them to bar international calls, suspend the trunk if needed, and say which calls they see from which IP; leaked trunk credentials may be used without touching your PBX. Ask about their fraud process, because terms vary and you may be liable.
  3. Preserve evidence. Copy logs, CDRs and firewall logs before they rotate, along with any SIP traces of the fraudulent calls.
  4. Find the way in. Look for registrations from unknown IPs, failed authentications followed by a success from the same address, and new extensions, trunks, routes, admin users or custom dial plan (extensions_custom.conf on FreePBX).
  5. Change every secret, from extensions, trunks and voicemail PINs to GUI, phone, SSH and database passwords, then re-provision the phones.
  6. Rebuild if the server was compromised. Unknown users, processes, cron jobs or files in the web root mean reinstalling and restoring reviewed configuration, not cleaning in place.
  7. Close the gap before reconnecting.

Hardening checklist

ControlDone when
SIP ports allowlistedOnly provider IPs, VPN and known sites reach 5060/5061
Admin interfaces privateGUI, portal, SSH and phone pages only via VPN or allowlist
Strong secretsRandom SIP secrets, non-trivial voicemail PINs, no default passwords
No anonymous callsAnonymous and guest SIP disabled or confined to inbound-only contexts
fail2ban activeAsterisk jail enabled and banning both UDP and TCP
Dial plan restrictedExplicit patterns, international separated, premium ranges blocked
Provider limitsSpend cap, channel limit, international barring or allowlist, IP lock
PatchedAsterisk, FreePBX modules, OS and phone firmware up to date
MonitoredDaily CDR review and automated alerts for international and after-hours calls

Try the SIP Response Codes

Every SIP status code from 100 to 608, with plain-English meanings, causes, fixes and example traces.

Keep reading