mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-24 01:08:32 +03:00
simtrace.py: Use mitm.py in phone and mitm mode
This commit is contained in:
@@ -2,6 +2,7 @@ import usb.core
|
|||||||
import usb.util
|
import usb.util
|
||||||
|
|
||||||
from ccid_raw import SmartcardConnection
|
from ccid_raw import SmartcardConnection
|
||||||
|
from smartcard_emulator import SmartCardEmulator
|
||||||
|
|
||||||
from contextlib import closing
|
from contextlib import closing
|
||||||
|
|
||||||
@@ -43,9 +44,13 @@ 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 do_mitm():
|
def do_mitm(sim_emul=True):
|
||||||
dev = find_dev()
|
dev = find_dev()
|
||||||
with closing(SmartcardConnection()) as sm_con:
|
if sim_emul == True:
|
||||||
|
my_class = SmartCardEmulator
|
||||||
|
else:
|
||||||
|
my_class = SmartcardConnection
|
||||||
|
with closing(my_class()) as sm_con:
|
||||||
atr = sm_con.getATR()
|
atr = sm_con.getATR()
|
||||||
|
|
||||||
apdus = []
|
apdus = []
|
||||||
|
|||||||
@@ -4,16 +4,11 @@ import argparse
|
|||||||
import sniffer
|
import sniffer
|
||||||
import ccid
|
import ccid
|
||||||
import ccid_select
|
import ccid_select
|
||||||
import phone
|
|
||||||
import mitm
|
import mitm
|
||||||
|
|
||||||
import usb.core
|
import usb.core
|
||||||
import usb.util
|
import usb.util
|
||||||
|
import sys
|
||||||
import hashlib
|
|
||||||
import os
|
|
||||||
import random
|
|
||||||
import re
|
|
||||||
import time
|
import time
|
||||||
|
|
||||||
cmd1 = {0x00, 0x10, 0x00, 0x00}
|
cmd1 = {0x00, 0x10, 0x00, 0x00}
|
||||||
@@ -91,9 +86,9 @@ def main():
|
|||||||
if args.select_file is True:
|
if args.select_file is True:
|
||||||
ccid_select.select()
|
ccid_select.select()
|
||||||
if args.phone is True:
|
if args.phone is True:
|
||||||
phone.emulate_sim()
|
mitm.do_mitm(sim_emul=True)
|
||||||
if args.mitm is True:
|
if args.mitm is True:
|
||||||
mitm.do_mitm()
|
mitm.do_mitm(sim_emul=False)
|
||||||
|
|
||||||
return
|
return
|
||||||
|
|
||||||
|
|||||||
45
usb_application/smartcard_emulator.py
Normal file
45
usb_application/smartcard_emulator.py
Normal file
@@ -0,0 +1,45 @@
|
|||||||
|
#!/usr/bin/env python
|
||||||
|
|
||||||
|
import constants
|
||||||
|
import array
|
||||||
|
|
||||||
|
INS = 1
|
||||||
|
CNT = 4
|
||||||
|
|
||||||
|
class SmartCardEmulator:
|
||||||
|
def getATR(self):
|
||||||
|
return array.array('B', constants.ATR_SYSMOCOM2)
|
||||||
|
|
||||||
|
def send_receive_cmd(self, cmd):
|
||||||
|
if len(cmd) == 5: # Received cmd from phone
|
||||||
|
if cmd[INS] == 0xA4:
|
||||||
|
resp = [cmd[INS]] # Respond with INS byte
|
||||||
|
elif cmd[INS] == 0xC0:
|
||||||
|
data = [0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x7F, 0x20, 0x02, 0x00,
|
||||||
|
0x00, 0x00, 0x00, 0x00,
|
||||||
|
0x09, 0x91, 0x00, 0x17,
|
||||||
|
0x04, 0x00, 0x83, 0x8A,
|
||||||
|
0x83, 0x8A]
|
||||||
|
SW = [0x90, 0x00]
|
||||||
|
resp = [cmd[INS]] + data + SW # Respond with INS byte
|
||||||
|
#state = WAIT_RST
|
||||||
|
else:
|
||||||
|
print("Unknown cmd")
|
||||||
|
resp = [0x60, 0x00]
|
||||||
|
elif len(cmd) == 2:
|
||||||
|
resp = [0x9F, 0x16]
|
||||||
|
else:
|
||||||
|
resp = [0x60, 0x00]
|
||||||
|
|
||||||
|
print("Cmd, resp: ")
|
||||||
|
print("".join("%02x " % b for b in cmd))
|
||||||
|
print("".join("%02x " % b for b in resp))
|
||||||
|
|
||||||
|
return array.array('B', resp)
|
||||||
|
|
||||||
|
def reset_card():
|
||||||
|
pass
|
||||||
|
|
||||||
|
def close(self):
|
||||||
|
pass
|
||||||
Reference in New Issue
Block a user