NS2 Code for Blackhole Attack (multiple blackholes) in AODV Protocol
The
following scenario consists of 25 nodes, in which 1,7 and 13 nodes are
blackholenodes and other nodes are non-malicious.
To create multiple blackhole attackers in AODV protocol
i)
In
aodv.h the following blue colour lines needs to be added to define balckhole attackers
/*
* History management
*/
double PerHopTime(aodv_rt_entry *rt);
nsaddr_t malicious1;
nsaddr_t malicious2;
nsaddr_t malicious3;
ii)
In aodv.cc the following blue colour lines needs to be added to
initialize the attackers
int
AODV::command(intargc,
const char*const* argv) {
if(argc ==
2) {
Tcl&tcl
= Tcl::instance();
if(strncasecmp(argv[1],
"id", 2) == 0) {
tcl.resultf("%d",
index);
return
TCL_OK;
}
if(strcmp(argv[1],
"blackhole1") == 0) {
malicious1= index;
printf("malicious
%d", malicious1);
return TCL_OK;
}
if(strcmp(argv[1],
"blackhole2") == 0) {
malicious2=index;
printf("malicious
%d", malicious2);
return TCL_OK;
}
if(strcmp(argv[1],
"blackhole3") == 0) {
malicious3=
index;
printf("malicious %d",
malicious3);
return TCL_OK;
}
AODV::AODV(nsaddr_t
id) : Agent(PT_AODV),
btimer(this), htimer(this), ntimer(this),
rtimer(this), lrtimer(this), rqueue() {
index = id;
seqno = 2;
bid = 1;
LIST_INIT(&nbhead);
LIST_INIT(&bihead);
malicious1=999;
malicious2=999;
malicious3=999;
Malicious nodes 1,7 and 13 generates
fake route replies using following blue colour code
//add in receive
route request
if(rq->rq_dst
== index) {
#ifdef
DEBUG
fprintf(stderr,
"%d - %s: destination sending reply\n",
index,
__FUNCTION__);
#endif //
DEBUG
// Just to be safe, I use the max. Somebody
may have
// incremented the dstseqno.
seqno =
max(seqno, rq->rq_dst_seqno)+1;
if
(seqno%2) seqno++;
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
index, // Dest IP Address
seqno, // Dest Sequence Num
MY_ROUTE_TIMEOUT, // Lifetime
rq->rq_timestamp); // timestamp
Packet::free(p);
}
//blackhole attackers
else
if(index==malicious1)
{
seqno =
max(seqno, rq->rq_dst_seqno)+1;
if
(seqno%2) seqno++;
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
rq->rq_dst,
seqno,
MY_ROUTE_TIMEOUT,
rq->rq_timestamp); // timestamp
//rt->pc_insert(rt0->rt_nexthop);
Packet::free(p);
}
else
if(index==malicious2)
{
seqno =
max(seqno, rq->rq_dst_seqno)+1;
if
(seqno%2) seqno++;
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
rq->rq_dst,
seqno,
MY_ROUTE_TIMEOUT,
rq->rq_timestamp); // timestamp
//rt->pc_insert(rt0->rt_nexthop);
Packet::free(p);
}
else
if(index==malicious3)
{
seqno =
max(seqno, rq->rq_dst_seqno)+1;
if
(seqno%2) seqno++;
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
rq->rq_dst,
seqno,
MY_ROUTE_TIMEOUT,
rq->rq_timestamp); // timestamp
//rt->pc_insert(rt0->rt_nexthop);
Packet::free(p);
}
Since, all
attackers do not have route to destination, attacker have to disable the send
(error).
The
following blue colour code disables the send (error)
// add in route resolve function (AODV::rt_resolve(Packet
*p) )
else {
Packet *rerr = Packet::alloc();
structhdr_aodv_error
*re = HDR_AODV_ERROR(rerr);
/*
* For now, drop the packet and send error
upstream.
* Now the route errors are broadcast to
upstream
* neighbors - Mahesh 09/11/99
*/
assert
(rt->rt_flags == RTF_DOWN);
re->DestCount
= 0;
re->unreachable_dst[re->DestCount]
= rt->rt_dst;
re->unreachable_dst_seqno[re->DestCount]
= rt->rt_seqno;
re->DestCount
+= 1;
#ifdef
DEBUG
fprintf(stderr,
"%s: sending RERR...\n", __FUNCTION__);
#endif
if((index==malicious1)||(index==malicious2)||
(index==malicious3));
else
sendError(rerr,
false);
drop(p,
DROP_RTR_NO_ROUTE);
iii) To define the blackhole attackers in tcl
add these lines after node initializations
$ns at
0.0 "[$n1 set ragent_] blackhole1"
$ns at
0.0 "[$n7 set ragent_] blackhole2"
$ns at
0.0 "[$n13 set ragent_] blackhole3"
Above scenario example tcl file blackhole attacks scenario
Goodput
calculation file goodput
To calculate goodput: type-> perl goodput.pl outputfile name granularity(for 1 or 2... n seconds) > filename
ex :-> perl goodput.pl out.tr 10 > results
Packet Delivery Ratio (pdr) file: pdr
Thanks for your personnel mail and attention.
I have successfully compiled the code on my machine
Steps:
cd ns-allinone folder
cd ns-2.35
make clean
make
make ./install
./configure
Packet Delivery Ratio (pdr) file: pdr
To calculate Packet Delivery Ratio:
$ perl pdr
trafile_name sour-node1 sour_node2 sour_node3 sour_node4 dest_node >fname
eg :
If error comes Solution\
Possible Errors
1. I added this code to aodv.h and aodv.cc as per your instructions and in
tcl file provided.But i can not understand about Goodput calculation
file and perl script.I use ns filename.tcl command to run.but errors are
there.How to run this to show results.I have ubuntu 13.04 version and
ns2(2.35)simulator.PLease suggest me if any extra thing needs to be
added to run this black hole attack project.
-------------------------------------------------------------------------
2. initially i got the output for all the three mailicious nodes.
but after that i didnt ge for three instead for only one i.e node number 13(working),when i remove the comment for all three its giving floaing point error(core dumped)
so sugges were would be the problem for me.plz its very urgent.
but after that i didnt ge for three instead for only one i.e node number 13(working),when i remove the comment for all three its giving floaing point error(core dumped)
so sugges were would be the problem for me.plz its very urgent.
Solution
This error occurs due to hop cout value is 0 of a malicious path in aodv.cc code
you should replace hop cout 0 with 1
please modify following aodv.cc code
else if(index==malicious1)
{
…………
……..
…………………..
1, // Hop Count
……………………..
……………………..
}
else if(index==malicious2)
{
…………
……..
…………………..
1, // Hop Count
……………………..
……………………..
}
else if(index==malicious3)
{
…………
……..
…………………..
1, // Hop Count
……………………..
……………………..
}
Then make clean followed by make to create new aodv object files
you should replace hop cout 0 with 1
please modify following aodv.cc code
else if(index==malicious1)
{
…………
……..
…………………..
1, // Hop Count
……………………..
……………………..
}
else if(index==malicious2)
{
…………
……..
…………………..
1, // Hop Count
……………………..
……………………..
}
else if(index==malicious3)
{
…………
……..
…………………..
1, // Hop Count
……………………..
……………………..
}
Then make clean followed by make to create new aodv object files
3. Possible error
I have replaced modified aodv.cc and aodv.h files with original aodv
files..but when i m running the tcl file i m getting the following
errors...
num_nodes is set 25
INITIALIZE THE LIST xListHead
ns: _o39 blackhole1:
(_o39 cmd line 1)
invoked from within
"_o39 cmd blackhole1"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o39" line 2)
(SplitObject unknown line 2)
invoked from within
"_o39 blackhole1"
num_nodes is set 25
INITIALIZE THE LIST xListHead
ns: _o39 blackhole1:
(_o39 cmd line 1)
invoked from within
"_o39 cmd blackhole1"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o39" line 2)
(SplitObject unknown line 2)
invoked from within
"_o39 blackhole1"
----------------------------
If steps are not clear
Thanks for your personnel mail and attention.
I have successfully compiled the code on my machine
Steps:
cd ns-allinone folder
cd ns-2.35
make clean
make
make ./install
./configure
5. Possible error
after running the tcl script i am getting this error
num_nodes is set 25
invalid command name "-antType"
while executing
"-antType $val(ant) \
"
(file "blackhole.tcl" line 73)
what does it mean?
num_nodes is set 25
invalid command name "-antType"
while executing
"-antType $val(ant) \
"
(file "blackhole.tcl" line 73)
what does it mean?
set val(ant) Antenna/OmniAntenna is the right command
an omnidirectional antenna is a class of antenna which radiates radio wave power uniformly in all directions in one plane, with the radiated power decreasing with elevation angle above or below the plane, dropping to zero on the antenna's axis.
an omnidirectional antenna is a class of antenna which radiates radio wave power uniformly in all directions in one plane, with the radiated power decreasing with elevation angle above or below the plane, dropping to zero on the antenna's axis.
6. If you are getting like this
num_nodes is set 25
INITIALIZE THE LIST xListHead
ns: _o39 blackhole1:
(_o39 cmd line 1)
invoked from within
"_o39 cmd blackhole1"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o39" line 2)
(SplitObject unknown line 2)
invoked from within
"_o39 blackhole1"
this the error what I am getting
INITIALIZE THE LIST xListHead
ns: _o39 blackhole1:
(_o39 cmd line 1)
invoked from within
"_o39 cmd blackhole1"
invoked from within
"catch "$self cmd $args" ret"
invoked from within
"if [catch "$self cmd $args" ret] {
set cls [$self info class]
global errorInfo
set savedInfo $errorInfo
error "error when calling class $cls: $args" $..."
(procedure "_o39" line 2)
(SplitObject unknown line 2)
invoked from within
"_o39 blackhole1"
this the error what I am getting
once you replace the original aodv files with blackhole aodv files
the open ns.2.xx folder
make clean
make
If it wont work follow these steps:
If it won't work follow these steps:
To overcome this problem, do the following steps 1:
1. Un-install all ns2 versions(if you have to are more) and thier path settings.
2. re-intall ns2.33 or ns2.34 version
3. follow steps mentioned in this blogg to create blackhole attacl
the open ns.2.xx folder
make clean
make
If it wont work follow these steps:
If it won't work follow these steps:
To overcome this problem, do the following steps 1:
1. Un-install all ns2 versions(if you have to are more) and thier path settings.
2. re-intall ns2.33 or ns2.34 version
3. follow steps mentioned in this blogg to create blackhole attacl
7.If u got this type of error
i am using ns2.35 and when i followed this step,
Steps:
cd ns-allinone folder
cd ns-2.35
make clean
make
make ./install
./configure
I got the following error:-
queue/priqueue.cc: In member function ‘virtual void PriQueue::recv(Packet*, Handler*)’:
queue/priqueue.cc:94:6: error: ‘PT_blackholeAODV’ was not declared in this scope
case PT_blackholeAODV:
^
make: *** [queue/priqueue.o] Error 1
I also modified aodv.cc and aodv.h file.
Steps:
cd ns-allinone folder
cd ns-2.35
make clean
make
make ./install
./configure
I got the following error:-
queue/priqueue.cc: In member function ‘virtual void PriQueue::recv(Packet*, Handler*)’:
queue/priqueue.cc:94:6: error: ‘PT_blackholeAODV’ was not declared in this scope
case PT_blackholeAODV:
^
make: *** [queue/priqueue.o] Error 1
I also modified aodv.cc and aodv.h file.
Solution This error indicates you have already added some blackhole patch, on top this your were trying to add our blackhole code my suggestion is better undo the previous patch then add our code or
delete the present ns2 and re-install ns2 then add our code
delete the present ns2 and re-install ns2 then add our code
8. If theis is the error
I re-installed ns2.35 and tried again.
After the make operation,this is the errors which i am getting:-
make[1]: Leaving directory `/home/ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/ucb'
Inspiron-1545:~/ns-allinone-2.35/ns-2.35$ make./install
bash: make./install: No such file or directory
After the make operation,this is the errors which i am getting:-
make[1]: Leaving directory `/home/ns-allinone-2.35/ns-2.35/indep-utils/webtrace-conv/ucb'
Inspiron-1545:~/ns-allinone-2.35/ns-2.35$ make./install
bash: make./install: No such file or directory
Solution after making changes in aodv.cc and aodv.h file... Check this code
#Setup a CBR Application over UDP connection
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 0.1Mb
$cbr1 set random_ null
$ns at 20.0 "$cbr1 start"
$ns at 40.0 "$cbr1 stop"
set cbr1 [new Application/Traffic/CBR]
$cbr1 attach-agent $udp1
$cbr1 set packetSize_ 1000
$cbr1 set rate_ 0.1Mb
$cbr1 set random_ null
$ns at 20.0 "$cbr1 start"
$ns at 40.0 "$cbr1 stop"
9.The root of problems
In ns2 when a node is created it
will acts like router.i.e it gets functionalities of three layers
(physical,data,n/w). Now to make a particular node as source or
destination ,we need to add remaining two layers functionalities (i.e
transport & application). So for that purpose we are adding UDP
agent over node.and then CBR application to generate traffic over
udp...UDP belongs to Transport layer and CBR belongs to Application
layer .Now the node will act like system ,you can make it as source or
destination to transfer data from on node to another...
Now coming to above code line by line
1) Creating an object cbr1 for CBR application
2)attaching it over udp..as we know application layer comes on top of transport layer
3,4,5 lines are used to set default values for parameters like packet size, rate of generation of packets ,motion
6,7 lines are used at what time this cbr traffic(i.e generating packets) to start and when to stop ....
Hope you understand now..
Now coming to above code line by line
1) Creating an object cbr1 for CBR application
2)attaching it over udp..as we know application layer comes on top of transport layer
3,4,5 lines are used to set default values for parameters like packet size, rate of generation of packets ,motion
6,7 lines are used at what time this cbr traffic(i.e generating packets) to start and when to stop ....
Hope you understand now..
Last Possible error
hello
I got the nam output .
What can I infer from that animation?
1,7,13 are the malicious nodes..How do they become the blackholes in the animation ?Please explain
I got the nam output .
What can I infer from that animation?
1,7,13 are the malicious nodes..How do they become the blackholes in the animation ?Please explain
Solution In the given tcl file ,1,7,13 are the blackhole nodes.But we can see only node '1' dropping the packets in the simulation.
Because the roots established by aodv does not take in to account the other nodes.
We can check by changing the malicious nodes to 15 ..and observe the change.
Because the roots established by aodv does not take in to account the other nodes.
We can check by changing the malicious nodes to 15 ..and observe the change.
Many of you are getting the error
"num_nodes is set 25
INITIALIZE THE LIST xListHead
ns: _o39 blackhole1:
(_o39 cmd line 1)
invoked from within
"_o39 cmd blackhole1"
invoked from within
"catch "$self cmd $arg............"
I got the output on my first run ..
Then this error was shown..
I had updated my nam instance in between..i believe this may be the cause..also if u have installed ubuntu updates or anything ..u may also get this error..
So before making changes to aodv ,I had kept a copy of ns-allinone folder..So i recopied it and again applied the changes ..
make
make clean
make ./install
./configure
i think may be my makefile or some crucial files may have changed ,because of that i got the error..
If u do not have a copy uninstall ns2 and then install and try from scratch..
This code is 100% working :)
"num_nodes is set 25
INITIALIZE THE LIST xListHead
ns: _o39 blackhole1:
(_o39 cmd line 1)
invoked from within
"_o39 cmd blackhole1"
invoked from within
"catch "$self cmd $arg............"
I got the output on my first run ..
Then this error was shown..
I had updated my nam instance in between..i believe this may be the cause..also if u have installed ubuntu updates or anything ..u may also get this error..
So before making changes to aodv ,I had kept a copy of ns-allinone folder..So i recopied it and again applied the changes ..
make
make clean
make ./install
./configure
i think may be my makefile or some crucial files may have changed ,because of that i got the error..
If u do not have a copy uninstall ns2 and then install and try from scratch..
This code is 100% working :)
No comments:
Post a Comment