Merge pull request #2593 from Akury83/master
[RRG-proxmark3.git] / tools / pm3_reblay-reading.py
blobc1220d0c7cbe47727d8d9673473be5776230f01d
1 #!/usr/bin/env python3
3 """
4 //-----------------------------------------------------------------------------
5 // Salvador Mendoza (salmg.net), 2021
6 //
7 // This code is licensed to you under the terms of the GNU GPL, version 2 or,
8 // at your option, any later version. See the LICENSE.txt file for the text of
9 // the license.
10 //-----------------------------------------------------------------------------
11 // Code to test Proxmark3 Standalone mode aka reblay by Salvador Mendoza
12 //-----------------------------------------------------------------------------
13 """
15 import serial
16 from smartcard.util import toHexString
18 ser = serial.Serial('/dev/rfcomm0') # open Proxmark3 Bluetooth port
20 def pd(data):
21 rapdu = map(ord, data)
22 return rapdu
24 apdu = [
25 [0x00, 0xA4, 0x04, 0x00, 0x0e, 0x32, 0x50, 0x41, 0x59, 0x2e, 0x53, 0x59, 0x53, 0x2e, 0x44, 0x44, 0x46, 0x30, 0x31, 0x00], # PPSE
26 [0x00, 0xA4, 0x04, 0x00, 0x07, 0xa0, 0x00, 0x00, 0x00, 0x03, 0x10, 0x10, 0x00], # Visa card
27 [0x80, 0xA8, 0x00, 0x00, 0x02, 0x83, 0x00, 0x00], # GET PROCESSING
28 [0x00, 0xb2, 0x01, 0x0c, 0x00] # SFI
31 print('Testing code: bluetooth has to be connected with the right rfcomm port!')
32 print('Waiting for data...')
33 initd = ser.read(1)
35 bufferlen = pd(initd)[0]
36 rping = ser.read(bufferlen)
38 ping = pd(rping)
39 if (len(ping) == 7):
40 print('UID:'),
41 print(toHexString(ping[:4]))
42 print('ATQA:'),
43 print(toHexString(ping[4:-1]))
44 print('SAK:'),
45 print(toHexString(ping[-1:]))
46 elif (len(ping) == 10):
47 print('UID:'),
48 print(toHexString(ping[:7]))
49 print('ATQA:'),
50 print(toHexString(ping[7:-1]))
51 print('SAK:'),
52 print(toHexString(ping[-1:]))
53 else:
54 print('got ping, no sure what it means: '),
55 print(ping)
57 for x in apdu:
58 print('Sending cmd: '),
59 ser.write(x)
60 print(toHexString(x))
62 lenpk = ser.read(1) #first byte is the buffer length
63 bufferlen = pd(lenpk)[0]
65 buffer = pd(ser.read(bufferlen))
66 print('Card Response:'),
67 print(toHexString(buffer))
68 print('--')
70 ser.write(b'1') #tell Proxmark3 that we finish the communication
71 ser.close()