測試設備
- Arduino UNO
- RFID-RC522,一組$280,含兩個 RFID Card 和 RFID Reader
測試步驟
1. 先在麵包版上,接上 RFID 與 Arduino UNO,接法如下
- VCC -> 3.3V
- GND -> GND
- RST -> PIN 9
- SDA -> PIN 10
- MOSI -> PIN 11
- MISO -> PIN 12
- SCK(NSS) -> PIN 13
截圖如下:
2. 直接使用 https://github.com/miguelbalboa/rfid/ 所提供的範例當成測試程式,使用程式範例 DumpInfo.ino 讀取測試卡片,此部份沒問題。
Card UID: 03 D9 7E BC
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
62 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
61 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
60 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
..... 略
1 7 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
6 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
5 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
4 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
0 3 00 00 00 00 00 00 FF 07 80 69 FF FF FF FF FF FF [ 0 0 1 ]
2 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
1 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 [ 0 0 0 ]
0 03 D9 7E BC 18 08 04 00 01 C5 23 7B 5D 43 6E 1D [ 0 0 0 ]
3. 使用程式範例讀取悠遊卡,只能讀出卡號,並且會顯示認證失敗的錯誤訊息。看來沒有正確的密碼,是不能讀卡的。基本的安全保護都有作到,還算不錯。
Card UID: 8A D1 46 65
PICC type: MIFARE 1KB
Sector Block 0 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 AccessBits
15 63 PCD_Authenticate() failed: Timeout in communication.
14 59 PCD_Authenticate() failed: Timeout in communication.
13 55 PCD_Authenticate() failed: Timeout in communication.
12 51 PCD_Authenticate() failed: Timeout in communication.
11 47 PCD_Authenticate() failed: Timeout in communication.
10 43 PCD_Authenticate() failed: Timeout in communication.
9 39 PCD_Authenticate() failed: Timeout in communication.
8 35 PCD_Authenticate() failed: Timeout in communication.
7 31 PCD_Authenticate() failed: Timeout in communication.
6 27 PCD_Authenticate() failed: Timeout in communication.
5 23 PCD_Authenticate() failed: Timeout in communication.
4 19 PCD_Authenticate() failed: Timeout in communication.
3 15 PCD_Authenticate() failed: Timeout in communication.
2 11 PCD_Authenticate() failed: Timeout in communication.
1 7 PCD_Authenticate() failed: Timeout in communication.
0 3 PCD_Authenticate() failed: Timeout in communication.
認證失敗是因為 key 不正確,MFRC522的卡片出場預設 key 為六個 0xFF,範例程式碼也是寫成 6 個 0xFF,因此此程式只能夠讀 MFRC522。若要讀取其他卡片,需找出對應的 key 才行。程式摘錄如下:
bool MFRC522::MIFARE_SetUid(byte *newUid, byte uidSize, bool logErrors) {
MIFARE_Key key = {0xFF, 0xFF, 0xFF, 0xFF, 0xFF, 0xFF};
byte status = PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, (byte)1, &key, &uid);
if (status != STATUS_OK) {
if (logErrors) {
Serial.print(F("PCD_Authenticate() failed: "));
Serial.println(GetStatusCodeName(status));
}
return false;
}
}
這裡提供了一個可以複製 RFID 的設備,表示此種保護機制已經被破解了,而且可以在15分鐘內破解。hitcon 有一篇探討晶片卡安全機制的文章可供參考。
4. 使用程式範例 ChangeUID.ino 修改 UID,失敗。
這是因為所買的 RFID Card 並不提供寫入 UID 的功能,因此無法修改UID。
若要修改 UID,需要購買特製的 RFID Card。
5. 原本目的是想要自己多做一個備份的門禁卡片。現在遇到了兩個問題,無法讀取卡片內容,無法修改卡片 UID,看來事情並沒那麼簡單。還是乖乖的給鎖行賺錢吧。
註:悠遊卡規格為ISO-14443 Type A,, 感應頻率為13.56MHz, 傳輸距離為 0~10公分
20160602 更新:白卡可以到淘寶買,一張可改寫UID的白卡約1~2塊人名幣。許多門禁系統只檢查UID,因此只要執行 ChangeUID就可以多一張門禁卡了。
參考資料: