This shows you the differences between two versions of the page.
pm:prj2022:cstan:id_project [2022/05/30 19:12] mihai_vlad.ionita [Software Design] |
pm:prj2022:cstan:id_project [2022/05/30 19:21] (current) mihai_vlad.ionita [Bibliografie/Resurse] |
||
---|---|---|---|
Line 34: | Line 34: | ||
<note tip> | <note tip> | ||
Biblioteca inclusa pe partea de software a fost cea MFRC522 de pe github (https://github.com/mdxs/MFRC522). | Biblioteca inclusa pe partea de software a fost cea MFRC522 de pe github (https://github.com/mdxs/MFRC522). | ||
- | |||
- | /* | ||
- | * Copy the RFID card data into variables and then | ||
- | * scan the second empty card to copy all the data | ||
- | * ---------------------------------------------------------------------------- | ||
- | * Example sketch/program which will try the most used default keys listed in | ||
- | * https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys to dump the | ||
- | * block 0 of a MIFARE RFID card using a RFID-RC522 reader. | ||
- | * | ||
- | * Typical pin layout used: | ||
- | * ----------------------------------------------------------------------------------------- | ||
- | * MFRC522 Arduino Arduino Arduino Arduino Arduino | ||
- | * Reader/PCD Uno/101 Mega Nano v3 Leonardo/Micro Pro Micro | ||
- | * Signal Pin Pin Pin Pin Pin Pin | ||
- | * ----------------------------------------------------------------------------------------- | ||
- | * RST/Reset RST 9 5 D9 RESET/ICSP-5 RST | ||
- | * SPI SS SDA(SS) 10 53 D10 10 10 | ||
- | * SPI MOSI MOSI 11 / ICSP-4 51 D11 ICSP-4 16 | ||
- | * SPI MISO MISO 12 / ICSP-1 50 D12 ICSP-1 14 | ||
- | * SPI SCK SCK 13 / ICSP-3 52 D13 ICSP-3 15 | ||
- | * | ||
- | * More pin layouts for other boards can be found here: https://github.com/miguelbalboa/rfid#pin-layout | ||
- | * | ||
- | */ | ||
#include <SPI.h> | #include <SPI.h> | ||
#include <MFRC522.h> | #include <MFRC522.h> | ||
- | #define RST_PIN 9 // Configurable, see typical pin layout above | + | #define RST_PIN 9 |
- | #define SS_PIN 10 // Configurable, see typical pin layout above | + | #define SS_PIN 10 |
- | MFRC522 mfrc522(SS_PIN, RST_PIN); // Create MFRC522 instance. | + | MFRC522 mfrc522(SS_PIN, RST_PIN); |
byte buffer[18]; | byte buffer[18]; | ||
Line 74: | Line 50: | ||
MFRC522::MIFARE_Key key; | MFRC522::MIFARE_Key key; | ||
- | // Number of known default keys (hard-coded) | + | |
- | // NOTE: Synchronize the NR_KNOWN_KEYS define with the defaultKeys[] array | + | |
#define NR_KNOWN_KEYS 8 | #define NR_KNOWN_KEYS 8 | ||
- | // Known keys, see: https://code.google.com/p/mfcuk/wiki/MifareClassicDefaultKeys | + | |
byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] = { | byte knownKeys[NR_KNOWN_KEYS][MFRC522::MF_KEY_SIZE] = { | ||
{0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default | {0xff, 0xff, 0xff, 0xff, 0xff, 0xff}, // FF FF FF FF FF FF = factory default | ||
Line 90: | Line 65: | ||
char choice; | char choice; | ||
- | /* | + | |
- | * Initialize. | + | |
- | */ | + | |
void setup() { | void setup() { | ||
- | Serial.begin(9600); // Initialize serial communications with the PC | + | Serial.begin(9600); |
- | while (!Serial); // Do nothing if no serial port is opened (added for Arduinos based on ATMEGA32U4) | + | while (!Serial); |
- | SPI.begin(); // Init SPI bus | + | SPI.begin(); |
- | mfrc522.PCD_Init(); // Init MFRC522 card | + | mfrc522.PCD_Init(); |
Serial.println(F("Try the most used default keys to print block 0 to 63 of a MIFARE PICC.")); | Serial.println(F("Try the most used default keys to print block 0 to 63 of a MIFARE PICC.")); | ||
Serial.println("1.Read card \n2.Write to card \n3.Copy the data."); | Serial.println("1.Read card \n2.Write to card \n3.Copy the data."); | ||
Line 108: | Line 81: | ||
- | //Via seriele monitor de bytes uitlezen in hexadecimaal | + | |
void dump_byte_array(byte *buffer, byte bufferSize) { | void dump_byte_array(byte *buffer, byte bufferSize) { | ||
Line 116: | Line 89: | ||
} | } | ||
} | } | ||
- | //Via seriele monitor de bytes uitlezen in ASCI | + | |
void dump_byte_array1(byte *buffer, byte bufferSize) { | void dump_byte_array1(byte *buffer, byte bufferSize) { | ||
Line 125: | Line 98: | ||
} | } | ||
- | /* | + | |
- | * Try using the PICC (the tag/card) with the given key to access block 0 to 63. | + | |
- | * On success, it will show the key details, and dump the block data on Serial. | + | |
- | * | + | |
- | * @return true when the given key worked, false otherwise. | + | |
- | */ | + | |
- | + | ||
bool try_key(MFRC522::MIFARE_Key *key) | bool try_key(MFRC522::MIFARE_Key *key) | ||
{ | { | ||
Line 138: | Line 105: | ||
for(byte block = 0; block < 64; block++){ | for(byte block = 0; block < 64; block++){ | ||
| | ||
- | // Serial.println(F("Authenticating using key A...")); | ||
status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &(mfrc522.uid)); | status = mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, key, &(mfrc522.uid)); | ||
if (status != MFRC522::STATUS_OK) { | if (status != MFRC522::STATUS_OK) { | ||
Line 146: | Line 112: | ||
} | } | ||
- | // Read block | + | |
byte byteCount = sizeof(buffer); | byte byteCount = sizeof(buffer); | ||
status = mfrc522.MIFARE_Read(block, buffer, &byteCount); | status = mfrc522.MIFARE_Read(block, buffer, &byteCount); | ||
Line 154: | Line 120: | ||
} | } | ||
else { | else { | ||
- | // Successful read | + | |
result = true; | result = true; | ||
Serial.print(F("Success with key:")); | Serial.print(F("Success with key:")); | ||
Line 160: | Line 126: | ||
Serial.println(); | Serial.println(); | ||
| | ||
- | // Dump block data | + | |
Serial.print(F("Block ")); Serial.print(block); Serial.print(F(":")); | Serial.print(F("Block ")); Serial.print(block); Serial.print(F(":")); | ||
- | dump_byte_array1(buffer, 16); //omzetten van hex naar ASCI | + | dump_byte_array1(buffer, 16); |
Serial.println(); | Serial.println(); | ||
| | ||
- | for (int p = 0; p < 16; p++) //De 16 bits uit de block uitlezen | + | for (int p = 0; p < 16; p++) |
{ | { | ||
waarde [block][p] = buffer[p]; | waarde [block][p] = buffer[p]; | ||
Line 178: | Line 144: | ||
Serial.println("1.Read card \n2.Write to card \n3.Copy the data."); | Serial.println("1.Read card \n2.Write to card \n3.Copy the data."); | ||
- | mfrc522.PICC_HaltA(); // Halt PICC | + | mfrc522.PICC_HaltA(); |
- | mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD | + | mfrc522.PCD_StopCrypto1(); |
return result; | return result; | ||
| | ||
Line 185: | Line 151: | ||
} | } | ||
- | /* | + | |
- | * Main loop. | + | |
- | */ | + | |
void loop() { | void loop() { | ||
start(); | start(); | ||
Line 214: | Line 178: | ||
} | } | ||
- | void keuze2(){ //Test waardes in blokken | + | void keuze2(){ |
| | ||
for(block = 4; block <= 62; block++){ | for(block = 4; block <= 62; block++){ | ||
Line 237: | Line 201: | ||
} | } | ||
- | void keuze3(){ //Copy the data in the new card | + | void keuze3(){ |
Serial.println("Insert new card..."); | Serial.println("Insert new card..."); | ||
- | // Look for new cards | + | |
if ( ! mfrc522.PICC_IsNewCardPresent()) | if ( ! mfrc522.PICC_IsNewCardPresent()) | ||
return; | return; | ||
- | // Select one of the cards | + | |
if ( ! mfrc522.PICC_ReadCardSerial()) | if ( ! mfrc522.PICC_ReadCardSerial()) | ||
return; | return; | ||
- | // Show some details of the PICC (that is: the tag/card) | ||
Serial.print(F("Card UID:")); | Serial.print(F("Card UID:")); | ||
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); | dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); | ||
Line 255: | Line 218: | ||
Serial.println(mfrc522.PICC_GetTypeName(piccType)); | Serial.println(mfrc522.PICC_GetTypeName(piccType)); | ||
| | ||
- | // Try the known default keys | + | |
- | /*MFRC522::MIFARE_Key key; | + | |
- | for (byte k = 0; k < NR_KNOWN_KEYS; k++) { | + | |
- | // Copy the known key into the MIFARE_Key structure | + | |
- | for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) { | + | |
- | key.keyByte[i] = knownKeys[k][i]; | + | |
- | } | + | |
- | }*/ | + | |
for (byte i = 0; i < 6; i++) { | for (byte i = 0; i < 6; i++) { | ||
key.keyByte[i] = 0xFF; | key.keyByte[i] = 0xFF; | ||
} | } | ||
- | for(int i = 4; i <= 62; i++){ //De blocken 4 tot 62 kopieren, behalve al deze onderstaande blocken (omdat deze de authenticatie blokken zijn) | + | for(int i = 4; i <= 62; i++){ |
if(i == 7 || i == 11 || i == 15 || i == 19 || i == 23 || i == 27 || i == 31 || i == 35 || i == 39 || i == 43 || i == 47 || i == 51 || i == 55 || i == 59){ | if(i == 7 || i == 11 || i == 15 || i == 19 || i == 23 || i == 27 || i == 31 || i == 35 || i == 39 || i == 43 || i == 47 || i == 51 || i == 55 || i == 59){ | ||
i++; | i++; | ||
Line 273: | Line 229: | ||
block = i; | block = i; | ||
| | ||
- | // Authenticate using key A | + | |
Serial.println(F("Authenticating using key A...")); | Serial.println(F("Authenticating using key A...")); | ||
status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid)); | status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_A, block, &key, &(mfrc522.uid)); | ||
Line 282: | Line 238: | ||
} | } | ||
| | ||
- | // Authenticate using key B | ||
Serial.println(F("Authenticating again using key B...")); | Serial.println(F("Authenticating again using key B...")); | ||
status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, block, &key, &(mfrc522.uid)); | status = (MFRC522::StatusCode) mfrc522.PCD_Authenticate(MFRC522::PICC_CMD_MF_AUTH_KEY_B, block, &key, &(mfrc522.uid)); | ||
Line 291: | Line 246: | ||
} | } | ||
| | ||
- | // Write data to the block | + | |
Serial.print(F("Writing data into block ")); | Serial.print(F("Writing data into block ")); | ||
Serial.print(block); | Serial.print(block); | ||
Line 309: | Line 264: | ||
} | } | ||
- | mfrc522.PICC_HaltA(); // Halt PICC | + | mfrc522.PICC_HaltA(); |
- | mfrc522.PCD_StopCrypto1(); // Stop encryption on PCD | + | mfrc522.PCD_StopCrypto1(); |
| | ||
Serial.println("1.Read card \n2.Write to card \n3.Copy the data."); | Serial.println("1.Read card \n2.Write to card \n3.Copy the data."); | ||
Line 316: | Line 271: | ||
} | } | ||
- | void keuze1(){ //Read card | + | void keuze1(){ |
Serial.println("Insert card..."); | Serial.println("Insert card..."); | ||
- | // Look for new cards | + | |
if ( ! mfrc522.PICC_IsNewCardPresent()) | if ( ! mfrc522.PICC_IsNewCardPresent()) | ||
return; | return; | ||
- | // Select one of the cards | + | |
if ( ! mfrc522.PICC_ReadCardSerial()) | if ( ! mfrc522.PICC_ReadCardSerial()) | ||
return; | return; | ||
- | // Show some details of the PICC (that is: the tag/card) | + | |
Serial.print(F("Card UID:")); | Serial.print(F("Card UID:")); | ||
dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); | dump_byte_array(mfrc522.uid.uidByte, mfrc522.uid.size); | ||
Line 334: | Line 289: | ||
Serial.println(mfrc522.PICC_GetTypeName(piccType)); | Serial.println(mfrc522.PICC_GetTypeName(piccType)); | ||
| | ||
- | // Try the known default keys | + | |
MFRC522::MIFARE_Key key; | MFRC522::MIFARE_Key key; | ||
for (byte k = 0; k < NR_KNOWN_KEYS; k++) { | for (byte k = 0; k < NR_KNOWN_KEYS; k++) { | ||
- | // Copy the known key into the MIFARE_Key structure | + | |
for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) { | for (byte i = 0; i < MFRC522::MF_KEY_SIZE; i++) { | ||
key.keyByte[i] = knownKeys[k][i]; | key.keyByte[i] = knownKeys[k][i]; | ||
} | } | ||
- | // Try the key | + | |
if (try_key(&key)) { | if (try_key(&key)) { | ||
- | // Found and reported on the key and block, | + | |
- | // no need to try other keys for this PICC | + | |
break; | break; | ||
} | } | ||
} | } | ||
} | } | ||
+ | |||
Line 424: | Line 379: | ||
<note tip> | <note tip> | ||
- | Care au fost rezultatele obţinute în urma realizării proiectului vostru. | + | In urma realizarii proiectului am reusit sa clonez cu usurinta cartele care functioneaza pe baza frecventelor radio</note> |
- | </note> | + | |
===== Concluzii ===== | ===== Concluzii ===== | ||
+ | A fost un proiect foarte fun si usor de realizat care are o aplicabilitate in domeniul securitatii cibernetice | ||
- | ===== Download ===== | ||
- | |||
- | <note warning> | ||
- | O arhivă (sau mai multe dacă este cazul) cu fişierele obţinute în urma realizării proiectului: surse, scheme, etc. Un fişier README, un ChangeLog, un script de compilare şi copiere automată pe uC crează întotdeauna o impresie bună ;-). | ||
- | |||
- | Fişierele se încarcă pe wiki folosind facilitatea **Add Images or other files**. Namespace-ul în care se încarcă fişierele este de tipul **:pm:prj20??:c?** sau **:pm:prj20??:c?:nume_student** (dacă este cazul). **Exemplu:** Dumitru Alin, 331CC -> **:pm:prj2009:cc:dumitru_alin**. | ||
- | </note> | ||
===== Jurnal ===== | ===== Jurnal ===== | ||
Line 446: | Line 394: | ||
<note> | <note> | ||
- | Listă cu documente, datasheet-uri, resurse Internet folosite, eventual grupate pe **Resurse Software** şi **Resurse Hardware**. | + | https://www.youtube.com/watch?v=VXx6l3vgBno&t=653s |
- | </note> | + | |
<html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> | <html><a class="media mediafile mf_pdf" href="?do=export_pdf">Export to PDF</a></html> |