Ns3 Projects for B.E/B.Tech M.E/M.Tech PhD Scholars.  Phone-Number:9790238391   E-mail: ns3simulation@gmail.com

How to Implement password sniffing attacks in ns3

To implement a password sniffing attack in ns3, we need to set up a network topology in which the attacker node inspects the packet for sensitive information, such as passwords by passively capturing them from the network and inspects them This type of attack is mainly used in the unencrypted communication protocols like HTTP or Telnet.

Here we have provided the instruction to implement password sniffing Attack in ns3.

Steps to Implement a Password Sniffing Attack in ns3

  1. Set Up ns-3 Environment:
    • Make sure ns3 is installed in the system.
    • Install necessary dependencies.
  2. Create a New ns-3 Script:
    • Create a new script file in the scratch directory of ns3, e.g., password_sniffing_attack.cc.
  3. Include Necessary Headers:
    • Include the necessary ns3 headers in the script.
  4. Define Network Topology:
    • Set up a network topology that includes multiple legitimate nodes and one attacker node.
  5. Implement Packet Sniffing Logic:
    • Use the packet capture functionality to capture and inspect packets at the attacker node.
  6. Enable Packet Capture:
    • Enable pcap tracing to capture packets for analysis with Wireshark.
  7. Run the Simulation:
    • Set the simulation time and run the simulation using Simulator::Run() and Simulator::Destroy().

Here is an example of how to implement a password sniffing attack in ns-3:

#include “ns3/core-module.h”

#include “ns3/network-module.h”

#include “ns3/internet-module.h”

#include “ns3/point-to-point-module.h”

#include “ns3/applications-module.h”

#include “ns3/packet.h”

#include “ns3/ipv4-header.h”

#include “ns3/tcp-header.h”

#include “ns3/udp-header.h”

using namespace ns3;

NS_LOG_COMPONENT_DEFINE (“PasswordSniffingAttack”);

void PacketCaptureCallback (Ptr<const Packet> packet)

{

Ptr<Packet> copy = packet->Copy ();

Ipv4Header ipv4Header;

TcpHeader tcpHeader;

UdpHeader udpHeader;

copy->PeekHeader (ipv4Header);

if (ipv4Header.GetProtocol () == 6) // TCP Protocol

{

copy->RemoveHeader (ipv4Header);

copy->PeekHeader (tcpHeader);

uint16_t srcPort = tcpHeader.GetSourcePort ();

uint16_t dstPort = tcpHeader.GetDestinationPort ();

if (dstPort == 80 || srcPort == 80) // HTTP Port

{

NS_LOG_INFO (“Captured HTTP packet: ” << *packet);

// Inspect the payload for passwords or other sensitive data

}

else if (dstPort == 23 || srcPort == 23) // Telnet Port

{

NS_LOG_INFO (“Captured Telnet packet: ” << *packet);

// Inspect the payload for passwords or other sensitive data

}

}

else if (ipv4Header.GetProtocol () == 17) // UDP Protocol

{

copy->RemoveHeader (ipv4Header);

copy->PeekHeader (udpHeader);

uint16_t srcPort = udpHeader.GetSourcePort ();

uint16_t dstPort = udpHeader.GetDestinationPort ();

 

if (dstPort == 69 || srcPort == 69) // TFTP Port

{

NS_LOG_INFO (“Captured TFTP packet: ” << *packet);

// Inspect the payload for sensitive data

}

}

}

int main (int argc, char *argv[])

{

bool verbose = true;

uint32_t nNodes = 3;

CommandLine cmd;

cmd.AddValue (“nNodes”, “Number of wifi STA devices”, nNodes);

cmd.AddValue (“verbose”, “Tell echo applications to log if true”, verbose);

cmd.Parse (argc, argv);

if (verbose)

{

LogComponentEnable (“PasswordSniffingAttack”, LOG_LEVEL_INFO);

}

 

NodeContainer nodes;

nodes.Create (nNodes);

NodeContainer attackerNode;

attackerNode.Create (1);

PointToPointHelper pointToPoint;

pointToPoint.SetDeviceAttribute (“DataRate”, StringValue (“5Mbps”));

pointToPoint.SetChannelAttribute (“Delay”, StringValue (“2ms”));

NetDeviceContainer devices;

for (uint32_t i = 0; i < nodes.GetN () – 1; ++i)

{

devices.Add (pointToPoint.Install (nodes.Get (i), nodes.Get (i + 1)));

}

devices.Add (pointToPoint.Install (nodes.Get (0), attackerNode.Get (0)));

InternetStackHelper stack;

stack.Install (nodes);

stack.Install (attackerNode);

Ipv4AddressHelper address;

address.SetBase (“10.1.1.0”, “255.255.255.0”);

Ipv4InterfaceContainer interfaces = address.Assign (devices);

// Install applications on legitimate nodes

UdpEchoServerHelper echoServer (9);

ApplicationContainer serverApps = echoServer.Install (nodes.Get (nNodes – 1));

serverApps.Start (Seconds (1.0));

serverApps.Stop (Seconds (10.0));

UdpEchoClientHelper echoClient (interfaces.GetAddress (nNodes – 1), 9);

echoClient.SetAttribute (“MaxPackets”, UintegerValue (100));

echoClient.SetAttribute (“Interval”, TimeValue (Seconds (0.1)));

echoClient.SetAttribute (“PacketSize”, UintegerValue (1024));

ApplicationContainer clientApps = echoClient.Install (nodes.Get (0));

clientApps.Start (Seconds (2.0));

clientApps.Stop (Seconds (10.0));

// Enable packet capture

pointToPoint.EnablePcapAll (“password_sniffing_attack”);

// Connect the packet capture callback on the attacker node

devices.Get (devices.GetN () – 1)->TraceConnectWithoutContext (“PhyRxDrop”, MakeCallback (&PacketCaptureCallback));

Simulator::Run ();

Simulator::Destroy ();

return 0;

}

Explanation:

  1. Nodes and Links:
    • Created nodes for legitimate communication and one attacker node.
    • Configured point-to-point links between the nodes.
  2. Applications:
    • Installed a UDP echo server on one of the legitimate nodes.
    • Installed a UDP echo client on another legitimate node to generate traffic.
  3. Packet Sniffing Logic:
    • Implemented a PacketCaptureCallback function to inspect captured packets for sensitive data, such as passwords.
    • Connected the packet capture function to the PhyRxDrop trace source of the attacker’s network device to capture packets.
  4. Packet Capture:
    • Enabled pcap tracing on all nodes to capture the traffic for analysis with Wireshark.
  5. Running the Simulation:
    • The simulation runs, with the attacker node passively capturing packets, and the traffic is captured in pcap files.

The implementation process of password sniffing attack in ns3 is explained clearly that it is mainly used in the unencrypted communication protocols that capture the packets and inspects them for secret information. Seek best programming  guidance on password sniffing attack in ns3 from our leading programmers.