Harald Welte | 94e8735 | 2021-04-02 13:38:00 +0200 | [diff] [blame] | 1 | pySim-shell |
| 2 | =========== |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 3 | |
| 4 | pySim-shell is an interactive command line shell for all kind of interactions with SIM cards. |
| 5 | |
| 6 | The interactive shell provides command for |
| 7 | |
| 8 | * navigating the on-card filesystem hierarchy |
| 9 | * authenticating with PINs such as ADM1 |
| 10 | * CHV/PIN management (VERIFY, ENABLE, DISABLE, UNBLOCK) |
| 11 | * decoding of SELECT response (file control parameters) |
| 12 | * reading and writing of files and records in raw, hex-encoded binary format |
| 13 | * for some files where related support has been developed: |
| 14 | |
| 15 | * decoded reading (display file data in JSON format) |
| 16 | * decoded writing (encode from JSON to binary format, then write) |
| 17 | |
| 18 | By means of using the python ``cmd2`` module, various useful features improve usability: |
| 19 | |
| 20 | * history of commands (persistent across restarts) |
| 21 | * output re-direction to files on your computer |
| 22 | * output piping through external tools like 'grep' |
| 23 | * tab completion of commands and SELECT-able files/directories |
| 24 | * interactive help for all commands |
| 25 | |
| 26 | |
| 27 | cmd2 basics |
| 28 | ----------- |
| 29 | |
| 30 | FIXME |
| 31 | |
| 32 | |
| 33 | |
| 34 | ISO7816 commands |
| 35 | ---------------- |
| 36 | |
| 37 | This category of commands relates to commands that originate in the ISO 7861-4 specifications, |
| 38 | most of them have a 1:1 resemblance in the specification. |
| 39 | |
| 40 | select |
| 41 | ~~~~~~ |
| 42 | |
| 43 | The ``select`` command is used to select a file, either by its FID, AID or by its symbolic name. |
| 44 | |
| 45 | Try ``select`` with tab-completion to get a list of all current selectable items: |
| 46 | |
| 47 | :: |
| 48 | |
| 49 | pySIM-shell (MF)> select |
| 50 | .. 2fe2 a0000000871004 EF.ARR MF |
| 51 | 2f00 3f00 ADF.ISIM EF.DIR |
| 52 | 2f05 7f10 ADF.USIM EF.ICCID |
| 53 | 2f06 7f20 DF.GSM EF.PL |
| 54 | 2f08 a0000000871002 DF.TELECOM EF.UMPC |
| 55 | |
| 56 | Use ``select`` with a specific FID or name to select the new file. |
| 57 | |
| 58 | This will |
| 59 | |
| 60 | * output the [JSON decoded, if possible] select response |
| 61 | * change the prompt to the newly selected file |
| 62 | * enable any commands specific to the newly-selected file |
| 63 | |
| 64 | :: |
| 65 | |
| 66 | pySIM-shell (MF)> select ADF.USIM |
| 67 | { |
| 68 | "file_descriptor": { |
| 69 | "shareable": true, |
| 70 | "file_type": "df", |
| 71 | "structure": "no_info_given" |
| 72 | }, |
| 73 | "df_name": "A0000000871002FFFFFFFF8907090000", |
| 74 | "proprietary_info": { |
| 75 | "uicc_characteristics": "71", |
| 76 | "available_memory": 101640 |
| 77 | }, |
| 78 | "life_cycle_status_int": "operational_activated", |
| 79 | "security_attrib_compact": "00", |
| 80 | "pin_status_template_do": "90017083010183018183010A83010B" |
| 81 | } |
| 82 | pySIM-shell (MF/ADF.USIM)> |
| 83 | |
| 84 | |
| 85 | |
| 86 | change_chv |
| 87 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 88 | .. argparse:: |
| 89 | :module: pySim-shell |
| 90 | :func: Iso7816Commands.change_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 91 | |
| 92 | |
| 93 | disable_chv |
| 94 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 95 | .. argparse:: |
| 96 | :module: pySim-shell |
| 97 | :func: Iso7816Commands.disable_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 98 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 99 | |
| 100 | enable_chv |
| 101 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 102 | .. argparse:: |
| 103 | :module: pySim-shell |
| 104 | :func: Iso7816Commands.enable_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 105 | |
| 106 | |
| 107 | unblock_chv |
| 108 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 109 | .. argparse:: |
| 110 | :module: pySim-shell |
| 111 | :func: Iso7816Commands.unblock_chv_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 112 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 113 | |
| 114 | verify_chv |
| 115 | ~~~~~~~~~~ |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 116 | This command allows you to verify a CHV (PIN), which is how the specifications call |
| 117 | it if you authenticate yourself with the said CHV/PIN. |
| 118 | |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 119 | .. argparse:: |
| 120 | :module: pySim-shell |
| 121 | :func: Iso7816Commands.verify_chv_parser |
| 122 | |
Harald Welte | a463161 | 2021-04-10 18:17:55 +0200 | [diff] [blame] | 123 | deactivate_file |
| 124 | ~~~~~~~~~~~~~~~ |
| 125 | Deactivate the currently selected file. This used to be called INVALIDATE in TS 11.11. |
| 126 | |
| 127 | |
| 128 | activate_file |
| 129 | ~~~~~~~~~~~~~ |
| 130 | Activate the currently selected file. This used to be called REHABILITATE in TS 11.11. |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 131 | |
Harald Welte | 703f933 | 2021-04-10 18:39:32 +0200 | [diff] [blame] | 132 | open_channel |
| 133 | ~~~~~~~~~~~~ |
| 134 | .. argparse:: |
| 135 | :module: pySim-shell |
| 136 | :func: Iso7816Commands.open_chan_parser |
| 137 | |
| 138 | close_channel |
| 139 | ~~~~~~~~~~~~~ |
| 140 | .. argparse:: |
| 141 | :module: pySim-shell |
| 142 | :func: Iso7816Commands.close_chan_parser |
| 143 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 144 | |
| 145 | pySim commands |
| 146 | -------------- |
| 147 | |
| 148 | Commands in this category are pySim specific; they do not have a 1:1 correspondence to ISO 7816 |
| 149 | or 3GPP commands. Mostly they will operate either only on local (in-memory) state, or execute |
| 150 | a complex sequence of card-commands. |
| 151 | |
| 152 | desc |
| 153 | ~~~~ |
| 154 | |
| 155 | Display human readable file description for the currently selected file. |
| 156 | |
| 157 | |
| 158 | dir |
| 159 | ~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 160 | .. argparse:: |
| 161 | :module: pySim-shell |
| 162 | :func: PySimCommands.dir_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 163 | |
| 164 | |
| 165 | export |
| 166 | ~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 167 | .. argparse:: |
| 168 | :module: pySim-shell |
| 169 | :func: PySimCommands.export_parser |
| 170 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 171 | |
| 172 | tree |
| 173 | ~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 174 | FIXME |
| 175 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 176 | |
| 177 | verify_adm |
| 178 | ~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 179 | FIXME |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 180 | |
| 181 | |
| 182 | Linear Fixed EF commands |
| 183 | ------------------------ |
| 184 | |
| 185 | These commands become enabled only when your currently selected file is of *Linear Fixed EF* type. |
| 186 | |
| 187 | read_record |
| 188 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 189 | .. argparse:: |
| 190 | :module: pySim.filesystem |
| 191 | :func: LinFixedEF.ShellCommands.read_rec_parser |
| 192 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 193 | |
| 194 | read_record_decoded |
| 195 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 196 | .. argparse:: |
| 197 | :module: pySim.filesystem |
| 198 | :func: LinFixedEF.ShellCommands.read_rec_dec_parser |
| 199 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 200 | |
Harald Welte | 850b72a | 2021-04-07 09:33:03 +0200 | [diff] [blame] | 201 | read_records |
| 202 | ~~~~~~~~~~~~ |
| 203 | .. argparse:: |
| 204 | :module: pySim.filesystem |
| 205 | :func: LinFixedEF.ShellCommands.read_recs_parser |
| 206 | |
| 207 | |
| 208 | read_records_decoded |
| 209 | ~~~~~~~~~~~~~~~~~~~~ |
| 210 | .. argparse:: |
| 211 | :module: pySim.filesystem |
| 212 | :func: LinFixedEF.ShellCommands.read_recs_dec_parser |
| 213 | |
| 214 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 215 | update_record |
| 216 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 217 | .. argparse:: |
| 218 | :module: pySim.filesystem |
| 219 | :func: LinFixedEF.ShellCommands.upd_rec_parser |
| 220 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 221 | |
| 222 | update_record_decoded |
| 223 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 224 | .. argparse:: |
| 225 | :module: pySim.filesystem |
| 226 | :func: LinFixedEF.ShellCommands.upd_rec_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 227 | |
| 228 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 229 | edit_record_decoded |
| 230 | ~~~~~~~~~~~~~~~~~~~ |
| 231 | .. argparse:: |
| 232 | :module: pySim.filesystem |
| 233 | :func: LinFixedEF.ShellCommands.edit_rec_dec_parser |
| 234 | |
| 235 | This command will read the selected record, decode it to its JSON representation, save |
| 236 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 237 | |
| 238 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 239 | text editor. |
| 240 | |
| 241 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 242 | back to the record on the SIM card. |
| 243 | |
| 244 | This allows for easy interactive modification of records. |
| 245 | |
| 246 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 247 | |
| 248 | Transparent EF commands |
| 249 | ----------------------- |
| 250 | |
| 251 | These commands become enabled only when your currently selected file is of *Transparent EF* type. |
| 252 | |
| 253 | |
| 254 | read_binary |
| 255 | ~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 256 | .. argparse:: |
| 257 | :module: pySim.filesystem |
| 258 | :func: TransparentEF.ShellCommands.read_bin_parser |
| 259 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 260 | |
| 261 | read_binary_decoded |
| 262 | ~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 263 | .. argparse:: |
| 264 | :module: pySim.filesystem |
| 265 | :func: TransparentEF.ShellCommands.read_bin_dec_parser |
| 266 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 267 | |
| 268 | update_binary |
| 269 | ~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 270 | .. argparse:: |
| 271 | :module: pySim.filesystem |
| 272 | :func: TransparentEF.ShellCommands.upd_bin_parser |
| 273 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 274 | |
| 275 | update_binary_decoded |
| 276 | ~~~~~~~~~~~~~~~~~~~~~ |
Harald Welte | d36f694 | 2021-04-04 14:37:55 +0200 | [diff] [blame] | 277 | .. argparse:: |
| 278 | :module: pySim.filesystem |
| 279 | :func: TransparentEF.ShellCommands.upd_bin_dec_parser |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 280 | |
Harald Welte | 0d4e98a | 2021-04-07 00:14:40 +0200 | [diff] [blame] | 281 | In normal operation, update_binary_decoded needs a JSON document representing the entire file contents as |
| 282 | input. This can be inconvenient if you want to keep 99% of the content but just toggle one specific |
| 283 | parameter. That's where the JSONpath support comes in handy: You can specify a JSONpath to an element |
| 284 | inside the document as well as a new value for tat field: |
| 285 | |
| 286 | Th below example demonstrates this by modifying the ofm field within EF.AD: |
| 287 | |
| 288 | :: |
| 289 | |
| 290 | pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded |
| 291 | { |
| 292 | "ms_operation_mode": "normal", |
| 293 | "specific_facilities": { |
| 294 | "ofm": true |
| 295 | }, |
| 296 | "len_of_mnc_in_imsi": 2 |
| 297 | } |
| 298 | pySIM-shell (MF/ADF.USIM/EF.AD)> update_binary_decoded --json-path specific_facilities.ofm false |
| 299 | pySIM-shell (MF/ADF.USIM/EF.AD)> read_binary_decoded |
| 300 | { |
| 301 | "ms_operation_mode": "normal", |
| 302 | "specific_facilities": { |
| 303 | "ofm": false |
| 304 | }, |
| 305 | "len_of_mnc_in_imsi": 2 |
| 306 | } |
| 307 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 308 | |
Harald Welte | 4145d3c | 2021-04-08 20:34:13 +0200 | [diff] [blame] | 309 | edit_binary_decoded |
| 310 | ~~~~~~~~~~~~~~~~~~~ |
| 311 | This command will read the selected binary EF, decode it to its JSON representation, save |
| 312 | that JSON to a temporary file on your computer, and launch your configured text editor. |
| 313 | |
| 314 | You may then perform whatever modifications to the JSON representation, save + leave your |
| 315 | text editor. |
| 316 | |
| 317 | Afterwards, the modified JSON will be re-encoded to the binary format, and the result written |
| 318 | to the SIM card. |
| 319 | |
| 320 | This allows for easy interactive modification of file contents. |
| 321 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 322 | |
Harald Welte | 15fae98 | 2021-04-10 10:22:27 +0200 | [diff] [blame] | 323 | USIM commands |
| 324 | ------------- |
| 325 | |
| 326 | authenticate |
| 327 | ~~~~~~~~~~~~ |
| 328 | .. argparse:: |
| 329 | :module: pySim.ts_31_102 |
| 330 | :func: ADF_USIM.AddlShellCommands.authenticate_parser |
| 331 | |
| 332 | |
| 333 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 334 | cmd2 settable parameters |
| 335 | ------------------------ |
| 336 | |
| 337 | ``cmd2`` has the concept of *settable parameters* which act a bit like environment variables in an OS-level |
| 338 | shell: They can be read and set, and they will influence the behavior somehow. |
| 339 | |
| 340 | conserve_write |
| 341 | ~~~~~~~~~~~~~~ |
| 342 | |
| 343 | If enabled, pySim will (when asked to write to a card) always first read the respective file/record and |
| 344 | verify if the to-be-written value differs from the current on-card value. If not, the write will be skipped. |
| 345 | Writes will only be performed if the new value is different from the current on-card value. |
| 346 | |
| 347 | If disabled, pySim will always write irrespective of the current/new value. |
| 348 | |
Harald Welte | 1748b93 | 2021-04-06 21:12:25 +0200 | [diff] [blame] | 349 | json_pretty_print |
| 350 | ~~~~~~~~~~~~~~~~~ |
| 351 | |
| 352 | This parameter determines if generated JSON output should (by default) be pretty-printed (multi-line |
| 353 | output with indent level of 4 spaces) or not. |
| 354 | |
| 355 | The default value of this parameter is 'true'. |
| 356 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 357 | debug |
| 358 | ~~~~~ |
| 359 | |
| 360 | If enabled, full python back-traces will be displayed in case of exceptions |
| 361 | |
Harald Welte | 7829d8a | 2021-04-10 11:28:53 +0200 | [diff] [blame] | 362 | apdu_trace |
| 363 | ~~~~~~~~~~ |
| 364 | |
| 365 | Boolean variable that determines if a hex-dump of the command + response APDU shall be printed. |
| 366 | |
Harald Welte | be9516f | 2021-04-03 11:30:10 +0200 | [diff] [blame] | 367 | numeric_path |
| 368 | ~~~~~~~~~~~~ |
| 369 | |
| 370 | Boolean variable that determines if path (e.g. in prompt) is displayed with numeric FIDs or string names. |
| 371 | |
| 372 | :: |
| 373 | |
| 374 | pySIM-shell (MF/EF.ICCID)> set numeric_path True |
| 375 | numeric_path - was: False |
| 376 | now: True |
| 377 | pySIM-shell (3f00/2fe2)> set numeric_path False |
| 378 | numeric_path - was: True |
| 379 | now: False |
| 380 | pySIM-shell (MF/EF.ICCID)> help set |