Showing posts with label 3G modem. Show all posts
Showing posts with label 3G modem. Show all posts

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

Monday, January 04, 2016

Remote GSM SIM Management with Raspberry Pi

Remote management of a GSM SIM card using a Raspberry Pi B+ and a Huawei E173 USB 3G modem. The RBox chat-bot connects to an XMPP/Jabber server and lets you send/receive SMS, make voice calls, and dial USSD codes — all from your phone's chat app, anywhere in the world.

Raspberry Pi B+ with Huawei E173 USB 3G modem

Raspberry Pi B+ with Huawei E173 USB 3G stick — the complete RBox GSM gateway.

Why remote SIM management?

  • Your SIM card has no roaming and you're travelling internationally
  • You're outside GSM coverage but have internet access and need SMS functionality
  • You manage multiple SIM cards and want centralized access
  • You need a self-hosted SMS gateway for sending/receiving over the internet
  • You have remote sensors that report data via SMS and want a central collection point

Ensure your SIM card is deployed at a safe and secure location to avoid possible misuse.

Items needed

  • Raspberry Pi B+
  • Micro or full-size SD card
  • Huawei E173 USB 3G stick
  • SIM card (PIN lock must be disabled)
  • 5 V / 2 A power supply
  • Two Google or Jabber accounts (one for you, one for the Raspberry Pi)
  • RBox SD card image

Setup

Setup diagram — Raspberry Pi with USB 3G modem connected to home router

Setup diagram — Huawei E173 plugged into the Raspberry Pi, which connects to the internet through a home router.

  1. Flash the RBox SD card image (see the RBox setup guide for details)
  2. Insert the PIN-unlocked SIM card into the Huawei E173 and plug it into the Raspberry Pi
  3. Connect the Raspberry Pi to your home router via Ethernet and power on with a 2 A supply
  4. On your phone's XMPP client (Xabber, Conversations, etc.), check that the Raspberry Pi account is online
  5. Send Help — the bot replies with the list of supported commands

Both XMPP accounts must be authorized as contacts before the Raspberry Pi is powered on — do this from a PC first.

When RBox boots without the USB 3G stick connected, SMS/SIM-related commands will not appear in the help list.

Reading SMS

  1. Send Smsupdate — immediate reply: InProgress : taskID=1
  2. Wait 3–5 seconds for the modem to read the SIM
  3. Reply Success : taskID=1 confirms messages are cached
  4. Send Smstotal — reply shows the count (e.g. Success : 2)
  5. Send Smsget 0 to read the first message, Smsget 1 for the second, etc.

Deleting SMS

  1. Send Smsdeleteall — immediate reply: InProgress : taskID=2
  2. Wait 3–5 seconds
  3. Reply Success : taskID=2 confirms deletion
  4. Verify with Smsupdate followed by Smstotal — if messages remain, repeat the delete

Sending SMS

  1. Send Smssend 009198xxxxxxxx hello this is a test message
  2. Immediate reply: InProgress : taskID=3
  3. Wait 3–5 seconds — reply Success : taskID=3 confirms the SMS was sent
  4. If sending fails, try omitting the international/country code prefix (0091)

Voice dialling

  1. Send Dialvoice 009198xxxxxxxx
  2. Immediate reply: InProgress : taskID=4
  3. The modem dials and rings for 20–25 seconds, then disconnects automatically
  4. Reply Success : taskID=4 confirms the call completed

Voice dialling currently places a silent call (no audio playback). Future RBox releases may support playing a recorded message for automation use cases.

USSD codes

USSD codes like *101# are useful for checking prepaid balance and other carrier queries.

  1. Send Dialussd *101# (the code varies by carrier)
  2. Immediate reply: InProgress : taskID=5
  3. Wait 3–5 seconds — reply Success : taskID=5 confirms the USSD response was received
  4. Send Readussd to read the carrier's response text

SOURCE CODE

github.com/hackboxguy/brbox — RBox sources and build instructions