mitm.py: import modules, added exceptions

This commit is contained in:
Christina Quast
2015-04-04 19:59:03 +02:00
parent 3252a317d5
commit 95270b1903

40
usb_application/mitm.py Normal file → Executable file
View File

@@ -1,6 +1,9 @@
import usb.core import usb.core
import usb.util import usb.util
import ccid_raw
import phone
def find_dev(): def find_dev():
dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004) dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
if dev is None: if dev is None:
@@ -19,35 +22,38 @@ PHONE_RD = 0x85
PHONE_INT = 0x86 PHONE_INT = 0x86
def check_msg_phone(): def check_msg_phone():
cmd = dev.read(PHONE_RD, 64, 1000) cmd = dev.read(PHONE_RD, 64, 100)
if cmd: if cmd is not None:
print("Phone sent: " + cmd) print("Phone sent: " + cmd)
return cmd return cmd
cmd = dev.read(PHONE_INT, 64, 1000) cmd = dev.read(PHONE_INT, 64, 100)
if cmd: if cmd is not None:
print("Phone sent int") print("Phone sent int")
return cmd return cmd
def write_phone(resp): def write_phone(resp):
dev.write(PHONE_WR, resp, 1000) dev.write(PHONE_WR, resp, 100)
def write_sim(data): def write_sim(data):
return do_intercept(data, dwActiveProtocol) return do_intercept(data, dwActiveProtocol)
def mitm(): def do_mitm():
dev = find_dev() dev = find_dev()
hcard, hcontext, dwActiveProtocol = init() hcard, hcontext, dwActiveProtocol = ccid_raw.ccid_raw_init()
while True: try:
if (cmd = check_msg_phone()): try:
resp = write_sim(cmd, dwActiveProtocol) while True:
if (resp is not None): cmd = check_msg_phone()
write_phone(resp) if (cmd is not None):
else: resp = write_sim(cmd, dwActiveProtocol)
if (resp is not None):
write_phone(resp)
exit(hcard, hcontext) else:
print("No responses.")
finally:
ccid_raw.ccid_raw_exit(hcard, hcontext)
except usb.USBError as e: except usb.USBError as e:
print e print(e)
pass pass