implementing the TCP SYN flood attack to my lte simple code (lena)

105 views
Skip to first unread message

Jemai Aymen

unread,
Apr 24, 2023, 7:56:53 PM4/24/23
to ns-3-users
hi guys i need urgent help for my master project ? any one can help me how to implement the TCP SYN flood attack on my code or any other attaque ( MITM, DOS, fake enodeb) 
i wanna see the difference and interrupt before and after the attack i'm using ns3.34 and netanim for visualisation. this is my code : 
#include "ns3/core-module.h" #include "ns3/point-to-point-module.h" #include "ns3/internet-module.h" #include "ns3/applications-module.h" #include "ns3/mobility-module.h" #include "ns3/config-store-module.h" #include "ns3/lte-module.h" #include "ns3/netanim-module.h" //#include "ns3/gtk-config-store.h" using namespace ns3; /** * Sample simulation script for LTE+EPC. It instantiates several eNodeBs, * attaches one UE per eNodeB starts a flow for each UE to and from a remote host. * It also starts another flow between each UE pair. */ NS_LOG_COMPONENT_DEFINE ("LenaSimpleEpc"); int main (int argc, char *argv[]) { uint16_t numNodePairs = 2; Time simTime = MilliSeconds (1100); double distance = 60.0; Time interPacketInterval = MilliSeconds (100); bool useCa = false; bool disableDl = false; bool disableUl = false; bool disablePl = false; // Command line arguments CommandLine cmd (_FILE_); cmd.AddValue ("numNodePairs", "Number of eNodeBs + UE pairs", numNodePairs); cmd.AddValue ("simTime", "Total duration of the simulation", simTime); cmd.AddValue ("distance", "Distance between eNBs [m]", distance); cmd.AddValue ("interPacketInterval", "Inter packet interval", interPacketInterval); cmd.AddValue ("useCa", "Whether to use carrier aggregation.", useCa); cmd.AddValue ("disableDl", "Disable downlink data flows", disableDl); cmd.AddValue ("disableUl", "Disable uplink data flows", disableUl); cmd.AddValue ("disablePl", "Disable data flows between peer UEs", disablePl); cmd.Parse (argc, argv); ConfigStore inputConfig; inputConfig.ConfigureDefaults (); // parse again so you can override default values from the command line cmd.Parse(argc, argv); if (useCa) { Config::SetDefault ("ns3::LteHelper::UseCa", BooleanValue (useCa)); Config::SetDefault ("ns3::LteHelper::NumberOfComponentCarriers", UintegerValue (2)); Config::SetDefault ("ns3::LteHelper::EnbComponentCarrierManager", StringValue ("ns3::RrComponentCarrierManager")); } Ptr<LteHelper> lteHelper = CreateObject<LteHelper> (); Ptr<PointToPointEpcHelper> epcHelper = CreateObject<PointToPointEpcHelper> (); lteHelper->SetEpcHelper (epcHelper); Ptr<Node> pgw = epcHelper->GetPgwNode (); // Create a single RemoteHost NodeContainer remoteHostContainer; remoteHostContainer.Create (1); Ptr<Node> remoteHost = remoteHostContainer.Get (0); InternetStackHelper internet; internet.Install (remoteHostContainer); // Create the Internet PointToPointHelper p2ph; p2ph.SetDeviceAttribute ("DataRate", DataRateValue (DataRate ("100Gb/s"))); p2ph.SetDeviceAttribute ("Mtu", UintegerValue (1500)); p2ph.SetChannelAttribute ("Delay", TimeValue (MilliSeconds (10))); NetDeviceContainer internetDevices = p2ph.Install (pgw, remoteHost); Ipv4AddressHelper ipv4h; ipv4h.SetBase ("1.0.0.0", "255.0.0.0"); Ipv4InterfaceContainer internetIpIfaces = ipv4h.Assign (internetDevices); // interface 0 is localhost, 1 is the p2p device Ipv4Address remoteHostAddr = internetIpIfaces.GetAddress (1); Ipv4StaticRoutingHelper ipv4RoutingHelper; Ptr<Ipv4StaticRouting> remoteHostStaticRouting = ipv4RoutingHelper.GetStaticRouting (remoteHost->GetObject<Ipv4> ()); remoteHostStaticRouting->AddNetworkRouteTo (Ipv4Address ("7.0.0.0"), Ipv4Mask ("255.0.0.0"), 1); NodeContainer ueNodes; NodeContainer enbNodes; enbNodes.Create (numNodePairs); ueNodes.Create (numNodePairs); // Install Mobility Model Ptr<ListPositionAllocator> positionAlloc = CreateObject<ListPositionAllocator> (); for (uint16_t i = 0; i < numNodePairs; i++) { positionAlloc->Add (Vector (distance * i, 0, 0)); } MobilityHelper mobility; mobility.SetMobilityModel("ns3::ConstantPositionMobilityModel"); mobility.SetPositionAllocator(positionAlloc); mobility.Install(enbNodes); mobility.Install(ueNodes); // Install LTE Devices to the nodes NetDeviceContainer enbLteDevs = lteHelper->InstallEnbDevice (enbNodes); NetDeviceContainer ueLteDevs = lteHelper->InstallUeDevice (ueNodes); // Install the IP stack on the UEs internet.Install (ueNodes); Ipv4InterfaceContainer ueIpIface; ueIpIface = epcHelper->AssignUeIpv4Address (NetDeviceContainer (ueLteDevs)); // Assign IP address to UEs, and install applications for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { Ptr<Node> ueNode = ueNodes.Get (u); // Set the default gateway for the UE Ptr<Ipv4StaticRouting> ueStaticRouting = ipv4RoutingHelper.GetStaticRouting (ueNode->GetObject<Ipv4> ()); ueStaticRouting->SetDefaultRoute (epcHelper->GetUeDefaultGatewayAddress (), 1); } // Attach one UE per eNodeB for (uint16_t i = 0; i < numNodePairs; i++) { lteHelper->Attach (ueLteDevs.Get(i), enbLteDevs.Get(i)); // side effect: the default EPS bearer will be activated } // Install and start applications on UEs and remote host uint16_t dlPort = 1100; uint16_t ulPort = 2000; uint16_t otherPort = 3000; ApplicationContainer clientApps; ApplicationContainer serverApps; for (uint32_t u = 0; u < ueNodes.GetN (); ++u) { if (!disableDl) { PacketSinkHelper dlPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), dlPort)); serverApps.Add (dlPacketSinkHelper.Install (ueNodes.Get (u))); UdpClientHelper dlClient (ueIpIface.GetAddress (u), dlPort); dlClient.SetAttribute ("Interval", TimeValue (interPacketInterval)); dlClient.SetAttribute ("MaxPackets", UintegerValue (1000000)); clientApps.Add (dlClient.Install (remoteHost)); } if (!disableUl) { ++ulPort; PacketSinkHelper ulPacketSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), ulPort)); serverApps.Add (ulPacketSinkHelper.Install (remoteHost)); UdpClientHelper ulClient (remoteHostAddr, ulPort); ulClient.SetAttribute ("Interval", TimeValue (interPacketInterval)); ulClient.SetAttribute ("MaxPackets", UintegerValue (1000000)); clientApps.Add (ulClient.Install (ueNodes.Get(u))); } if (!disablePl && numNodePairs > 1) { ++otherPort; PacketSinkHelper packetSinkHelper ("ns3::UdpSocketFactory", InetSocketAddress (Ipv4Address::GetAny (), otherPort)); serverApps.Add (packetSinkHelper.Install (ueNodes.Get (u))); UdpClientHelper client (ueIpIface.GetAddress (u), otherPort); client.SetAttribute ("Interval", TimeValue (interPacketInterval)); client.SetAttribute ("MaxPackets", UintegerValue (1000000)); clientApps.Add (client.Install (ueNodes.Get ((u + 1) % numNodePairs))); } } serverApps.Start (MilliSeconds (500)); clientApps.Start (MilliSeconds (500)); lteHelper->EnableTraces (); // Uncomment to enable PCAP tracing //p2ph.EnablePcapAll("lena-simple-epc"); AnimationInterface anim ("lte.xml"); Simulator::Stop (simTime); Simulator::Run (); /*GtkConfigStore config; config.ConfigureAttributes();*/ Simulator::Destroy (); return 0; 
} 

Tommaso Pecorella

unread,
Apr 25, 2023, 7:59:36 AM4/25/23
to ns-3-users
> hi guys i need urgent help for my master project ? any one can help me how to implement the TCP SYN flood attack on my code or any other attaque ( MITM, DOS, fake enodeb) 

First things first: if you ask help, it should be for an implementation details. I doubt that anyone can modify your script for you to match your requirements.

Second problem: before doing a simulation, ask yourself "what data am I trying to get out of the simulation".
  • SYN flood: just craft a SYN packet "manually" (create a packet, add the relevant headers, send it with the NetDevice directly). However, the only thing you'll "see" is that the receiver will open a ton of sockets, your simulation memory will increase, and nothing else will happen.
  • MITM: almost impossible with LTE, because it's LTE. You *could* do it with ns-3, but it's totally unrealistic.
  • DOS: same as SYN flood.
  • fake eNB: all the eNB are simulated, the "fake" one will be just another eNB. Same issue with SYN flood: what data are you going to collect?
So, before simulating, you' should have a plan. You do simulations to collect data that prove something, but first you have to have something to prove. Not the other way around.
Reply all
Reply to author
Forward
0 new messages