NETWORK ATTACKS FRAMEWORK  1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
NA_IPv4 Class Reference

Dropping attack hacked module. More...

#include <NA_IPv4.h>

Inheritance diagram for NA_IPv4:
NA_HackedModule

List of all members.

Public Member Functions

void handleMessageFromAttackController (cMessage *msg)
 Overridden function.

Protected Member Functions

virtual void initialize ()
 Method from cSimpleModule class, to initialize the simple module.
virtual void handlePacketFromNetwork (IPv4Datagram *datagram, InterfaceEntry *fromIE)
 Overridden function to implement the dropping behavior.
virtual simtime_t startService (cPacket *msg)
 Overridden function to implement the delay behavior.

Static Protected Attributes

static simsignal_t dropSignal = SIMSIGNAL_NULL
 Drop signal for statistics.
static simsignal_t delaySignal = SIMSIGNAL_NULL
 Delay signal for statistics.
static simsignal_t rcvdPktSignal = SIMSIGNAL_NULL
 Packet received signal for statistics.

Private Attributes

NA_NesgLog log
 Log reference.
bool droppingAttackIsActive
 Flag to activate dropping attack.
double droppingAttackProbability
 Probability for dropping packets when dropping attack is active.
long numDrops
 Count the number of packet discarded.
bool delayAttackIsActive
 Flag to activate delay attack.
double delayAttackProbability
 Probability for delaying a packet.
long numDelays
 Number of packets delayed.
long totalDelayTime
 Accumulated delay time for all the packets delayed.
ParPtr delayAttackValue
 elayValue for the simulation.
long numRecvPacket
 Number of data packet received by the host.

Detailed Description

Dropping attack hacked module.

This hacked module is in charge of implement the dropping behavior on IP layer. When this module receive a dropping control message from the controller this activate or deactivate the dropping behavior. The packets are discarded randomly following a normal distribution with a

droppingAttackProbability 

probability.

Implemented attacks:

  • Dropping
  • Delay
See also:
NA_HackedModule, NA_DroppingAttack
Author:
Gabriel Maciá Fernández, gmacia@ugr.es
Date:
01/22/2013

Definition at line 71 of file NA_IPv4.h.


Member Function Documentation

void NA_IPv4::handleMessageFromAttackController ( cMessage *  msg) [virtual]

Overridden function.

Reimplemented from NA_HackedModule.

Definition at line 63 of file NA_IPv4.cc.

                                                             {

    // It is necessary to call Enter_Method for doing context switching (4.10 of User Manual)
    Enter_Method("NA_IPv4: handle message from attack controller");

    LOG << "NA_IPv4: Received message: " << msg->getFullName() << "\n";

    /*-------------------------- DROPPING ATTACK -------------------------*/
    if (not strcmp(msg->getFullName(), "droppingActivate")) {
        NA_DroppingMessage *dmsg;
        dmsg = check_and_cast<NA_DroppingMessage *>(msg);
        LOG << "--> Activating module NA_IPv4 for Dropping Attack...\n";
        LOG << "    Dropping Attack Probability received: "
                << dmsg->getDroppingAttackProbability() << "\n";
        //Now dropping attack is activated in this module
        droppingAttackIsActive = true;
        droppingAttackProbability = dmsg->getDroppingAttackProbability();
        delete (msg);

    } else if (not strcmp(msg->getFullName(), "droppingDeactivate")) {
        NA_DroppingMessage *dmsg;
        dmsg = check_and_cast<NA_DroppingMessage *>(msg);
        LOG << "Deactivating module NA_IPv4 for Dropping Attack...\n";
        //Now dropping attack is deactivated
        droppingAttackIsActive = false;
        delete (msg);

        /*-------------------------- DELAY ATTACK -------------------------*/

    } else if (not strcmp(msg->getFullName(), "delayActivate")) {
        NA_DelayMessage *dmsg;
        dmsg = check_and_cast<NA_DelayMessage *>(msg);
        LOG << "--> Activating module NA_IPv4 for Delay Attack...\n";
        LOG << "    Delay Attack Probability received: "
                << dmsg->getDelayAttackProbability() << "\n";
        LOG << "    Delay Attack Value received: "
                << dmsg->getDelayAttackValue() << "\n";
        delayAttackIsActive = true;
        delayAttackProbability = dmsg->getDelayAttackProbability();
        delayAttackValue = dmsg->getDelayAttackValue();
        delete (msg);

    } else if (not strcmp(msg->getFullName(), "delayDeactivate")) {
        NA_DelayMessage *dmsg;
        dmsg = check_and_cast<NA_DelayMessage *>(msg);
        LOG << "Deactivating module NA_IPv4 for Delay Attack...\n";
        delayAttackIsActive = false;
        delayAttackValue = NULL;
        delete (msg);

    } else {
        LOG
                << "ERROR: Message unknown in NA_IPv4::handleMessageFromAttackController. Msg: "
                << msg->getFullName() << "\n";
    }
}
void NA_IPv4::handlePacketFromNetwork ( IPv4Datagram *  datagram,
InterfaceEntry *  fromIE 
) [protected, virtual]

Overridden function to implement the dropping behavior.

First check if the dropping behavior is active. Then check if the received packet is a valid packet to drop (PING, UDP and/or TCP). Finally discard it or not randomly.

Definition at line 120 of file NA_IPv4.cc.

                                {

    ASSERT(datagram);

    //cout << simTime() << ": Incoming packet: " << datagram->getFullPath() << endl;
    //cout << simTime() << ": Source address: " << datagram->getSrcAddress().str() << endl;
    //cout << simTime() << ": Destination address: " << datagram->getDestAddress().str() << endl;

    // Count the number of total data packet received, for statistics.
    if (!strncmp(datagram->getName(), PING_DATA, 4)
            || !strncmp(datagram->getName(), UDP_DATA, 3)
            || !strncmp(datagram->getName(), TCP_DATA, 3)) {
        numRecvPacket++; // The number of packets is updated
        emit(rcvdPktSignal, numRecvPacket); // Sending of the signal indicating that we have received a new data packet.
    }

    //Packet is a ping/UDP/TCP (data packet)
    if (droppingAttackIsActive) {
        LOG << "Received packet after activating dropping attack ... " << "\n";
        if (!strncmp(datagram->getName(), PING_DATA, 4)
                || !strncmp(datagram->getName(), UDP_DATA, 3)
                || !strncmp(datagram->getName(), TCP_DATA, 3)) {
            LOG << "Is a valid packet for dropping ..." << "\n";
            if (uniform(0, 1) < droppingAttackProbability) {
                numDrops++; // The number of droppings is updated
                emit(dropSignal, numDrops); // Sending of the signal indicating a drop
                LOG << "Discarding packet: " << datagram->getName() << ": "
                        << numDrops << " dropping times." << endl;
                cout << simTime() << ": Discarding packet: "
                        << datagram->getName() << endl;
                delete datagram; //Deletes the datagram thus calling its destructor
            } else {
                IPv4::handlePacketFromNetwork(datagram, fromIE);
            }
        } else { //Packet is not a data packet --> normal behavior
            IPv4::handlePacketFromNetwork(datagram, fromIE);

        }

    } else { // --> Normal behavior.
        IPv4::handlePacketFromNetwork(datagram, fromIE);
    }
}
void NA_IPv4::initialize ( ) [protected, virtual]

Method from cSimpleModule class, to initialize the simple module.

Overridden function.

Definition at line 40 of file NA_IPv4.cc.

                         {

    // Dropping attack initialization
    numDrops = 0;
    dropSignal = registerSignal("droppings");
    droppingAttackProbability = 0;
    droppingAttackIsActive = false;

    // Delay attack initialization
    delayAttackIsActive = false;
    delayAttackProbability = 0;
    numDelays = 0;
    delaySignal = registerSignal("delayed");
    totalDelayTime = 0;
    delayAttackValue = NULL;

    // Number of data packet received
    numRecvPacket = 0;
    rcvdPktSignal = registerSignal("rcvdPkt");

    IPv4::initialize();
}
simtime_t NA_IPv4::startService ( cPacket *  msg) [protected, virtual]

Overridden function to implement the delay behavior.

First check if the delay behavior is active. Then check if the received packet is a valid packet to delay (PING, UDP and/or TCP). Finally add a delay time in a random way.

Definition at line 165 of file NA_IPv4.cc.

                                            {

    // The value for the variable "delay" is obtained in QueueBase::initialize from the .ned parameter "procDelay".
    // Here, the delay attack add a new delay.

    double delayAttack = 0;

    if (delayAttackIsActive) {
        if (delayAttackValue != NULL) {
            if (!strncmp(msg->getName(), PING_DATA, 4)
                    || !strncmp(msg->getName(), UDP_DATA, 3)
                    || !strncmp(msg->getName(), TCP_DATA, 3)) {
                if (uniform(0, 1) < delayAttackProbability) {
                    delayAttack = delayAttackValue->doubleValue();
                    if (delayAttack < 0)
                        delayAttack = 0; //Avoid negative delays from a random distribution
                    numDelays++; // The number of packets delayed is updated
                    emit(delaySignal, numDelays); // Sending of the signal indicating a drop
                    LOG << "(NA_IPv4) Applied delay of: " << delayAttack
                            << "s. Packet name: " << msg->getFullName() << endl;
                    //cout << simTime() << ": (NA_IPv4) Applied delay of: " << delayAttack << "s. Packet name: " << msg->getFullName() << "\n";
                }
            }
        }
    }
    return delayAttack + delay;
}

Member Data Documentation

Flag to activate delay attack.

Definition at line 100 of file NA_IPv4.h.

Probability for delaying a packet.

Definition at line 105 of file NA_IPv4.h.

elayValue for the simulation.

Implemented as a pointer to allow functions as values

Definition at line 120 of file NA_IPv4.h.

simsignal_t NA_IPv4::delaySignal = SIMSIGNAL_NULL [static, protected]

Delay signal for statistics.

Definition at line 167 of file NA_IPv4.h.

Flag to activate dropping attack.

Definition at line 84 of file NA_IPv4.h.

Probability for dropping packets when dropping attack is active.

Definition at line 89 of file NA_IPv4.h.

simsignal_t NA_IPv4::dropSignal = SIMSIGNAL_NULL [static, protected]

Drop signal for statistics.

Definition at line 147 of file NA_IPv4.h.

Log reference.

Reimplemented from NA_HackedModule.

Definition at line 78 of file NA_IPv4.h.

long NA_IPv4::numDelays [private]

Number of packets delayed.

For statistics

Definition at line 110 of file NA_IPv4.h.

long NA_IPv4::numDrops [private]

Count the number of packet discarded.

For dropping statistics

Definition at line 94 of file NA_IPv4.h.

long NA_IPv4::numRecvPacket [private]

Number of data packet received by the host.

Definition at line 126 of file NA_IPv4.h.

simsignal_t NA_IPv4::rcvdPktSignal = SIMSIGNAL_NULL [static, protected]

Packet received signal for statistics.

Definition at line 173 of file NA_IPv4.h.

long NA_IPv4::totalDelayTime [private]

Accumulated delay time for all the packets delayed.

For statistics

Definition at line 115 of file NA_IPv4.h.


The documentation for this class was generated from the following files:
 All Classes Files Functions Variables Typedefs Enumerator Defines