python libraires and command line tools for SIM/UICC/USIM/ISIM card analysis and programming. https://osmocom.org/projects/pysim
Go to file
Harald Welte bb3b5df8bf Introduce new object-oriented TLV parser/decoder/encoder
This introduces a new TLV library that heavily builds upon python object
oriented concepts.  Contrary to classic TLV parsers it doesn't focus on
the structure of Tag, Length and binary Value only, but it supports
actual decoding/interpretation of the value part into some kind of JSON
serializable dict.  The latter can be achieved by imperative
encode/decode methods, or by using our existing declarative 'construct'
based approach.

The TLV library supports both BER-TLV and COMPREHENSION-TLV for both
nested and non-nested TLV definitions.

As an example we include TLV definitions for a number of CAT (Card
Application Toolkit) IEs.

Change-Id: I7fc1699443bc9d8a4e7cdd2687af9af7cc03c30e
2021-06-05 10:47:17 +02:00
contrib contrib: Add sim-rest-{server,client}.py 2021-05-25 09:43:13 +02:00
docs Introduce new object-oriented TLV parser/decoder/encoder 2021-06-05 10:47:17 +02:00
pySim Introduce new object-oriented TLV parser/decoder/encoder 2021-06-05 10:47:17 +02:00
pysim-testdata pySim-read: adjust meaning of HPLMN/OPLMN flags in EF_SPN 2021-05-23 10:06:08 +00:00
tests utils: COMPREHENSION-TLV support 2021-05-29 22:13:56 +02:00
.gitignore Add README, COPYING, .gitignor 2009-12-27 09:43:51 +01:00
.gitreview add .gitreview 2018-07-19 23:51:00 +02:00
COPYING Add README, COPYING, .gitignor 2009-12-27 09:43:51 +01:00
README.md Update README 2021-05-17 18:08:45 +02:00
csv-format pySim-prog: Use CSV format with headers 2019-09-03 20:11:48 +02:00
pySim-prog.py Use construct for EF_AD in pySim-{shell, prog, read}.py, cards.py 2021-04-13 11:27:37 +00:00
pySim-read.py pySim-read: adjust meaning of HPLMN/OPLMN flags in EF_SPN 2021-05-23 10:06:08 +00:00
pySim-shell.py shell: Fix activate_file + deactivate_file commands 2021-05-25 22:23:00 +02:00
pyproject.toml Introduce setuptools support 2021-04-04 10:54:46 +02:00
requirements.txt Add codecs for EF_SPN and GSM strings via construct 2021-05-10 06:15:39 +02:00
setup.py Add codecs for EF_SPN and GSM strings via construct 2021-05-10 06:15:39 +02:00

README.md

pySim - Read, Write and Browse Programmable SIM/USIM Cards

This repository contains Python programs that can be used to read, program (write) and browse certain fields/parameters on so-called programmable SIM/USIM cards.

Such SIM/USIM cards are special cards, which - unlike those issued by regular commercial operators - come with the kind of keys that allow you to write the files/fields that normally only an operator can program.

This is useful particularly if you are running your own cellular network, and want to issue your own SIM/USIM cards for that network.

Homepage and Manual

Please visit the official homepage for usage instructions, manual and examples.

Git Repository

You can clone from the official Osmocom git repository using

git clone git://git.osmocom.org/pysim.git

There is a cgit interface at https://git.osmocom.org/pysim

Installation

Please install the following dependencies:

  • pyscard
  • serial
  • pytlv
  • cmd2
  • jsonpath-ng
  • construct
  • bidict
  • gsm0338

Example for Debian:

apt-get install python3-pyscard python3-serial python3-cmd2 python3-pip python3-yaml
pip3 install pytlv jsonpath-ng construct bidict gsm0338

Alternatively, everything can be installed using pip:

pip3 install -r requirements.txt

After installing all dependencies, the pySim applications pySim-read.py, pySim-prog.py and pySim-shell.py may be started directly from the cloned repository.

Archlinux Package

Archlinux users may install the package python-pysim-git from the Arch User Repository (AUR). The most convenient way is the use of an AUR Helper, e.g. yay or pacaur. The following example shows the installation with yay.

# Install
yay -Sy python-pysim-git

# Uninstall
sudo pacman -Rs python-pysim-git

Mailing List

There is no separate mailing list for this project. However, discussions related to pysim-prog are happening on the openbsc@lists.osmocom.org mailing list, please see https://lists.osmocom.org/mailman/listinfo/openbsc for subscription options and the list archive.

Please observe the Osmocom Mailing List Rules when posting.

Contributing

Our coding standards are described at https://osmocom.org/projects/cellular-infrastructure/wiki/Coding_standards

We are using a gerrit-based patch review process explained at https://osmocom.org/projects/cellular-infrastructure/wiki/Gerrit

Usage Examples

  • Program customizable SIMs. Two modes are possible:
  • one where you specify every parameter manually:
./pySim-prog.py -n 26C3 -c 49 -x 262 -y 42 -i <IMSI> -s <ICCID>
  • one where they are generated from some minimal set:
./pySim-prog.py -n 26C3 -c 49 -x 262 -y 42 -z <random_string_of_choice> -j <card_num>

With <random_string_of_choice> and <card_num>, the soft will generate 'predictable' IMSI and ICCID, so make sure you choose them so as not to conflict with anyone. (for e.g. your name as <random_string_of_choice> and 0 1 2 ... for <card num>).

You also need to enter some parameters to select the device:

-t TYPE : type of card (supersim, magicsim, fakemagicsim or try auto)
-d DEV : Serial port device (default /dev/ttyUSB0)
-b BAUD : Baudrate (default 9600)

  • Interact with SIMs from a python interactive shell (e.g. ipython):
from pySim.transport.serial import SerialSimLink
from pySim.commands import SimCardCommands

sl = SerialSimLink(device='/dev/ttyUSB0', baudrate=9600)
sc = SimCardCommands(sl)

sl.wait_for_card()

	# Print IMSI
print(sc.read_binary(['3f00', '7f20', '6f07']))

	# Run A3/A8
print(sc.run_gsm('00112233445566778899aabbccddeeff'))