Harald Welte | c1cd027 | 2011-12-07 01:51:46 +0100 | [diff] [blame^] | 1 | = osmo-sim-auth = |
| 2 | |
| 3 | This is a small script that can be used with a PC-based smart card |
| 4 | reader to obtain GSM/UMTS authentication parameters from a SIM/USIM |
| 5 | card. |
| 6 | |
| 7 | == prerequisites == |
| 8 | |
| 9 | We assume that you have |
| 10 | |
| 11 | * A smart card reader compatible with pcsc-lite |
| 12 | * Installed python program and pyscard library |
| 13 | |
| 14 | |
| 15 | === smart card reader === |
| 16 | |
| 17 | Any reader supported by pcsc-lite will work. However, a reader |
| 18 | compatible with the USB CCID device class is much recommended. |
| 19 | |
| 20 | Please verify that the hardware and driver setup is working, e.g. by |
| 21 | using the 'pcsc_scan' tool included with pcsc-lite. You should get an |
| 22 | output like: |
| 23 | {{{ |
| 24 | V 1.4.17 (c) 2001-2009, Ludovic Rousseau <ludovic.rousseau@free.fr> |
| 25 | Compiled with PC/SC lite version: 1.5.5 |
| 26 | Scanning present readers... |
| 27 | 0: OmniKey CardMan 5121 00 00 |
| 28 | |
| 29 | Wed Dec 7 01:32:37 2011 |
| 30 | Reader 0: OmniKey CardMan 5121 00 00 |
| 31 | Card state: Card inserted, Shared Mode, |
| 32 | ATR: 3B 9F 95 80 1F C7 80 31 E0 73 FE 21 13 57 12 29 11 02 01 00 00 C2 |
| 33 | |
| 34 | ATR: 3B 9F 95 80 1F C7 80 31 E0 73 FE 21 13 57 12 29 11 02 01 00 00 C2 |
| 35 | }}} |
| 36 | |
| 37 | plus many more lines of output decoding the ATR. |
| 38 | |
| 39 | If you only get |
| 40 | {{{ |
| 41 | PC/SC device scanner |
| 42 | V 1.4.17 (c) 2001-2009, Ludovic Rousseau <ludovic.rousseau@free.fr> |
| 43 | Compiled with PC/SC lite version: 1.5.5 |
| 44 | Scanning present readers... |
| 45 | 0: OmniKey CardMan 5121 00 00 |
| 46 | |
| 47 | Wed Dec 7 01:35:08 2011 |
| 48 | Reader 0: OmniKey CardMan 5121 00 00 |
| 49 | Card state: Card removed, |
| 50 | }}} |
| 51 | |
| 52 | then your card was not detected in the reader. |
| 53 | |
| 54 | If you don't even get any displayed readers, your hardware and/or driver |
| 55 | setup are likely wrong. |
| 56 | |
| 57 | |
| 58 | === pyscard === |
| 59 | |
| 60 | pyscard can be installed from packages of major Linux distributions. |
| 61 | |
| 62 | If you want to build it from source, it is available from |
| 63 | http://pyscard.sourceforge.net/ |
| 64 | |
| 65 | |
| 66 | == running osmo-sim-auth == |
| 67 | |
| 68 | {{{ |
| 69 | $ ./osmo-sim-auth.py --help |
| 70 | Usage: osmo-sim-auth.py [options] |
| 71 | |
| 72 | Options: |
| 73 | -h, --help show this help message and exit |
| 74 | -a AUTN, --autn=AUTN AUTN parameter from AuC |
| 75 | -r RAND, --rand=RAND RAND parameter from AuC |
| 76 | -d, --debug Enable debug output |
| 77 | -s, --sim SIM mode (default: USIM) |
| 78 | }}} |
| 79 | |
| 80 | you can run the program in two modes: |
| 81 | * running GSM authentication (classic SIM card protocol) |
| 82 | * running UMTS authentication (USIM card protocol) |
| 83 | |
| 84 | === classic GSM authentication === |
| 85 | |
| 86 | This mode will use the "RUN GSM ALGORITHM" command as specified in GMS |
| 87 | TS 11.11 |
| 88 | |
| 89 | You have to specify |
| 90 | * the 16 byte RAND value from the AuC (-r) as 32 hex digits |
| 91 | * the '-s' flag to enable SIM mode |
| 92 | |
| 93 | {{{ |
| 94 | $ ./osmo-sim-auth.py -r 00000000000000000000000000000000 -s |
| 95 | Testing SIM card with IMSI 901700000000403 |
| 96 | |
| 97 | GSM Authentication |
| 98 | SRES: 215fdb4d |
| 99 | Kc: 6de816a759a42912 |
| 100 | }}} |
| 101 | |
| 102 | === UMTS authentication === |
| 103 | |
| 104 | This mode will use the "AUTHENTICATE" command as specified in 3GPP TS |
| 105 | 31.102 |
| 106 | |
| 107 | You have to specify |
| 108 | * the 16 byte RAND value from the AuC (-r) as 32 hex digits |
| 109 | * the 16 byte AUTN value from the AuC (-a) as 32 hex digits |
| 110 | |
| 111 | ==== successful operation ==== |
| 112 | |
| 113 | In this case, the tool will output the following values obtained from |
| 114 | the card: |
| 115 | * RES authentication result value |
| 116 | * CK ciphering key |
| 117 | * IK integrity key |
| 118 | * Kc for inter-RAN handover from UMTS -> 2G |
| 119 | |
| 120 | Secondly, the tool will re-run the authentication in "2G authentication |
| 121 | context" in order to obtain the SRES result. This value would be used |
| 122 | if a 3G/2G dual-mode phone registers on a 2G network. |
| 123 | |
| 124 | {{{ |
| 125 | python ./osmo-sim-auth.py -r 00000000000000000000000000000000 -a ec9320c2c2000000e1dd22c1ad3e2d3d |
| 126 | [+] UICC AID found: |
| 127 | found [AID 1] 3GPP || USIM || (255, 134) || (255, 255) || (137, 255, |
| 128 | 255, 255, 255) |
| 129 | [+] USIM AID selection succeeded |
| 130 | |
| 131 | Testing USIM card with IMSI 901700000000403 |
| 132 | |
| 133 | UMTS Authentication |
| 134 | RES: e9fc88ccc8a35381 |
| 135 | CK: 7200a184d8f2c758fbdf87900ddbf275 |
| 136 | IK: 12cb2dd3e0ec8378f6fc1d606c619f47 |
| 137 | Kc: 6de816a759a42912 |
| 138 | |
| 139 | GSM Authentication |
| 140 | SRES: 215fdb4d |
| 141 | Kc: 6de816a759a42912 |
| 142 | }}} |
| 143 | |
| 144 | ==== synchronization required ==== |
| 145 | |
| 146 | In this case, the AUTHENTICATE command will return the AUTS parameter, |
| 147 | which has to be sent to the AuC in order to re-synchronzie the SQN |
| 148 | counter which is kept in both the USIM as well as the AuC. |
| 149 | |
| 150 | {{{ |
| 151 | ./osmo-sim-auth.py -r 00000000000000000000000000000000 -a ec9320c2c2120000c8b7de2a3449f1bd |
| 152 | [+] UICC AID found: |
| 153 | found [AID 1] 3GPP || USIM || (255, 134) || (255, 255) || (137, 255, |
| 154 | 255, 255, 255) |
| 155 | [+] USIM AID selection succeeded |
| 156 | |
| 157 | Testing USIM card with IMSI 901700000000403 |
| 158 | |
| 159 | UMTS Authentication |
| 160 | AUTS: 8711a0ec9e2be2f766881a64605b |
| 161 | |
| 162 | GSM Authentication |
| 163 | SRES: 215fdb4d |
| 164 | Kc: 6de816a759a42912 |
| 165 | }}} |