Vous êtes sur la page 1sur 8

M Y W OR KS

CON TA CT M E

Search

Re-gaining Root Access after Cupcake Install

NS2 : sim ple m ethod to analy ze traces

AD V ER TIS EM ENT CA TEGO R IES

NS2: Adding Malicious Node to AODV


by E L M O on O C TO B ER 24 , 200 9 3 1 C O MMENTS

Android Linux / Unix Network Simulator (NS2)

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 / * T h eR o u t i n gA g e n t* / c l a s sA O D V :p u b l i cA g e n t{ . . . / * *H i s t o r ym a n a g e m e n t * / d o u b l e P e r H o p T i m e ( a o d v _ r t _ e n t r y* r t ) ; . . .

Programming Research Issues Uncategorized


B L OGR O LL

Mobile Embedded System Lab. LifeMap Project Yohan Chon Hyojeong Shin

add following line 1 b o o l m a l i c i o u s ;


ME TA

With this variable we are trying to define if the node is malicious or not. In aodv.cc after 1 / * 2 C o n s t r u c t o r 3 * / 4 A O D V : : A O D V ( n s a d d r _ ti d ):A g e n t ( P T _ A O D V ) , b t i m e r ( t h i s ) , h t i m e r ( t h i s ) ,n t i m e r ( t h i s ) ,r t i m e r ( t h i s ) ,l r t i m e r ( t h i s ) ,r q u e u e ( ) { 5 i n d e x=i d ; 6 s e q n o=2 ; 7 b i d=1 ; 8 . . . add following line 1 m a l i c i o u s=f a l s e ; 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 i f ( a r g c= =2 ){ 2 T c l &t c l=T c l : : i n s t a n c e ( ) ; 3 4 i f ( s t r n c a s e c m p ( a r g v [ 1 ] ," i d " ,2 )= =0 ){ 5 t c l . r e s u l t f ( " % d " ,i n d e x ) ; 6 r e t u r nT C L _ O K ; 7 } add following line 1 i f ( s t r c m p ( a r g v [ 1 ] ," h a c k e r " )= =0 ){ 2 m a l i c i o u s=t r u e ; 3 r e t u r nT C L _ O K ; 4 } 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 $ n sa t0 . 0" [ $ m n o d e _ ( 5 )s e tr a g e n t _ ]h a c k e r " Y ou may add this line after

Log in Entries RSS Comments RSS WordPress.org

1 2 3 4

f o r{ s e ti0 }{ $ i& l t ;$ v a l ( n n ) }{i n c ri}{ $ n si n i t i a l _ n o d e _ p o s$ m n o d e _ ( $ i )1 0 } . . .

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 / * R o u t eH a n d l i n gF u n c t i o n s * / v o i d A O D V : : r t _ r e s o l v e ( P a c k e t* p ){ s t r u c th d r _ c m n* c h=H D R _ C M N ( p ) ; s t r u c th d r _ i p* i h=H D R _ I P ( p ) ; a o d v _ r t _ e n t r y* r t ; . . .

We add a few lines 1 / /i fIa mm a l i c i o u sn o d e 2 i f( m a l i c i o u s= =t r u e){ 3 d r o p ( p ,D R O P _ R T R _ R O U T E _ L O O P ) ; 4 / /D R O P _ R T R _ R O U T E _ L O O Pi sa d d e df o rn or e a s o n . 5 } 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
Tagge d with: AODV malicious node NS 2 routing

If you enjoyed this article, please consider sharing it!

31 Responses to ns2: adding malicious node to aodv


Devi G says:
October 2 9 , 2 009 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 says:
Nov em ber 2 , 2 009 at 3 :3 1 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 says:
Decem ber 1 0, 2 009 at 1 1 :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 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 says:
January 3 , 2 01 0 at 4 :2 6 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 says:
January 1 6 , 2 01 0 at 3 :1 8 pm

Shen, Mehdi sorry guys. I have made mistake here, which I have fixed. You must add following code 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 says:
January 2 4 , 2 01 0 at 1 2 :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 says:
January 2 6 , 2 01 0 at 4 :4 9 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 says:
January 2 9 , 2 01 0 at 5:07 am

Thanks your guidance. Best regards Feiz

Resmy says:
February 2 , 2 01 0 at 5:1 0 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 says:
February 2 , 2 01 0 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 says:
February 3 , 2 01 0 at 1 :2 3 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 says:
February 9 , 2 01 0 at 2 :1 4 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) 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 says:
March 1 7 , 2 01 0 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 says:


March 2 3 , 2 01 0 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-allinone2.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*)]+07): undefined reference to `hdr_raodv::offset_ collect2: ld returned 1 exit status make: *** [ns] Error 1

Ashwin Perti says:


March 2 3 , 2 01 0 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*): cmu-trace.cc: (.text._ZN9hdr_raodv6accessEPK6Packet[hdr_raodv::access(Packet const*)]+07): undefined reference to `hdr_raodv::offset_ collect2: ld returned 1 exit status make: *** [ns] Error 1

smartnode says:
March 2 4 , 2 01 0 at 1 :1 8 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 says:
April 2 , 2 01 0 at 3 :1 8 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 says:
April 1 , 2 01 0 at 6 :1 7 pm

All in one is enough

tim says:
April 5, 2 01 0 at 1 2 :4 6 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 says:
April 5, 2 01 0 at 3 :3 9 pm

Where did you guys add following lines? if(strcmp(argv[1], hacker) == 0) { malicious = true; return TCL_OK; } is it on the line 86 of the aodv.cc file? If yes, it is hard to understand why this error happens.

tim says:
April 5, 2 01 0 at 5:4 6 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 says:
April 8, 2 01 0 at 9 :3 6 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 says:
April 8, 2 01 0 at 1 2 :3 6 am

Try with ns2.34

jin kim says:


April 8, 2 01 0 at 9 :3 7 am

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

rohitkg says:
April 8, 2 01 0 at 9 :3 8 am

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 says:
April 8, 2 01 0 at 9 :3 9 am

^^^^^ smartnode, please help me in solving the above problem.

smartnode says:
April 1 2 , 2 01 0 at 2 :3 1 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 says:
April 1 2 , 2 01 0 at 1 1 :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.

Raj says:
April 1 2 , 2 01 0 at 1 1 :01 am

hello smartnode Kindly help in implementing watchdog concept please

Daniel Zvolensky says:


April 1 6 , 2 01 0 at 9 :3 1 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*)]+07): 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 says:
April 1 8, 2 01 0 at 5:4 2 pm

thank u i have done it. i had the same problem with tim, add the if(strcmp(argv[1],

2012 Elmurod A. Talipov

Vous aimerez peut-être aussi