Menu

Port Scan Attack

2017-03-06
2017-03-06
  • Amit Khandelwal

    Amit Khandelwal - 2017-03-06

    Hi,
    I am trying to extend the Simple port Scanner so that it displays the open ports found. For which I made following changes and launched the application. '
    But it turned out that the method "handleIncomingPacket" is never getting executed?
    1. Does that mean the server is not replying? ( I have profiled a server with Echo Server profile)
    2. Or is there a fault in the logic?

    import de.dailab.nessi.core.api.annotations.Description;
    import de.dailab.nessi.core.api.annotations.IntegerField;
    import de.dailab.nessi.core.api.annotations.StringField;
    import de.dailab.nessi.core.api.events.Event;
    import de.dailab.nessi.core.api.events.TickedEvent;
    import de.dailab.nessi.ip.api.address.IPFactory;
    import de.dailab.nessi.ip.api.address.IPv4Address;
    import de.dailab.nessi.ip.api.layer.ILayerHandler;
    import de.dailab.nessi.ip.api.layer.ITransportLayer;
    import de.dailab.nessi.ip.api.protocols.Packet;
    import de.dailab.nessi.ip.api.protocols.ip.IPv4Header;
    import de.dailab.nessi.ip.api.protocols.udp.UDPHeader;
    import de.dailab.nessi.ip.handler.IPApplication;
    import java.util.Random;
    
    public class Port_AK extends IPApplication
    {
    
        public Port_AK()
        {
            startPort = 1;
            endPort = 1024;
            targetIp = "0.0.0.0";
            startTick = 100;
            System.out.print("Inside constructor ");
    
        }
    
        public void handleEvent(Event e)
        {
            System.out.print("Insie handleevent ");
            Random ran = new Random(123L);
            for(int i = startPort; i < endPort; i++)
            {
                System.out.print("Inside for loop ");
                byte payload[] = new byte[28];
                ran.nextBytes(payload);
                getLayerHandler().getTransportLayer().sendUDPPacket(7, i, destinationIP, payload);
            }
            System.out.print("Exiting handle event ");
            //super.handleEvent(e);
        }
    
        public boolean start()
        {
            System.out.print("Inside start ");
            destinationIP = IPFactory.createIPv4Address(targetIp);
            TickedEvent e = new TickedEvent(this, startTick);
            getLayerHandler().addEvent(e);
            System.out.print("Exiing start ");
    
            return super.start();
        }
    
        @Override
        public void handleIncomingPacket(Packet packet) {
            System.out.print("Inside handle incoming packets ");
        IPv4Header ipHeader = packet.findHeader(IPv4Header.class);
        UDPHeader udpHeader = packet.findHeader(UDPHeader.class);
        if (ipHeader == null || udpHeader == null) {
        return;
        }  
        System.out.print("The port replied back is ");
        System.out.println(udpHeader.getSourcePort());
        }
    
        @IntegerField("Start Port")
        @Description("Start Port number")
        private int startPort;
        @IntegerField("End Port")
        @Description("End")
        private int endPort;
        @StringField("IP Address")
        private String targetIp;
        private int startTick;
        private IPv4Address destinationIP;
    }
    
     
  • Karsten Bsufka

    Karsten Bsufka - 2017-03-06

    What do you mean by launched the application? Did you add your implemented application to profile and placed in the profile on a node in the network before launching a new simulation?

    Also from the Javadoc of handleIncomingPacket: "Called when a packet arrives. It is only used for normal applications which have registered a UDP port (see
    ITransportLayer#registerUDPPort(int, IIPApplication)). This should preferably be done by overriding the start method."

    I could not see that you registered any port.

     
    • Amit Khandelwal

      Amit Khandelwal - 2017-03-06

      Yes, by launching I mean : I created a elipse/maven prject with above source code. Then "mvn clean install". Then copied the .jar file into nessi backend and gui application folder. Then built a plug in project in Nessi2 GUI and placed this newly generatd appliction(profile) into a node. Then launched the simulation.

       
      • Amit Khandelwal

        Amit Khandelwal - 2017-03-06

        Thanks for the reply... I will try out your suggestions

         

Log in to post a comment.