To implement the hello flood attack in ns3, in a wireless network it is denial of service attacks that can sends an enormous amount of Hello packets to use the resources of the target node. Usually this type of vulnerability pertinent in wireless sensor network and can interrupt the network interaction by devastate the target node with too much Hello messages. Here are the procedures to implement the hello flood attacks in ns3:
Step-by-Step Implementation:
- Set Up ns3 Environment:
- Make certain ns3 installed in the computer.
- Download all the essential dependencies.
- Create a New ns3 Script:
- Create a new script file in the scratch directory of ns3, e.g., hello_flood_attack.cc.
- Include Necessary Headers:
- Include the necessary ns3 headers in your script.
- Define Network Topology:
- Set up a wireless network topology that includes multiple legitimate nodes and one attacker node.
- Implement Hello Flood Attack Logic:
- To send a flood of Hello packets from the attacker node to the target node by use of custom application.
- Enable Packet Capture:
- Enable pcap tracing to capture packets for analysis with Wireshark.
- Run the Simulation:
- Set the simulation time and run the simulation using Simulator::Run() and Simulator::Destroy().
Example
Here we can see the sample illustrative steps to implement the Hello flood attacks in ns3:
#include “ns3/core-module.h”
#include “ns3/network-module.h”
#include “ns3/internet-module.h”
#include “ns3/point-to-point-module.h”
#include “ns3/applications-module.h”
#include “ns3/wifi-module.h”
#include “ns3/mobility-module.h”
#include “ns3/flow-monitor-module.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“HelloFloodAttack”);
void SendHelloFlood (Ptr<Node> attackerNode, Mac48Address broadcastAddress, uint32_t packetSize, uint32_t numPackets, Time interval)
{
Ptr<WifiNetDevice>wifiDevice= DynamicCast<WifiNetDevice> (attackerNode>GetDevice (0));
Ptr<WifiMac> wifiMac = wifiDevice->GetMac ();
for (uint32_t i = 0; i < numPackets; ++i)
{
Ptr<Packet> packet = Create<Packet> (packetSize);
WifiMacHeader hdr;
hdr.SetType (WIFI_MAC_MGT);
hdr.SetSubtype (WIFI_MAC_MGT_PROBE_REQ);
hdr.SetAddr1 (broadcastAddress);
hdr.SetAddr2 (wifiMac->GetAddress ());
hdr.SetAddr3 (wifiMac->GetAddress ());
packet->AddHeader (hdr);
wifiDevice->Send (packet, broadcastAddress, 0);
Simulator::Schedule (interval, &SendHelloFlood, attackerNode, broadcastAddress, packetSize, numPackets, interval);
}
}
int main (int argc, char *argv[])
{
uint32_t nWifi = 10; // Number of legitimate nodes
uint32_t packetSize = 100; // Size of Hello packet
uint32_t numPackets = 1000; // Number of packets to send
Time interval = Seconds (0.1); // Interval between packets
CommandLine cmd;
cmd.AddValue (“nWifi”, “Number of wifi STA devices”, nWifi);
cmd.AddValue (“packetSize”, “Size of Hello packets”, packetSize);
cmd.AddValue (“numPackets”, “Number of Hello packets”, numPackets);
cmd.AddValue (“interval”, “Interval between Hello packets”, interval);
cmd.Parse (argc, argv);
NodeContainer wifiStaNodes;
wifiStaNodes.Create (nWifi);
NodeContainer wifiApNode;
wifiApNode.Create (1);
NodeContainer attackerNode;
attackerNode.Create (1);
YansWifiChannelHelper channel = YansWifiChannelHelper::Default ();
YansWifiPhyHelper phy = YansWifiPhyHelper::Default ();
phy.SetChannel (channel.Create ());
WifiHelper wifi = WifiHelper::Default ();
wifi.SetRemoteStationManager (“ns3::AarfWifiManager”);
WifiMacHelper mac;
Ssid ssid = Ssid (“ns-3-ssid”);
mac.SetType (“ns3::StaWifiMac”,
“Ssid”, SsidValue (ssid),
“ActiveProbing”, BooleanValue (false));
NetDeviceContainer staDevices;
staDevices = wifi.Install (phy, mac, wifiStaNodes);
mac.SetType (“ns3::ApWifiMac”,
“Ssid”, SsidValue (ssid));
NetDeviceContainer apDevice;
apDevice = wifi.Install (phy, mac, wifiApNode);
mac.SetType (“ns3::StaWifiMac”,
“Ssid”, SsidValue (ssid),
“ActiveProbing”, BooleanValue (false));
NetDeviceContainer attackerDevice;
attackerDevice = wifi.Install (phy, mac, attackerNode);
// Install the internet stack
InternetStackHelper stack;
stack.Install (wifiApNode);
stack.Install (wifiStaNodes);
stack.Install (attackerNode);
// Assign IP addresses
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer staInterfaces = address.Assign (staDevices);
Ipv4InterfaceContainer apInterface = address.Assign (apDevice);
Ipv4InterfaceContainer attackerInterface = address.Assign (attackerDevice);
// Set mobility model
MobilityHelper mobility;
mobility.SetPositionAllocator (“ns3::GridPositionAllocator”,
“MinX”, DoubleValue (0.0),
“MinY”, DoubleValue (0.0),
“DeltaX”, DoubleValue (5.0),
“DeltaY”, DoubleValue (10.0),
“GridWidth”, UintegerValue (3),
“LayoutType”, StringValue (“RowFirst”));
mobility.SetMobilityModel (“ns3::ConstantPositionMobilityModel”);
mobility.Install (wifiApNode);
mobility.Install (wifiStaNodes);
mobility.Install (attackerNode);
// Install applications on legitimate nodes
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (wifiApNode.Get (0));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (apInterface.GetAddress (0), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (1));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (1.0)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (wifiStaNodes);
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Enable packet capture
phy.EnablePcapAll (“hello_flood_attack”);
// Schedule Hello Flood attack
Simulator::Schedule (Seconds (3.0), &SendHelloFlood, attackerNode.Get (0),
Mac48Address::GetBroadcast (), packetSize, numPackets, interval);
// Run simulation
Simulator::Run ();
Explanation:
Here, we explain the structured description to hello flood attacks in ns3:
- Nodes and Links:
- Created nodes for the AP, clients, and an attacker node.
- Configured a wireless network using YansWifiChannelHelper and YansWifiPhyHelper.
- Applications:
- Installed a UDP echo server on the AP and UDP echo clients on the client nodes to generate traffic.
- Hello Flood Attack Logic:
- Implemented a SendHelloFlood function to create and send Hello packets from the attacker node to the broadcast address.
- Scheduled the Hello Flood attack to start at a specific time in the simulation.
- Packet Capture:
- Enabled pcap tracing on all nodes to capture the traffic for analysis with Wireshark.
- Running the Simulation:
- The simulation runs with the attacker node sending a flood of Hello packets to disrupt the wireless communication, and the traffic is captured in pcap files.
In conclusion, we had implemented the hello flood attacks in ns3 that has captured the network traffic and it analysed it. We also offer more information regarding the execution of the hello flood attacks in alternative simulation tools.
Furthermore we provide you with Flood Attacks in ns3 with basic programming guidelines tailored to your needs.