mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-25 17:58:32 +03:00
python simtrace suit: sniffer, ccid reader
This commit is contained in:
@@ -1,7 +1,3 @@
|
|||||||
#!/usr/bin/env python
|
|
||||||
|
|
||||||
import usb.core
|
|
||||||
import usb.util
|
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
from pySim.commands import SimCardCommands
|
from pySim.commands import SimCardCommands
|
||||||
@@ -9,12 +5,6 @@ from pySim.utils import h2b, swap_nibbles, rpad, dec_imsi, dec_iccid
|
|||||||
from pySim.transport.pcsc import PcscSimLink
|
from pySim.transport.pcsc import PcscSimLink
|
||||||
|
|
||||||
|
|
||||||
import hashlib
|
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import re
|
|
||||||
|
|
||||||
|
|
||||||
class find_class(object):
|
class find_class(object):
|
||||||
def __init__(self, class_):
|
def __init__(self, class_):
|
||||||
self._class = class_
|
self._class = class_
|
||||||
@@ -35,6 +25,11 @@ class find_class(object):
|
|||||||
|
|
||||||
return False
|
return False
|
||||||
|
|
||||||
|
def set_conf(conf):
|
||||||
|
devs = usb.core.find(find_all=1, custom_match=find_class(0xb)) # 0xb = Smartcard
|
||||||
|
for dev in devs:
|
||||||
|
dev.set_configuration(conf)
|
||||||
|
|
||||||
|
|
||||||
def pySim_read():
|
def pySim_read():
|
||||||
sl = PcscSimLink(0)
|
sl = PcscSimLink(0)
|
||||||
@@ -101,42 +96,3 @@ def pySim_read():
|
|||||||
|
|
||||||
# Done for this card and maybe for everything ?
|
# Done for this card and maybe for everything ?
|
||||||
print("Done !\n")
|
print("Done !\n")
|
||||||
|
|
||||||
cmd1 = {0x00, 0x10, 0x00, 0x00}
|
|
||||||
cmd2 = {0x00, 0x20, 0x00, 0x00, 0x02}
|
|
||||||
cmd_poweron = {0x62, 0x62, 0x00, 0x00}
|
|
||||||
cmd_poweroff = {0x63, 0x63, 0x00, 0x00}
|
|
||||||
cmd_get_slot_stat = {0x65, 0x65, 0x00, 0x00}
|
|
||||||
cmd_get_param = {0x00, 0x6C, 0x00, 0x00}
|
|
||||||
|
|
||||||
# main code
|
|
||||||
def main():
|
|
||||||
devs = usb.core.find(find_all=1, custom_match=find_class(0xb)) # 0xb = Smartcard
|
|
||||||
for dev in devs:
|
|
||||||
dev.set_configuration(2)
|
|
||||||
|
|
||||||
pySim_read()
|
|
||||||
|
|
||||||
# dev.write(0x1, cmd_poweroff)
|
|
||||||
# dev.write(0x1, cmd_poweron)
|
|
||||||
# dev.write(0x1, cmd2)
|
|
||||||
# dev.write(0x1, cmd_get_slot_stat)
|
|
||||||
# ret = dev.read(0x82, 64)
|
|
||||||
print(ret)
|
|
||||||
#dev.write(0x1, {0x62, 0x62}) # PC_TO_RDR_ICCPOWERON
|
|
||||||
return
|
|
||||||
|
|
||||||
# (epi, epo) = find_eps(dev)
|
|
||||||
while True:
|
|
||||||
#ep_out.write("Hello")
|
|
||||||
try:
|
|
||||||
ans = dev.read(0x82, 64, 1000)
|
|
||||||
print("".join("%02x " % b for b in ans))
|
|
||||||
except KeyboardInterrupt:
|
|
||||||
print("Bye")
|
|
||||||
sys.exit()
|
|
||||||
except:
|
|
||||||
print("Timeout")
|
|
||||||
# print(ep_in.read(1, 5000));
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|||||||
87
usb_application/simtrace.py
Executable file
87
usb_application/simtrace.py
Executable file
@@ -0,0 +1,87 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import argparse
|
||||||
|
import sniffer
|
||||||
|
import ccid
|
||||||
|
|
||||||
|
import usb.core
|
||||||
|
import usb.util
|
||||||
|
|
||||||
|
import hashlib
|
||||||
|
import os
|
||||||
|
import random
|
||||||
|
import re
|
||||||
|
|
||||||
|
cmd1 = {0x00, 0x10, 0x00, 0x00}
|
||||||
|
cmd2 = {0x00, 0x20, 0x00, 0x00, 0x02}
|
||||||
|
cmd_poweron = {0x62, 0x62, 0x00, 0x00}
|
||||||
|
cmd_poweroff = {0x63, 0x63, 0x00, 0x00}
|
||||||
|
cmd_get_slot_stat = {0x65, 0x65, 0x00, 0x00}
|
||||||
|
cmd_get_param = {0x00, 0x6C, 0x00, 0x00}
|
||||||
|
|
||||||
|
class find_class(object):
|
||||||
|
def __init__(self, class_):
|
||||||
|
self._class = class_
|
||||||
|
def __call__(self, device):
|
||||||
|
# first, let's check the device
|
||||||
|
if device.bDeviceClass == self._class:
|
||||||
|
return True
|
||||||
|
# ok, transverse all devices to find an
|
||||||
|
# interface that matches our class
|
||||||
|
for cfg in device:
|
||||||
|
# find_descriptor: what's it?
|
||||||
|
intf = usb.util.find_descriptor(
|
||||||
|
cfg,
|
||||||
|
bInterfaceClass=self._class
|
||||||
|
)
|
||||||
|
if intf is not None:
|
||||||
|
return True
|
||||||
|
|
||||||
|
return False
|
||||||
|
|
||||||
|
|
||||||
|
# main code
|
||||||
|
def main():
|
||||||
|
parser = argparse.ArgumentParser()
|
||||||
|
parser.add_argument("-C", "--conf", type=int, choices=[1, 2, 3], help="Set USB config")
|
||||||
|
parser.add_argument("-b", "--read_bin", help="read ICCID, IMSI, etc.", action='store_true')
|
||||||
|
parser.add_argument("-c", "--cmd", help="cmds to send to sim card (Not supported yet)",
|
||||||
|
choices=["cmd1", "cmd2", "cmd_poweron", "cmd_poweroff", "cmd_get_slot_stat", "cmd_get_param"])
|
||||||
|
parser.add_argument("-s", "--sniff", help="Sniff communication!", action='store_true')
|
||||||
|
|
||||||
|
args = parser.parse_args()
|
||||||
|
print("args: ", args)
|
||||||
|
|
||||||
|
# FIXME: why is it a ccid function?
|
||||||
|
if args.conf is not None:
|
||||||
|
devs = usb.core.find(find_all=1, custom_match=find_class(0xb)) # 0xb = Smartcard
|
||||||
|
for dev in devs:
|
||||||
|
dev.set_configuration(args.conf)
|
||||||
|
|
||||||
|
if args.read_bin is True:
|
||||||
|
ccid.pySim_read()
|
||||||
|
|
||||||
|
if args.cmd is not None:
|
||||||
|
devs = usb.core.find(find_all=1, custom_match=find_class(0xb)) # 0xb = Smartcard
|
||||||
|
for dev in devs:
|
||||||
|
dev.write(0x1, args.cmd)
|
||||||
|
ret = dev.read(0x82, 64)
|
||||||
|
print(ret)
|
||||||
|
if args.sniff is True:
|
||||||
|
sniffer.sniff()
|
||||||
|
return
|
||||||
|
|
||||||
|
# (epi, epo) = find_eps(dev)
|
||||||
|
while True:
|
||||||
|
#ep_out.write("Hello")
|
||||||
|
try:
|
||||||
|
ans = dev.read(0x82, 64, 1000)
|
||||||
|
print("".join("%02x " % b for b in ans))
|
||||||
|
except KeyboardInterrupt:
|
||||||
|
print("Bye")
|
||||||
|
sys.exit()
|
||||||
|
except:
|
||||||
|
print("Timeout")
|
||||||
|
# print(ep_in.read(1, 5000));
|
||||||
|
|
||||||
|
main()
|
||||||
@@ -44,9 +44,8 @@ def find_eps(dev):
|
|||||||
return (ep_in, ep_out)
|
return (ep_in, ep_out)
|
||||||
|
|
||||||
# main code
|
# main code
|
||||||
def main():
|
def sniff():
|
||||||
dev = find_dev()
|
dev = find_dev()
|
||||||
# (epi, epo) = find_eps(dev)
|
|
||||||
|
|
||||||
while True:
|
while True:
|
||||||
#ep_out.write("Hello")
|
#ep_out.write("Hello")
|
||||||
@@ -58,6 +57,3 @@ def main():
|
|||||||
sys.exit()
|
sys.exit()
|
||||||
except:
|
except:
|
||||||
print("Timeout")
|
print("Timeout")
|
||||||
# print(ep_in.read(1, 5000));
|
|
||||||
|
|
||||||
main()
|
|
||||||
|
|||||||
Reference in New Issue
Block a user