From 95270b19036604b60d2800d1d718d5a5b311cbd2 Mon Sep 17 00:00:00 2001 From: Christina Quast Date: Sat, 4 Apr 2015 19:59:03 +0200 Subject: [PATCH] mitm.py: import modules, added exceptions --- usb_application/mitm.py | 40 +++++++++++++++++++++++----------------- 1 file changed, 23 insertions(+), 17 deletions(-) mode change 100644 => 100755 usb_application/mitm.py diff --git a/usb_application/mitm.py b/usb_application/mitm.py old mode 100644 new mode 100755 index 3d8ea4c1..e74bc84e --- a/usb_application/mitm.py +++ b/usb_application/mitm.py @@ -1,6 +1,9 @@ import usb.core import usb.util +import ccid_raw +import phone + def find_dev(): dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004) if dev is None: @@ -19,35 +22,38 @@ PHONE_RD = 0x85 PHONE_INT = 0x86 def check_msg_phone(): - cmd = dev.read(PHONE_RD, 64, 1000) - if cmd: + cmd = dev.read(PHONE_RD, 64, 100) + if cmd is not None: print("Phone sent: " + cmd) return cmd - cmd = dev.read(PHONE_INT, 64, 1000) - if cmd: + cmd = dev.read(PHONE_INT, 64, 100) + if cmd is not None: print("Phone sent int") return cmd def write_phone(resp): - dev.write(PHONE_WR, resp, 1000) + dev.write(PHONE_WR, resp, 100) def write_sim(data): return do_intercept(data, dwActiveProtocol) -def mitm(): +def do_mitm(): dev = find_dev() - hcard, hcontext, dwActiveProtocol = init() + hcard, hcontext, dwActiveProtocol = ccid_raw.ccid_raw_init() - while True: - if (cmd = check_msg_phone()): - resp = write_sim(cmd, dwActiveProtocol) - if (resp is not None): - write_phone(resp) - else: - - - exit(hcard, hcontext) + try: + try: + while True: + cmd = check_msg_phone() + if (cmd is not None): + resp = write_sim(cmd, dwActiveProtocol) + 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: - print e + print(e) pass