Friday, November 18, 2022

Bridge SMS to XMPP: Receive 2FA Codes Abroad

Bridge your mobile SMS with XMPP instant messaging so you can read and send text messages from anywhere over the internet. The primary use case: receiving 2FA verification codes while travelling internationally, without roaming or asking someone at home to read them out for you.

Setup diagram — SMS flows from GSM network through Raspberry Pi to XMPP client

Setup overview — a Raspberry Pi with a USB 3G modem bridges SMS to XMPP via a public Jabber server.

The setup uses a Raspberry Pi with a Huawei E173 (or E303) USB 3G dongle and an encrypted XMPP connection to deliver SMS securely to your phone's chat app. All code is open source, and you can use any public Jabber server (or host your own with Prosody).

Preparing the SD card

  1. Download the Raspberry Pi Imager
  2. Open it and select: CHOOSE OS → Raspberry Pi OS (Other) → Raspberry Pi OS Lite (32-bit)
  3. Select your SD card via CHOOSE STORAGE
  4. Press Ctrl + Shift + X to open the advanced options
  5. Set hostname, enable SSH, username, password, and timezone as shown below, then click SAVE
  6. Click WRITE to create the bootable SD card
Raspberry Pi Imager advanced options dialog

Raspberry Pi Imager — advanced options for hostname, SSH, and credentials.

Setting up the Raspberry Pi

  1. Insert your SIM card (PIN lock must be disabled) into the Huawei E173/E303 dongle and connect it to the Raspberry Pi
  2. Keep the Pi powered on and connected to your home internet 24/7
  3. Once booted, SSH in:
ssh pi@my-raspi-001
  1. Install the XMPP remote agent:
sudo apt-get install -y git
git clone --recursive https://github.com/hackboxguy/xmpp-remote-agent.git
cd xmpp-remote-agent
./setup.sh -u raspi-sim-1@jabber.de -p my-raspi-xmpp-secret-pw
sudo reboot; exit

Replace the example XMPP username and password with your own credentials.

The setup.sh script may take 10–15 minutes on a Raspberry Pi 1.

On your phone's Xabber app (Android or iOS), log in with your XMPP account (e.g. john.doe@jabber.de). The Raspberry Pi should appear online — send help to get the list of available commands.

Reading SMS

smsupdate       # fetch SMS from SIM to cache (wait for Success response)
smstotal        # show number of cached messages
smsget 0        # read the first message

Sending SMS

smssend +919876543210 this is a test message

Deleting SMS

When the SIM memory is full, new messages stop arriving. Delete all stored messages with:

smsdeleteall

Voice dialling and USSD codes

Ring a GSM phone (caller ID shows as SIM-1's number, no audio — ringing only):

dialvoice +919876543210

Check prepaid balance or send other USSD codes:

dialussd *100#     # send USSD code (wait for Success response)
readussd           # read the carrier's response

How it works internally

Two services run on the Raspberry Pi:

  • bboxsmsrv — based on libgammu, handles SMS read/write/delete via the USB 3G modem
  • xmproxysrv — based on libgloox, acts as a headless XMPP client that logs into the Jabber server and maintains an always-on connection

When a 2FA SMS arrives, it is stored in the SIM memory by the 3G modem. On your phone's Xabber app, you send smsupdate → xmproxysrv parses the command and asks bboxsmsrv to fetch messages from the SIM → once complete, a Success response is sent back → you then read the messages with smsget.

For sending, the flow reverses: your chat message travels through the XMPP server to xmproxysrv, which hands it to bboxsmsrv, which sends the SMS via the 3G modem — delivering an SMS to any phone number without roaming charges.

SOURCE CODE

github.com/hackboxguy/xmpp-remote-agent — setup scripts and configuration

github.com/hackboxguy/brbox — bboxsmsrv and xmproxysrv sources

3 comments:

  1. This comment has been removed by the author.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. This comment has been removed by a blog administrator.

    ReplyDelete