打造基于Zigbee的IoT漏洞安全試驗環境
前言
目前,Zigbee已經成為智能家居和醫療設備中最流行的物聯網無線電通信協議,本文將討論它的安全性以及相關的物聯網設備的利用技術。
Zigbee簡介
Zigbee是在智能家居設備和其他物聯網設備中最常見的通信協議之一。 由于Zigbee具備低功耗、網狀網絡和易用性的優勢,所以日益成為制造商的首選。它是在IEEE 802.15.4的基礎之上,由Zigbee聯盟成員公司共同創建的一個開放協議,該聯盟成員包括TI、Silicon Labs、Philips等公司。Zigbee協議已經進行了多次迭代,當前版本是Zigbee 3.0。
可能的攻擊
作為一種無線電通信協議,Zigbee同樣免不了受到標準無線電協議的漏洞的影響。在使用Zigbee進行通信時,可能發生的攻擊有:
1. 攻擊者能夠嗅探傳輸的數據
2. 捕獲傳輸的數據后重放數據包,從而執行惡意動作
3. 在初始通信期間嗅探加密密鑰
4. 修改捕獲的數據包,然后重放
5. 欺騙攻擊
6. 拒絕服務攻擊
本文只是一個入門指南,介紹如何搭設利用Zigbee漏洞的實驗環境和有關的基礎知識,在后續文章中,我們將在此基礎上進一步介紹上述每種類型的安全漏洞的利用技術。
硬件要求
在繼續閱讀下文之前,請不要忘了,這里介紹的硬件只是探索Zigbee安全性的可能硬件組合之一。實際上,有各種其他類型的硬件可資使用,例如我們既可以使用Zigbee開發套件,也可以使用商業IoT設備發射Zigbee信號等。
下面是一個供我們入門的簡單配置:
1. Arduino Uno/Nano
2. DigiKey Xbee module / Arduino Xbee shield
3. Atmel RzRaven USB stick
4. Attify Badge
Arduino:Arduino已經在各種類型的電子項目中廣為普及了。實際上,你很可能已經在大學或高中階段早就用過它了。Nano是體積最小的Arduino nano,但是對于本文的用途來說,它的功能已經足夠了。
DigiKey Xbee module / Xbee Shield :為了學習Zigbee,你需要一些可以發送和接收Zigbee信號的東西。 Xbee是一種全雙工收發器,能夠使用Zigbee標準協議與其他Xbee模塊進行無線通信。
Atmel RzRaven USB Stick:這是半雙工模塊,它能執行嗅探,并且可以將捕獲的Zigbee數據包進行相應的修改后再次傳輸。如果你熟悉其他類型的無線電利用技術的話,可以將其視為“用于Zigbee的HackRF”。
Attify Badge:您可以將其插到系統上,然后使用它和XCTU對Xbee模塊進行編程。之所以這么做,是因為Xbee通常沒有miniUSB或類似的端口,所以無法直接插入進行編程。如果您沒有Attify Badge或類似的硬件,可以通過亞馬遜或您當地的商店購買一個用于Xbee的迷你USB套件,比如類似于頁面https://www.sparkfun.com/products/11812中這樣的套件。
用于Xbee的MiniUSB電路板
或者,你也可以通過郵件(secure@attify.com)方式購買 Attify BadgeAttify Badge。
利用Attify攻擊物聯網嵌入式設備
對于編程和硬件連接來說,使用它是最簡單的方案,只需要連接下列引腳:power => power,Gnd => Gnd,Tx到Rx,Rx到Tx。如果需要的話,您可以進一步參考Xbee模塊相應版本的說明書。
對Arduino和Xbee進行編程
對Arduino進行編程
要想對Arduino進行編程,只需從https://www.arduino.cc/en/Main/Software下載使用Arduino IDE即可。加載后,可以從Attify的github庫中逐一打開每個Arduino的Hub和Node程序。
代碼本身提供了詳細的內聯注釋,你可以通過注釋來了解代碼的含義。另外,提供的代碼示例還可以通過傳感器和DHT庫來獲取溫度、濕度和光照值。它非常適合用于進行完整的分析,以及通過傳輸一個硬編碼字符串進行攻擊,而不是使用DHT值。此外,如果你想原封不動地使用這些代碼的話,則需要購買DHT11和所需的其他附屬設備。
所需工具
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 *任意數量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("!");
- }
- }
- }
一旦完成了這兩個Arduino的編程工作,下一步就是使用XCTU來配置Xbees。
對Xbee進行編程
啟動XCTU并單擊Discover Radio模塊,這時將顯示已插入設備的可用COM端口的列表。然后,選擇與Xbee模塊對應的COM端口(如果您不太確定,就全部選上)。
其他配置總是8N1、8個數據位、無奇偶校驗位和1個停止位。 此外,您還需要為給定的Xbee模塊指定波特率。 如果您不知道模塊使用的波特率,您可以給模塊選擇所有波特率,XCTU將掃描所有波特率并為您找到正確的波特率。
結束模塊的搜索后,點擊Finish,它就能識別出該設備。 單擊Add the Device。
利用XCTU識別出的設備
在這一步中,您將看到設備的各種屬性,例如信道名稱和PAN ID,這兩個屬性對于我們來說非常重要。在Zigbee中,每個頻帶總共有16個信道,每個信道間隔5MHz,2MHz的帶寬用于無噪聲數據傳輸。我們可以從http://www.digi.com/wiki/developer/index.php/Channels,_Zigbee找到所有Zigbee通道的清單。 Zigbee網絡的PAN ID是唯一的標識符,其對于該網絡上的所有設備都是相同的。我們可以將信道名稱和PAN ID配置為任何特定的值,只需要確保其他Xbee也使用相同的信道名稱和PAN ID即可。
XCTU中顯示的Xbee屬性
后記
到此為止,我們一家搭建好了Zigbee的漏洞實驗環境。在將來的Zigbee安全文章中,我們將在這個實驗平臺上面介紹各種利用技術,包括控制商業設備發射Zigbee信號等。