To implement quench attack in ns3, we need to create a scenario based on attacker node sending ICMP Source Quench messages to the victim node. Because when an attacker sending ICMP Source Quench messages to a target, it slow down its transmission rate due to falsely indicating network congestion. So we have to made attacker node to send the victim node a quench message.
The following steps will guide on implementing a source quench attack in ns3:
Steps to Implement a Source Quench Attack in ns-3
- Set Up ns3 Environment:
- Ensure ns3 is installed
- Create a New ns-3 Script:
- Create a new script file in the scratch directory of ns3, e.g., quench_attack.cc.
- Include Necessary Headers:
- Include the necessary ns3 headers in your script.
- Define Network Topology:
- Set up a network topology with multiple legitimate nodes and an attacker node.
- Implement Quench Attack Logic:
- Use the attacker node to send ICMP Source Quench messages to the victim node.
- 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 Code:
#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/icmpv4-header.h”
#include “ns3/ipv4-header.h”
using namespace ns3;
NS_LOG_COMPONENT_DEFINE (“QuenchAttack”);
void SendQuenchPacket (Ptr<Node> attackerNode, Ipv4Address victimAddress, uint32_t numPackets, Time interval)
{
Ptr<Socket> socket = Socket::CreateSocket (attackerNode, TypeId::LookupByName (“ns3::Ipv4RawSocketFactory”));
socket->SetAttribute (“Protocol”, UintegerValue (1)); // ICMP protocol number
Ipv4Header ipv4Header;
ipv4Header.SetDestination (victimAddress);
ipv4Header.SetSource (attackerNode->GetObject<Ipv4> ()->GetAddress (1, 0).GetLocal ());
ipv4Header.SetProtocol (1); // ICMP protocol number
Icmpv4Header icmpHeader;
icmpHeader.SetType (Icmpv4Header::ICMP_SOURCE_QUENCH);
icmpHeader.SetCode (0);
for (uint32_t i = 0; i < numPackets; ++i)
{
Ptr<Packet> packet = Create<Packet> (100); // Create a packet of 100 bytes
packet->AddHeader (icmpHeader);
packet->AddHeader (ipv4Header);
socket->Send (packet);
Simulator::Schedule (interval, &SendQuenchPacket, attackerNode, victimAddress, numPackets, interval);
}
}
int main (int argc, char *argv[])
{
bool verbose = true;
uint32_t nNodes = 2; // Number of legitimate nodes
uint32_t numPackets = 10; // Number of packets to send
Time interval = Seconds (1.0); // Interval between packets
CommandLine cmd;
cmd.AddValue (“nNodes”, “Number of legitimate nodes”, nNodes);
cmd.AddValue (“numPackets”, “Number of packets to send”, numPackets);
cmd.AddValue (“interval”, “Interval between packets”, interval);
cmd.Parse (argc, argv);
if (verbose)
{
LogComponentEnable (“QuenchAttack”, LOG_LEVEL_INFO);
}
NodeContainer nodes;
nodes.Create (nNodes + 1); // +1 for the attacker node
Ptr<Node> attacker = nodes.Get (nNodes);
PointToPointHelper pointToPoint;
pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));
pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));
NetDeviceContainer devices;
for (uint32_t i = 0; i < nodes.GetN () – 1; ++i)
{
devices.Add (pointToPoint.Install (nodes.Get (i), nodes.Get (i + 1)));
}
InternetStackHelper stack;
stack.Install (nodes);
Ipv4AddressHelper address;
address.SetBase (“10.1.1.0”, “255.255.255.0”);
Ipv4InterfaceContainer interfaces = address.Assign (devices);
// Install applications on legitimate nodes
UdpEchoServerHelper echoServer (9);
ApplicationContainer serverApps = echoServer.Install (nodes.Get (nNodes – 1));
serverApps.Start (Seconds (1.0));
serverApps.Stop (Seconds (10.0));
UdpEchoClientHelper echoClient (interfaces.GetAddress (nNodes – 1), 9);
echoClient.SetAttribute (“MaxPackets”, UintegerValue (100));
echoClient.SetAttribute (“Interval”, TimeValue (Seconds (0.1)));
echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));
ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));
clientApps.Start (Seconds (2.0));
clientApps.Stop (Seconds (10.0));
// Schedule source quench attack
Simulator::Schedule (Seconds (3.0), &SendQuenchPacket, attacker,
interfaces.GetAddress (nNodes – 1), numPackets, interval);
// Enable packet capture
pointToPoint.EnablePcapAll (“quench_attack”);
Simulator::Run ();
Simulator::Destroy ();
return 0;
}
Explanation:
- Nodes and Links:
- Created nodes for legitimate communication and one attacker node.
- Configured point-to-point links between the nodes.
- Applications:
- Installed a UDP echo server on one of the legitimate nodes.
- Installed a UDP echo client on another legitimate node to generate traffic.
- Quench Attack Logic:
- Implemented a SendQuenchPacket function to create and send ICMP Source Quench messages from the attacker node to the victim node.
- Scheduled the source quench 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:
- While the traffic is captured in pcap files,the simulation runs with the attacker node sending ICMP Source Quench messages to the victim node.
From the steps provided here, we had a clear idea about implementing the quench attack in ns3 while sending ICMP source quench messages to a target from an attacker node if falsely indicate network congestion we need a scenario to send messages directly to victim node.
Implementation on quench attack in ns3 with tailored comparative analysis based on your project are worked by ns3simulation.com team.