قالب وردپرس درنا توس
Home / Tips and Tricks / How to Program a $ 6 NodeMCU to Discover Wi-Fi Jamming Attacks in the Arduino IDE «Null Byte :: WonderHowTo

How to Program a $ 6 NodeMCU to Discover Wi-Fi Jamming Attacks in the Arduino IDE «Null Byte :: WonderHowTo



Hackers and manufacturers are often grouped under the same label. While hackers rely on computer literacy to write programs and find bugs, manufacturers use electrical engineering to create hardware prototypes from microprocessor boards such as the Arduino. We both practice abilities to program a $ 6 NodeMCU to indicate the status of a Wi-Fi connection via an LED so that we can monitor for jamming attacks.

While it's easy to launch attacks against Wi-Fi Most attacks are relatively simple. Under normal circumstances, IoT devices can easily connect to a Wi-Fi network and perform useful functions. During a jamming attack, devices such as smart speakers or connected Wi-Fi cameras are the most vulnerable because they do not have a backup Ethernet connection.

To detect such attacks, we can use a low-cost IoT device such as a NodeMCU, a "canary in a coal mine," to warn us when the connection to a particular Wi-Fi network becomes impossible. Instead of looking for upstream connectivity, we program a simple detector that attempts to connect to a monitored Wi-Fi network and change an LED indicator to tell us whether a standard connection is not possible.

Designing the Detector [19659005] The first step in our project is to decide what our hardware prototype should do. Because most Wi-Fi related attacks abuse management frames to make a standard connection impossible, we can test the overall capability of devices by checking the Wi-Fi link of an IoT device. To keep things simple on our first project, we will create a link monitor focused on checking the ability of a Wi-Fi device to maintain a normal connection to a network. If this is not possible, we generate a warning message to warn you that there is a problem with the network.

Since we are not trying to establish and verify a network connection, there are some limitations to this tactic. First, we will not be alerted (or receive false positives) if the router is unable to connect to the Internet, but the Wi-Fi connection between the router and the detector is OK. Secondly, we are not looking for the telltale signs of deauthentication and dissociation frames; As we discuss this in a future build, the design we're going to do is going to be simpler and will also be triggered by more subtle jamming attacks.

Of course, if an attacker filters his jamming attacks to attack only other devices on the network and leaves the "canary" alone, then the detector always has a valid Wi-Fi connection and continues to signal that the connection is okay even if other devices can not connect.

In a future build, we will create a Deauthentication and Dissociation packet detector that is capable of detecting frequent Deauth attacks in the environment. For the moment, we will begin our journey as a manufacturer with a simpler design to understand how IoT programming works. We start with a look at the underlying hardware.

The ESP8266 Chip

The ESP8266 Wi-Fi radio chip is known among manufacturers for its intriguing combination of relatively high-performance, hackable hardware and a low price. Makers began noticing and documenting this chip, eventually allowing the ESP8266 to support the Arduino IDE. Simple Arduino-like devices that use this Wi-Fi radio can be easily programmed to do anything a manufacturer can imagine with Wi-Fi. Out of this chip have emerged some popular types of firmware, including the NodeMCU and the Arduino ESP8266 core.

The NodeMCU

An Arduino-like device that has become popular among manufacturers developing prototypes is the NodeMCU devkit 1.0. This cheap board, which I've seen somewhere between $ 5 and $ 9 apiece, is based on the ESP8266. It can be programmed in a variety of well-documented languages ​​such as Arduino, Lua and MicroPython, so virtually anyone can start creating Wi-Fi-connected IoT devices that use a breadboard and any number of other electronics to control WIRELESS INTERNET ACCESS. By simply connecting a NodeMCU to a breadboard, a beginner can learn how to control and flash LED lights of different color combinations in just a few minutes.

Get It on Amazon: ESP8266 NodeMCU CP2102 Wi-Fi Internet Development Board Wireless Module

When a programmer writes his first program, it is common practice to write "Hello World" as the first output. In the maker community, the appropriate right of transition is to flash an LED. For our prototype we need the NodeMCU to tell us if it is no longer able to connect normally, which means we need an indicator that lets us know if there are connectivity issues. For this we can use the onboard LED on the NodeMCU, which is blue and turns on and off. Alternatively, we could use a tri-color RGB LED to give us some more options for our warning display.

In this guide, we'll use a four-pin RGB LED to blink blue if you're trying to find a connection in green if the connection is normal and red if the connection is disrupted or the network is degraded.

Parts Needed for This Manual

I have already stated the parts needed for this manual, but to make it super clear, here is what I used in the end:

Step 1: Setting Up the Arduino IDE

There are several languages ​​in which you can program a NodeMCU, and depending on your background, you can use what you're most comfortable with. In this guide, we will use the free and cross-platform Arduino IDE, which allows us to quickly prototype what we need. Arduino IDE (the IDE stands for "integrated development environment") enables fast writing and uploading of scripts to Arduino-like microcontroller devices.

You can download the Arduino IDE from the official website. Once you have downloaded and installed it, you will need to click on the "Arduino" drop-down menu and then select "Preferences" from the displayed menu.

In the following Settings menu, paste the following URL into the Additional Board Manager URLs box. Once this is done, click "OK" to close the menu.

  http://arduino.esp8266.com/stable/package_esp8266com_index.json 

Step 2: Configure the Arduino IDE for the ESP8266

Next, you must submit the NodeMCU to the Boards Manager Add. To do this, you need to click on "Tools" and then hover over the "Board" area to see the drop-down list of supported boards. Click on "Boards Manager" above to open the window where you can add more boards.

When the Boards Manager window pops up, type "esp8266" in the search bar. Select "esp8266" from "ESP8266 Community" and install it to add support for the NodeMCU to your Arduino IDE.

Ready, you should be ready to program your NodeMCU. Plug your breadboard to your computer where the NodeMCU should already be connected. If you click on "Tools", you should see the correct port automatically selected. Select the "NodeMCU 1.0" as shown in the picture below. If you use a faulty cable, the port may not be displayed. If you do not see anything after completing the other steps, try another cable first.

There are two main keys at the top. One compiles and checks our code for errors before uploading, and the second icon, which looks like an arrow, pushes the code to the NodeMCU.

Step 3: Cabling the NodeMCU with an LED

Our first challenge is to get the NodeMCU to flash a particular color when we say it, and allow us to use an RGB LED to check the status of to display something we can not see – the Wi-Fi connection. Let's write a code to flash an LED!

The type of RGB LED we use is very easy to control. We have a ground pin that is longer than the other pins, and then a pin for each color, red, green, and blue.

If you look at the top of the NodeMCU, you will notice that the pins are labeled. The D0 to D8 pins can be programmed to drive an LED, while the GND (ground) pin connects the ground pin of the LED, the circuit close and light up the LED. We will connect the RGB LED next to the GND D5 D6 and D7 pins at the NodeMCU, with the longer pin with the position GND connected. We need to assign each pin to a color, so in our program, if we tell a pin that it's turned on, it will turn that particular color on.

To understand how a breadboard is used to connect pins, take a look at this image of the back of a full-sized breadboard. Here you can see that the rows are connected in the middle, while the columns at each edge are connected to apply current and ground.

Step 4: Write a Simple Program for the NodeMCU

To test the connections and set up our colors, we use a basic program to flash the LED colors. You can see the following code:

  int highTime = 1000, lowTime = 100; // First we define how long the light should be on (highTime) and how long the light should be off (lowTime) per blink in milliseconds (1000 = 1 sec)

void red () {// Next we create a function for the color red. You can test or replace it after testing. For now, we will map pin D5 to our function "red"
digitalWrite (D5, HIGH), Delay (HighTime), DigitalWrite (D5, LOW), Delay (LowTime);
}
void green () {// We will repeat this process for the color green. As an annotation, these are "void" functions because, unlike normal functions, they do not return data, just do something.
digitalWrite (D6, HIGH), Delay (HighTime), DigitalWrite (D6, LOW), Delay (LowTime);
}
void blue () {// Finally, we also create a function for the color blue.
digitalWrite (D7, HIGH), Delay (HighTime), DigitalWrite (D7, LOW), Delay (LowTime);
}
void setup () {// This is set up first for our program and runs only once. In this step we will tune the pins.
Pin mode (D5, OUTPUT), pin mode (D6, OUTPUT), pin mode (D7, OUTPUT); // Here we turn on pins D5, D6 and D7 for output.
}

void loop () {// This loop will be executed again and again.
red green blue (); // Here we call our red (), green () and blue () functions in turn to test our flashing LEDs.
Delay (100); // The last thing we do is add a delay to make a break between flashing our lights in milliseconds.
} 

Let's break that down to understand what it does.

There are a few main elements in a basic Arduino program. First, we have variables and libraries that we record; This will control the resulting code by allowing us to change how long the LEDs will flash.

We begin by creating two variables to determine how long a blink should be by defining how long to turn it on and off each time we turn it on. We create the variable highTime to store how long the LED stays on in milliseconds and lowTime how long the LED should stay off per flashing.

  int highTime = 1000, lowTime = 100; // First we define how long the light should be switched on (highTime) and how long the light should be switched off (lowTime) per blink in milliseconds (1000 = 1 sec) 

Next we create and define three functions call every time we want the LED to flash a particular color. These must be "empty" functions, because unlike a regular function that returns data, these functions do something without providing a result.

To flash the red LED, we create a red () function, and then inside the curly braces, use the built-in function digitalWrite () to exclude a pin and turn it back on.

To use the digitalWrite () function, you must insert the pin you want to call and the power setting to change the pin between brackets. If I want to power D5 I enter digitalWrite (D5, HIGH) and turn off the same pin, digitalWrite (D5, LOW) ; This would enable and disable the D5 color LED pin.

With this logic, we can use the following code to assign each color function to the correct pin so that the call of the function is first turned on and then reversed from the LED color associated with that pin. If your colors do not match the PIN number for the first time, you can change the PIN numbers in your code the way you wired them.

  void red () {// Next we create a function for the color red. You can test or replace them after testing. For now, we will map pin D5 to our function "red"
digitalWrite (D5, HIGH), Delay (HighTime), DigitalWrite (D5, LOW), Delay (LowTime);
}
void green () {// We will repeat this process for the color green. As an annotation, these are "void" functions because, unlike normal functions, they do not return data, just do something.
digitalWrite (D6, HIGH), Delay (HighTime), DigitalWrite (D6, LOW), Delay (LowTime);
}
void blue () {// Finally, we also create a function for the color blue.
digitalWrite (D7, HIGH), Delay (HighTime), DigitalWrite (D7, LOW), Delay (LowTime);
} 

Next we need to address the part of the program that runs only once and has the function called setup ; This is mandatory in Arduino programs. In ours we will use the built-in function pinMode (pin, mode) to activate the pins we will use to tell the function which pin to call and which mode to set on it. To set the pins D5 D6 and D7 to OUTPUT we use the following code.

  void setup () {
Pin mode (D5, OUTPUT), pin mode (D6, OUTPUT), pin mode (D7, OUTPUT);
} 

Finally we have the section loop ; That will always work. In this section, we'll call each of the color functions we've written and then add a delay in milliseconds at the end of each cycle. This should cause NodeMCU to light up every color in the LED in turn.

  void loop () {
red green blue ();
Delay (100);
} 

Step 5: Flash the Simple Program for NodeMCU

Now we are ready to test! Connect your NodeMCU to your computer via a micro USB cable if you have not already done so, and make sure the pins of the LED are connected to the GRD D5 D6 and D7 Pins on the breadboard

Copy the script and paste it into an empty Arduino IDE sketch at the beginning of step 4 and click the "Upload" button at the top left that looks like one Arrow out, and the program will write to the NodeMCU, as shown below.

After the Program is Completely Loaded NodeMCU should turn on and start flashing through the three colors in sequence, where you programmed them.

If you want to download my script to flash the lights directly, you can run the following command to it Download from my GitHub repository. You can open the .INO file in the resulting folder in the Arduino IDE to see the code.

  git clone https://gitlab.com/skickar/NodeMCUWiFiLinkMonitor.git
cd NodeMCUWiFiLinkMonitor
ls 

Step 6: Write the Wi-Fi Check Code

If the indicator light test has worked, you can proceed with our short code. We need to add a few more variables at the beginning for the Wi-Fi monitor to work. We use the LED color functions to display three states:

In the first condition, the NodeMCU can never connect to the access point (AP). This means that the password is incorrect, the AP may not be active or something is wrong with the SSID and password. We will make the light blue in this state to warn us that the code may need to be corrected.

To do that, we create a variable called "connectSuccess" and set the value to zero. This variable will keep track of whether we can connect to the destination network. Once the value of connectSuccess is above zero, we can tell our program that instead of the blue LED, the red LED flashes if the connection does not inform us that a previously possible connection is blocked or otherwise unavailable

To begin, we need to add the library "ESP8266WiFi.h" to connect the Wi-Fi card to our previous code. After that, we need to create a variable containing the SSID and password for the network you want to join. We create a variable to store the current Wi-Fi state each time we loop, and then add our connectSuccess variable set to zero.

  const char * ssid = "Control"; // Next, we'll set the name of the network to be monitored.
const char * password = "testytest"; // Then we enter the password of the network to be monitored.
int wifi status; // Here we create a variable to check the status of the Wi-Fi connection.
int connectSuccess = 0, HighTime = 100, Lowtime = 100; // And now we're setting a variable to count how many times we've successfully connected and how long the LED stays on and off.

void red () {// Here we will map a function called "red" to the right pin, which illuminates the red LED for the time we have defined in hightTime for the duration of the lighting and LowTime for the duration every time we light a red LED.
digitalWrite (D5, HIGH), Delay (highTime), digitalWrite (D5, LOW), Delay (Lowtime); // We assign the red function to the D5 pin so that every time we call red (), the voltage on the D5 pin pulses.
}
void green () {// We do the same with green by assigning the D6 pin to the green () function.
digitalWrite (D6, HIGH), delay (highTime), digitalWrite (D6, LOW), delay (lowtime);
}
void blue () {// Finally, we do the same with blue by mapping it to the D7 pin.
digitalWrite (D7, HIGH), delay (highTime), digitalWrite (D7, LOW), delay (lowtime);
} 

Now, in the Setup loop, we call WiFi.begin (SSID, password) to connect to the wireless network. We will add everything that was in our LED program as well.

  void setup () {// The setup function will run only once when the device starts up.
Pin mode (D5, OUTPUT), pin mode (D6, OUTPUT), pin mode (D7, OUTPUT); // In this case, we enable pins D5, D6, and D7 for the output mode.
WiFi.begin (SSID, password); // The last part of the setup we're going to write is to start the Wi-Fi connection process.
} 

Next we add a new logic to the function loop () .

First we check the Wi-Fi status and write the result into the variable we called wifiStatus . Next, we check that we have successfully connected by checking that the value of connectSuccess is greater than zero. If the value is still zero, we will flash the blue LED by calling the blue () function to tell the user that we still need to make a successful connection to the target AP.

Next we will check if the value of wifiStatus is equal WL_CONNECTED . If so, we turn on the green LED with the function green () and increase the value of the counter variable connectSuccess by one by using connectSuccess ++ . Now, if the connection fails, the red LED is activated instead of the blue LED, because the value of connectSuccess is greater than zero.

If the value of wifiStatus is anything other than WL_CONNECTED and the value of connectSuccess is not null, we will turn on the red LED by using the Call function red () . After we finish the logic, we can add one last command to create a 1 second delay between each check of Wi-Fi status.

  void loop () {// This loop will run repeatedly, unlike the setup function, which runs only once.
wifiStatus = WiFi.status (); // First we check the status of the Wi-Fi connection and save the result in the wifiStatus variable we created.
if (connectSuccess == 0) {blue ();} // If the device is not connected and has never been successfully connected, the blue light flashes. This could mean that the network does not exist, is out of range, or you have entered the SSID or password incorrectly.
if (wifiStatus == WL_CONNECTED) {green (), connectSuccess ++;} // When the device is connected, flash the green light and add one to count the variable "connectSuccess". In this way we will make the red light blink when we lose the connection.
otherwise if (connectSuccess! = 0) {red (); } // If the connection is not active, but we were able to connect before, the red LED flashes. This means that the AP is off, a jamming attack is in progress, or a normal connection is impossible.
Delay (1000); // Set a delay of one second per cycle to check the status of the connection.
} 

Our final code will look like the following example.

  // SIMPLE WI-FI LINK MONITOR FROM SKICKAR - Based on Henry's Bench Wi-Fi Link Checker
// This project aims to connect an ioT device to a Wi-Fi network and monitor the ability to establish a normal wireless connection.
// The project uses only three components - a node MCU, a breadboard, and an RGB LED.
#include  // First we'll add the libraries we need to make this work on the ESP8266

const char * ssid = "control"; // Next, we'll set the name of the network to be monitored.
const char * password = "testytest"; // Then we enter the password of the network to be monitored.
int wifi status; // Here we create a variable to check the status of the Wi-Fi connection.
int connectSuccess = 0, HighTime = 100, Lowtime = 100; // And now we're setting a variable to count how many times we've successfully connected and how long the LED stays on and off.

void red () {// Here we will map a function called "red" to the right pin, which illuminates the red LED for the time we have defined in hightTime for the duration of the lighting and LowTime for the duration every time we light a red LED.
digitalWrite (D5, HIGH), Delay (highTime), digitalWrite (D5, LOW), Delay (Lowtime); // We assign the red function to the D5 pin so that every time we call red (), the voltage on the D5 pin pulses.
}
void green () {// We do the same with green by assigning the D6 pin to the green () function.
digitalWrite (D6, HIGH), delay (highTime), digitalWrite (D6, LOW), delay (lowtime);
}
void blue () {// Finally, we do the same with blue by mapping it to the D7 pin.
digitalWrite (D7, HIGH), delay (highTime), digitalWrite (D7, LOW), delay (lowtime);
}
void setup () {// The setup function only runs once when the unit starts up.
Pin mode (D5, OUTPUT), pin mode (D6, OUTPUT), pin mode (D7, OUTPUT); // In this case, we enable pins D5, D6, and D7 for the output mode.
WiFi.begin (SSID, password); // The last part of the setup we're going to write is to start the Wi-Fi connection process.
}

void loop () {// This loop will run repeatedly, unlike the setup function, which runs only once.
wifiStatus = WiFi.status (); // First we check the status of the Wi-Fi connection and save the result in the wifiStatus variable we created.
if (connectSuccess == 0) {blue ();} // If the device is not connected and has never been successfully connected, the blue light flashes. This could mean that the network does not exist, is out of range, or you have entered the SSID or password incorrectly.
if (wifiStatus == WL_CONNECTED) {green (), connectSuccess ++;} // When the device is connected, flash the green light and add one to count the variable "connectSuccess". In this way we will make the red light blink when we lose the connection.
      sonst if (connectSuccess! = 0) {red (); } // Wenn die Verbindung nicht aktiv ist, wir aber zuvor eine Verbindung herstellen konnten, blinkt die rote LED. Das bedeutet, dass der AP ausgeschaltet ist, ein Jamming-Angriff im Gange ist oder eine normale Verbindung unmöglich ist.
      Verzögerung (1000); // Legen Sie eine Verzögerung von einer Sekunde pro Zyklus fest, um den Status der Verbindung zu überprüfen.
} 

Sie finden diesen Code auch im selben GitHub – Repo, aus dem die blinkende .INO – Datei heruntergeladen wurde.

Schritt 7: Ausführen des Codes & Testen

Laden Sie Ihren Code mit diesem Code auf die NodeMCU in der Arduino IDE und warten Sie, bis der Neustart abgeschlossen ist. Jetzt ist es an der Zeit, das Gerät zu testen.

Der beste Weg dazu ist der drahtlose Hotspot Ihres Telefons. Stellen Sie die SSID und das Passwort in Ihrem Programm auf die Ihres Hotspots ein, um einfach zu testen, ob das Programm funktioniert. Starten Sie die NodeMCU mit ausgeschaltetem Hotspot, und sie sollte blau blinken, ohne eine Verbindung herstellen zu können. Wenn Sie Ihren WLAN-Hotspot einschalten, sollte dieser grün blinken, und wenn Sie den Hotspot wieder ausschalten, sollte er rot blinken.

Wenn Sie kein Telefon mit einem Hotspot haben, können Sie es auf Ihrem Smartphone testen Netzwerk auch. Verwenden Sie einen unserer Anleitungen zu MDK3 oder Aireplay-ng, verbinden Sie die NodeMCU mit einem Netzwerk, für das Sie die Berechtigung haben, zu testen, und attackieren Sie die NodeMCU (oder den Kanal, falls Sie dazu berechtigt sind) mit einem Deauthentifizierungs- oder Dissoziationsangriff. 19659092] Wie programmiert man einen $ 6 NodeMCU, um Wi-Fi Jamming-Angriffe in der Arduino IDE zu erkennen ” width=”532″ height=”532″ style=”max-width:532px;height:auto;”/>

Sie sollten sehen, dass die LED rot wird, sobald Ihr Angriff wirksam wird, und dann wieder grün wird, wenn der Angriff abklingt. Sie können die NodeMCU als "Opfer" -Gerät verwenden, um Jamming- und Deauthentifizierungsangriffe mit einer einfachen LED-Anzeige zu üben, um zu zeigen, wann Sie erfolgreich sind.

Erstaunliche Projekte sind mit der ESP8266 & Arduino IDE möglich

Bewaffnet mit niedrigen Kosten Board und Arduino IDE haben wir einen einfachen Code zur Überwachung einer Netzwerkverbindung erstellt und gezeigt, wie einfach es ist, eine kleine nützliche Funktion mit einem IoT-Gerät zu automatisieren. Neben der Erkennung von Angriffen kann der ESP8266 auch Netzwerke angreifen und wurde in Projekten eingesetzt, die von komplizierten LED-Masken bis hin zu kleinen Deauthentifizierungs-Paketgeneratoren wie dem von Spacehuhn [1979055] esp8266 reichen.

Mit so vielen kostengünstigen Gebäuden Blöcke wie die NodeMCU verfügbar, die mit Wi-Fi eingebaut sind, diese Geräte mit einem Netzwerk zu verbinden, um grundlegende nützliche Funktionen zu tun, ist selbst für einen beginnenden Hersteller einfach. Fortschrittlichere und kreativere Anwendungen dieser Bausteine ​​können Netzwerke von zielgerichteten WLAN-Protokoll-Störsendern ermöglichen, um die Abdeckung über einen weiten Bereich zu verhindern, oder Detektoren zur Automatisierung der Wi-Fi-Überwachung.

Ich hoffe, Sie haben diesen Leitfaden zur Erkennung genossen Wi-Fi Jamming-Angriffe durch Programmierung einer NodeMCU in der Arduino IDE. Wenn Sie Fragen zu diesem Tutorial zur Arduino-Programmierung haben oder einen Kommentar haben, können Sie mich auf Twitter @KodyKinzie oder im Kommentar dazu erreichen.

Verpassen Sie nicht: Deaktivieren Sie Sicherheitskameras auf jedem drahtlosen Netzwerk mit Aireplay-ng

Cover Foto und Screenshots von Kody / Null Byte (sofern nicht anders angegeben)




Source link