mirror of
https://gitea.osmocom.org/sim-card/simtrace2.git
synced 2026-03-16 21:28:33 +03:00
replace.py: Moved replace func,mitm: addr book replace
Moved the replace function from mitm.py to replace.py. This implementation is context insensitive for now. It would be better, to have a mitm class or to pass state information to the function. Because how else can the MITM code know, whether it gets passed data to or from the sim card, to or from the phone?
This commit is contained in:
@@ -12,6 +12,8 @@ from util import HEX
|
||||
from constants import *
|
||||
from apdu_split import Apdu_splitter, apdu_states
|
||||
|
||||
from replace import replace
|
||||
|
||||
def pattern_match(inpt):
|
||||
print("Matching inpt", inpt)
|
||||
if (inpt == ATR_SYSMOCOM1) or (inpt == ATR_STRANGE_SIM):
|
||||
@@ -38,24 +40,6 @@ def write_phone(dev, resp):
|
||||
print("WR: ", HEX(resp))
|
||||
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', NEW_ATR)
|
||||
elif data[0] == 0x9F:
|
||||
print("*** Replace return val")
|
||||
# return array('B', [0x60, 0x00])
|
||||
elif data == PHONE_BOOK_RESP:
|
||||
print("*** Replace phone book")
|
||||
return PHONE_BOOK_RESP_MITM
|
||||
except ValueError:
|
||||
print("*** Value error! ")
|
||||
return data
|
||||
|
||||
def do_mitm(dev, sim_emul=True):
|
||||
if sim_emul == True:
|
||||
my_class = SmartCardEmulator
|
||||
|
||||
46
usb_application/replace.py
Executable file
46
usb_application/replace.py
Executable file
@@ -0,0 +1,46 @@
|
||||
#!/usr/bin/env python
|
||||
|
||||
import array
|
||||
from constants import *
|
||||
|
||||
|
||||
# Address book entries
|
||||
name = 'deine mudda'
|
||||
phone = '0123456789abcdef'
|
||||
|
||||
def replace(data):
|
||||
print(replace.last_req)
|
||||
if data is None:
|
||||
raise MITMReplaceError
|
||||
else:
|
||||
try:
|
||||
if data[0] == 0xA0:
|
||||
print("INS: ", hex(data[1]))
|
||||
replace.last_req = data
|
||||
return data
|
||||
|
||||
if data[0] == 0x3B:
|
||||
return data
|
||||
#print("*** Replace ATR")
|
||||
#return array('B', NEW_ATR)
|
||||
elif data[0] == 0x9F:
|
||||
return data
|
||||
# print("*** Replace return val")
|
||||
# return array('B', [0x60, 0x00])
|
||||
elif replace.last_req[1:5] == array('B', [0xB2, 0x01, 0x04, 0x1A]): # phone book request
|
||||
print("*** Replace phone book")
|
||||
# return array('B', [0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0x66, 0xff, 0xff, 0xff, 0xff, 0x09, 0x81, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0x55, 0xff, 0xff, 0xff, 0xff, 0x90, 0x00])
|
||||
resp = map(ord, name) + ([0xff]*(12-len(name))) + [len(name) + 1] + [0x81]
|
||||
for x in range(1,len(phone)/2+1):
|
||||
list.append(resp, int(phone[x*2-2:2*x:], 16))
|
||||
resp += ([0xff]*(replace.last_req[4]-len(resp))) + [0x90, 0x00]
|
||||
return array('B', resp)
|
||||
except ValueError:
|
||||
print("*** Value error! ")
|
||||
return data
|
||||
|
||||
replace.last_req = array('B')
|
||||
|
||||
if __name__ == '__main__':
|
||||
print("Replacing PHONE_BOOK_REQ", PHONE_BOOK_REQ, "with", replace(PHONE_BOOK_REQ))
|
||||
print("Replacing PHONE_BOOK_RESP", PHONE_BOOK_RESP, "with", replace(PHONE_BOOK_RESP))
|
||||
Reference in New Issue
Block a user