Project

General

Profile

Manually Testing USIM Authentication » History » Version 1

laforge, 04/27/2022 05:17 PM

1 1 laforge
h1. Manually Testing USIM Authentication
2
3
This page describes how  you can use Osmocom tools to manually test USIM / ISIM authentication against a SIM card.
4
5
h2. Prerequisites
6
7
* A USIM card of which you know the secret key K + OP/OPc
8
* A smart card interface device ("reader") supported by pysim (such as any pcsc-lite / libccid compatible reader)
9
* @osmo-auc-gen@ program (part of [[libosmocore:]])
10
* @pySim-shell@ program (part of [[pysim:]])
11
12
13
h2. Step-by-step guide
14
15
16
17
h3. Generate a 16-byte random challenge
18
19
Let's use @/dev/random@ to generate 16 bytes of randomness; conver it to hexadecimal
20
21
<pre>
22
$ dd if=/dev/random bs=16 count=1 2>/dev/null | xxd -p -l 100
23
8188388ad5cdd481b02298ff29827791
24
</pre>
25
26
h3. Generating the actual quintuple using @osmo-auc-gen@
27
28
This process mimics what is happening inside the Authentication Centre part of the HLR/HSS of your 2G/3G/4G network: Deriving RES from K, OP/OPc and SEQ/SQN.
29
30
We use the card-specific K + OPc values we received from the card manufacturer, as well as the random  value we generated in the previous  step
31
32
<pre>
33
$ osmo-auc-gen --3g --algorithm MILENAGE --key 77291F1E17132ADD86DC23A3AF601C89 --opc 831AFD01EF48692EC6FD18AEAB6CF381 --rand 8188388ad5cdd481b02298ff29827791
34
osmo-auc-gen (C) 2011-2012 by Harald Welte
35
This is FREE SOFTWARE with ABSOLUTELY NO WARRANTY
36
37
RAND:   8188388ad5cdd481b02298ff29827791
38
AUTN:   7f62c464f6d60000b77b88e0f6b9449c
39
IK:     43c7bc1e8e193ed2e0e7e164126bbed5
40
CK:     a0188b5f7724878b86b9a336d8f2e327
41
RES:    b4013d66d107a2b6
42
IMS nonce:      gYg4itXN1IGwIpj/KYJ3kX9ixGT21gAAt3uI4Pa5RJw=
43
IMS res:        tAE9ZtEHorY=
44
SRES:   65069fd0
45
Kc:     8581751333a4e4ab
46
SQN:    32
47
IND:    0
48
</pre>
49
50
This shows us the following information
51
* input data (RAND, IND, SQN)
52
* the challenge the network would send via radio interface to the UE/phone/modem (RAND, AUTN)
53
* the data the network keeps on the network side and does *not* send over radio:
54
** the A3 authentication result value (RES)
55
** the A8 generated keys for integrity protection and ciphering (IK, CK)
56
** the derived GSM values in case of fall-back to 2G (Kc, SRES)
57
58
h3. Performing authentication with the card, using @pySim-shell@
59
60
We now perform what the phone/modem does with the SIM card when it receives the RAND + AUTN values from the cellular network via a @AUTHENTICATION REQUEST@.
61
62
For this, we use  [[pysim:]], specifically the @authentication@ command in it.  It takes two parameters: @rand@ and @autn@
63
64
As we want to do UMTS-AKA against the USIM application on the card, we must first select @ADF.USIM@.
65
66
<pre>
67
$ ./pySim-shell.py -p0
68
Using PC/SC reader interface
69
Waiting for card...
70
Autodetected card type: sysmoISIM-SJA2
71
Info: Card is of type: UICC-SIM
72
AIDs on card:
73
 USIM: a0000000871002ffffffff8907090000 (EF.DIR)
74
 ISIM: a0000000871004ffffffff8907090000 (EF.DIR)
75
 ADF.ISD: a000000003000000
76
 ARA-M: a00000015141434c00
77
Detected CardModel: SysmocomSJA2
78
Welcome to pySim-shell!
79
pySIM-shell (MF)> select ADF.USIM
80
pySIM-shell (MF/ADF.USIM)> authenticate 8188388ad5cdd481b02298ff29827791 7f62c464f6d60000b77b88e0f6b9449c
81
{
82
    "successful_3g_authentication": {
83
        "res": "b4013d66d107a2b6",
84
        "ck": "a0188b5f7724878b86b9a336d8f2e327",
85
        "ik": "43c7bc1e8e193ed2e0e7e164126bbed5",
86
        "kc": "8581751333a4e4ab"
87
    }
88
}
89
</pre>
90
91
In this successful case, we see the card has accepted the AUTN nonce and generated the following output parameters:
92
* authentication result (RES); would be sent back to the network, where the network compares it with the expected RES value it has computed earlier. If it matches, authentication is OK.
93
* integrity protection (IK) and ciphering (CK) keys
94
** used for air interface protection on 3G/UMTS after a @CIPHERING MODE COMMAND
95
** used in derived forms for air interface protection and NAS protection in 4G/LTE
96
* GSM ciphering key (Kc); used for encryption on 2G/GSM/GPRS after a @CIPHERING MODE COMMAND@
Add picture from clipboard (Maximum size: 48.8 MB)