Black Hole Attack Implementation in NS-2 [转载]

本文介绍如何在NS2中实现黑洞攻击,一种恶意节点通过伪装路由请求并丢弃数据包来干扰网络通信的安全威胁。文章详细说明了六个步骤,包括配置TCL文件、修改AODV类以及实现恶意节点的行为。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

Original Website: http://byuvraj.blogspot.jp/2013/04/black-hole-attack-implementation-in-ns-2.html

---------------------------------------------------


Introduction

Black Hole Attack in Networking basically occurs when a node particiaptes in data transmission act as forwarder .It receives data from the sender and replies it sent the data without sending it to receiver. it does not know any path , simply its goal to drop the packet data. In receive request function of .cc file there it directly reply the packet with highest sequence number to the source and the when data received it will drop these data at recv function of .cc file in the AODV.

Procedure for Creating malicious node to present Blackhole attack in AODV.


step 1 :  Is for the tcl code, add this below line in your .tcl file
(tclfile)
#$ns_ at 0.0 “[$n2 set ragent_] malicious”

Below 2 would be at aodv.h in anywhere AODV class. add boolian variable BLACKHOLE in aodv.h

step 2  : (aodv.h)
    
bool     BLACKHOLE;

in 3 add the BLACKHOLE as false in aodv constructor

step 3  : (aodv.cc)

aodv::aodv(nsaddr_t id) : Agent(PT_aodvplain),-----------
{
------
bid = 1;
  LIST_INIT(&nbhead);
  LIST_INIT(&bihead);
BLACKHOLE=false;
  logtarget = 0;
------
}

in 4, check malicious variable is set or not in tcl file.

step 4 : (aodv.cc(AODV::command))
    
-----------
 if(strncasecmp(argv[1], "id", 2) == 0) {
      tcl.resultf("%d", index);
      return TCL_OK;
    }
    if(strcmp(argv[1], "malicious") == 0) {
        BLACKHOLE = true;
       return TCL_OK;
    }
-------------

step 5  : Is for adding blackhole behaviour in node which drop the data packet.
(aodv.cc(recv))
----------
 if(ch->ptype() == PT_aodvplain) {
   ih->ttl_ -= 1;
   recvaodvplain(p);
   return;
 }

if(BLACKHOLE)
{
//If destination address is itsself
if ( (u_int32_t)ih->saddr() == index)
   forward((aodv_rt_entry*) 0, p, NO_DELAY);
else

    drop(p, DROP_RTR_ROUTE_LOOP);
}
else
{
 /*
  *  Must be a packet I'm originating...
  */
if((ih->saddr() == index) && (ch->num_forwards() == 0)) {
 /*
  * Add the IP Header
  */
   ch->size() += IP_HDR_LEN;
 ------

}

step 6 :  Is for replying a request packet, in request packet use the maximum 32 bit number as sequence number.
(aodv.cc(recvreqeust))
    
--------
   // Just to be safe, I use the max. Somebody may have
   // incremented the dst seqno.
   seqno = max(seqno, rq->rq_dst_seqno)+1;
   if (seqno%2) seqno++;

if(BLACKHOLE)
seqno= rq->rq_dst=rq->rq_src=4294967295;

---------

/*
  * Can't reply. So forward the  Route Request
  */

 else {
if(BLACKHOLE)
{
 sendReply(rq->rq_src,       // IP Destination
             1,         // Hop Count
             rq->rq_dst,     // Dest IP Address
             4294967295,        // Highest Dest Sequence Num that is largest 32-bit integers from -2147483647 to +2147483647
           MY_ROUTE_TIMEOUT,    // Lifetime
             rq->rq_timestamp); // timestamp

Packet::free(p);
}
else
{
  ih->saddr() = index;
   ih->daddr() = IP_BROADCAST;
   rq->rq_hop_count += 1;
   // Maximum sequence number seen en route
   if (rt) rq->rq_dst_seqno = max(rt->rt_seqno, rq->rq_dst_seqno);
   forward((aodvplain_rt_entry*) 0, p, DELAY);
 }

}

credit to “http://elmurod.net/index.php/2009/10/24/adding-malicious-node-in-aodv/” ans "http://narentada.com"

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值