Vous êtes sur la page 1sur 12

elmurod.

net
Seek knowledge from the cradle to the grave

Navigate to...

NS2: Adding Malicious Node to AODV


October 24, 2009
Article

Many people have asked me how to implement malicious drop in AODV. I have decided to write simple code for adding malicious node in AODV ( or in any routing protocol).
First you need to modify aodv.cc and aodv.h files. In aodv.h after
1
2
3
4
5
6
7
8

/* The Routing Agent */


class AODV: public Agent {
...
/*
* History management
*/
double PerHopTime(aodv_rt_entry *rt);
...

add following line


1

bool

malicious;

With this variable we are trying to define if the node is malicious or not. In aodv.cc after
1
2
3
4
5
6
7
8

/*
Constructor
*/
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;
...

add following line


1

malicious = false;

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
1
2
3
4
5
6
7

if(argc == 2) {
Tcl& tcl = Tcl::instance();

if(strncasecmp(argv[1], "id", 2) == 0) {
tcl.resultf("%d", index);
return TCL_OK;
}

add following line


1
2
3
4

if(strcmp(argv[1], "hacker") == 0) {
malicious = true;
return TCL_OK;
}

Now we will do some work in TCL to set a malicious node. Using script in my post , we add following line to set node 5 as malicious node.
1

$ns at 0.0 "[$mnode_(5) set ragent_] hacker"

You may add this line after


1
2

for {set i 0} {$i < $val(nn)} { incr i } {


$ns initial_node_pos $mnode_($i) 10

converted by Web2PDFConvert.com

3
4

}
...

Alright, 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
1
2
3
4
5
6
7
8
9

/*
Route Handling Functions
*/

void
AODV::rt_resolve(Packet *p) {
struct hdr_cmn *ch = HDR_CMN(p);
struct hdr_ip *ih = HDR_IP(p);
aodv_rt_entry *rt;
...

We add a few lines


1
2
3
4
5

// if I am malicious node
if (malicious == true ) {
drop(p, DROP_RTR_ROUTE_LOOP);
// DROP_RTR_ROUTE_LOOP is added for no reason.
}

And implementing malicious node is done. I hope the post will be helpful to design your secure routing protocol.
P.S. Guys please dont ask me c/c++ questions, check your book first
Categories: Network Simulator (NS2)
Tags: AODV, malicious node, NS2, routing

31 COMMENTS

Devi G

October 29, 2009 at 2:54 am Respected Sir,


One humble ques.. How long did it take for u to work in NS confidently and are there any specific works that help us explore it safely?
Awaiting ur reply

smartnode

November 2, 2009 at 3:31 pm To work in NS confidently depends on how hard you work. Yet, not less than several months. Best way to learn is analyze whole source code of some protocol (e.g.
DSR or AODV). That will help a lot.

shen.wen

December 10, 2009 at 11:57 am I modified aodv.cc and aodv.h as you demonstrate above,while run the aodv script ,
ns: _o112 hacker:
(_o112 cmd line 1)
invoked from within
_o112 cmd hacker
invoked from within
catch $self cmd $args ret
converted by Web2PDFConvert.com

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 _o112 line 2)
(SplitObject unknown line 2)
invoked from within
_o112 hacker
what is the meaning of this?

MEHDI

January 3, 2010 at 4:26 pm I followed your step to change aodv.cc and aodv.h. however, when i compile tcl script, this error occurred:
num_nodes is set 500
INITIALIZE THE LIST xListHead
ns: _o112 hacker:
(_o112 cmd line 1)
invoked from within
_o112 cmd hacker
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 _o112 line 2)
(SplitObject unknown line 2)
invoked from within
_o112 hacker
when i modified aodv file then recompile ns2 and the run tcl script again. the error occurred again:
i use this command for recompile ns2:
make clean
make
sudo make install
please, help me. It is really really really important for my thesis

smartnode

January 16, 2010 at 3:18 pm Shen, Mehdi sorry guys. I have made mistake here, which I have fixed.
You must add following code
converted by Web2PDFConvert.com

if(strcmp(argv[1], hacker) == 0) {
malicious = true;
return TCL_OK;
}
In the following place
if(argc == 2) {
Tcl& tcl = Tcl::instance();
if(strncasecmp(argv[1], id, 2) == 0) {
tcl.resultf(%d, index);
return TCL_OK;
}
// ABOVE CODE GOES HERE :
if(strcmp(argv[1], hacker) == 0) {
malicious = true;
return TCL_OK;
}

}
I believe it should work then

MEHDI

January 24, 2010 at 12:57 am Hello


Thank you for your attention. I change the place of code. it work correct .
I read AODV code in ns2. I want malicious node flood the network by RREQ. I review AODV C++ code but I did not find function that perform broadcasting. I see
network wide braodcasting in AODV.cc. I think, the solution is adding one function that flood RREQ. Is this correct?
Best regards
Mehdi Feiz

smartnode

January 26, 2010 at 4:49 pm sendRequest() is routine which sends RREQ messages. Just add timer function and run sendRequest() in the timer. or You can just call sendRequest() whenever
you need.

MEHDI

January 29, 2010 at 5:07 am Thanks your guidance.


Best regards
Feiz

converted by Web2PDFConvert.com

Resmy

February 2, 2010 at 5:10 pm Sir i too tried to modify the codes in aodv.cc and aodv.h to introduce malicious nodes..
But the same error what Mehdi told occured again whyI made the modification u told
but its not working..can u plz reply..

Resmy

February 2, 2010 at 7:02 pm its get corrected and i ran the tcl codebut i didnt see any changes
5th node is the malicious nodebut nothing happening for this node

smartnode

February 3, 2010 at 1:23 am Resmy I dont know what you are trying to do. Do you want the node 5 drop all packets those go through this node, or do you want the node 5 flood useless RREQ
continuously? if the latter one is what you want, the above code does not provide it. You have to make more changes. Either you have to create a time function or
the simple method is following code, wich sends RREQ to node 0 at every BCAST_ID_SAVE period.
void
BroadcastTimer::handle(Event*) {
agent->id_purge();
// add form here
if (agent->malicious == true ) {
agent->sendRequest(0);
}
// to here Scheduler::instance().schedule(this, &intr, BCAST_ID_SAVE);
}

Muralidharan

February 9, 2010 at 2:14 am hi..


I modified DSR protocol to inject Blackhole attack. the modified version acts as a new protocol. i recompiled all the files and also made necessaryt changes..
makefile s succesfully created.
But when i run a tcl file with the new protocol it shows the following error.. can u help me how to solve this..
blackholeDSR is the new protocol
num_nodes is set 7
warning: Please use -channel as shown in tcl/ex/wireless-mitf.tcl
INITIALIZE THE LIST xListHead
Starting Simulation
ns: _o14 start-blackholedsr:
(_o18 cmd line 1)

converted by Web2PDFConvert.com

invoked from within


_o18 cmd startblackholedsr
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 _o18 line 2)
(SplitObject unknown line 2)
invoked from within
$dsr_agent_ startblackholedsr
(procedure _o14 line 3)
(SRNodeNew start-blackholedsr line 3)
invoked from within
_o14 start-blackholedsr

irvan

March 17, 2010 at 3:50 pm Dear Sir


Im student from Indonesia, i want to make my final project in modifying ad hoc routing protocol too
In what u have done? do you have such literature of your project above to improve my knowledge
im starting to understand how aodv work by studying its C++ code
Thank for your help

Ashwin Perti

March 23, 2010 at 9:58 am Sir


When I run make command I got the following error
clcl-1.19 -ltclcl -L/home/ashwin/ns-allinone-2.34/otcl -lotcl -L/home/ashwin/ns-allinone-2.34/lib -ltk8.4 -L/home/ashwin/ns-allinone-2.34/lib -ltcl8.4 -lXext lX11 -lnsl -ldl -lm -lm
trace/cmu-trace.o: In function `hdr_raodv::access(Packet const*):
cmu-trace.cc:(.text._ZN9hdr_raodv6accessEPK6Packet[hdr_raodv::access(Packet const*)]+0x7): undefined reference to `hdr_raodv::offset_
collect2: ld returned 1 exit status
make: *** [ns] Error 1

Ashwin Perti

March 23, 2010 at 6:01 pm When make command is executed it is giving the following error:
allinone-2.34/lib -ltk8.4 -L/home/ashwin/ns-allinone-2.34/lib -ltcl8.4 -lXext -lX11 -lnsl -ldl -lm -lm
trace/cmu-trace.o: In function `hdr_raodv::access(Packet const*):
converted by Web2PDFConvert.com

cmu-trace.cc:(.text._ZN9hdr_raodv6accessEPK6Packet[hdr_raodv::access(Packet const*)]+0x7): undefined reference to `hdr_raodv::offset_


collect2: ld returned 1 exit status
make: *** [ns] Error 1

smartnode

March 24, 2010 at 1:18 am Ashwin I dont understand what you are talking about. What are you trying to compile? Read your question yourself, and tell me do you understand it? You did make
command of what? Why?

Aditi

April 2, 2010 at 3:18 am Sir,


Do i need to install ns-2 by parts to make it work properl,i hv done it using all in one package.
And, how to introduce wormhole attack in ns-2

smartnode

April 1, 2010 at 6:17 pm All in one is enough

tim

April 5, 2010 at 12:46 pm Hi,smartnode


I modified the aodv.cc & aodv.h & aodv_802_15_4.tcl according to your method above.
However, I meet the same problem with the Dr.MEHDI.
num_nodes is set 500
INITIALIZE THE LIST xListHead
ns: _o112 hacker:
(_o112 cmd line 1)
invoked from within

smartnode

April 5, 2010 at 3:39 pm Where did you guys add following lines?
if(strcmp(argv[1], hacker) == 0) {
malicious = true;
return TCL_OK;
converted by Web2PDFConvert.com

is it on the line 86 of the aodv.cc file? If yes, it is hard to understand why this error happens.

tim

April 5, 2010 at 5:46 pm yes, on the line 86.


AODV::command(int argc, 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;
}
// ABOVE CODE GOES HERE :
if(strcmp(argv[1],

jin

April 8, 2010 at 9:36 am I experienced same problem with tim.


I installed ns 2.33
I exactly placed if(strcmp(argv[1], hacker)==0){} structure in the right place line86.
What is the problem?

smartnode

April 8, 2010 at 12:36 am Try with ns2.34

jin kim

April 8, 2010 at 9:37 am I experienced same problem.


I exactly placed the code block on line 86.
But same error occurred.

rohitkg

April 8, 2010 at 9:38 am converted by Web2PDFConvert.com

i want to make a node behave as blackhole node, using the above technique. The above method drops all packets that go through it, but it doesnt kind of forces a
packet to go through it by sending a high sequence number.
For that, i have done this within this fn. AODV::recvRequest(Packet *p):
if(malicious==true) {
sendReply(rq->rq_src, // IP Destination
1, // Hop Count
index, // Dest IP Address
4294967295, // Max. Dest Sequence Num if the node is malicious
MY_ROUTE_TIMEOUT, // Lifetime
rq->rq_timestamp); // timestamp
}
else {
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
}
and removed
if(malicious == true) {
drop(p, DROP_RTR_ROUTE_LOOP);
}
from rt_resolve() fn.
Now, what changes do i need to make, so that the code can distinguish data packets and management packets, so that it could drop the data packets.

rohitkg

April 8, 2010 at 9:39 am ^^^^^


smartnode, please help me in solving the above problem.

smartnode

April 12, 2010 at 2:31 am Rohitg, if you want to drop only data packets you need to check packet type reger HDR_CMN for more info.
Raj i am NOT going to do what you asked. It is whole algorithm

rahul

April 12, 2010 at 11:00 am heythank u for this post.its really helping but i am required to create malicious node in a 20 node tcl script in DSR protocol.plz help me out with that.thanking u
in anticipation urgent.

converted by Web2PDFConvert.com

Raj

April 12, 2010 at 11:01 am hello smartnode


Kindly help in implementing watchdog concept please

Daniel Zvolensky

April 16, 2010 at 9:31 am Hi Smartnode.


I am trying implement my own MAODV protocol into NS-2.34. I already have done structure of packets, routing tables and now I would like programme
communication between nodes. So I created class node in file node.h where I define the IP address and seq. num of node and functions such as void
recv(Packet*, Handler*). In file node.cc in function void recv(Packet* p, Handler* h) I put following:
void node::recv(Packet* p, Handler* h)
{
struct hdr_maodv* maodvh = HDR_MAODV(p);
struct hdr_ip* iph = HDR_IP(p);
}
..and when I make compilation, the following error appears:
In function hdr_ip::access(Packet const*):
node.cc: (.text.ZN6hdr_ip6accessEPK6Packet[hdr_ip::access(Packet const*)]+0x7):
undefined reference to hdr_ip::offset_
collect2: ld returned 1 exit status
Could you help me? Do you have any idea where could be a problem?
Regards
Daniel

velkan

April 18, 2010 at 5:42 pm thank u i have done it.


i had the same problem with tim,
add the
if(strcmp(argv[1],

Blogroll
Mobile Embedded System Lab.
LifeMap Project
Yohan Chon
converted by Web2PDFConvert.com

Hyojeong Shin

Categories
Algorithms
Android
Linux / Unix
Network Simulator (NS2)
Programming
Research Issues
Uncategorized

Meta
Log in
Entries RSS
Comments RSS
WordPress.org

Search
Search

Copyright elmurod.net 2016 | Theme by Theme in Progress | Proudly powered by WordPress

converted by Web2PDFConvert.com

converted by Web2PDFConvert.com

Vous aimerez peut-être aussi