mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-26 18:28:32 +03:00
mitm.py: using new ccid_raw.py functions
This commit is contained in:
@@ -1,9 +1,12 @@
|
|||||||
import usb.core
|
import usb.core
|
||||||
import usb.util
|
import usb.util
|
||||||
|
|
||||||
import ccid_raw
|
from ccid_raw import SmartcardConnection
|
||||||
import phone
|
import phone
|
||||||
|
|
||||||
|
from contextlib import closing
|
||||||
|
|
||||||
|
|
||||||
def find_dev():
|
def find_dev():
|
||||||
dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
|
dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
|
||||||
if dev is None:
|
if dev is None:
|
||||||
@@ -12,6 +15,14 @@ def find_dev():
|
|||||||
print("Found device")
|
print("Found device")
|
||||||
return dev
|
return dev
|
||||||
|
|
||||||
|
def pattern_match(inpt):
|
||||||
|
print("Matching inpt", inpt)
|
||||||
|
if (inpt == ATR_SYSMOCOM1):
|
||||||
|
return NEW_ATR
|
||||||
|
elif (inpt == CMD_SEL_FILE):
|
||||||
|
return CMD_SEL_ROOT
|
||||||
|
else:
|
||||||
|
return inpt
|
||||||
|
|
||||||
SIM_WR = 0x1
|
SIM_WR = 0x1
|
||||||
SIM_RD = 0x82
|
SIM_RD = 0x82
|
||||||
@@ -21,39 +32,38 @@ PHONE_WR = 0x4
|
|||||||
PHONE_RD = 0x85
|
PHONE_RD = 0x85
|
||||||
PHONE_INT = 0x86
|
PHONE_INT = 0x86
|
||||||
|
|
||||||
def check_msg_phone():
|
ERR_TIMEOUT = 110
|
||||||
cmd = dev.read(PHONE_RD, 64, 100)
|
|
||||||
if cmd is not None:
|
|
||||||
print("Phone sent: " + cmd)
|
|
||||||
return cmd
|
|
||||||
cmd = dev.read(PHONE_INT, 64, 100)
|
|
||||||
if cmd is not None:
|
|
||||||
print("Phone sent int")
|
|
||||||
return cmd
|
|
||||||
|
|
||||||
def write_phone(resp):
|
def poll_ep(dev, ep):
|
||||||
dev.write(PHONE_WR, resp, 100)
|
try:
|
||||||
|
return dev.read(ep, 64, 1000)
|
||||||
|
except usb.core.USBError as e:
|
||||||
|
if e.errno != ERR_TIMEOUT:
|
||||||
|
raise
|
||||||
|
return None
|
||||||
|
|
||||||
def write_sim(data):
|
def write_phone(dev, resp):
|
||||||
return do_intercept(data, dwActiveProtocol)
|
dev.write(PHONE_WR, resp, 1000)
|
||||||
|
|
||||||
|
def reset_sim(sm_con):
|
||||||
|
sm_con.disconnect_card()
|
||||||
|
sm_con.connect_card()
|
||||||
|
|
||||||
def do_mitm():
|
def do_mitm():
|
||||||
dev = find_dev()
|
dev = find_dev()
|
||||||
hcard, hcontext, dwActiveProtocol = ccid_raw.ccid_raw_init()
|
with closing(SmartcardConnection()) as sm_con:
|
||||||
|
|
||||||
try:
|
while True:
|
||||||
try:
|
cmd = poll_ep(dev, PHONE_INT)
|
||||||
while True:
|
if cmd is not None:
|
||||||
cmd = check_msg_phone()
|
print(cmd)
|
||||||
if (cmd is not None):
|
assert cmd[0] == ord('R')
|
||||||
resp = write_sim(cmd, dwActiveProtocol)
|
reset_sim(sm_con)
|
||||||
if (resp is not None):
|
|
||||||
write_phone(resp)
|
|
||||||
else:
|
|
||||||
print("No responses.")
|
|
||||||
finally:
|
|
||||||
ccid_raw.ccid_raw_exit(hcard, hcontext)
|
|
||||||
|
|
||||||
except usb.USBError as e:
|
cmd = poll_ep(dev, PHONE_RD)
|
||||||
print(e)
|
if cmd is not None:
|
||||||
pass
|
print(cmd)
|
||||||
|
sim_data = sm_con.send_receive_cmd(cmd)
|
||||||
|
if sim_data is None:
|
||||||
|
continue
|
||||||
|
write_phone(dev, sim_data)
|
||||||
|
|||||||
Reference in New Issue
Block a user