Search This Blog

Blackhole Attack in ns-2

Labels: , , ,

Reactions: 

The patch provided in this post enables a ns-2 user to simulate "Blackhole Attack in ns-2" for Mobile Ad hoc Network (MANET) Simulations. Blackhole attack has been implemented using Ad hoc On demand Distance Vector (AODV) routing protocol. As of now the patch will only work on ns-2.35 version! Patches for older versions of ns-2 will be provided soon.

Material provided with this post:

1. A patch to simulate Blackhole attack in ns-2.35 and steps to apply that patch.
2. Sample TCL script to demonstrate how to configure a malicious nodes.
3. AWK Script that calculates Packet Delivery Ratio (to confirm whether the code really works!)

Follow the steps given below to apply Blackhole patch to ns-2.35:

1. Download ns-allinone-2.35.tar.gz

2. Download Blackhole.patch

3. Unzip ns-allinone-2.35.tar.gz. You will get a folder named ns-allinone-2.35

4. Paste the downloaded Blackhole patch in the above mentioned folder.

5. Give the following command:

patch -p1 -t < Blackhole.patch

6. Go in ns-allinone-2.35 via terminal and give the following command (It is always recommended to be in root mode while giving the below command):

./install

If you already have an installed copy of ns-allinone-2.35, then follow the steps given below to apply the Blackhole patch:

1. Paste the downloaded Blackhole patch in ns-allinone-2.35 directory.

2. Give the following command:

patch -p1 -t < Blackhole.patch

3. Go in ns-allinone-2.35/ns-2.35 directory and give the following commands:

./configure
make clean
make
make install

You are done with it!

Sample TCL Script and AWK Script to verify the working of Blackhole Patch:

Download blackhole.tcl and pdf.awk from the links given below and keep them in the same folder:

blackhole.tcl

pdf.awk

How to use these files for verification?

I. Open blackhole.tcl and comment the following line (remember: # is used for commenting)

$ns at 0.0 "[$n5 set ragent_] hacker"

$n5 in the above line represents node 5. The word "hacker" has been used to represent "attacker". You may try making any other node as an hacker also. 

0.0 in the above line indicates that from beginning of the simulation itself, node 5 acts an attacker in the network. Blackhole attack is mainly launched during the Route Establishment phase and hence it is important to configure a node to be an attacker from the beginning of the simulation.

We comment the above line so that we can first analyze the behavior of a normal network without Blackhole attack. At a later point, we will uncomment this line and analyze the behavior of the network when it is attacked by node 5.

II. Run blackhole.tcl by giving the following command:

ns blackhole.tcl

III. Give the following command to run the pdf.awk and note down the results:

awk -f pdf.awk blackhole.tr

IV. Open blackhole.tcl again and uncomment the line which you commented earlier (i.e., this time the attacker will attack the network)

V. Run blackhole.tcl by using the same command as mentioned in Step II.

VI. Note down new results by running the pdf.awk as mentioned in Step III.

You would observe that none of the packets are delivered and ratio turns out to be zero.

You can also verify the working of the patch by observing packet drops in NAM window. Here is one snapshot which shows the same:

[Click on the Image to enlarge]

Acknowledgements: 

1. Thanks to E. Talipov's link: http://elmurod.net/en/index.php/archives/196 using which a major part of the patch has been designed.

2. Thanks to Gaurav Gupta for designing the sample TCL script named "blackhole.tcl" and also for his assistance in shaping up this patch.

3. Thanks to Knud F. L. for his crucial feedback on the design of the patch.

Hope it helps.

Regards,
Mohit P. Tahiliani

Comments (76)

thanks a lot sir

Thanks sir its very helpful for our phd scholar

Sir,

Can you please say some method by which this can be prevented..
That is if the node A discovers that the node B to which it has forwarded the packet is not trustworthy, it (node A)should not forward the packet to B.. how can it be done???

Thanks sir

Hello Sir,
I'm working on LEACH implementation in ns2.34.
Now i got stucked with cluster forming and don't know how to form cluster and select cluster head. could you please help me!!

hi sir,

i got the following error while running blackhole.tcl
kindly help me to solve it


num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"

hi sir,
can you have the patch for wormhole attack
will you please provide the link or tutorial for learning its development procedure..

hi..
sir i want to implement grayhole and sinkhole attack
on aodv and dsr using
ns2.35..How can i implement...please help me... Please,Can u send me
ns2 code or patch for implementation of these attacks on
aodv and dsr routing protocol in manet...
thanks in advance

Sir,

I am also getting the same error while running blackhole.tcl which is as follows.
kindly suggest some solution


num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"

Hello sir, I am student of Walchand College Of Engg, Sangli, This semester I am doing project on ns2 named as "Detection And Localization Of Spoofing Attackers in Wireless Network". But I facing the problem in giving unique id for each node for detecting attackers, And I am not also aware of .cc & .h file in ns2.. So please help me. I am kindly waiting for your replay

same error in blackhole patch
[divan@localhost blackhole]$ ns blackhole.tcl
num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"

@Anjana, Arminder Kaur and Divan Raimagia - Probably you all did not give the final command of recompilation i.e.,

sudo make install

Please give this command and try again!

@Anjana - As of now I do not have a code for wormhole attack.

@Monika Verma - I am not sure about the code for sinkhole but for grayhole you can get some assistance from the following link:

http://naren.ketantada.com/category/ns2/

@Ujwala Gavit - ns-2 gives a unique id for every node anyways. May be you can try looking at node.cc and node.h in the ns-2.xx/common directory.

Hope it helps.

Regards,
Mohit P. Tahiliani

hello mohit sir,
i hv used the patch and install it but while running it is giving segmentation fault even without malicious node.. plz reply me soon

Sir,
I got the following error while running blackhole.tcl

num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"

The error still occurs even after giving the command sudo make install. Pls help me with it ..

Hey sir, Your Blog is really helpful for us. Can you give us a solution to our problem we are facing. We are working on a solution against blackhole attacks.But we don`t know how to create a Patch??
Can you guide us how to implement the solution using patch

Hello sir, I am a final year student of JNTUH college of engineering.currently i am doing a project titled "Prevention of black hole and sink hole attacks in manet".I have launched blackhole attack in ns2 using patch provided by you.Can you please help me get few solutions for black hole attack in manet ?

@Shraddha - There is no problem in the patch as per my understanding because it has been several times. I suggest you to try in a fresh copy of ns-2.

@Liya - Try giving the following command:

sudo make install

@Payal - Here is the link that explains how to create a patch:

http://linux.byexamples.com/archives/163/how-to-create-patch-file-using-patch-and-diff/

On a side note: First you need to code your solution and then you have to create a patch.

@Techne: There are quite a good number of papers available that present different ways to solve the problem of Blackhole attack. I suggest you to go through such papers and frame your solutions.

Hope it helps.

Regards,
Mohit P. Tahiliani

Hello Sir,
Thanks a lot for the patch and references that helped me a lot.

one more request I have, can you help me with GreyHole attack simulation. I searched for it but not able find anything helpful. Please share some information regarding the same.
(or a patch would be better ;) )

@Pranav - I haven't worked much on these attacks.

But I found one code for Gray hole attack on the following link:

http://www.dokurer.net/files/others/grayholeaodv.zip

I am not sure about the correctness of this code, but thought of sharing with you so that you can try testing it.

Hope it helps.

Regards,
Mohit P. Tahiliani

hello sir,
can we use the same "black hole attack in ns2 for MANET" code for wireless sensor networks?

@Ramya - Yes, you can use it provided you select AODV as your routing protocol for WSN.

Hope it helps.

Regards,
Mohit P. Tahiliani

Thank you sir

hello sir,
I have installed the given ns-allinone2.35.tar.gz in my system.But after installing,when I check in terminal window by giving ns,I am getting "SEGMENTATION FAULT". What could be the reason and can you help me sir?


regards,
Ramya Sundararaj

@Ramya - The installation may be incomplete.

Are you sure your installation did not give any errors?

Regards,
Mohit P. Tahiliani

sir,

can i get the procedure for blackhole attcak in dsr protocol??

Hello sir.
I have installed NS2 successfully in my system but while trying to run awk script,I came to know it is not installed.while trying to install it I received a warning that "the following packages cannot be authenticated"

Regards,
Ramya Sundararaj

can you please help us sir?

Regards,
Ramya Sundararaj

@Ramya - There is no need to install AWK separately. It comes along with the OS.

Try running any matching AWK script.

Hope it helps.

Regards,
Mohit P. Tahiliani

@Rani - The procedure remains same as the one for AODV. However, you may have to study the C++ code of DSR in ns-2 first and then try implementing Blackhole attack.

Hope it helps.

Regards,
Mohit P. Tahiliani

thank you sir

regards,
Ramya Sundararaj

i need the tcl script for idsaodv that u have u have created to prevent blackhole attack

@Michael - I have not created idsaodv TCL script for blackhole attack implementation. Blackhole attack has been implemented in C++ and sample TCL script for same has been provided in this post itself.

Hope it helps.

Regards,
Mohit P. Tahiliani

ok so how best can i detect and remove blackhole attack or a simple method to remove or minimize blackhole attack that you have created

@Michael - This patch only helps you to launch the "blackhole attack in ns-2 using AODV".

Methods to detect the attack and prevent it are not implemented because each researcher has his/her own way of detecting or preventing this attack.

Hope it helps.

Regards,
Mohit P. Tahiliani

Hi sir, Thanks for your share but I have problem. Plz help me..
When I used to command: sudo make install. I got the following:
for d in /usr/local/man/man1; do \
if [ ! -d $d ]; then \
mkdir -p $d ;\
fi;\
done
/usr/bin/install -c -m 755 ns /usr/local/bin
/usr/bin/install: cannot stat ‘ns’: No such file or directory
Then i got the following error while running blackhole.tcl
kindly help me to solve it


num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"
Can you help me. Thanks so much

@Vo Thi - The error that you got while giving "sudo make install" shows that your "make" was not successful and it did not create a new "ns" object.

This means there is an error during "make" which you should resolve first and only after it completes successfully, you should run "sudo make install".

Since "ns" is not created - TCL script would certainly throw an error.

Hope it helps.

Regards,
Mohit P. Tahiliani

Thanks sir, I got command "sudo make install" again and I have solve:
for d in /usr/local/man/man1; do \
if [ ! -d $d ]; then \
mkdir -p $d ;\
fi;\
done
/usr/bin/install -c -m 755 ns /usr/local/bin
/usr/bin/install -c -m 644 ns.1 usr/local/man/man1
Then i got the following error while running blackhole.tcl
kindly help me to solve it
num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"
Sorry to bother, but I very need your blackhole attack. So can you help me a solution to solve this problem.
Thanks so much and Best Regards,

@Vo Thi - This shows that the patch has not been applied correctly.

I recommend you to install a new copy of ns-2 and then try applying the patch again. Follow the steps carefully which are given on this post and then try again.

Also check whether you are using the correct version of ns-2 which has been mentioned in this post.

Hope it helps.

Regards,
Mohit P. Tahiliani

hello sir

i tried to add new protocol from this link-http://elmurod.net/en/index.php/archives/category/network-simulator-ns2

but i am getting errors so
i want to ask that can we directly change in aodv's .cc and .h our code according to our develop technique and can we get result???

@Ankur - Yes, you can directly change the .cc and .h files of AODV. After your changes are done, re-compile ns-2. If you don't re-compile - changes that you made will not be visible in the results.

Hope it helps.

Regards,
Mohit P. Tahiliani

sir
i am trying to follow the steps mentioned but on running the "patch -p1 -t ..." command i get an error saying program "patch" not installed .
what does it mean ?
should i install the patch ? will it hinder ns2 installation ?

i tried installing patch file then got the error:
Hunk #1 failed at 82
Hunk #2 failed at 144
...
2 out of 5 hunks failed .

Sir how to remove this error.

@Shiven - Which OS are you using? Have you updated the packages of that OS?

Regarding the Hunk failed error - are you sure you are using ns-2.35? Make sure you place the downloaded patch in the correct directory and then give the "patch" command.

Another thing is do not try to apply the patch again and again on same ns-2. If there is an error - remove whole ns-2 and then try patching on newer ns-2.

Hope it helps.

Regards,
Mohit P. Tahiliani

Thankyou sir
I am using unbuntu 12.04 .
i applied the patch in ns-allinone-2.35 folder.
i downloaded ns2.35 from the link in your post.
sir, inspite of the error i ran the code and it showed "r" parameter zero when the attack is implemented and 1238 otherwise.
Is this right?
is this how it is supposed to be ?
Thankyou in advance for your help

@Shiven - Yes, there won't be any received packets.

That's an anticipated result.

I hope the patch is working fine for you now.

Regards,
Mohit P. Tahiliani

hello sir

i tried to use protocol AOMDV for blackhole attack, but i am getting errors so i want to ask, can u help me how to modified AOMDV with blackhole attack? can i get patch for AOMDV. Thankyou in advance for your help

Sir,
CAn I get ns2.35 tcl script fro wsn please.

@Qodri - I have not designed a patch for Blackhole attack with AOMDV. What are the errors that you are getting?

@Meena - Try running a sample Zigbee TCL file available in

ns-2.xx/tcl/ex/wpan

Run only the files that have .tcl extension.

Hope it helps.

Regards,
Mohit P. Tahiliani

Please help..i m getting error in make
make: *** No rule to make target `sp/SP.o', needed by `ns'. Stop.

@Vaibhavi - Try doing this:

make clean

and then give:

make

Hope it helps.

Regards,
Mohit P. Tahiliani

Hi sir,

Can you please help me in the implementation of black hole attack in manet for DSR protocol?

Thank you
Akhilesh

hello sir,
i am getting following error on giving ./configure in ns2.35
configure: error: Installation of tcl seems incomplete or can't be found automatically.
Please correct the problem by telling configure where tcl is
using the argument --with-tcl=/path/to/package
(perhaps after installing it),
or the package is not required, disable it with --with-tcl=no.
arshad@arshad-VPCEG2AEN:~/ns-allinone-2.35/ns-2.35$ make clean
Makefile.in is newer than Makefile.
You need to re-run configure.
false
Makefile:439: recipe for target 'Makefile' failed
make: *** [Makefile] Error 1
plz help

can i use this blackhole code for AOMDV ( Multipath)....?

hello sir,
I am working on hybrid protocols for m2m communication. Those protocols are csma and tdma and ieee 802.11 dcf 4 way handshake. how should i simulate these protocols using ns2. can you give me some help regarding hybrid protocols design at mac layer?

@Mitul - No, this code cannot be used as it is for AOMDV. You may have change it as per your requirement.

@Akshat - I haven't worked on hybrid protocols at MAC layer, so cannot help you much with it.

Regards,
Mohit P. Tahiliani

sir please give me the explaination for the blackhole.path file coding

sir,can you provide code to detect packet dropping node in ns2??

sir, please give me the wormhole attack patch in ns2

Hi..I m doing project in MANET. in that i want to send bait packets(packet with fake destination address) to bait or catch malicious nodes.can u provide code for this.

Sir can u help me on how to clone a protocol in ns2..

Dear Sir
Iam looking for prevention of blackhole and wormhole attack plgp code can u assist me please sir iam dam working hard on my projet at b,.teh level

sir, how to rectify this error in make install command?
for d in /usr/local/man/man1; do \
if [ ! -d $d ]; then \
mkdir -p $d ;\
fi;\
done
/usr/bin/install -c -m 755 ns /usr/local/bin
/usr/bin/install: cannot remove `/usr/local/bin/ns': Permission denied
make: *** [install-ns] Error 1

Hi Sir,

Thank you for the above code.
Can you please give me or assist me for blackhole attack on DSR and ZRP protocols patch files.

Thank you

Hello Sir,

Can you please help me to understand energy model in ns2..if u have code please give me sir

Hello Sir,

Can you help me to understand about solar sensors..How i can implement solar sensors in ns2..if u have code please give me sir

plzzzzzzzzzzz ... help m ... implementation solution black hole in aomdv o aomdv plzzz

kindly help me to do blackhole attack in ns2. Asking password for ksss if i use sudo make install. kindly help sir

hello. plzzzz help me

i have problem in "make install"

for d in /usr/local/man/man1; do \
if [ ! -d $d ]; then \
mkdir -p $d ;\
fi;\
done
mkdir: cannot create directory `/usr/local/man/man1': Permission denied
make: *** [dirs] Error 1


how can solve it? plz help

Hello Sir,

i have implemented blackhole attack successfully. but my task is to prevent black hole attack. so plz sir provide me help for preventing blackhole attack.

if you dont have code then provide me some ways by which i can prevent black hole attack.

plzz sir...

email id: deepak.patidar007@gmail.com

Hii sir,


same error in blackhole patch
[divan@localhost blackhole]$ ns blackhole.tcl
num_nodes is set 7
INITIALIZE THE LIST xListHead
ns: _o107 hacker:
(_o107 cmd line 1)
invoked from within
"_o107 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 "_o107" line 2)
(SplitObject unknown line 2)
invoked from within
"_o107 hacker"

My Normal work is happened correct..but when i uncomment this below line..attacker does not attack and packet sends normally to destination.
$ns at 0.0 "[$n5 set ragent_] hacker"


Please help me sir..

Thanks a lot sir i have successfully run the blachkhole patch , blackhole.tcl file and got the result with attack and without attack.

but sir i want to implement the sinkhole attack so what i can do to get the result using AODV routing protocol.'


thanks again sir , pls do the need full to me for sinkhole attack.

neelam@neelam-Lenovo-G550:~/ns-allinone-2.35/ns-2.35/grayholeaodv$ ns grayholeaodv.tcl
invalid command name "Agent/rtProto/grayholeAODV"
while executing
"Agent/rtProto/grayholeAODV instproc init args {
$self next $args
} "
(file "grayholeaodv.tcl" line 19)
find this type of error when i run the grayhole.tcl file

pls do needful to me

neelam@neelam-VirtualBox:~/Downloads/Mohit P. Tahiliani/blackhole attack ns2.35$ ns
Sir ,

when i run balckhole.tcl , i have command the node 5 attacker line #===================================
# Set node 5 as attacker
#===================================
#$ns at 0.0 "[$n5 set ragent_] hacker"

end the nam file
i given following error pls help me


blackhole.tcl
num_nodes is set 7
INITIALIZE THE LIST xListHead
channel.cc:sendUp - Calc highestAntennaZ_ and distCST_
highestAntennaZ_ = 1.5, distCST_ = 550.0
SORTING LISTS ...DONE!
neelam@neelam-VirtualBox:~/Downloads/Mohit P. Tahiliani/blackhole attack ns2.35$ Missing required flag -x in: W -t 100.0

Missing required flag -y in: W -t 100.0

Parsing error in event.

rachna@ubuntu:~/Desktop$ cd /home/rachna/ns-allinone-2.35/ns-2.35
rachna@ubuntu:~/ns-allinone-2.35/ns-2.35$ ./configure
./configure: line 2097: config.log: Permission denied
./configure: line 2107: config.log: Permission denied
rachna@ubuntu:~/ns-allinone-2.35/ns-2.35$



Sir I am getting this error

hello sir,
I am working on prevention of black-hole attack for my dissertation work of M. Tech. I want to know one thing that, how black hole attack will be done in real time. I mean what are the methods through which we can do black hole attack in real time. I am not implementing this but i want to know this things for my dissertation. Sir, if you have any idea about this then please mail me at monikamistry7@gmail.com. If u tell me then it will be very useful for my dissertation work.


hellp sir, even iam working for solution against balck hole attack.. please let me know if there is any sought of soluyion to monimize the effect

sir
Can you please help me i need to simulate a sybil attack based on RSSI(Received signal strength indicator),and the blackhole attack on WSN (wirelles sensor network) to compare them ,please help me if you have any idea about the simulation .

Guest Book...!!!