Programming a SinkHole Attack in MANET

Introduction

SinkHole attacks are one of the intrusion attacks that a MANET faces. In a SinkHole attack, the intruder node/malicious node sends fake routing information claiming that it has an optimum route to the target which causes other nodes in the Ad Hoc Network to route data packets through it. Thus, the malicious node gets access to all the traffic and is free to tamper the data as it wishes. In this example, we show how to implement a SinkHole attack on Manet running the DSR routing Protocol using Netsim by a simple modification of the DSR Protocol source code.

Code Modification

We create a file Malicious.c in which we write the following  three functions.

int fn_NetSim_DSR_MaliciousNode(NetSim_EVENTDETAILS* ); — This function returns 1 if the current Device is the Malicious node that we have set.

int fn_NetSim_DSR_MaliciousRouteAddToCache(NetSim_EVENTDETAILS* ,DSR_PRIMITIVES* ); — This function adds the route from the current node to the target in the current nodes’ route cache.

int n_NetSim_DSR_MaliciousProcessSourceRouteOption(NetSim_EVENTDETAILS * ,DSR_PRIMITIVES* ); — This function receives the data packet from the transmitting node, sends an acknowledge request and then receives the data.

In the existing file DSR.c, in the case ctrlPacket_Route_Request in Network_In_Event, we add a false route from the present node to target in the route cache of a malicious node. Thus the malicious node will send a fake route reply. In the default case of a data packet, the malicious node will receive the data packet and then it generates an acknowledge request.

Source Code 

The following files are attached:

Visit: www.tetcos.com E-Mail: sales@tetcos.com

Accessing protocol metrics when writing custom code in NetSim

Given below is a brief example of how users can access NetSim protocol / device metrics when writing custom code. This example is based on DSR protocol in NetSim v7.1

The various DSR metrics are available in the DSR.h file, under the following structures –

struct stru_DSR_DeviceVar
{
unsigned int nRREQIdentification;
struct stru_DSR_RouteCache* pstruRouteCache;
struct stru_DSR_SendBuffer* pstruSendBuffer;
struct stru_DSR_RouteRequestTable* pstruRREQTable;
enum
{
LINK_LAYER_ACK,
NETWORK_LAYER_ACK,
}AckType;
DSR_MAINT_BUFFER* pstruMaintBuffer;
struct stru_DSR_Metrics dsrMetrics;   // This structure is defined below
};

struct stru_DSR_Metrics
{
unsigned int rreqSent;
unsigned int rreqForwarded;
unsigned int rrepSent;
unsigned int rrepForwarded;
unsigned int rerrSent;
unsigned int rerrForwarded;
unsigned int routeBreak;
unsigned int packetTransmitted;
unsigned int packetOrginated;
unsigned int packetReceived;
unsigned int packetDropped;
};

These have been type def’ed for ease of use and you can add the following code in DSR.c in fn_NetSim_DSR_Run() to get packets received

// CODE TO BE ADDED

DSR_DEVICE_VAR* device1 =  DSR_DEV_VAR(1)

/* Enter the device ID whose metrics you need. The ID of present device being executed can be got by pstruEventDetails>nDeviceID */

printf(“%d”,device1->dsrMetrics.packetReceived);

/* Similarly you can access different metrics for each of the devices */

// END OF CODE

Note that

printf(“%d\n”,devVar1->dsrMetrics.rreqSent);  //  Writes to log file available in the I/O path where the configuration file is present

fprintf(stderr,”%d\n”,devVar1->dsrMetrics.rreqSent); // Writes to command prompt.