How to Implement Wireless Attacks in NS2

 

To implement wireless attacks in Network Simulator 2 (NS2) has needs to mimic the numerous types of attacks that can arise in a wireless network, like jamming, denial of service (DoS), packet dropping, or black hole attacks. Basically NS2 has support for wireless network simulations via the use of wireless nodes, wireless channel models, and routing protocols such as AODV, DSR, etc. By manipulating these, we can mimic the diverse types of wireless attacks. For unparalleled implementation guidance, we invite you to reach out to us.

The given below is the overall procedure to implement the wireless attacks in ns2:

Common Wireless Attacks in NS2:

  1. Jamming Attack: A malicious node sends continuous packets to jam the wireless channel, disturbing the communication.
  2. Black Hole Attack: A malicious node advertises itself as having the shortest route to the destination and drops all the packets.
  3. Packet Dropping Attack: The attacker node selectively drops packets in transit.
  4. Denial of Service (DoS) Attack: The attacker node sends a high volume of traffic to overwhelm the target.

Steps to Implement Wireless Attacks in NS2:

  1. Set Up Wireless Network Topology:
  • Describe multiple wireless nodes using the setdest tool or Tcl script.
  • Use a suitable wireless routing protocol like AODV or DSR to allow interaction among nodes.
  1. Identify and Configure Attacker Node:
  • Choose a node to act as the attacker.
  • Relaying on the type of attack such as jamming, black hole, packet dropping, we need to adjust the behaviour of this node.
  1. Configure Wireless Parameters:
  • Configure wireless channel metrics such as propagation model, antenna type, and transmission range.
  • This is vital in wireless simulations to control how far nodes can interact and how interference is managed.
  1. Implement Different Types of Wireless Attacks:

Example: Black Hole Attack

In a black hole attack, the malicious node assertions to have the best route to the destination nevertheless drop all received packets.

Example Script for Black Hole Attack:

# Define a simulator object

set ns [new Simulator]

# Create the output trace file

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define the topology object

set topo [new Topography]

$topo load_flatgrid 500 500

# Configure the wireless channel

create-god 3

# Define wireless nodes

set n0 [$ns node]  ;# Source node

set n1 [$ns node]  ;# Intermediate node

set n2 [$ns node]  ;# Destination node

set n3 [$ns node]  ;# Malicious node (Black hole)

# Configure the nodes’ parameters

$ns node-config -adhocRouting AODV \

-llType LL \

-macType Mac/802_11 \

-ifqType Queue/DropTail/PriQueue \

-ifqLen 50 \

-antType Antenna/OmniAntenna \

-propType Propagation/TwoRayGround \

-phyType Phy/WirelessPhy \

-channelType Channel/WirelessChannel \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-movementTrace OFF

# Set node initial positions

$ns at 0.0 “$n0 setdest 100 200 0”

$ns at 0.0 “$n1 setdest 200 200 0”

$ns at 0.0 “$n2 setdest 300 200 0”

$ns at 0.0 “$n3 setdest 150 200 0”  ;# Malicious node

# Create TCP connections

set tcp0 [new Agent/TCP]

set sink0 [new Agent/TCPSink]

$ns attach-agent $n0 $tcp0

$ns attach-agent $n2 $sink0

$ns connect $tcp0 $sink0

# Create an FTP application to generate traffic

set ftp0 [new Application/FTP]

$ftp0 attach-agent $tcp0

$ns at 1.0 “$ftp0 start”

# Malicious node behavior (Black Hole Attack)

# Modify AODV to make n3 advertise itself as having the shortest path

$ns at 1.5 “puts \”Malicious node n3 advertising itself as the best route\””

$ns at 1.5 “$n3 ragent set malicious_ 1”

# Define the simulation end

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

Explanation of the Script:

  • Nodes:
    • n0: Source node.
    • n1: Intermediate node.
    • n2: Destination node.
    • n3: Malicious node (black hole attacker).
  • Routing Protocol: The AODV protocol is used for routing among the nodes.
  • Black Hole Attack Behavior: The malicious node (n3) is designed to act as a black hole by advertising itself as having the shortest route to the destination and then dropping all packets.
  • Traffic Generation: The source node (n0) sends TCP traffic to the destination node (n2) using FTP, but the malicious node disturbs the flow by dropping the packets.

Example: Jamming Attack

In a jamming attack, a malicious node constantly transfers packets on the wireless channel that leads interference and blocking communication.

Example Script for Jamming Attack:

# Define a simulator object

set ns [new Simulator]

# Create the output trace file

set tracefile [open out.tr w]

$ns trace-all $tracefile

# Define the topology object

set topo [new Topography]

$topo load_flatgrid 500 500

# Configure the wireless channel

create-god 3

# Define wireless nodes

set n0 [$ns node]  ;# Source node

set n1 [$ns node]  ;# Destination node

set n2 [$ns node]  ;# Malicious node (Jammer)

# Configure the nodes’ parameters

$ns node-config -adhocRouting AODV \

-llType LL \

-macType Mac/802_11 \

-ifqType Queue/DropTail/PriQueue \

-ifqLen 50 \

-antType Antenna/OmniAntenna \

-propType Propagation/TwoRayGround \

-phyType Phy/WirelessPhy \

-channelType Channel/WirelessChannel \

-topoInstance $topo \

-agentTrace ON \

-routerTrace ON \

-macTrace OFF \

-movementTrace OFF

# Set node initial positions

$ns at 0.0 “$n0 setdest 100 200 0”

$ns at 0.0 “$n1 setdest 300 200 0”

$ns at 0.0 “$n2 setdest 150 200 0”  ;# Malicious node (Jammer)

# Create UDP traffic between n0 and n1

set udp0 [new Agent/UDP]

set null0 [new Agent/Null]

$ns attach-agent $n0 $udp0

$ns attach-agent $n1 $null0

$ns connect $udp0 $null0

# Create a CBR traffic generator

set cbr [new Application/Traffic/CBR]

$cbr attach-agent $udp0

$ns at 1.0 “$cbr start”

# Jamming behavior: n2 sends continuous traffic to jam the channel

set udp_jammer [new Agent/UDP]

$ns attach-agent $n2 $udp_jammer

set jam [new Application/Traffic/CBR]

$jam set packetSize_ 512

$jam set interval_ 0.001

$jam attach-agent $udp_jammer

$ns at 1.0 “$jam start”

# Define the simulation end

$ns at 10.0 “finish”

proc finish {} {

global ns tracefile

$ns flush-trace

close $tracefile

exit 0

}

# Run the simulation

$ns run

Explanation of Jamming Attack Script:

  • Nodes:
    • n0: Source node.
    • n1: Destination node.
    • n2: Malicious node (jammer).
  • Jamming Behavior: The malicious node (n2) continuously sends UDP traffic with a very small interval that leads interference in the wireless channel and avoiding other nodes from successfully transferring their packets.
  • Traffic Generation: A liable communication session is introduced among n0 and n1 using UDP traffic, however the jammer disturbs it.

Example: Packet Dropping Attack

In this attack, the malicious node selectively drops some or all packets that pass over it.

We need to adjust the above scripts for diverse attacks such as DoS, Wormhole, and Gray Hole attacks by manipulating how the malicious node performs like dropping packets, creating routing loops, etc.

Post-Simulation Analysis:

  • Trace File Analysis: After executing the simulation, the trace file will demonstrate that packets were sent, received, or dropped. We need to assess the packet loss, delays, and throughput to measure the impacts of the attack.
  • NAM (Network Animator): we can also use NAM to visualize the attack and confirm the behaviour of the malicious node.

We had successfully executed the wireless attacks that were executed using the tool of ns2 that has to generate the topology then apply the different type of wireless attacks and finally analyse the outcomes. If you need more information about the wireless attacks we will provide it.