Skip to content
Smuggling / CRLF Write-up Intermediate

Smuggling SIP headers past Session Border Controllers FTW!

Kamailio's remove_hf() function failed to strip SIP headers whose names contained a trailing space or tab, allowing an attacker to smuggle headers past the session border controller to downstream systems like Asterisk. This could enable toll fraud, billing other customers, and caller-ID spoofing.

rtcsec.com

Published on rtcsec.com

Sandro Gauci, Enable Security

The author, on rtcsec.com

The full write-up lives on its author's site

It belongs to its author, so we link to it rather than copy it. The other two tabs are our own rewrites, checked against it.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

How it worked

Root cause

Likely Kamailio's remove_hf() function did not correctly parse header names that included trailing whitespace, while the downstream SIP parser (pjsip in Asterisk) did.

Impact

In this particular case, it could be abused for toll fraud, billing other customers and also caller-ID spoofing.

What the attacker needed

Kamailio SBC using remove_hf(); Downstream SIP server that parses headers differently; Ability to send SIP messages to the SBC

The fix

The issue was fixed in Kamailio 5.4.0 by trimming whitespace and later restricting header names to specific characters; for older versions, use remove_hf_re with regular expressions to cover whitespace.

How it was found

  1. Set up a Kamailio server in front of an Asterisk server that removes a header called X-Bypass-me.
  2. Configure Asterisk dialplan to route calls to an internal context if the X-Bypass-me header is present.
  3. Send a SIP INVITE with the header name followed by a space (e.g., 'X-Bypass-me : value').
  4. Observe that Kamailio forwards the header and Asterisk processes it, answering the call.

Explained by bugbounty.wiki with AI from the original and checked against quotes from it; it can still be wrong. Read the original before relying on a detail.

Not written yet. The AI write-up for this write-up has not been written yet. The Original tab links to the source.

A session border controller (SBC) is a security device that sits between phone networks and removes dangerous headers from messages. The bug was that Kamailio's removal function didn't recognise a header if there was an extra space after its name, so the header slipped through to the internal phone system, which then trusted it.

What is Smuggling / CRLF?

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.

Similar reports

View all

Same bug class and techniques, clearest first.

Request smuggling and header injection

The lesson behind this report.

A front end and a back end split one connection's bytes into requests differently, letting an attacker hide a request inside another user's.