How to access a SIM card programmatically?

混江龙づ霸主 提交于 2021-02-05 12:44:30

问题


Just any old GSM compatible SIM card (bonus for 3G USIM).

I presume I need some hardware? Can anyone recommend something cheap for hobbyist, and something more professional?

I presume that there will be full docs of an API with the h/w, so maybe this should be tagged "no-programming-related"? Sorry, if so.

Any good URLs or books (I am conversant with the 3GPP standards).

I'm not (black hat) hacking, don't worry, just not pleased with the likes of SIM Card Secretary, Data Doctor Recovery, etc, so would like to code my own, but might turn it commercial, or offer SIM card programming services (data recover from damaged card, etc) as a sideline.


Update: while I am primarily interested just reading my SMS for backup, it might be a bonus if someone knows of a cheap SIM card writer (so that I can back up all or part of the SIM and restore it later)


回答1:


You can do that with any PC/SC smart card reader (and writer, as others pointed out) and a program that can read and parse the data for you.

  • Talking to a card is done via APDU commands (defined in ISO-7816)
  • The command set used by SIM (2G) and USIM (3G) cards is different, so you have to keep that in mind
  • The structure and format of the file system of a SIM card is defined in GSM 11.11 (for 2G) and ETSI TS 131.102 (for 3G) - all this documentation is public and available free of charge
  • The SMS are kept in a file called EF SMS, its name is 0x6F3C, its structure is defined in section 10.5.3 of GSM 11.11

Direct answers to your questions:

  • Here's where to buy a SIM reader, click on 'photos' to see pics of the device and screenshots of the software
  • SIM Manager is the program that does everything you want (including reading SMS, restoring SMS, it can even attempt to recover deleted SMS - if they're still physically on the card)
  • A SIM card SDK is available too. It is a DLL you can load and apply in your program. This thing does all the hard work for you, all you need is to create a GUI on top of it

I am one of the people from the team that created SIM Manager and the aforementioned SDK.




回答2:


You'll certainly need a smartcard reader and from what I've been able to find out, pretty much any one will do because they all have to support the standard functionality. They also happen to be pretty cheap. Mine is an OmniKey (not sure what model because I don't have it here right now).

Presuming that you're developing under Windows, the Windows API has functions that make it possible to access smartcards. Here is an article on CodeProject that discussees this in greater detail as part of a set of several C# classes that give you access to a bunch of this stuff without having to tangle with the nuts and bolts. I think that the guy's example app is specifically for SIM cards, so that'll probably help.




回答3:


There's lots of products and hardware to read and write SIM cards, have a look at http://forum.gsmhosting.com/vbb/f500/ in this forum you will find plenty of info concerning sim cards, mobile phones.. one of the bigest resource since 1999! for hardware programmers, you can build your own like JDM or ICprog.. check kiscan.net for some info..




回答4:


You can use simLAB tool for reading and editing almost any SIM file. It works with every PC/SC smartcard reader. The tool also allows you to backup SIM file system.

Have a look at https://github.com/kamwar/simLAB




回答5:


  1. pySim

    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.

    $ ./pySim-prog.py -p 0 -n OpenBSC -t sysmosim-gr1 -i 901700000003080 -c 001 -x 001 -y 02 -s 1791198229180000075
    

Is it enough just filling the new SIM card with new meta and will it working the same way as original? pyusb

Here is the full list of options:

$ ./pySim-prog.py -help
  Usage: pySim-prog.py [options]  Options:   
  -h, --help            show this help message and exit
  -d DEV, --device=DEV  Serial Device for SIM access [default: /dev/ttyUSB0]
  -b BAUD, --baud=BAUD  Baudrate used for SIM access [default: 9600]
  -p PCSC, --pcsc-device=PCSC
                        Which PC/SC reader number for SIM access
  -t TYPE, --type=TYPE  Card type (user -t list to view) [default: auto]
  -a PIN_ADM, --pin-adm=PIN_ADM
                        ADM PIN used for provisioning (overwrites default)
  -e, --erase           Erase beforehand [default: False]   
  -S SOURCE, --source=SOURCE
                        Data Source[default: cmdline]
  -n NAME, --name=NAME  Operator name [default: Magic]
  -c CC, --country=CC   Country code [default: 1]
  -x MCC, --mcc=MCC     Mobile Country Code [default: 901]
  -y MNC, --mnc=MNC     Mobile Network Code [default: 55]
  -m SMSC, --smsc=SMSC  SMSP [default: '00 + country code + 5555']
  -M SMSP, --smsp=SMSP  Raw SMSP content in hex [default: auto from SMSC]
  -s ID, --iccid=ID     Integrated Circuit Card ID
  -i IMSI, --imsi=IMSI  International Mobile Subscriber Identity
  -k KI, --ki=KI        Ki (default is to randomize)
  -o OPC, --opc=OPC     OPC (default is to randomize)
  --op=OP               Set OP to derive OPC from OP and KI
  --acc=ACC             Set ACC bits (Access Control Code). not all card types are supported
  -z STR, --secret=STR  Secret used for ICCID/IMSI autogen
  -j NUM, --num=NUM     Card # used for ICCID/IMSI autogen
  --batch               Enable batch mode [default: False]
  --batch-state=FILE    Optional batch state file
  --read-csv=FILE       Read parameters from CSV file rather than command line
  --write-csv=FILE      Append generated parameters in CSV file
  --write-hlr=FILE      Append generated parameters to OpenBSC HLR sqlite3
  --dry-run             Perform a 'dry run', don't actually program the card

The source code is available.

  1. Also the SIM card is just a smart card. You can use pyscard or pyusb to operate on it. I found this Q&A helpful.


来源:https://stackoverflow.com/questions/2792354/how-to-access-a-sim-card-programmatically

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!