New
Apps 6,355Makers 6,334This week 13
Promote your app−30%
TFPS screenshot 1
4views in
the last 30 days

Telephony Fraud Prevention System for SIP networks. One static binary, no cloud, no policy configuration.

TFPS detects and prevents SIP fraud by banning attacker addresses in the kernel. Think of it as a faster fail2ban: it reads SIP straight off the wire instead of tailing and parsing log files, so it reacts in packets rather than log-flush intervals, and it catches attacks the logs never record. As a side effect the banned traffic vanishes from your sngrep.

Install

curl -fsSL https://tfps.co/install.sh | sh

Linux x86_64, kernel 5.15 or newer with BTF, systemd. That is the whole install; it asks for sudo if needed, and running it again upgrades. Pinning a version, air-gapped hosts, building from source and uninstalling are in INSTALL.md.

Two layers, and the first is the product:

  • Prevention (default, on): drops SIP scanning, brute-force and known-bad sources — the fail2ban job, done faster and without log parsing. Most installs only ever want this.
  • Behavioural detection (--behavioural, off, highly experimental): goes where no other system does — the compromised downstream PBX, where the attacker already holds valid credentials and every perimeter signal is clean. It catches IRSF by anomaly. It is a research-grade layer, not a guarantee.

Not a guarantee. Use at your own risk. TFPS sees SIP on the wire only. It cannot detect every fraud type (SIP over TLS/TCP content, IPv6, billing or insider fraud, social engineering, low-and-slow mimicry, fraud that never touches the network). Behavioural detection is experimental and report-only by default. Source-level XDP blocking is opt-in with --enforce-behavioural, and the forged SIP 603 is still missing. Validate it on your own traffic; it is not a substitute for a security audit or financial controls. See the full Disclaimer below.

  • Static musl binaries — tfps ≈ 4.3 MB, tfps_ctl ≈ 2.3 MB. No glibc dependency; they run on Ubuntu 24.04, Debian 12 and forward.
  • No UDP bind — capture is AF_PACKET, so your softswitch keeps its own socket on 5060 and never notices.
  • Kernel-level drop — condemned sources vanish from sngrep, tcpdump and tshark.

⭐ If TFPS keeps your sngrep clean or your bill honest, please star the repo — it is open source and non-commercial, and a star is how it reaches the next operator who needs it.


The garbage disappears from sngrep

This is what the product delivers, and it works because of one specific ordering inside the Linux kernel:

NIC → driver → XDP ← TFPS drops here
                 ↓
            sk_buff → ptype_all ← libpcap hooks here (sngrep, tcpdump, tshark)
                        ↓
                    netfilter ← iptables and nftables act here

A packet dropped at XDP never reaches the libpcap tap. That is why nftables would not work for this purpose: its drop happens later, and your capture would still be polluted.

Verified in production: with ~2,000 sources blocked (APIBAN + perimeter), a tcpdump filtered to a sample of them captured a fraction of the packets a control window did. It is not hermetic — the occasional packet slips through — but the reduction is drastic, and the noisiest scanners disappear from the capture entirely.


Two layers, one binary

Prevention (default) Behavioural detection (--behavioural)
what it does bans scanning, injection, brute-force, known-bad IPs catches the compromised PBX — IRSF by anomaly
compared to a faster fail2ban, no log parsing goes where fail2ban structurally cannot
maturity production highly experimental
needs learning? no — effective from minute one yes — 30-day learning window before it acts
the signal user-agent, URI shape, failed auth, APIBAN four-arm sequential detector (see below)
default on off
tfps                 # prevention only — the product
tfps --behavioural   # add the experimental behavioural layer

The banner always says which of the two you are running, so it is never ambiguous.

Why faster than fail2ban

fail2ban tails a log file and matches a regex, so it is bounded by how often the softswitch flushes logs and by whether the event is logged at all — Asterisk's security channel ships off, PJSIP does not log below 5 requests in 5 s. TFPS reads the SIP on the wire: a rejected credential or a scanner user-agent is seen as the packet arrives, and the ban is written to the kernel immediately. It also sees what the logs never record, and it needs no logging configured on the softswitch at all.


Status — v0.3.1

working not yet
AF_PACKET capture, no port bind —
XDP enforcement of perimeter blocks (native/generic) SIP over TCP (detection)
perimeter: user-agent, URI injection, failed auth IPv6, SIP over TLS
APIBAN, background-synced and persisted call-duration signal via BYE
ignoreip, with the host's own addresses always exempt day-31 activation confirmation
four-arm behavioural detector, self-calibrating
source-level behavioural enforcement (--enforce-behavioural) forged SIP 603
SQLite persistence and control tool

The perimeter enforces today; the behavioural layer detects and reports by default. During the 30-day learning window it prints WOULD BLOCK lines and blocks nothing. After that it prints BLOCK (report-only, not enforced) lines with the evidence. With --enforce-behavioural (or "enforce_behavioural": true) the same verdict is written into XDP for block_ttl and logged as BLOCKED ... reason=behavioural; the forged SIP 603 Decline of SPEC.md §8 is still missing. A registered peer is exempt from the third-party APIBAN feed, but no longer from the perimeter's or behavioural layer's own active evidence (injection, auth failure, registration scanning, auth volume); only a successful REGISTER grants known-good status, for 24 hours. Read the WOULD BLOCK/BLOCK lines and the tfps_ctl stats calibration to judge how the detector fits your traffic before wiring enforcement on.


The perimeter — the default product

Every packet on a watched port is checked, cheapest first. A match condemns the source: its next packets die at XDP and vanish from the capture.

  • Known scanner user-agents — 18 built-in signatures (friendly, sipcli, sipvicious, pplsip, sipsorcery, Nmap NSE…). Weak as detection — a competent attacker forges a legitimate UA — but most scanning traffic uses a default one, so as a volume filter it earns its place. A missing User-Agent is not noise.
  • URI injection — 11 built-in patterns (', %27, --, ?=?, union, select, and ; inside the user part), matched against the user@host of the Request-URI, From and To only — never the display name, so an Irish surname is not mistaken for SQL injection. Higher confidence than a user-agent: no real phone puts a single quote in a From header.
  • Scanner identity — a known scanner domain or tool name in the From/To/Contact/ Request-URI, matched on every method (scanners probe with OPTIONS as much as INVITE). This catches the self-identifying research scanners the user-agent list misses — Censys announces itself as censysinspect@censys.io, and there are Shodan, LeakIX and the rest, plus tool/service domains like sip5060.net. A real caller is never @censys.io. Extend the built-in list with scanners in the config.
  • Registration scanning — a source that probes many different extensions with REGISTER and completes none (no 2xx). This catches extension enumeration and the no-credential probing the failed-auth rule can't see: the attacker spreads a few tries per extension across the dial plan, so no single extension crosses the brute-force threshold — but one source touching several distinct extensions with zero successful registrations is a scan. The count is of distinct extensions, not raw attempts, and that is deliberately the safe design: a real phone registers its own one extension (a multi-line device its own few) however many times it retransmits or re-registers, and whether or not its responses are captured, so it never climbs; and any single successful registration exempts the source outright. The threshold sits well above any plausible legitimate device, so a NAT or gateway behind one IP is never caught — only a source spraying the dial plan is.
  • Failed authentication — see below.
  • APIBAN — the collaborative bad-IP list, if a key is configured.

The perimeter does not exist to catch fraud. It exists to keep noise out of the behavioural baseline: if scanning fed a source's baseline, the detector would learn that bursts to strange destinations are normal there, and poison itself.

Failed authentication, and what does not count

A bare 401 means nothing. Digest is a two-step flow: every legitimate REGISTER gets a 401 with a nonce and is resent with Authorization. Counting challenges would block every customer.

What counts is a request that carried a credential and was answered 401/407 anyway:

REGISTER (no Authorization)  →  401 + nonce     the normal handshake, ignored
REGISTER (Authorization)     →  200 OK          accepted — the count is cleared
REGISTER (Authorization)     →  401 again       a rejected password. This is the signal.

Five rejections in ten minutes condemn the source — fail2ban's maxretry/findtime for the Asterisk jail, deliberately, but read off the wire instead of a log the softswitch may not be writing. Requests are matched to responses by the Via branch (RFC 3261 §17.1.3), falling back to Call-ID + CSeq. A retransmitted 401 counts once; an accepted credential clears only that AOR's failures, so someone who fixes a typo is not blocked by their next slip, while a valid account cannot reset a run against a different extension. The source of the response must also match the request's destination. A NAT whose phones succeed is below the registration-scan floor; a NAT with no captured responses can still look like an enumerator, so put it in ignoreip.

The backstop: where the softswitch rejects probes without answering (measured on the reference server: one outbound packet in 45 s against hundreds inbound), the failure counter cannot rise, so a volume rule remains — 50 authenticated attempts in 60 s with no challenge seen. When that condition is detected, TFPS says so on the report, because a rule that structurally cannot fire is the fail2ban blindness this project exists to avoid.


Behavioural detection — the experimental layer

⚠️ Highly experimental. This layer is research-grade: it addresses a case no other tool reaches, but it has not earned the confidence the prevention layer has. Run it in learning mode, read the WOULD BLOCK lines, and judge it on your own traffic before trusting it.

It exists for one case the prevention layer — and fail2ban, and reputation lists — cannot touch: the compromised downstream PBX. The attacker already holds a valid credential, the traffic arrives authenticated from the usual IP, and every perimeter signal is clean. Nothing that keys on reputation or authentication failure sees it. TFPS keys on behaviour: what a source does with those valid credentials.

Turn it on with --behavioural. It learns each source IP's normal behaviour and flags IRSF by anomaly.

Enable it

{
  "behavioural": true,
  "enforce_behavioural": false,
  "intl_prefixes": ["+", "00", "011", "9011"],
  "home_countries": ["BR"],
  "learn_days": 30,
  "ignoreip": ["10.0.0.0/8"]
}
tfps --behavioural                              # 30-day learning window, report-only
tfps --behavioural --enforce-behavioural        # block after learning
tfps --behavioural --active --enforce-behavioural # block now; do not do this on day one

The first 30 days are learning: it prints WOULD BLOCK and blocks nothing. Each new source also has its own 24 h / 20 international call warm-up (WARMING). After that the verdict is printed as BLOCK (report-only, not enforced) unless --enforce-behavioural (or "enforce_behavioural": true) is set, in which case the source is written into XDP for block_ttl and the log says BLOCKED ... reason=behavioural. The perimeter still enforces; the forged SIP 603 is the remaining piece. Watch WOULD BLOCK lines and tfps_ctl stats during the window. To disable, remove --behavioural or set "behavioural": false; learned state stays on disk until tfps_ctl forget.

Use --no-enforce-one-way (or "no_enforce_one_way": true) if the one-way perimeter evidence is exposed to spoofing: those verdicts stay report-only; behavioural detection is unchanged.

Prerequisite — configure your international prefixes. The behavioural layer reasons only about international destinations, and intl_prefixes (global and per-peer) is how it tells a real outbound international call from an internal extension or an inbound call to an E.164 DID. Get them wrong and the wrong calls are judged. The defaults are a starting point, not a fit for your installation — set them, and the detector's job becomes correct.

Two companions to that setting, both about not judging traffic that isn't outbound international fraud:

  • home_countries — your own country (or countries), as ISO labels (+1 is NANP). A destination that resolves to one of them is national, not international, even when it arrives with a + or in E.164 — so an inbound call to your own DID is not mistaken for a foreign destination. Without it, startup recommends setting it.
  • ignoreip your inbound gateways — the carriers that deliver calls to your internal destinations should never be judged or blocked. Put their IPs in ignoreip; startup recommends this too.

The full design and its literature are in docs/anomaly-detection.md; in brief:

The B-number cannot be classified. Tested against a real libphonenumber port, classic IRSF destinations (Latvia, Somalia, the Philippines) validate as ordinary mobile numbers, while some genuine ranges are rejected. Neither validity nor number-type separates fraud from legitimate traffic. Detection has to be behavioural.

IRSF has a behavioural signature, in phases, and each maps onto a solved problem:

  • Scanning — finding a target, working out how to dial out, then finding which premium numbers route. The SIP search for a target belongs to the perimeter; the other two are first-contact discovery and are detected with a Threshold Random Walk (Jung et al., IEEE S&P 2004) — a sequential test that accumulates evidence per call and fires the moment it is sufficient. Three arms run: a new dialling prefix (00, 011, 9011, +…), a new destination range (the B-number with its last four digits dropped — the premium-rate hunt), and a failed completion (a call answered 4xx/5xx/6xx, or never — the AT&T signature, "the call never came here"). A never-seen country is not a separate arm: every new country is already a new range, and country novelty was too fragile on its own. The seen-country set is still tracked for the report.
  • Exploitation — hammering the route it found shows as a volume spike against the source's own norm, scored with hierarchical Gamma-Poisson surprise.

The four arms produce evidence in the same log-likelihood units, so they add; enforcement fires when the total crosses a bound set by the error rates you choose (α, β) — not a hand-picked threshold. Every block is one explainable sentence: "14 nats: 9 range-scan, 3.5 volume." Each arm also has a hard floor (4 dialling prefixes, 10 destination ranges, 10 failed novel ranges), and a new source is observed for 24 hours / 20 international calls before it can be blocked. Those floors are the false-positive control; the SPRT decides once a burst is real.

It self-calibrates. The benign hypotheses — how often a normal source uses a new dialling prefix or a new destination range, how often calls fail, the population's rate distribution — are learned from the deployment's own aggregate traffic during the learning window and refit at each checkpoint. The only policy numbers are α and β — the tolerated false-alarm and miss rates — never a traffic constant. They are compiled-in defaults today (1e-4, 1e-2), not yet exposed in the config file. tfps_ctl stats shows the learned values.

Its one honest weakness: a low-and-slow attacker who mimics a legitimate profile at low volume. Which is exactly why this layer is opt-in, blocks are temporary, and the unban rate is watched as the precision proxy.


Configuration — /etc/tfps/config.json

Every field is optional and the system works without the file. What lives here is installation configuration — where to look, how to read the numbers — plus optional integrations. Never policy configuration, which would say what fraud is.

{
  "ports": [5060, 5061],
  "intl_prefixes": ["+", "00", "011", "9011"],

  "peers": {
    "10.0.0.5":    { "intl_prefixes": ["9011", "011"] },
    "203.0.113.7": { "bare_e164": true }
  },

  "signatures": ["MyLocalScanner", "=sipsak"],
  "injection": ["xp_cmdshell"],
  "scanners": ["newscanner.example.com"],
  "ignoreip": ["10.0.0.0/8", "203.0.113.7"],
  "home_countries": ["BR"],

  "behavioural": false,
  "enforce_behavioural": false,
  "no_enforce_one_way": false,
  "apiban_key": "optional-key",

  "learn_days": 30,
  "block_ttl": 3600,
  "stats_every": 120,
  "checkpoint_every": 300,
  "iface": "eth0",
  "db": "/var/lib/tfps/tfps.db"
}

Precedence: command line > file > built-in default, so you can debug in production without editing a file. An unknown field is an error, not silence: an apiban_kei quietly ignored would make you believe you enabled APIBAN when you did not. Malformed JSON and an invalid peer IP become startup alarms too. (Renamed fields keep an alias, so a config from an earlier version still loads rather than silently reverting to defaults.)

peers — the dial plan per PBX

Declaring beats learning because it holds on that peer's very first call instead of waiting for convergence, and the weight is large: 20.3% of destinations do not resolve to a country without correct prefix stripping. bare_e164 says the PBX sends plain E.164 with no prefix — common in wholesale; it is an explicit field because the semantics are dangerous: with it on, 2125551234 is Morocco; with it off, a domestic US number.

NANPA (+1) — the Caribbean is international

+1 is not one country. The US and Canada share it with ~30 Caribbean and territory nations — Dominica (+1-767), Grenada (+1-473), Jamaica (+1-876), Antigua (+1-268)… — and several are IPRN hotspots: fraud that looks like a domestic +1 call but routes internationally to a premium range. TFPS breaks +1 into all of them; only geographic US/Canada resolves to NANP.

To catch it as a NANPA operator, two settings:

{ "peers": { "10.0.0.5": { "bare_e164": true } }, "home_countries": ["NANP"] }
  • bare_e164 (or the + prefix) so a +1XXX number keeps its country code and resolves to the real country — never a stripped "1" prefix: stripping the 1 turns 1-212 into 212 (Morocco) and 1-767 into 767… (Russia). TFPS warns at startup if it sees "1" configured as a prefix.
  • home_countries: ["NANP"] so geographic US/Canada is national, while the Caribbean +1 countries — separate ent

Description taken from the repository README.

Ratings

–
0 ratings
5 0
4 0
3 0
2 0
1 0

Rate this app

Sign in to rate

Comments 0

Sign in to comment

No comments yet.

Related apps

#telephony · #security · #voip