0

我需要一段 C++ 代码来模拟带有恶意节点的 AODV 网络,该节点进行重放攻击。我需要将它嵌入到我的 OMNet++ 项目中。

我试图在 OMNet++ 中更改示例项目中的原始代码,但我又回到了起点。

找到帮助会很棒。

我不能包含一个字符相当长的示例代码,如果您需要查看我的试验直到现在,请告诉我在哪里可以分享我的项目。

4

1 回答 1

1

由于 OPs 问题缺少一些细节,我将按照Wikipedia article's example for the Replay attack提供一个模拟解决方案:

假设爱丽丝想向鲍勃证明她的身份。Bob 请求她的密码作为身份证明,Alice 尽职尽责地提供了该密码(可能经过一些像哈希函数这样的转换之后);与此同时,Eve 正在窃听对话并保留密码(或哈希)。交换结束后,Eve(冒充 Alice)连接到 Bob;当被要求提供身份证明时,Eve 发送从上次会话中读取的 Alice 的密码(或哈希),Bob 接受该密码,从而授予 Eve 访问权限。


我将通过向 UDPPacket 添加目标字段来创建一个新数据包(扩展 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
}

现在让我们看看给定示例中的 3 个不同角色:

  1. Alice:需要认证
  2. Bob:认证者
  3. 夏娃:窃听者

如果我们认为每个节点都有一个包含其名称的特定 ID,我们可以为每个角色执行以下操作:

爱丽丝:

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");
    }
}

前夕:

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");
    }
}

鲍勃:

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");
    }
}

请记住,这是一个模拟实现,您可以添加更智能的条件检查以使应用程序表现得更好。

于 2015-05-25T11:13:37.757 回答