blob: e74bc84e39e2eaf1d65080a85d35a5fa2e40dbd6 [file] [log] [blame]
Christina Quast69d1f902015-04-03 11:41:23 +02001import usb.core
2import usb.util
3
Christina Quast95270b12015-04-04 19:59:03 +02004import ccid_raw
5import phone
6
Christina Quast69d1f902015-04-03 11:41:23 +02007def find_dev():
8 dev = usb.core.find(idVendor=0x03eb, idProduct=0x6004)
9 if dev is None:
10 raise ValueError("Device not found")
11 else:
12 print("Found device")
13 return dev
14
15
16SIM_WR = 0x1
17SIM_RD = 0x82
18SIM_INT = 0x83
19
20PHONE_WR = 0x4
21PHONE_RD = 0x85
22PHONE_INT = 0x86
23
24def check_msg_phone():
Christina Quast95270b12015-04-04 19:59:03 +020025 cmd = dev.read(PHONE_RD, 64, 100)
26 if cmd is not None:
Christina Quast69d1f902015-04-03 11:41:23 +020027 print("Phone sent: " + cmd)
28 return cmd
Christina Quast95270b12015-04-04 19:59:03 +020029 cmd = dev.read(PHONE_INT, 64, 100)
30 if cmd is not None:
Christina Quast69d1f902015-04-03 11:41:23 +020031 print("Phone sent int")
32 return cmd
33
34def write_phone(resp):
Christina Quast95270b12015-04-04 19:59:03 +020035 dev.write(PHONE_WR, resp, 100)
Christina Quast69d1f902015-04-03 11:41:23 +020036
37def write_sim(data):
38 return do_intercept(data, dwActiveProtocol)
39
Christina Quast95270b12015-04-04 19:59:03 +020040def do_mitm():
Christina Quast69d1f902015-04-03 11:41:23 +020041 dev = find_dev()
Christina Quast95270b12015-04-04 19:59:03 +020042 hcard, hcontext, dwActiveProtocol = ccid_raw.ccid_raw_init()
Christina Quast69d1f902015-04-03 11:41:23 +020043
Christina Quast95270b12015-04-04 19:59:03 +020044 try:
45 try:
46 while True:
47 cmd = check_msg_phone()
48 if (cmd is not None):
49 resp = write_sim(cmd, dwActiveProtocol)
50 if (resp is not None):
51 write_phone(resp)
52 else:
53 print("No responses.")
54 finally:
55 ccid_raw.ccid_raw_exit(hcard, hcontext)
Christina Quast69d1f902015-04-03 11:41:23 +020056
57 except usb.USBError as e:
Christina Quast95270b12015-04-04 19:59:03 +020058 print(e)
Christina Quast69d1f902015-04-03 11:41:23 +020059 pass