mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-20 07:18:33 +03:00
mitm.py: Dirty hack for replacing ATR live
This commit is contained in:
@@ -45,6 +45,21 @@ def write_phone(dev, resp):
|
|||||||
print("WR: ", HEX(resp))
|
print("WR: ", HEX(resp))
|
||||||
dev.write(PHONE_WR, resp, 10)
|
dev.write(PHONE_WR, resp, 10)
|
||||||
|
|
||||||
|
def replace(data):
|
||||||
|
if data is None:
|
||||||
|
raise MITMReplaceError
|
||||||
|
else:
|
||||||
|
try:
|
||||||
|
if data[0] == 0x3B:
|
||||||
|
print("*** Replace ATR")
|
||||||
|
return array('B', ATR_SYSMOCOM2)
|
||||||
|
elif data[0] == 0x9F:
|
||||||
|
print("*** Replace return val")
|
||||||
|
# return array('B', [0x60, 0x00])
|
||||||
|
except ValueError:
|
||||||
|
print("*** Value error! ")
|
||||||
|
return data
|
||||||
|
|
||||||
def do_mitm(sim_emul=True):
|
def do_mitm(sim_emul=True):
|
||||||
dev = find_dev()
|
dev = find_dev()
|
||||||
if sim_emul == True:
|
if sim_emul == True:
|
||||||
@@ -65,7 +80,7 @@ def do_mitm(sim_emul=True):
|
|||||||
# FIXME: restart card anyways?
|
# FIXME: restart card anyways?
|
||||||
# sm_con.reset_card()
|
# sm_con.reset_card()
|
||||||
print("Write atr: ", HEX(atr))
|
print("Write atr: ", HEX(atr))
|
||||||
write_phone(dev, atr)
|
write_phone(dev, replace(atr))
|
||||||
apdus = []
|
apdus = []
|
||||||
apdu = Apdu_splitter()
|
apdu = Apdu_splitter()
|
||||||
|
|
||||||
@@ -82,17 +97,17 @@ def do_mitm(sim_emul=True):
|
|||||||
if apdu.state == apdu_states.APDU_S_SW1:
|
if apdu.state == apdu_states.APDU_S_SW1:
|
||||||
if apdu.data is not None and len(apdu.data) == 0:
|
if apdu.data is not None and len(apdu.data) == 0:
|
||||||
# FIXME: implement other ACK types
|
# FIXME: implement other ACK types
|
||||||
write_phone(dev, array('B', [apdu.ins]))
|
write_phone(dev, replace(array('B', [apdu.ins])))
|
||||||
apdu.split(apdu.ins)
|
apdu.split(apdu.ins)
|
||||||
else:
|
else:
|
||||||
sim_data = sm_con.send_receive_cmd(apdu.buf)
|
sim_data = sm_con.send_receive_cmd(apdu.buf)
|
||||||
write_phone(dev, sim_data)
|
write_phone(dev, replace(sim_data))
|
||||||
for c in sim_data:
|
for c in sim_data:
|
||||||
apdu.split(c)
|
apdu.split(c)
|
||||||
elif apdu.state == apdu_states.APDU_S_SEND_DATA:
|
elif apdu.state == apdu_states.APDU_S_SEND_DATA:
|
||||||
sim_data = sm_con.send_receive_cmd(apdu.buf)
|
sim_data = sm_con.send_receive_cmd(replace(apdu.buf))
|
||||||
sim_data.insert(0, apdu.ins)
|
sim_data.insert(0, apdu.ins)
|
||||||
write_phone(dev, sim_data)
|
write_phone(dev, replace(sim_data))
|
||||||
apdu.state = apdu_states.APDU_S_SW1
|
apdu.state = apdu_states.APDU_S_SW1
|
||||||
for c in sim_data:
|
for c in sim_data:
|
||||||
apdu.split(c)
|
apdu.split(c)
|
||||||
|
|||||||
Reference in New Issue
Block a user