Project

General

Profile

Wiki » History » Version 30

wirelesss, 10/26/2016 08:08 AM

1 4 wirelesss
{{>toc}}
2
3
h1. pySim WiKi 
4 1 laforge
5
pySim-prog is a small command line utility written in python, which is used for programming various programmable SIM/USIM cards.
6
7
h2. Supported Cards
8
9
* [[cellular-infrastructure:SysmoUSIM-SJS1]]
10
* [[cellular-infrastructure:GrcardSIM]]
11
* [[cellular-infrastructure:GrcardSIM2]]
12
* [[cellular-infrastructure:MagicSIM]]
13 5 wirelesss
14 14 wirelesss
h3. 1. Install dependencies
15 5 wirelesss
16
 sudo apt-get install pcscd pcsc-tools libccid libpcsclite-dev
17
18
h3. 2. Connected your SIM card reader
19
20 16 wirelesss
h3. 3. Plug your programmable SIM card in
21 5 wirelesss
22
h3. 4. Check the status of connection by execution of the following command:
23
24
 pcsc_scan
25
26 24 wirelesss
h3. 5. If SIM card reader is recognised then we can expect something similar to the below output:
27 5 wirelesss
28
 $ pcsc_scan
29
 PC/SC device scanner
30
 V 1.4.25 (c) 2001-2011, Ludovic Rousseau ludovic.rousseau@free.fr
31
 Compiled with PC/SC lite version: 1.8.14
32
 Using reader plug'n play mechanism
33
 Scanning present readers...
34
 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00 
35
 Tue Oct 18 11:48:08 2016
36
 Reader 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00
37
 Card state: Card inserted, 
38
 ATR: 3B 99 18 00 11 88 22 33 44 55 66 77 60
39
 + TS = 3B --> Direct Convention
40
 + T0 = 99, Y(1): 1001, K: 9 (historical bytes)
41
  TA(1) = 18 --> Fi=372, Di=12, 31 cycles/ETU
42
  129032 bits/s at 4 MHz, fMax for Fi = 5 MHz => 161290 bits/s
43
  TD(1) = 00 --> Y(i+1) = 0000, Protocol T = 0 
44
 -----
45
 + Historical bytes: 11 88 22 33 44 55 66 77 60
46
 Category indicator byte: 11 (proprietary format)
47
 Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
48
 3B 99 18 00 11 88 22 33 44 55 66 77 60
49
 sysmocom sysmoSIM-GR1
50
51 20 wirelesss
h4. 5.1  We could expect the following output from pcsc_scan command, when we have Super SIM card plugged in
52
53
 $ pcsc_scan
54
 PC/SC device scanner
55
 V 1.4.25 (c) 2001-2011, Ludovic Rousseau ludovic.rousseau@free.fr
56
 Compiled with PC/SC lite version: 1.8.14
57
 Using reader plug'n play mechanism
58
 Scanning present readers...
59
 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00
60
 Wed Oct 19 13:13:20 2016
61
 Reader 0: SCM Microsystems Inc. SCR 3310 [CCID Interface] 00 00
62
  Card state: Card inserted, 
63
  ATR: 3B 9A 94 00 92 02 75 93 11 00 01 02 02 21
64
  ATR: 3B 9A 94 00 92 02 75 93 11 00 01 02 02 21
65
 + TS = 3B --> Direct Convention
66
 + T0 = 9A, Y(1): 1001, K: 10 (historical bytes)
67
   TA(1) = 94 --> Fi=512, Di=8, 64 cycles/ETU
68
     62500 bits/s at 4 MHz, fMax for Fi = 5 MHz => 78125 bits/s
69
   TD(1) = 00 --> Y(i+1) = 0000, Protocol T = 0 
70
 -----
71
 + Historical bytes: 92 02 75 93 11 00 01 02 02 21
72
   Category indicator byte: 92 (proprietary format)
73
 Possibly identified card (using /usr/share/pcsc/smartcard_list.txt):
74
 3B 9A 94 00 92 02 75 93 11 00 01 02 02 21
75
 3B 9A 94 00 92 02 75 93 11 00 01 02 02 ..
76
	 SuperSIM (X-sim)
77
78 6 wirelesss
h3. 6. Exit pcsc_scan : _Ctrl+C_
79 5 wirelesss
80
h3. 7. Get the code of PySIM by entering command:
81
82
 git clone git://git.osmocom.org/pysim pysim
83
84
 cd pysim
85
86
h3. 8. Run the /pySim-read.py to read your SIM card:
87
88
 ./pySim-read.py -p0 or ./pySim-read.py -p1 
89
90
h3. 9. Using sysmoSIM-GR1 and if everything is done correctly, you will see something similar to:
91
 
92
 $ ./pySim-read.py -p0 
93
 Reading ...
94
 ICCID: 1791198229180000071
95
 IMSI: 001640000000071
96
 SMSP: ffffffffffffffffffffffffe1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
97
 ACC: ffff
98
 MSISDN: Not available
99
 Done !
100
101 8 wirelesss
h3. 9.1. In case of sysmoUSIM-SJS1 SIM card, you will see something similar to:
102 5 wirelesss
103
 $ ./pySim-read.py -p0
104
 Reading ...
105
 ICCID: 8988211000000106594
106
 IMSI: 901700000010659
107
 SMSP: ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff
108
 ACC: 0200
109
 MSISDN: Not available
110
 Done !
111
112 8 wirelesss
h3. 9.2. In case of SuperSIM/X-sim card, you will see something similar to:
113 5 wirelesss
114
 $ ./pySim-read.py -p0
115
 Reading ...
116
 ICCID: 8949901990000000184
117
 IMSI: 901990000000018
118
 SMSP: ffffffffffffffffffffffffe1ffffffffffffffffffffffff058100945555ffffffffffff000000
119
 ACC: ffff
120
 MSISDN: Not available
121
 Done !
122
123
124 17 wirelesss
h3. 10. Program your SIM card
125 5 wirelesss
126 7 wirelesss
Enter @./pySim-prog.py -help@ to get overview of possible options. 
127 5 wirelesss
128
Similar result should appear: 
129
130
 $ ./pySim-prog.py -help
131
 Usage: pySim-prog.py [options]
132
 Options:
133
   -h, --help            show this help message and exit
134
   -d DEV, --device=DEV  Serial Device for SIM access [default: /dev/ttyUSB0]
135
   -b BAUD, --baud=BAUD  Baudrate used for SIM access [default: 9600]
136
   -p PCSC, --pcsc-device=PCSC
137
                         Which PC/SC reader number for SIM access
138
   -t TYPE, --type=TYPE  Card type (user -t list to view) [default: auto]
139
   -a PIN_ADM, --pin-adm=PIN_ADM
140
                         ADM PIN used for provisioning (overwrites default)
141
   -e, --erase           Erase beforehand [default: False]
142
   -S SOURCE, --source=SOURCE
143
                         Data Source[default: cmdline]
144
   -n NAME, --name=NAME  Operator name [default: Magic]
145
   -c CC, --country=CC   Country code [default: 1]
146
   -x MCC, --mcc=MCC     Mobile Country Code [default: 901]
147
   -y MNC, --mnc=MNC     Mobile Network Code [default: 55]
148
   -m SMSC, --smsc=SMSC  SMSP [default: '00 + country code + 5555']
149
   -M SMSP, --smsp=SMSP  Raw SMSP content in hex [default: auto from SMSC]
150
   -s ID, --iccid=ID     Integrated Circuit Card ID
151
   -i IMSI, --imsi=IMSI  International Mobile Subscriber Identity
152
   -k KI, --ki=KI        Ki (default is to randomize)
153
   -o OPC, --opc=OPC     OPC (default is to randomize)
154
   --op=OP               Set OP to derive OPC from OP and KI
155
   --acc=ACC             Set ACC bits (Access Control Code). not all card types
156
                         are supported
157
   -z STR, --secret=STR  Secret used for ICCID/IMSI autogen
158
   -j NUM, --num=NUM     Card # used for ICCID/IMSI autogen
159
   --batch               Enable batch mode [default: False]
160
   --batch-state=FILE    Optional batch state file
161
   --read-csv=FILE       Read parameters from CSV file rather than command line
162
   --write-csv=FILE      Append generated parameters in CSV file
163
   --write-hlr=FILE      Append generated parameters to OpenBSC HLR sqlite3
164
   --dry-run             Perform a 'dry run', don't actually program the card
165
166 18 wirelesss
h3. 11. Example of how to program a sysmoSIM-GR1 card 
167 5 wirelesss
168
The GRcard SIM is a programmable GSM SIM card. It uses a mixture of TS11.11 / ISO7816-4 and proprietary commands for programming.
169 12 wirelesss
170 25 wirelesss
In the below example, we are changing the card’s IMSI to 901700000003080 (option -i) and we are specifying a new set of -n NAME (Operator name), -t TYPE (Card type), -c CC (Country code), -x MCC (Mobile Country Code), -y MNC (Mobile Network Code) and -s ID (Integrated Circuit Card ID) values.
171 5 wirelesss
 
172
 $ ./pySim-prog.py -p 0 -n OpenBSC -t sysmosim-gr1 -i 901700000003080 -c 001 -x 001 -y 02 -s 1791198229180000075
173
 Insert card now (or CTRL-C to cancel)
174
 Generated card parameters :
175
  > Name    : OpenBSC
176
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
177
  > ICCID   : 1791198229180000075
178
  > MCC/MNC : 1/2
179
  > IMSI    : 901700000003080
180
  > Ki      : 7edaeb6addbd72d2b2cc6ed7bfecc9c9
181
  > OPC     : 23f075ab9b1a113d4db822d8195ea20c
182 1 laforge
  > ACC     : None
183 5 wirelesss
 Programming ...
184
 Done !
185
186 19 wirelesss
h3. 12. Example of how to program a SysmoUSIM-SJS1 (orange) card
187 5 wirelesss
188
(U)SIM cards are Java capable and there is the Globalplatform that specifies standards API. SMS can be addressed directly to the SIM card, the SIM card will get events for network selection and others, it can modify call establishment attempts.
189
190
191 13 wirelesss
Provisioning of different identities or keys.
192 5 wirelesss
 
193
If you have a variant of the card-individual ADM1 key of your sysmoUSIM-SJS1 card,  you can change any identity (IMSI, ICCID, MSISDN) stored on the (U)SIM, as well as the private key data (K, OPC).
194
195 26 wirelesss
In the below example, we are changing the card’s IMSI to 901700000003080 (option -i) and we are specifying a new set of -t TYPE (Card type), - a ADM_PIN (ADM PIN used for provisioning), -x MCC (Mobile Country Code), -y MNC (Mobile Network Code), -s ID (Integrated Circuit Card ID), -o OPC and -k KI (Ki) values.
196 5 wirelesss
197 11 wirelesss
 $ ./pySim-prog.py -p 0 -t sysmoUSIM-SJS1 -a 58001006  -x 901 -y 71 -i 901700000010659 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
198 5 wirelesss
 Insert card now (or CTRL-C to cancel)
199
 Generated card parameters :
200
  > Name    : Magic
201
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
202
  > ICCID   : 8988211000000110000
203
  > MCC/MNC : 901/71
204
  > IMSI    : 901700000010659
205
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
206
  > OPC     : 398153093661279FB1FC74BE07059FEF
207
  > ACC     : None
208
 Programming ...
209 1 laforge
 Done !
210 23 wirelesss
211
h3. 13 Example of how to program a Magic SIM / SuperSIM 16-in-1 / X-sim card
212
213 29 laforge
The 16-in-1 SIM cards are intended for COMP128v1 based cloning and enable the user to aggregate up to 16 SIM card identities in a single card. This multi-IMSI property is not used in the context of Osmocom.
214 23 wirelesss
215
Below example shows how we can change the card’s IMSI to 901990000000018 (option -i) and at the same time we are specifying a new set of -x MCC (Mobile Country Code), -y MNC (Mobile Network Code), -s ID (Integrated Circuit Card ID) , -o OPC and -k KI (Ki) values.
216
217
 $ ./pySim-prog.py -p 0 -x 801 -y 71 -i 901990000000018 -s 8988211000000110000 -o 398153093661279FB1FC74BE07059FEF -k 1D8B2562B992549F20D0F42113EAA6FA
218
 Insert card now (or CTRL-C to cancel)
219
 Autodetected card type fakemagicsim
220
 Generated card parameters :
221
  > Name    : Magic
222
  > SMSP    : e1ffffffffffffffffffffffff0581005155f5ffffffffffff000000
223
  > ICCID   : 8988211000000110000
224
  > MCC/MNC : 801/71
225
  > IMSI    : 901990000000018
226
  > Ki      : 1D8B2562B992549F20D0F42113EAA6FA
227
  > OPC     : 398153093661279FB1FC74BE07059FEF
228
  > ACC     : None
229
 Programming ...
230
 Done !
231
232
h3. 14 README 
233 5 wirelesss
234
pySim comes with following README file:
235
236 1 laforge
This utility allows to :
237
238 5 wirelesss
* Program customizable SIMs. Two modes are possible:
239 1 laforge
240 5 wirelesss
- one where you specify every parameter manually :
241 6 wirelesss
_
242
./pySim-prog.py -n 26C3 -c 49 -x 262 -y 42 -i <IMSI> -s <ICCID>_
243 5 wirelesss
244
- one where they are generated from some minimal set :
245
246 6 wirelesss
_./pySim-prog.py -n 26C3 -c 49 -x 262 -y 42 -z <random_string_of_choice> -j <card_num>_
247 5 wirelesss
248
With <random_string_of_choice> and <card_num>, the soft will generate
249
'predictable' IMSI and ICCID, so make sure you choose them so as not to
250
conflict with anyone. (for eg. your name as <random_string_of_choice> and
251
0 1 2 ... for <card num>).
252
253
You also need to enter some parameters to select the device :
254
-t TYPE : type of card (supersim, magicsim, fakemagicsim or try 'auto')
255
-d DEV  : Serial port device (default /dev/ttyUSB0)
256
-b BAUD : Baudrate (default 9600)
257
258
* Interact with SIMs from a python interactive shell (ipython for eg :)
259
260
from pySim.transport.serial import SerialSimLink
261 1 laforge
from pySim.commands import SimCardCommands
262 5 wirelesss
263 1 laforge
sl = SerialSimLink(device='/dev/ttyUSB0', baudrate=9600)
264 5 wirelesss
sc = SimCardCommands(sl)
265
266
sl.wait_for_card()
267
268
# Print IMSI
269 6 wirelesss
_print sc.read_binary(['3f00', '7f20', '6f07'])_
270 5 wirelesss
271
# Run A3/A8
272 6 wirelesss
_print sc.run_gsm('00112233445566778899aabbccddeeff')_
Add picture from clipboard (Maximum size: 48.8 MB)