Adding Malicious Node to AODV
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
/* The Routing Agent */
class AODV: public Agent {
...
/*
* History management
*/
double PerHopTime(aodv_rt_entry *rt);
...
add following line
bool malicious;
With this variable we are trying to define if the node is malicious or not. In aodv.cc after
/*
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
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
if(argc == 2) {
Tcl& tcl = Tcl::instance();
if(strncasecmp(argv[1], "id", 2) == 0) {
tcl.resultf("%d", index);
return TCL_OK;
}
add following line
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.
$ns at 0.0 "[$mnode_(5) set ragent_] hacker"
You may add this line after
for {set i 0} {$i < $val(nn)} { incr i } {
$ns initial_node_pos $mnode_($i) 10
}
...
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
/*
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
// 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 don't ask me c/c++ questions, check your book first
October 29th, 2009 - 02:54
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
November 2nd, 2009 - 15:31
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.
December 10th, 2009 - 11:57
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?
January 3rd, 2010 - 16:26
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
January 16th, 2010 - 15:18
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
January 24th, 2010 - 00:57
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
January 26th, 2010 - 16:49
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.
January 29th, 2010 - 05:07
Thanks your guidance.
Best regards
Feiz
February 2nd, 2010 - 17:10
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..
February 2nd, 2010 - 19:02
its get corrected and i ran the tcl code…but i didnt see any changes…
5th node is the malicious node…but nothing happening for this node…
February 3rd, 2010 - 01:23
Resmy I don’t 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);
}
February 9th, 2010 - 02:14
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”
March 17th, 2010 - 15:50
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
March 23rd, 2010 - 09:58
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*)]+0×7): undefined reference to `hdr_raodv::offset_’
collect2: ld returned 1 exit status
make: *** [ns] Error 1
March 23rd, 2010 - 18:01
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*)]+0×7): undefined reference to `hdr_raodv::offset_’
collect2: ld returned 1 exit status
make: *** [ns] Error 1
March 24th, 2010 - 01:18
Ashwin I don’t 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?
April 1st, 2010 - 18:17
All in one is enough
April 2nd, 2010 - 03:18
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
April 5th, 2010 - 12:46
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
“_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”
meanwhile, I indeed add the
if(strcmp(argv[1], “hacker”) == 0) {
malicious = true;
return TCL_OK;
}
to the aodv.cc , but the same problem shown above.
otherwise, I also use the make clean, and make to launch, however, same problem shown above
thanks a lot!
April 5th, 2010 - 15:39
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.
April 5th, 2010 - 17:46
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], “hacker”) == 0) {
malicious = true;
return TCL_OK;
}
if(strncasecmp(argv[1], “start”, 2) == 0) {
btimer.handle((Event*) 0);
#ifndef AODV_LINK_LAYER_DETECTION
htimer.handle((Event*) 0);
ntimer.handle((Event*) 0);
#endif // LINK LAYER DETECTION
it is so confusion.
By the way, Mr. smartnode,
I want to get the traffic data of the normal sensor networks , is your aodv-802-15-4.tcl avaiable?
meanwhile, I need the traffic data of the sensor networks that has a wormhole attack or others,just want to get the attacked status, Could you please give me some suggestions for this simulation? I feel very difficult.
April 8th, 2010 - 00:36
Try with ns2.34
April 8th, 2010 - 09:36
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?
April 8th, 2010 - 09:37
I experienced same problem.
I exactly placed the code block on line 86.
But same error occurred.
April 8th, 2010 - 09:38
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 doesn’t 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.
April 8th, 2010 - 09:39
^^^^^
smartnode, please help me in solving the above problem….
April 12th, 2010 - 02:31
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 …
April 12th, 2010 - 11:00
hey…thank 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….
April 12th, 2010 - 11:01
hello smartnode
Kindly help in implementing watchdog concept please
April 16th, 2010 - 09:31
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*)]+0×7):
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
April 18th, 2010 - 17:42
thank u i have done it.
i had the same problem with tim,
add the
if(strcmp(argv[1], “hacker”) == 0) {
malicious = true;
return TCL_OK;
}
to aodv.cc and the same error
but now i found the answer for we should make sure that we use the new compiled ns to run the .tcl