NETWORK ATTACKS FRAMEWORK
1.0.0
A NETwork Attacks framework. Making network attacks impact evaluation easier!
|
Dropping attack hacked module. More...
#include <NA_IPv4.h>
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. |
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:
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; }
bool NA_IPv4::delayAttackIsActive [private] |
double NA_IPv4::delayAttackProbability [private] |
ParPtr NA_IPv4::delayAttackValue [private] |
simsignal_t NA_IPv4::delaySignal = SIMSIGNAL_NULL [static, protected] |
bool NA_IPv4::droppingAttackIsActive [private] |
double NA_IPv4::droppingAttackProbability [private] |
simsignal_t NA_IPv4::dropSignal = SIMSIGNAL_NULL [static, protected] |
NA_NesgLog NA_IPv4::log [private] |
long NA_IPv4::numDelays [private] |
long NA_IPv4::numDrops [private] |
long NA_IPv4::numRecvPacket [private] |
simsignal_t NA_IPv4::rcvdPktSignal = SIMSIGNAL_NULL [static, protected] |
long NA_IPv4::totalDelayTime [private] |