How to Hack 5G - Part 2

Fingerprint Icon Written by Chris Powell

Previous Article | Next Article

Hacking 5G

This post is the second in a series that provides an overview of 5G security. Last time I discussed telecommunications standards and what 5G means, this week, I'm introducing smart cards and their use as Subscriber Identity Modules's (SIMs).

Smart Cards

You've probably owned several smart cards throughout your life and most likely noticed that they always have a small metal rectangle on the front. Have you ever asked yourself why?

It may come as a surprise to some of you, but smart cards are tiny computers, and the metal rectangle bit is a set of contact pads. Afterall modern-day machines are electrical and thus require power to operate.

An interesting thing to note is that we're not limited to transmitting electricity through contacts or wires. We've got pretty good at powering devices wirelessly, hence why bank cards are now contactless.

Contacts

Below is a diagram of the smart card contacts as part of the ISO/IEC 7816 standard. 7816 is the standard that documents smart card sizes, power usage and transmission protocols.

Smart Card Contacts
- Standard contacts on a Smart Card
  • GND - Ground (Earth in the UK)

    • Where the power goes to or drains.
  • VCC - Power

    • Where the power comes in.
  • RST - Reset

    • Whenever the smart card powers up, we use the reset pin to place it into a known “good” state by issuing a reset signal on the pad.
  • CLK - Clock

    • The clock lets you supply an external oscillating (wavy) signal used for circuit timing or communicating. Whether this pad gets used or not depends on the underlying Integrated Circuit (IC) design that makes up the smart card. These days most ICs have an internal clock.
  • VPP - Power for Erasing

    • Memory on chips is most often NAND flash, which contains these things called “Erase Blocks”. They have this name because you first need to erase an entire block of memory back to 0's or 1's before you can overwrite it with “new” data.

      One downside of erasing entire blocks of memory at once is that it requires more energy, which is especially tricky on tiny chips such as smart cards. That's why there is a second power pad available, in case a card requires more power during programming.

      Similar to the clock pad, it has become obsolete because of modern-day IC's and their ability to boost voltages to the required level.

  • I/O

    • As expected, the Input/Output pin is a communication channel.
  • C4 and C8

    • Unused and reserved for future use

Architecture

So we've discussed what the pads on the outside are for, and what their names mean. But what's actually inside a smart card? If they're a computer, do they have a CPU or RAM, or even non-volatile (permanent) storage?

Here is an image of a smart card die, specifically a Universal Integrated Circuit Card (UICC), which is the official name of a SIM card. It's been decapped (plastic removed) and has had the tamper-proof shield removed.

Smart Card Image
- Smart card internals

As I don't have access to a fume cupboard or high powered microscope, I've borrowed this image from https://electronupdate.blogspot.com/2016/10/decap-of-cell-phone-sim-card.html. It highlights some of the circuitry in a relatively old smart card.

What's important to realise with this picture, is that while it's possible to probe and access the smart card's memory directly, it's incredibly difficult and costly to do. It's why programs such as Common Criteria can certify hardware security protections of ICs. It's not about making these things impossible to hack. It's about making it so expensive that the value gained from exploitation isn't worth the effort.

It's for this reason that smart card technology is used within cellular devices. They offer sufficient protection as SIM cards, whose main job is the storage and security of cryptographic keys. And the value gained from hacking any single SIM isn't high enough to justify doing it in the first place.

The job of people like me is to use a combination of advanced mathematical techniques, physical hardware hacking and lots of analysis to reduce the cost for an attacker. Why is that a good thing? Because it's better if someone ethical hacks it first so we can improve the security of the next-generation devices.

Operating System

The final bit of the puzzle is discussing the software that controls these tiny embedded ICs.

There are broadly two competing systems in the world of smart cards, MULTOS and Javacard. I've not played much with MULTOS myself, so I shan't discuss it further. But they are both similar in what they do, and how they operate.

Java is one of the most prevalent smart card technologies, and a Javacard is nothing more than a tiny computer that runs a highly constrained virtual machine. You can load applications written in a subset of Java onto it and interact with external devices via the system API.

One of the main difference between the smart card version and its counterpart is the lack of the in-memory byte verifier. This verifier ensures type-safety, e.g. preventing number types storing letter types. However, the limitations of the embedded hardware mean this check gets performed off-card.

It is, therefore, possible to modify the Java byte code directly, then provided your signature matches, load it onto the card. Some researchers did this a few years ago to bypass the built-in firewall to read out secret information from other applications such as cryptographic values.

Javacard
- Javacard code compilation

SIM Cards

Finally, we can start talking about why this matters to cellular networks, but there are a couple of problems we must first discuss. It turns out that people care about personal security when using their phone, some common concerns are.

  • Can my neighbour listen in on my phone calls?
  • Am I connecting to the right network?
  • Is this person being charged for the calls they're making?

We can try and solve these by adding encryption and authentication to the air interface. An excellent choice, but where can we keep, distribute and protect the cryptographic keys?

Surely we'd need some bit of cheap hardware that is small enough to send the mail, can store cryptographic information and is highly secure. Fortunately, smart cards address all of these problems!

The UICC I mentioned before is nothing more than a smart card with a few application-specific bits added to make it function as a SIM card. They are also used to store information such as your location and current signal strength. But their primary function is to protect the cryptographic information associated with you.

User Identification

Before I can talk about how 5G is different with regards to the SIM card, I first need to discuss three types of information used to identify subscribers.

Phone Number

The first we all recognise, the Mobile Station International Subscriber Directory Number (MSISDN), or phone number. In the UK, a typical example looks like this, +447911123456, or 07911123456 for short.

You dial them when you want to call someone, but part of the process is physically locating them in the network. How else would a specific cell tower know to send out a signal to the particular individual in some location? It wouldn't, and that's why we use MSISDNs.

One important point to make is that you can also transfer numbers around, such as from one provider to another, using the Mobile Number Portability (MNP) system.

IMEI

Now I want you to perform a trick, find your mobile phone and dial this code precisely *#06#. You don't need the period at the end, only what's written in bold. Hopefully, you'll see a large seemingly random-looking number, or if you're me, three random-looking numbers.

One of the numbers, I hope, will be an International Mobile Equipment Identity (IMEI). They identify physical equipment to the network, e.g. your mobile phone to your network provider. Typically you have one IMEI per SIM card slot, so my phone with two slots has two IMEIs.

My IMEI Number
- My IMEI numbers

They are used to identify handsets and work with a device called an Equipment Identity Register (EIR), essentially a giant IMEI database. This database keeps track of all blacklisted IMEIs and prevents any handset using one of these IMEI numbers from attaching to the network.

In an ideal world, if stolen, your handset shouldn't ever work on the network again. However, in practice, IMEIs can be forged, and it's a bit annoying if you bar your phone only to find it under the sofa a week later.

I won't go into precisely what the numbers mean, but the first eight digits make up something called a Type Allocation Code (TAC). Generally, it identifies the handset manufacturer, and you can look it up in a global register http://imeitacdb.com.

IMSI

The final and most important identifier I will discuss is the International Mobile Subscriber Identity (IMSI) number. It's baked into your SIM card, and its sole purpose is to identify you, the subscriber.

Unlike your cryptographic data, it can be read directly out of your SIM card. But it really shouldn't be transmitted in the clear, especially over the air.

Fortunately, these numbers are almost always masked with a temporary identifier, commonly referred to as a TMSI. They change regularly and serve to hide your permanent identifier, the IMSI, from prying eyes.

Not transmitting the IMSI in the clear is one of the most significant changes to the 5G New Radio (NR) standard. But I don't want to go too far into describing how a mobile attaches to a network yet. Just know that if you roam onto a new “unknown” system, one of the first things your mobile will do is transmit your IMSI, in the clear, over the air.

Notice how I used the word “unknown”, that's because almost all of the time your mobile will communicate using one of the temporary identifiers mentioned above. But it can only do this if it previously connected to a network.

Known vs Unknown Attach
- Known vs unknown network attach

Conclusion

I spoke a bit about how UICCs are a type of smart card developed into SIMs for use in your phone. And that they are an excellent hardware protection for securing your cryptographic data. I also spoke about three general types of identities that exist in a cellular network and what they mean.

Remember that an MSISN is a phone number, an IMEI identifies your device and an IMSI identifies your SIM card, i.e. you, the subscriber. In this, I hinted on an essential point for my next topic, IMSI catchers, which take advantage of the need to transmit IMSIs, in the clear, to unknown networks.

I also plan to discuss hardware attacks, glitching attacks and timing attacks via Correlation Power Analysis at a later date. But I want to get the whole 5G bit out of the way first.

Upcoming Topics

  • How IMSI catchers work
  • How 5G protects you against them
  • How cryptography protects your wireless data
  • Attaching to a network in 5G
  • How your SIM works with the User Data Repository (UDR)