打造基于Zigbee的IoT漏洞安全試驗(yàn)環(huán)境
前言
目前,Zigbee已經(jīng)成為智能家居和醫(yī)療設(shè)備中最流行的物聯(lián)網(wǎng)無線電通信協(xié)議,本文將討論它的安全性以及相關(guān)的物聯(lián)網(wǎng)設(shè)備的利用技術(shù)。
Zigbee簡介
Zigbee是在智能家居設(shè)備和其他物聯(lián)網(wǎng)設(shè)備中最常見的通信協(xié)議之一。 由于Zigbee具備低功耗、網(wǎng)狀網(wǎng)絡(luò)和易用性的優(yōu)勢,所以日益成為制造商的首選。它是在IEEE 802.15.4的基礎(chǔ)之上,由Zigbee聯(lián)盟成員公司共同創(chuàng)建的一個(gè)開放協(xié)議,該聯(lián)盟成員包括TI、Silicon Labs、Philips等公司。Zigbee協(xié)議已經(jīng)進(jìn)行了多次迭代,當(dāng)前版本是Zigbee 3.0。
可能的攻擊
作為一種無線電通信協(xié)議,Zigbee同樣免不了受到標(biāo)準(zhǔn)無線電協(xié)議的漏洞的影響。在使用Zigbee進(jìn)行通信時(shí),可能發(fā)生的攻擊有:
1. 攻擊者能夠嗅探傳輸?shù)臄?shù)據(jù)
2. 捕獲傳輸?shù)臄?shù)據(jù)后重放數(shù)據(jù)包,從而執(zhí)行惡意動(dòng)作
3. 在初始通信期間嗅探加密密鑰
4. 修改捕獲的數(shù)據(jù)包,然后重放
5. 欺騙攻擊
6. 拒絕服務(wù)攻擊
本文只是一個(gè)入門指南,介紹如何搭設(shè)利用Zigbee漏洞的實(shí)驗(yàn)環(huán)境和有關(guān)的基礎(chǔ)知識(shí),在后續(xù)文章中,我們將在此基礎(chǔ)上進(jìn)一步介紹上述每種類型的安全漏洞的利用技術(shù)。
硬件要求
在繼續(xù)閱讀下文之前,請不要忘了,這里介紹的硬件只是探索Zigbee安全性的可能硬件組合之一。實(shí)際上,有各種其他類型的硬件可資使用,例如我們既可以使用Zigbee開發(fā)套件,也可以使用商業(yè)IoT設(shè)備發(fā)射Zigbee信號(hào)等。
下面是一個(gè)供我們?nèi)腴T的簡單配置:
1. Arduino Uno/Nano
2. DigiKey Xbee module / Arduino Xbee shield
3. Atmel RzRaven USB stick
4. Attify Badge
Arduino:Arduino已經(jīng)在各種類型的電子項(xiàng)目中廣為普及了。實(shí)際上,你很可能已經(jīng)在大學(xué)或高中階段早就用過它了。Nano是體積最小的Arduino nano,但是對于本文的用途來說,它的功能已經(jīng)足夠了。
DigiKey Xbee module / Xbee Shield :為了學(xué)習(xí)Zigbee,你需要一些可以發(fā)送和接收Zigbee信號(hào)的東西。 Xbee是一種全雙工收發(fā)器,能夠使用Zigbee標(biāo)準(zhǔn)協(xié)議與其他Xbee模塊進(jìn)行無線通信。
Atmel RzRaven USB Stick:這是半雙工模塊,它能執(zhí)行嗅探,并且可以將捕獲的Zigbee數(shù)據(jù)包進(jìn)行相應(yīng)的修改后再次傳輸。如果你熟悉其他類型的無線電利用技術(shù)的話,可以將其視為“用于Zigbee的HackRF”。
Attify Badge:您可以將其插到系統(tǒng)上,然后使用它和XCTU對Xbee模塊進(jìn)行編程。之所以這么做,是因?yàn)閄bee通常沒有miniUSB或類似的端口,所以無法直接插入進(jìn)行編程。如果您沒有Attify Badge或類似的硬件,可以通過亞馬遜或您當(dāng)?shù)氐纳痰曩徺I一個(gè)用于Xbee的迷你USB套件,比如類似于頁面https://www.sparkfun.com/products/11812中這樣的套件。
用于Xbee的MiniUSB電路板
或者,你也可以通過郵件(secure@attify.com)方式購買 Attify BadgeAttify Badge。
利用Attify攻擊物聯(lián)網(wǎng)嵌入式設(shè)備
對于編程和硬件連接來說,使用它是最簡單的方案,只需要連接下列引腳:power => power,Gnd => Gnd,Tx到Rx,Rx到Tx。如果需要的話,您可以進(jìn)一步參考Xbee模塊相應(yīng)版本的說明書。
對Arduino和Xbee進(jìn)行編程
對Arduino進(jìn)行編程
要想對Arduino進(jìn)行編程,只需從https://www.arduino.cc/en/Main/Software下載使用Arduino IDE即可。加載后,可以從Attify的github庫中逐一打開每個(gè)Arduino的Hub和Node程序。
代碼本身提供了詳細(xì)的內(nèi)聯(lián)注釋,你可以通過注釋來了解代碼的含義。另外,提供的代碼示例還可以通過傳感器和DHT庫來獲取溫度、濕度和光照值。它非常適合用于進(jìn)行完整的分析,以及通過傳輸一個(gè)硬編碼字符串進(jìn)行攻擊,而不是使用DHT值。此外,如果你想原封不動(dòng)地使用這些代碼的話,則需要購買DHT11和所需的其他附屬設(shè)備。
所需工具
Arduino * 1 https://www.sparkfun.com/products/11021
DHT 11 * 1 https://www.adafruit.com/product/386
XBee S1模塊(S2模塊需要不同的配置)* 2 LDR / Photocell * 1 https://www.sparkfun.com/products/9088
BC547 * 1 https://www.sparkfun.com/products/8928
LED *任意數(shù)量https://www.sparkfun.com/products/10635
跳線https://www.sparkfun.com/products/13870
面包板https://www.sparkfun.com/products/12046
Xbee shield * 2 https://www.sparkfun.com/products/128
電路圖
下面是我們的入門套件配置的電路圖。
Node電路圖:
Node電路圖
Hub電路圖:
Hub電路圖
Node代碼:
- // Offensive IoT Exploitation by Attify
- // www.attify.com | www.offensiveiotexploitation.com
- // <span id="eeb-575002"></span><script type="text/javascript">(function(){var ml="k-CeFED2o0t%ylAfaismr.4ch3un",mi=";I2@;79HD3?;I6;77C@A=:8;I>B3GJD3;F9@::A?<EG8C;77;79;79G=@BB;I6;77C@A=:81=AK0;77;I5B3GJD3;F9@::A?<EG8C;I2;74@;I5",o="";for(var j=0,l=mi.length;j<l;j++){o+=ml.charAt(mi.charCodeAt(j)-48);}document.getElementById("eeb-575002").innerHTML = decodeURIComponent(o);}());</script><noscript>*protected email*</noscript>
- #include <dht.h> //Library for DHT11 Humidity
- #define dht_dpin A0 // DTH11 Data pin connected to AO of arduino
- #define led 2 // Led connected to Pin D2
- #define ldr A1 // LDR connected to Pin A1
- dht DHT; // Creating DHT function
- void setup() {
- // initialize serial:
- Serial.begin(2400); // Initiliaze Hardware serial for xbee
- pinMode(2, OUTPUT); // Pin direction of LED to Output as it sends current
- }
- void loop() { // Continous loop
- // if there's any serial available, read it:
- DHT.read11(dht_dpin); // Reading DHT11 using the library
- int lig = analogRead(ldr); // Reading analog values from LDR
- int ligp = map(lig, 0, 1023, 0, 100); // Mapping the 10bit resolution ADC to 0 to 100
- int h = DHT.humidity; // Humidity value
- int t = DHT.temperature; // Temperature value
- while (Serial.available() > 0) { // Checking for any data on Xbee
- int red = Serial.parseInt(); // look for the next valid integer in the incoming serial stream
- if (Serial.read() == '!') // Check if the next Serial data is '!'
- {
- if(red == 1) // if the recieved data is 1!
- {
- Serial.print(h,DEC); // Send humidity value with '!'
- Serial.print("!");
- }
- else
- if(red == 2) // if the recieved data is 2!
- {
- Serial.print(t,DEC); // Send Temperature value with '!'
- Serial.print("!");
- }
- else
- if(red == 3) // if the recieved data is 3!
- {
- Serial.print(ligp,DEC); // Send Light value with '!'
- Serial.print("!");
- }
- else
- if(red == 4) // if the recieved data is 4!
- {
- digitalWrite(2, HIGH); // Turn ON the LED
- delay(100);
- }
- else if(red == 5) // if the recieved data is 5!
- {
- digitalWrite(2, LOW); //Turn OFF the LEd
- delay(100);
- Serial.print("!attify!"); // Send the AES key
- }
- }
- }
- }
Hub代碼:
- // Offensive IoT Exploitation by Attify
- // www.attify.com | www.offensiveiotexploitation.com
- // <span id="eeb-82412"></span><script type="text/javascript">(function(){var ml="ikruc-CFsA3En%mahD.2l04oyfte",mi="=:6?=CE@2KI=:A=CC>?0DJG=:98K432K=FE?JJ0IHB4G>=CC=CE=CE4D?88=:A=CC>?0DJG5D0<1=CC=:;8K432K=FE?JJ0IHB4G>=:6=C7?=:;",o="";for(var j=0,l=mi.length;j<l;j++){o+=ml.charAt(mi.charCodeAt(j)-48);}document.getElementById("eeb-82412").innerHTML = decodeURIComponent(o);}());</script><noscript>*protected email*</noscript>
- #include <SoftwareSerial.h> // Software based UART port to use Zigbee module
- int a = 1;
- float hum = 0, temp = 0; // Float Variable to store Temperature and Humidity
- SoftwareSerial xbee(3, 2); // RX, TX
- void setup() //One time preloading function
- {
- Serial.begin(9600); // Hardware Serial initialization to be connected to a bluetooth module or PC
- xbee.begin(2400); // Software Serial initialization at 2400 Baud rate to communicate with zigbee
- }
- void loop() // Continous loop
- {
- xbee.print(a); // Sends (a) with "!" to Xbee -> "1!" Requests temperature data and vice versa
- xbee.println("!");
- while(xbee.available() > 0) //Checks is any data has been recieved from zigbee.
- {
- char aChar = xbee.read(); //reading the value from the Xbee serial port
- if(aChar == 33) //If the first character is 33 ie) ! in ASCII
- {
- xbee.flush(); // Clear the buffer and
- aChar = NULL;
- }
- if(aChar >= 100) // If it is more than 100 or random ASCII character flush the data
- {
- xbee.flush();
- aChar = NULL;
- }
- Serial.print(aChar); //Printing the Read value
- }
- if(a == 3) // if a = 3 create new line or end of one set of data transmission
- {
- Serial.println(); //New line print
- }
- else
- {
- Serial.print(","); // if a not 3 then add ","
- }
- if(a> 3) // after a > 3 print the AES encryted data to xbee
- {
- a =1; // initialize a = 1 back
- xbee.print("!f+F8YW+9W3+Cg0S1NVBexycQxz32biWTmzVsxO48+fk=!");
- }
- delay(100); // Wait for few ms for this to happen
- xbee.flush(); // flush any data in Xbee serial port
- a=a+1; //Increment data
- if(Serial.available()); // Check if any data is sent from Hardware serial port
- {
- int r = Serial.parseInt(); // Recieving any integer data
- if(r== 1) // if recieved data is 1. Send 4! which turns the LED on the Node.
- {
- xbee.print(4);
- xbee.print("!");
- delay(100);
- }
- if(r== 2)// if recieved data is 2. Send 5! which turns the LED off the Node.
- {
- xbee.print(5);
- xbee.print("!");
- }
- }
- }
一旦完成了這兩個(gè)Arduino的編程工作,下一步就是使用XCTU來配置Xbees。
對Xbee進(jìn)行編程
啟動(dòng)XCTU并單擊Discover Radio模塊,這時(shí)將顯示已插入設(shè)備的可用COM端口的列表。然后,選擇與Xbee模塊對應(yīng)的COM端口(如果您不太確定,就全部選上)。
其他配置總是8N1、8個(gè)數(shù)據(jù)位、無奇偶校驗(yàn)位和1個(gè)停止位。 此外,您還需要為給定的Xbee模塊指定波特率。 如果您不知道模塊使用的波特率,您可以給模塊選擇所有波特率,XCTU將掃描所有波特率并為您找到正確的波特率。
結(jié)束模塊的搜索后,點(diǎn)擊Finish,它就能識(shí)別出該設(shè)備。 單擊Add the Device。
利用XCTU識(shí)別出的設(shè)備
在這一步中,您將看到設(shè)備的各種屬性,例如信道名稱和PAN ID,這兩個(gè)屬性對于我們來說非常重要。在Zigbee中,每個(gè)頻帶總共有16個(gè)信道,每個(gè)信道間隔5MHz,2MHz的帶寬用于無噪聲數(shù)據(jù)傳輸。我們可以從http://www.digi.com/wiki/developer/index.php/Channels,_Zigbee找到所有Zigbee通道的清單。 Zigbee網(wǎng)絡(luò)的PAN ID是唯一的標(biāo)識(shí)符,其對于該網(wǎng)絡(luò)上的所有設(shè)備都是相同的。我們可以將信道名稱和PAN ID配置為任何特定的值,只需要確保其他Xbee也使用相同的信道名稱和PAN ID即可。
XCTU中顯示的Xbee屬性
后記
到此為止,我們一家搭建好了Zigbee的漏洞實(shí)驗(yàn)環(huán)境。在將來的Zigbee安全文章中,我們將在這個(gè)實(shí)驗(yàn)平臺(tái)上面介紹各種利用技術(shù),包括控制商業(yè)設(shè)備發(fā)射Zigbee信號(hào)等。