diff options
author | Christina Quast <chrysh.ng+git@gmail.com> | 2015-06-24 15:44:36 +0200 |
---|---|---|
committer | Christina Quast <chrysh.ng+git@gmail.com> | 2015-06-24 15:48:41 +0200 |
commit | ad6f4d3fd21e60d0892cdc69899e6f5dd16e9892 (patch) | |
tree | 16ef6885b949dfcfc593d1c9b6e8d3f6b0087010 | |
parent | 2cafadb2a15da6f1bce00591abd12986dc868b08 (diff) |
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?
-rwxr-xr-x | usb_application/mitm.py | 20 | ||||
-rwxr-xr-x | usb_application/replace.py | 46 |
2 files changed, 48 insertions, 18 deletions
diff --git a/usb_application/mitm.py b/usb_application/mitm.py index 5e8ff6e..4b53bc7 100755 --- a/usb_application/mitm.py +++ b/usb_application/mitm.py @@ -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 diff --git a/usb_application/replace.py b/usb_application/replace.py new file mode 100755 index 0000000..b8fb004 --- /dev/null +++ b/usb_application/replace.py @@ -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)) |