Wi-Fi Security and Attacks


Wi-Fi networks are an integral part of our daily lives, providing internet access for everything from streaming media to conducting business. However, the convenience of wireless connectivity comes with its own set of risks. Cyber attackers often target Wi-Fi networks to intercept sensitive data, gain unauthorized access, or disrupt service. In this post, we'll explore common Wi-Fi security threats, how these attacks work, and most importantly, what you can do to protect your network.


What is Wi-Fi Security?

Wi-Fi security refers to the protective measures implemented to secure a wireless network from unauthorized access, data interception, and other types of cyberattacks. Securing your Wi-Fi network is essential not just for personal privacy but also for the protection of your devices and online transactions.

Common Wi-Fi security protocols include:

  • WEP (Wired Equivalent Privacy): An outdated and insecure encryption standard.
  • WPA (Wi-Fi Protected Access): A more secure protocol that replaced WEP.
  • WPA2: The standard encryption protocol that uses AES encryption and is considered secure when properly configured.
  • WPA3: The latest protocol with stronger encryption, providing enhanced protection for both home and enterprise networks.

While WPA2 and WPA3 offer strong protection, Wi-Fi networks remain vulnerable to various forms of attack, especially if they are not configured correctly or are using outdated protocols.


Common Wi-Fi Security Threats and Attacks


1. Eavesdropping (Packet Sniffing)

Description:

Eavesdropping, also known as packet sniffing, occurs when an attacker intercepts the data being transmitted over a Wi-Fi network. Attackers can capture unencrypted traffic and gain access to sensitive information such as passwords, login credentials, or browsing activity.

How It Works:

If a Wi-Fi network is not encrypted (or uses weak encryption like WEP), anyone within range of the signal can use tools like Wireshark or Kismet to capture packets transmitted across the network.

Prevention:

  • Use WPA2 or WPA3 Encryption: Always use WPA2 or WPA3 to secure your Wi-Fi network. These encryption protocols are designed to prevent unauthorized access and eavesdropping.
  • Use HTTPS: When browsing the web, make sure the websites you're visiting use HTTPS, which encrypts the communication between your browser and the server.
Sample Code: Sniffing Wi-Fi Traffic with Python and Scapy
from scapy.all import *

def packet_callback(packet):
    if packet.haslayer(Dot11):
        print(packet.show())

# Sniff Wi-Fi packets on interface wlan0
sniff(iface="wlan0", prn=packet_callback, store=0)

Explanation:
This Python script uses the scapy library to sniff Wi-Fi packets. If you are on an unsecured network, you might be able to capture sensitive data being sent between users and the access point.


2. Man-in-the-Middle (MITM) Attacks

Description:

In a Man-in-the-Middle (MITM) attack, an attacker intercepts the communication between two devices on a network. This allows the attacker to spy on, alter, or even redirect traffic without the knowledge of the victim.

How It Works:

One common form of MITM on Wi-Fi networks is the Evil Twin attack. In this attack, the attacker sets up a rogue access point with the same SSID as a legitimate network. When users unknowingly connect to the rogue access point, the attacker can capture and manipulate the data being transmitted.

Prevention:

  • Avoid Public Wi-Fi for Sensitive Transactions: Avoid accessing sensitive websites or banking information over public or unsecured Wi-Fi networks.
  • Use a VPN: A Virtual Private Network (VPN) encrypts your data, making it unreadable to attackers even if they intercept your traffic.
Sample Code: Setting Up an Evil Twin Attack Using Aircrack-ng
# Start monitoring mode on your wireless interface
sudo ip link set wlan0 down
sudo iw dev wlan0 set type monitor
sudo ip link set wlan0 up

# Deauthenticate a device from the network
sudo aireplay-ng -0 1 -a <target_AP_MAC> -c <client_MAC> wlan0

# Create a fake Wi-Fi network
sudo airbase-ng -e "Fake WiFi Network" -c 6 wlan0mon

Explanation:
This set of commands uses aircrack-ng to create a rogue access point with the same name (SSID) as a legitimate network, effectively tricking users into connecting to it. Once connected, attackers can intercept and manipulate data.


3. Brute Force Attacks on Wi-Fi Passwords

Description:

A brute force attack occurs when an attacker attempts to guess the Wi-Fi password by trying every possible combination until the correct one is found. This is often done after capturing the WPA handshake during the connection process.

How It Works:

Once an attacker captures a WPA handshake (the process that occurs when a device connects to the network), they can use a tool like aircrack-ng to perform a dictionary attack or brute-force attack to guess the password.

Prevention:

  • Use Strong, Complex Passwords: Choose a long and complex password with a combination of letters, numbers, and special characters.
  • Enable WPA3: WPA3 has protections against offline brute-force attacks, making it significantly more secure than WPA2.
Sample Code: Cracking WPA Handshake Using Aircrack-ng
# Capture WPA handshake
sudo airodump-ng --bssid <target_AP_MAC> -c 6 -w handshake wlan0mon

# Crack the captured handshake using a wordlist
aircrack-ng handshake-01.cap -w /path/to/dictionary.txt

Explanation:
This code captures the WPA handshake and then uses a dictionary file to try to crack the password. Brute-force attacks are often successful against weak passwords, but strong, complex passwords can make this process difficult and time-consuming.


4. Denial of Service (DoS) and Jamming Attacks

Description:

A Denial of Service (DoS) or jamming attack floods a Wi-Fi network with excessive traffic or interference, rendering the network unavailable to legitimate users.

How It Works:

In Wi-Fi networks, attackers can perform deauthentication attacks using tools like aireplay-ng to send fake deauthentication packets, causing devices to disconnect from the network repeatedly.

Prevention:

  • Limit Broadcast Traffic: Avoid unnecessary broadcasts, as they can overload the network.
  • Monitor Network for Suspicious Activity: Use intrusion detection systems (IDS) to monitor the network for unusual traffic patterns.
  • Use Strong Encryption: Securing the network with WPA2 or WPA3 helps reduce the risk of attacks that exploit weaknesses in older encryption protocols.
Sample Code: Performing a DoS Attack Using aireplay-ng
# Send deauthentication packets to disconnect a device
sudo aireplay-ng -0 0 -a <target_AP_MAC> -c <client_MAC> wlan0mon

Explanation:
This command floods the targeted access point with deauthentication packets, forcing devices to repeatedly disconnect from the network. This causes a denial of service for the targeted users.


5. Wi-Fi Password Cracking via WPS (Wi-Fi Protected Setup)

Description:

WPS is a feature designed to simplify the process of connecting devices to a Wi-Fi network. However, WPS can be vulnerable to brute-force attacks, where an attacker guesses the 8-digit PIN to gain access to the network.

How It Works:

WPS-enabled routers generate an 8-digit PIN used for connecting devices. If this feature is enabled, an attacker can use tools like reaver to perform a brute-force attack and crack the PIN.

Prevention:

  • Disable WPS: If WPS is not necessary, it should be disabled in the router settings to prevent attackers from exploiting this vulnerability.
  • Use Strong Passwords: For routers that do not support WPS, use strong WPA2 or WPA3 passwords.
Sample Code: Cracking WPS PIN with Reaver
# Brute-force the WPS PIN to gain access
sudo reaver -i wlan0mon -b <target_AP_MAC> -vv

Explanation:
Reaver is a popular tool used for brute-forcing WPS PINs. By guessing the PIN, the attacker can eventually gain access to the target network.