Uploaded by بسام حسن

Blackhole attack

advertisement
Blackhole attack
Blackhole attack in MANET
• A Mobile Ad hoc Network (MANET): comprises of mobile
nodes that moves independently in an open environment.
Communication between the nodes in a MANET is enabled with
the aid of intermediate routers. The nature of MANET such as
open medium, dynamic network topology, lack of centralized
monitoring, and lack of clear defense mechanisms makes it
vulnerable to several routing attacks In MANET routing, there is
a high probability for intermediate nodes to be malicious that
might be a threat to the security.
• Blackhole: is the common attack in ad hoc routing in which the
malicious node uses the process of routing to state itself of
being the shortest path to the destination. Once it receives the
data packets, it drops the data packets instead of forwarding
them to its neighbours
2
create Blackhole attack in MANET
using ns2
First you need to modify aodv.cc and aodv.h
files. In aodv.h after:
add following line
bool
malicious;
3
Adding Malicious Node to AODV
With this variable we are trying to define if the
node is malicious or not. In aodv.cc after
add following line
malicious = false;
4
Adding Malicious Node to AODV
The above code is needed to initialize, and all
nodes are initially not malicious. Then we will
write a code to catch which node is set as
malicious. In aodv.cc after:
5
Adding Malicious Node to AODV
add following line
if(strcmp(argv[1], "hacker") == 0)
{
malicious = true;
return TCL_OK;
}
6
Adding Malicious Node to AODV
we have set malicious node but we did not
tell malicious node what to do. As it is
known, rt_resolve(Packet *p) function is used
to select next hop node when routing data
packets. So, we tell malicious node just drop
any packet when it receives. To do that after:
7
Adding Malicious Node to AODV
We add a few lines
// if I am malicious node
if (malicious == true ) {
drop(p, DROP_RTR_ROUTE_LOOP);
// DROP_RTR_ROUTE_LOOP is added
for no reason.
}
8
set a malicious node in TCL
Now we will do some work in TCL to set a malicious
node.
we add following line to set node 0 as malicious
node:
$ns at 0.0"[$node_(0) set ragent_]malicious"
Or
$ns at 0.0"[$node_(0) set ragent_]hacker"
9
Random Topology Creation
#*******************Random Topology Creation*******************#
for {set i 0} {$i < $val(nn)} {incr i} {
set node_($i) [$ns node]
$node_($i) set X_ [expr rand()*$val(x)]
$node_($i) set Y_ [expr rand()*$val(y)]
$node_($i) set Z_ 0
$ns initial_node_pos $node_($i) 30
}
10
Random Mobility
#****Defining Random Mobility****#
for {set i 1} {$i < 4} {incr i} {
set xr [expr rand()*$val(x)]
set yr [expr rand()*$val(y)]
$ns at 2.0 "$node_($i) setdest $xr $yr 50"
}
11
calculate distance between nodes
using NS2
#*******************DISTANCE CALCULATION********************#
for {set i 0} {$i < $val(nn) } { incr i } {
puts "\n"
puts $r "\n"
for {set j 0} {$j < $val(nn) } { incr j } {
set dx [expr $xx($i) - $xx($j)]
set dy [expr $yy($i) - $yy($j)]
12
calculate distance between nodes
using NS2
set dx2 [expr $dx * $dx]
set dy2 [expr $dy * $dy]
set h2 [expr $dx2 + $dy2]
set h($i-$j) [expr pow($h2, 0.5)]
puts "distance of node($i) from node($j) = $h($i-$j)"
puts $r "distance of node($i) from node($j) h($i-$j) = $h($i-$j)"
}
}
13
Example: sample20.tcl
Run sample20.tcl code
14
Example: sample20.tcl
In sample20.tcl:
• the blackhole attacker does not obey the
communication model.
• Data Transmission is established between nodes
using UDP agent and CBR traffic.
• Sender sends the data via attacker.
• Source node transfers data to attacker that does
not have shortest route to Destination. Attacker
does not forward data to its neighbours
15
NAM : sample20.tcl
16
Download