How do SIM Cards work? - SIMtrace - YouTube

Channel: unknown

[0]
Have you ever looked at the chip of a credit card and a mobile phone sim card and thought,
[4]
wait... they look quite similar?
[7]
And would you like to know what makes these two old phones, a nokia and motorola, so special,
[12]
even in 2018?
[15]
In this series I want to talk about mobile networks and mobile network security.
[20]
And by that I don’t mean android or iOS apps.
[22]
I mean the networks.
[24]
SIM Cards, Baseband and Basestations.
[27]
Most of us know how the internet works.
[29]
It’s so easy to setup a lab and use wireshark to look at the traffic.
[34]
But we basically don’t really learn about how mobile networks work.
[38]
You can’t just wireshark the radio network.
[41]
I only learned about this a few years ago in university, where I took a course on telecommunication
[47]
security.
[48]
And that was a great foundation that I will obviously use for these video, but it’s
[51]
really hard to do anything practical with mobile networks for reasons you will see soon.
[57]
But then Vadim Yanitskiy, @axilirator on twitter, contacted me, if I would want to see some
[63]
GSM osmocom demos and I could record it for some videos.
[67]
And of course I took this opportunity and met up with him, and that was so awesome.
[71]
So thanks to him I finally got some real hands-on practical experience with this topic and I’m
[77]
so excited to try to pass this on to you.
[80]
I hope over the course of several videos you will have a great basic understanding of how
[85]
the mobile network works and you know where to go to, in case you want to learn more.
[95]
So I started this video showing you a credit card and a sim card.
[99]
And the reason why they look so similar, is because both are so called smart cards.
[104]
A smart card, or chip card, is any pocket-sized card that has embedded integrated circuits.
[110]
Many smart cards include a pattern of metal contacts to electrically connect to the internal
[114]
chip.
[115]
Here on wikipedia you can see some great images.
[118]
The actual chip is smaller than the gold connectors, and they just connect with tiny bond wires
[124]
to there.
[125]
And all the outer stuff is just plastic.
[127]
Here you see how they are connected, crazy right?
[131]
So when you look at your phone, and I would ask you, how many computers are in there?
[136]
What would you answer.
[138]
That was actually an opening question in the university class I had, and I think it’s
[142]
a great question.
[144]
Maybe some people would respond with one, it’s a single small smartphone computer.
[149]
But maybe you knew, that the sim card is actually a tiny computer itself.
[153]
Your phone computer communicates with the tiny embedded sim card computer.
[158]
And that computer can’t do much, but it can do a lot more than some of you might think.
[163]
In a very simple way you can imagine this small computer just contains a private key.
[167]
And with public-private key cryptography you can use it to authenticate to something.
[173]
And the idea is that it’s super hard to extract that private key from the smart card.
[177]
Not comparable to the simple magnetic strip on a credit card.
[181]
The private key never leaves the chip.
[183]
If you want to do some crypto, your phone will communicate with the sim card and ask
[187]
it to do it.
[188]
In the same way a credit card reader, using the chip, will do so.
[192]
Nobody can clone a sim card or credit card that way.
[195]
There are attacks on smart cards which I have touched on before with power analysis and
[200]
other crazy hardware hacks.
[202]
But generally the cost is pretty high to do that.
[205]
But in theory if you could extract the private key from it, you could clone a sim card or
[210]
clone a credit card chip.
[212]
So you can’t clone a sim card that easily, but what if you just steal a sim card?
[218]
Can you just use it?
[219]
And that is why you need a pin for your credit card when you use the chip or sim card.
[224]
The small computer inside the sim card refuses to do the crypto stuff you want, if you wont
[230]
tell it the secret pin.
[231]
That’s another protection.
[233]
So how does this look like in practice?
[236]
Vadim showed me SIMtrace.
[239]
So Osmocom SIMtrace or SIMtrace 2 is a software and hardware system for passively tracing
[244]
the SIM mobile equipment communication.
[247]
As you can see here, you have this basically fake sim card that is connected with a flat
[252]
flexi-pcb cable and connects to this board.
[255]
And this is where you put the real SIM card.
[257]
So basically the phone is still using the real sim card, it’s just forwarded through
[261]
that.
[262]
But because the sim card is not inside the phone anymore, you can now intercept and record
[267]
that communication and forward that via USB to your PC.
[271]
And then you can observe all the messages and commands the phone sends to the SIM card
[275]
and see how the sim card responds.
[278]
So when you turn on the phone, the phone asks you to enter the PIN.
[282]
Let’s enter the pin and then look what happened.
[287]
Here is wireshark
 wireshark you ask?
[290]
How what?
[291]
Okay
 so wireshark is a convenient tool to analyze packet based communication.
[296]
And in this case you can see here the protocol is GSM SIM.
[299]
And wireshark is listening on localhost.
[302]
So the simtrace software actually records the SIM communication and then puts them into
[307]
a UDP packet and send them onto localhost.
[310]
That’s why you can use wireshark to then collect all these packets.
[315]
And it looks like they have an ethernet layer, and an IP layer and the UDP layer.
[319]
But that’s just to transport the data.
[322]
The actual interesting payload is the GSM SIM protocol.
[325]
Somebody wrote a payload decoder for wireshark to analyse that data.
[330]
So ignore all the references to IPs and MAC addresses, that’s not what is sent between
[335]
the SIM card and the phone.
[336]
You only focus on the GSM SIM layer.
[339]
Anyway.
[340]
When we look at the packets that were collected after the pin was entered, we can see what
[344]
the sim and phone did.
[346]
The first important packet here is the VERIFY CHV.
[349]
The info also says something about ISO/IEC 7816-4.
[355]
And when you look that up, you will learn that this is a prtocol stadard.
[359]
ISO 7816 is an international standard related to electronic identification cards with contacts,
[366]
especially smart cards.
[368]
And sspecifically section 4 is about Organization, security and commands for interchange.
[373]
It was created in 1995 and According to its abstract, it specifies things such as “contents
[380]
of command-response pairs”, “access methods to files and data in the card” (remember
[386]
the sim card is a small computer, so the sim card also has files).
[390]
And also defines “access methods to the algorithms processed by the card.”.
[395]
So what does VERIFY CHV mean.
[397]
Let’s peek into the GSM standard.
[400]
Here CHV is described as “Card Holder Verification information”; access condition used by the
[406]
SIM for the verification of the identity of the user.
[410]
Can you guess what that is?
[411]
That’s a fancy description for your pin.
[415]
The user who knows the pin can verify that they are the user, by presenting the pin to
[420]
the simcard.
[421]
And we can also check what VERIFY does.
[423]
This function verifies the CHV (so the pin) presented by the ME (the mobile equipment,
[429]
the phone) by comparing it with the relevant one stored in the SIM.
[434]
The verification process is subject to the following conditions being fulfilled:
[437]
- CHV is not disabled; - CHV is not blocked
[442]
So either your pin is blocked because you entered it too much.
[446]
Or you had disabled the pin.
[448]
And further we can read.
[449]
If the CHV presented is false, the number of remaining CHV attempts for that CHV shall
[455]
be decremented.
[456]
After 3 consecutive false CHV presentations, not necessarily in the same card session,
[462]
the respective CHV shall be blocked and the access condition can never be fulfilled until
[468]
the UNBLOCK CHV function has been successfully performed on the respective CHV.
[473]
So this is all fancy documentation language.
[476]
But here is basically defined that you have three attempts for your pin.
[479]
And if you fail, the sim is locked, until you use that other special longer code to
[483]
unblock it again.
[485]
Interesting, right?
[487]
Anyway
 after that we can see some SELECT FILE commands.
[490]
So the phone requested the content of files stored on the SIM card.
[495]
One file contains the IMSI. the international mobile subscriber identity, which uniquely
[500]
identifies this sim card.
[503]
Also remember that you can store some contacts on your sim card?
[506]
W ell here you can see how the phone requested the phonebook on the SIM card.
[511]
There is one other cool thing.
[514]
Vadim looked at the wireshark trace and saw this.
[516]
“Oh also very interesting thing, I will show you.
[518]
It is related to the sim card menu.”
[523]
And I was like, sim card menu?
[524]
I have never seen a sim card menu. “you will, for example menu Vodafone services.”...
[532]
ohhh that’s what this menu always was.
[535]
It’s like a thing I never used.
[538]
So this is a menu running on the simcard?
[540]
“Exactly.
[541]
it’s Probably java application.”.
[543]
You heard right.
[544]
Usually there is JAVA running on SIM cards.
[547]
Java Card refers to a software technology that allows Java-based applications to be
[552]
run securely on smart cards.
[554]
It is widely used in SIM cards (used in GSM mobile phones) and ATM cards.
[560]
Crazy right.
[561]
And when we click around on that menu, the phone obviously has to forward whatever we
[565]
did in the menu to the sim card, and the sim card has to respond what kind of text to show
[570]
on the screen.
[571]
“We can choose one.
[573]
It’s in german I think.
[575]
“ For example here.
[576]
TERMINAL RESPONSE SELECT ITEM. we select an item in the menu.
[580]
And then the sim card responds with a new text for the menu.
[584]
FETCH.
[585]
DISPLAY TEXT.
[586]
“Simcard said, please display text.
[588]
I’m not sure if wireshark is powerful..
[590]
OH OK. it is here.”.
[593]
So Vadim wasn’t sure if that weird part of the SIM protocol was actually implemented
[597]
in wireshark, but it was.
[599]
Here it shows the text “MMS-InfoServices koennen nur mit MMS faehigen Handys empfangen
[604]
werden”.
[605]
So that’s german, its a german sim card, so the menu was german and it translates to:
[610]
“MMS infoServices can only be received with phones that support MMS.”
[615]
And I had pressed the back button on the phone.
[617]
So the terminal response.
[619]
So the response WE gave and the phone forwarded to the SIM card was hex 11.
[625]
Which stands for “backward move requested by user”.
[628]
Isn’t that awesome.
[631]
We use these mobile phones every day, but we have almost no understanding and insight
[635]
into how they work.
[636]
I hope you found this interesting, thanks so much to Vadim and all the others in the
[640]
OSMOCOM project for creating all those tools.
[644]
stay tuned for the next videos.
[645]
We will soon learn what makes these phones so special.