mfoc安裝編譯
系統環境 UBUNTU16.04,要安裝好各種基礎的編譯環境,這就不說了,如果不知道需要什麼,那就編譯時出錯時看到什麼安裝什麼吧
下載原始碼包libnfc, mfoc, mfcuk,都是github上,原始碼都可以從https://github.com/nfc-tools中下面找到。
-
安裝依賴:
安裝前要稍看下README之類的,有的有依賴關係,比如,LIBNFC可能需要LIBUSB之類的,但不是必須的,根據你的硬體,如果是PN532使用UART,就需要下面的部分:
apt-get install libpcsclite-dev libusb-dev libusb-0.1-4 libpcsclite1 libccid pcscd
-
編譯安裝libnfc
進入到原始碼目錄下,需要autoreconf一下,這樣才會有INSTALL等檔案出現,而這又需要libtool開發工具,如果沒有就需要安裝下
[email protected]:~/nfc/libnfc-master$ sudo apt-get install libtool
安裝好後,執行autoreconf
[email protected]:~/nfc/libnfc-master$ autoreconf -is libtoolize: putting auxiliary files in `.'. libtoolize: linking file`./ltmain.sh' libtoolize: putting macros in AC_CONFIG_MACRO_DIR, `m4'. libtoolize: linking file `m4/libtool.m4' libtoolize: linking file `m4/ltoptions.m4' libtoolize: linking file `m4/ltsugar.m4' libtoolize: linking file `m4/ltversion.m4' libtoolize: linking file `m4/lt~obsolete.m4' configure.ac:27: installing './config.guess' configure.ac:27: installing './config.sub' [email protected]-host:~/nfc/libnfc-master$
有的時候,會出現MACRO錯誤的字樣,並提示版本不匹配aclocal功能版本的原因,刪除aclocal.m4後,安裝新版本,並執行aclocal重新生成即可,這裡沒有出現,就不演示了。
繼續配置,因為使用的是PN532 UART,所以按下面的配置並MAKE
[email protected]:~/nfc/libnfc-master$ ./configure --sysconfdir=/etc --prefix=/usr --with-drivers=pn532_uart
[email protected]:~/nfc/libnfc-master$ make
[email protected]:~/nfc/libnfc-master$ sudo make install
如果順得的話,就編譯完成了,已經完成了一半的工作,因為還需要配置,否則很大的機率是不能工作的,如下圖,反正我這裡是不能工作的,
[email protected]:~/nfc/libnfc-master$ sudo LIBNFC_LOG_LEVEL=3 nfc-list
info libnfc.config Unable to open file: /etc/nfc/libnfc.conf
debug libnfc.config Unable to open directory: /etc/nfc/devices.d
debug libnfc.general log_level is set to 3
debug libnfc.general allow_autoscan is set to true
debug libnfc.general allow_intrusive_scan is set to false
debug libnfc.general 0 device(s) defined by user
nfc-list uses libnfc 1.7.1
No NFC device found.
[email protected]:~/nfc/libnfc-master$
從上圖中,設定了LIBNFC_LOG_LEVEL=3後,發現/etc/nfc/libnfc.conf,/etc/nfc/devices.d都是不存在的。其實,GITHUB上首面就已經有相關的操作方法了
sudo mkdir /etc/nfc sudo cp libnfc.conf.sample /etc/nfc/libnfc.conf
第二個配置檔案官方給的例子是是
sudo mkdir -p /etc/nfc/devices.d printf 'name = "My first device"\nconnstring = "pn532_uart:/dev/ttyACM0"\n' | sudo tee /etc/nfc/devices.d/first.conf printf 'name = "My second device"\nconnstring = "pn532_uart:/dev/ttyACM1"\n' | sudo tee /etc/nfc/devices.d/second.conf
上面建立了兩個檔案,指出需要去檢測ttyACM0 ttyACM1兩個作為pn532來使用,而我的設定是ttyUSB0,可以連上硬體後,通過ls /dev 和 lsusb 等命令去確認你的是哪個裝置,所以我這裡ttyACM0改為了ttyUSB0,如下圖:
[email protected]:/etc/nfc/devices.d$ ls first.conf [email protected]-host:/etc/nfc/devices.d$ cat first.conf name = "My first device" connstring = "pn532_uart:/dev/ttyUSB0" [email protected]-host:/etc/nfc/devices.d$
繼續檢查
[email protected]:/etc/nfc/devices.d$ sudo nfc-list nfc-list uses libnfc 1.7.1 NFC device: My first device opened
-
編譯mfoc
這就容易多了,解壓後進入原始碼目錄,根據README.MD,執行下面的編譯過程退可
autoreconf -is ./configure make && sudo make install
在我的計算機上,直接成功完成
- 測試
在連好硬體後,執行mfoc命令
[email protected]:~/nfc/mfoc-master$ mfoc -O ~/home.dump error libnfc.driver.pn532_uart Invalid serial port: /dev/ttyUSB0 No NFC device found. [email protected]-host:~/nfc/mfoc-master$ sudo mfoc -O ~/home.dump Found Mifare Classic 1k tag ISO/IEC 14443A (106 kbps) target: ATQA (SENS_RES): 00 04 * UID size: single * bit frame anticollision supported UID (NFCID1): b5 4a cc 73 SAK (SEL_RES): 08 * Not compliant with ISO/IEC 14443-4 * Not compliant with ISO/IEC 18092 Fingerprinting based on MIFARE type Identification Procedure: * MIFARE Classic 1K * MIFARE Plus (4 Byte UID or 4 Byte RID) 2K, Security level 1 * SmartMX with MIFARE 1K emulation Other possible matches based on ATQA & SAK values: Try to authenticate to all sectors with default keys... Symbols: '.' no key found, '/' A key found, '\' B key found, 'x' both keys found [Key: ffffffffffff] -> [xxxxxxxxx..xx.xx] [Key: a0a1a2a3a4a5] -> [xxxxxxxxx..xx.xx] [Key: d3f7d3f7d3f7] -> [xxxxxxxxx..xx.xx] [Key: 000000000000] -> [xxxxxxxxx..xx.xx] [Key: b0b1b2b3b4b5] -> [xxxxxxxxx..xx.xx] [Key: 4d3a99c351dd] -> [xxxxxxxxx..xx.xx] [Key: 1a982c7e459a] -> [xxxxxxxxx..xx.xx] [Key: aabbccddeeff] -> [xxxxxxxxx..xx.xx] [Key: 714c5c886e97] -> [xxxxxxxxx..xx.xx] [Key: 587ee5f9350f] -> [xxxxxxxxx..xx.xx] [Key: a0478cc39091] -> [xxxxxxxxx..xx.xx] [Key: 533cb6c723f6] -> [xxxxxxxxx..xx.xx] [Key: 8fd0a4f256e9] -> [xxxxxxxxx..xx.xx] Sector 00 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 01 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 02 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 03 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 04 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 05 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 06 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 07 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 08 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 09 - Unknown Key A Unknown Key B Sector 10 - Unknown Key A Unknown Key B Sector 11 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 12 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 13 - Unknown Key A Unknown Key B Sector 14 - Found Key A: ffffffffffff Found Key B: ffffffffffff Sector 15 - Found Key A: ffffffffffff Found Key B: ffffffffffff Using sector 00 as an exploit sector Sector: 9, type A, probe 0, distance 32 ..... Found Key: A [474249433434] Data read with Key A revealed Key B: [474249433434] - checking Auth: OK Sector: 10, type A Data read with Key A revealed Key B: [474249433434] - checking Auth: OK Found Key: A [474249433434] Sector: 13, type A, probe 0, distance 32 ..... Found Key: A [112233445214] Data read with Key A revealed Key B: [57454942494e] - checking Auth: OK Auth with all sectors succeeded, dumping keys to a file! Block 63, type A, key ffffffffffff :00 00 00 00 00 00 ff 07 80 bc ff ff ff ff ff ff Block 62, type A, key ffffffffffff :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 ..........
.......... Block 02, type A, key ffffffffffff :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Block 01, type A, key ffffffffffff :00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 Block 00, type A, key ffffffffffff :b5 4a cc 73 40 08 04 00 62 63 64 65 66 67 68 69 [email protected]-host:~/nfc/mfoc-master$
以上說明命令執行完成,反過來說明PN532工作正常。
- 設定USB串列埠的許可權
目前為止,執行MFOC需要ROOT許可權,因為硬體裝置一般是不能隨便一個使用者就可以開啟的,這就需要改變USB-SERIAL的許可權。
這個問題實際上LIBNFC已經給出瞭解決的程式碼,在GITHUB的程式碼首頁上就已經有說明了,首先你曾閱讀了它。
[email protected]:~/nfc/libnfc-master$ sudo cp contrib/udev/93-pn53x.rules /lib/udev/rules.d/
然後,你再編輯/lib/udev/rules.d/93-pn53x.rules檔案中的裝置中的PID和VID即可。
不過,上面的方法是在編譯前設定的,現在再開始似乎不能生效-至少在我這裡是無效的。
只好使用另外的方法
printf 'SUBSYSTEMS=="usb", ATTRS{idVendor}=="067b", ATTRS{idProduct}=="2303", GROUP="users", MODE="0666"\n' | sudo tee /etc/udev/rules.d/50-myusb.rules
然後再生效
[email protected]:/lib/udev/rules.d$ sudo udevadm control --reload
重新插拔後,再檢視發現裝置已經任何使用者都可以讀寫了
[email protected]:/etc/udev/rules.d$ ls /dev/ttyU* -l crw-rw-rw- 1 root dialout 188, 0 11月 10 12:57 /dev/ttyUSB0
至此,配置完成
-
編譯安裝mfcuk
autoreconf -is ./configure make
sudo make install
沒有懸念地成功了