Having the ability to sniff cellular traffic can be very helpful when analyzing certain mobile and IoT devices. One of the tools that we use to do this is a Range Networks OpenBTS 5150 unit. OpenBTS is open source software that simulates a GSM network-in-a-box using a Software Defined Radio (SDR) to transmit/receive GSM protocols, and route them appropriately to other phones and the internet. Inside the 5150, OpenBTS converts voice calls from your mobile phone into SIP messages and uses Asterisk to route calls to real phones using a VoIP provider or route locally to other phones connected to the OpenBTS. It also has software to send, queue, and receive SMS messages and to let you connect to the internet over GPRS. This allows you to create your own (small) GSM network enabling voice, SMS, and GPRS services.
RangeNetworks now calls the 5150 their "OpenCell" product. The 5150 is a small PC ITX board running Ubuntu connected to a custom SDR. The PC runs the open source OpenBTS software and allows us to create a small 2G GSM network supporting GPRS in the 1900 frequency band (which is what the SDR came tuned to). This turned out to be perfect for testing in our lab to find a way to intercept the GPRS connection and to create a .pcap of collected traffic.
Note: If you are not familiar with GSM or telecommunications, you should know that every service provider (AT&T, T-Mobile, Verizon, etc) internationally has assigned Mobile Country Codes (MCCs) and Mobile Network Codes (MNCs). MCCs are a standard code defined by the International Telecommunications Union to allocate numeric codes to every country with cellular networks in order to distinguish between them, along with the help of the MNC. The MNC is used to identify network providers within a country (within a MCC). A MCC with 001 is used as a test network code, so for our setup, we used that. We were also keeping the RF power attenuated so we did not disrupt our neighbors.
Warning: Following these steps, you may disrupt cellular service to phones in the area. I take no responsibility for anything that happens to you or your neighbors if you try these steps. You do so at your own risk.
Here are the basic steps I went through:
- Get OpenBTS running and connected to the Internet
- Have a smartphone attached & registered on the voice and GPRS sides of OpenBTS
- Sniff all the phone's packets and get a .pcap
- Win.
Here's how we set it up to sniff GPRS traffic.
Equipment:
- OpenBTS 5150 unit (aka OpenCell)
- VGA Monitor
- USB Keyboard
- Wired internet connection
- SIM Cards
- SIM reader/writer
- GSM compatible tri/quad-band phone
Step 1 - Get OpenBTS running and on the Internet
If you have never worked with OpenBTS, I recommend starting with their free O'Reilly book to get comfortable installing, configuring, and running the system. The book is well written and should help you get it up and running using a standard SDR, like an Ettus Research B210, foe example. We opted for a hardware solution using the 5150.
Image 1 - OpenBTS 5150 opened up in our lab and connected to a VGA monitor and USB keyboard (not pictured). Note the PC on the left & the custom SDR on the right.
The 5150 should automatically start the OpenBTS software. Once the system boots up, you can configure networking for Ubuntu by modifying /etc/services/networking to use static or dynamic IPs. We have DHCP in our lab so we left this alone. Note the last "pre-up" line was added, and is referenced, in the OpenBTS book:
# This file describes the network interfaces available on your system
# and how to activate them. For more information, see interfaces(5).
# The loopback network interface
auto lo
iface lo inet loopback
# The primary network interface
auto eth0
iface eth0 inet dhcp
pre-up iptables-restore < /etc/OpenBTS/iptables.rules
Once you've got it on the network, you can SSH to it for remote administration and the OpenBTS CLI. On to step 2!
Step 2 - Get a smartphone attached & registered on OpenBTS for voice and GPRS
Now the fun begins. I used the OpenBTSCLI (also documented well in the OpenBTS book) for configuring the GSM parameters so that we could connect actual phones. The RangeNetworks 5150 version of OpenBTS included a small web server and web application you could use to modify each of the parameters directly from a browser (which manipulates the underlying sqlite configuration database in /etc/OpenBTS/). This provides the easiest interface for configuring the system and adding subscribers, however you can achieve all this manually using the OpenBTSCLI (located at /OpenBTS/OpenBTSCLI). Here is a screenshot of the web GUI:
Image 2 - Screenshot of the "Wizard" browser based configuration showing the basic parameters.
The most important parameters here are GSM.Identity.MCC and GSM.Identity.MNC. I ensured these were set to our test network, 001 and 04, respectively. Our 5150 only supports one GSM frequency (Band 1900), so everything else can stay at default.
If you click "Full" at the top of the GUI, you can modify a LOT more of the parameters, including those specific to the GGSN. The GGSN is a node in the GSM core network, simulated by software in OpenBTS. The GGSN is essentially the router running DHCP & NAT inside the core network, and sits between the cell network and the Internet. It is what allocates an IP address to your phone when you are connected to your provider.
Each of the configuration parameters can be directly configured in the OpenBTSCLI using the 'config' command and a value, like so:
> config <param> <value>
# example
> config GSM.Identity.MNC 04
# Running config GSM.Identity.MNC simply prints the current value
The "Full" configuration window looks like this once you click "GGSN":
Image 3 - Screenshot of the "Full" wizard, under the "GGSN" tab. Highlighted in yellow are the critical parameters that must be set.
I highlighted in orange two parameters you should verify and change if incorrect: GPRS.Enable which must be "1", and GGSN.DNS which must be set to the IP for the router/DNS server for your network.
The last thing you need to verify is the GSM.LUR.OpenRegistration parameter. This parameter is crucial to configuring who and who is not allowed to attach and register to the network. This parameter's value must be a string that represents a regular expression for the IMSI number series allowed to attach. Below, I only want the IMSIs which start with 00104 (MCCMNC) to be able to connect to our system and no one else.
If you set this to ".*", the system will attach and register ANY IMSI in a phone with the correct frequency range. This would be "A Bad Thing"®, but great for testing and debugging purposes if you are having issues.
Image 4 - Control.LUR.OpenRegistration regex as seen in the web GUI. This can also be configured via command line as shown above using OpenBTSCLI.
The next step is to program a SIM using your SIM reader/writer to use the 001 04 network, cut it (if necessary for your phone), and pop it into your phone and power it on.
We used an Android Nexus 5 for testing. Once we put the SIM in, we had one last thing to do before sweet internet access at 2.5G speeds: we had to set the Access Point Name (APN) in "Settings ➝ Mobile Networks ➝ Access Point Names". An APN is what configures the connection to the gateway between the carrier's cellular network (or in our case, our test network) and the public Internet. The OpenBTS software requires an APN, but it can be anything, it just has to exist and must be enabled. I created a new APN since none existed on my phone, set the name to "test" and APN to "test", saved it, and enabled it. Also make sure "Data enabled" and "Data roaming" are enabled. See this Google page for reference. Here is how to verify & set your APN for iPhones.
To test if your phone attaches & registers on the network, try connecting to the network first (if your phone did not already automatically—it may if the other settings are automatically correct). Go to "Settings ➝ Under Wireless & Networks touch More ➝ Cellular/Mobile networks ➝ Network Operators" and select your OpenBTS's network. Ours is called "Range", but on some phones it simply appears as "001 04". If you select your new network and the phone says "Registered", congratulations! You have attached and registered your phone successfully.
You can easily test voice calls by dialing "2600", which is an echo test number setup in Asterisk by the OpenBTS software by default. If the call connects, you should be able to hear an echo of your voice. Success!
Lastly, let's try the Internet. This gave us some trouble and was a little flakey, but we were able to see it work. Make sure you are attached and registered, and on Android we looked for the "G" in the corner next to the signal strength bars. The G for GPRS shows the phone has registered a data connection and you can start browsing! Really really slowly. Try it! We noticed our OpenBTS did not maintain the GPRS connection for a long time (over 1-2 hours) consistently, but did work reliably if continued to be used. Rebooting the phone and rebooting the OpenBTS sometimes did the trick, but I found cold booting the OpenBTS was the most reliable method to get the GPRS connection to work properly.
3. Sniff all the phone's packets and get a .pcap
Now we can have some fun. Login to the OpenBTS over ssh and have your connected phone handy. As root on your OpenBTS host, you simply have to use tcpdump to sniff GPRS traffic and create a pcap of phone's traffic. Note: If you have multiple phones attached and registered on GPRS with your OpenBTS, this procedure will collect ALL of their traffic as it sniffs the OpenBTS tunneling GPRS network interface. Fortunately, you can filter by IP address in Wireshark later.
Here, you must specify the special sgsntun interface.
tcpdump -i sgsntun -s 1514 -w /path/to/file.pcap
This will run tcpdump until stopped, with a snaplen of 1514 bytes for standard packets, and write all the data collected to a .pcap specified with -w. Hit Ctrl-C to finish and save the .pcap. You can use scp/sftp to copy the file off to your local machine for analysis using Wireshark or your favorite pcap tool. That's it! You have successfully sniffed GPRS traffic from a smartphone over a GSM network.
4. Win.
That's all you have to do, which is quite a lot. This may seem a tedious process, and that's because it is, but it is a good method to obtain cellular traffic for testing and research. Be cautious to not turn your power too high, so as to not affect those around you, and remember to use test IMSIs and test MCC and MNC.