Reputation: 115
I need a snippet of c++ code that simulate AODV network with a malicious node that does a replay attack. I need to embed this in my OMNet++ project.
I tried to change the original code in the sample project in OMNet++ but I'm back at the starting point.
It'll be great to find help.
I can't include a sample code it's fairly long in characters, if you need to see my trials until now, show me where can I share my project.
Upvotes: 0
Views: 672
Reputation: 1565
Since the OPs question lacks some details, I will provide a mock solution following Wikipedia article's example for the Replay attack:
Suppose Alice wants to prove her identity to Bob. Bob requests her password as proof of identity, which Alice dutifully provides (possibly after some transformation like a hash function); meanwhile, Eve is eavesdropping on the conversation and keeps the password (or the hash). After the interchange is over, Eve (posing as Alice) connects to Bob; when asked for a proof of identity, Eve sends Alice's password (or hash) read from the last session, which Bob accepts thus granting access to Eve.
I would create a new packet (extending the UDPPacket) to serve your specific application goal, by adding source and destination fields to the UDPPacket:
cplusplus {{
#include "<directory_path_for_the_udp_packet_goes_here>/UDPPacket_m.h" // inheriting the parent class
}}
class ExtendedUDPPacket; // you can call it whatever you want
message ExtendedUDPPacket extends UDPPacket
{
string sourceNode; // name of the sender
string destinationNode; // name of the receiver
}
Now let's look at the 3 different roles in the given example:
If we consider that each node has a specific ID which holds its name we can do the following for each role:
ALICE:
void MalAODVRouter::handleMessage(cMessage *msg)
{
ExtendedUDPPacket *eUDPmsg = dynamic_cast<UDPPacket *>(msg);
if (this->myID == eUDPmsg->getDestinationNode()) // myID is "Alice"
{
ExtendedUDPPacket *ExtendedUDPPacket= new UDPPacket();
ExtendedUDPPacket->setSourceAddress(myID.c_str());
ExtendedUDPPacket->setDestinationAddress(std::string("Bob").c_str());
send(udpPacket, "ipOut");
}
}
EVE:
void MalAODVRouter::handleMessage(cMessage *msg)
{
ExtendedUDPPacket *eUDPmsg = dynamic_cast<UDPPacket *>(msg);
if (this->myID != eUDPmsg->getDestinationNode()) // myID is "Eve"
{
ExtendedUDPPacket *ExtendedUDPPacket= new UDPPacket();
ExtendedUDPPacket->setSourceAddress(std::string("Alice").c_str()); // fake the message
ExtendedUDPPacket->setDestinationAddress(std::string("Bob").c_str());
send(udpPacket, "ipOut");
}
}
BOB:
void MalAODVRouter::handleMessage(cMessage *msg)
{
ExtendedUDPPacket *eUDPmsg = dynamic_cast<UDPPacket *>(msg);
if (eUDPmsg->getSourceNode() == 'Alice')
{
ExtendedUDPPacket *ExtendedUDPPacket= new UDPPacket();
ExtendedUDPPacket->setSourceAddress(std::string("Bob").c_str());
ExtendedUDPPacket->setDestinationAddress(std::string("Alice").c_str());
send(udpPacket, "ipOut");
}
}
Bear in mind this is a mock implementation, you can add smarter conditional checks to make the application behave better.
Upvotes: 1