Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to implement ICMP attack in ns3

To implement the ICMP attack in ns3, we need to simulate where the attackers (one node) can send the ICMP packets to victim (another node) to flood it with ICMP Echo Requests. We also deliver more interesting information about how the ICMP attacks will perform further tools.

This type of vulnerability is known as “Ping Flood”. Here we can see how to implement the ICMP attack in ns3 tool:

Step-by-step Implementation:

  1. Set Up ns3 Environment:
    • Make certain ns3 is installed.
    • Download necessary dependencies.
  2. Create a New ns3 Script:
    • Create a new script file in the scratch directory of ns3, e.g., icmp_attack.cc.
  3. Include Necessary Headers:
    • implicate the essential ns3 headers in the script.
  4. Define Network Topology:
    • Set up a network topology that includes multiple nodes and one attacker node.
  5. Implement ICMP Attack Logic:
    • Use raw sockets to send ICMP Echo Request packets from the attacker node.
  6. Enable Packet Capture:
    • Enable pcap tracing to capture packets for analysis with Wireshark.
  7. Run the Simulation:
    • Set the simulation time and run the simulation using Simulator::Run() and Simulator::Destroy().

Example:

The given below is the fundamental sample to illustrative the ICMP attack 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/ipv4-raw-socket-factory.h”

#include “ns3/icmpv4-header.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“IcmpAttack”);

void SendIcmpPacket (Ptr<Node> attackerNode, Ipv4Address destination)

{

Ptr<Socket>socket=Socket::CreateSocket(attackerNode,Ipv4RawSocketFactory::GetTypeId ());

socket->SetAttribute (“Protocol”, UintegerValue (1)); // ICMP protocol number

Ptr<Packet> packet = Create<Packet> (100); // Create a packet of 100 bytes

// Create and add ICMP header

Icmpv4Echo echo;

echo.SetSequenceNumber (1);

echo.SetIdentifier (1);

packet->AddHeader (echo);

// Create and add IP header

Ipv4Header ipHeader;

ipHeader.SetDestination (destination);

ipHeader.SetProtocol (1); // ICMP

ipHeader.SetPayloadSize (100);

packet->AddHeader (ipHeader);

socket->Send (packet);

}

int main (int argc, char *argv[])

{

// Set up logging

LogComponentEnable (“IcmpAttack”, LOG_LEVEL_INFO);

// Create nodes

NodeContainer nodes;

nodes.Create (3); // Two legitimate nodes and one attacker node

// Create point-to-point links

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

NetDeviceContainer devices;

devices = pointToPoint.Install (nodes.Get (0), nodes.Get (1));

devices.Add (pointToPoint.Install (nodes.Get (1), nodes.Get (2))); // Attacker connected to one of the nodes

// Install the internet stack

InternetStackHelper stack;

stack.Install (nodes);

// Assign IP addresses

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (devices);

// Install applications on legitimate nodes

uint16_t port = 9; // Discard port (RFC 863)

// Server application

UdpEchoServerHelper echoServer (port);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

// Client application

UdpEchoClientHelper echoClient (interfaces.GetAddress (1), port);

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));

// Enable packet capture

pointToPoint.EnablePcapAll (“icmp_attack”);

// Schedule ICMP attack

for (uint32_t i = 1; i < 100; ++i)

{

Simulator::Schedule (Seconds (1.0 + i * 0.1), &SendIcmpPacket, nodes.Get (2), interfaces.GetAddress (1));

}

// Run simulation

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation:

Here we offer the detailed explanation for the ICMP attack process that are given below:

  1. Nodes and Links:
    • Created 3 nodes: two legitimate nodes and one attacker node.
    • Configured point-to-point links between the nodes.
  2. Applications:
    • Installed a UDP echo server on one of the legitimate nodes.
    • Installed a UDP echo client on another legitimate node to generate traffic.
  3. ICMP Attack Logic:
    • Implemented a SendIcmpPacket function to create and send ICMP Echo Request packets using raw sockets.
    • Scheduled the ICMP attack to send multiple ICMP packets to the victim node.
  4. Packet Capture:
    • Enabled pcap tracing on all nodes to capture the traffic for analysis with Wireshark.
  5. Running the Simulation:
    • The simulation runs, with the attacker node sending ICMP Echo Request packets to the victim node, and the traffic is captured in pcap files.

Finally, as we discussed about how the ICMP attack will perform and executed in ns3 simulation tool. ICMP attack in ns3 programming are properly executed by us so stay in touch with us for best result.