private void StartAttackButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartAttackButtonActionPerformed
    PreparedStatement ps = null, ps_update = null;
    ResultSet rs = null;
    Connection conn = null;
    String HTTPRequest = "", output = "";
    String line = "";
    File WorkingDirectory = null;
    int count = 0, ATTACK_PAYLOADS_ID = 0;
    DatabaseAccess JavaDBAccess2 = new DatabaseAccess(DBprops);
    Timestamp StartAttackGlobal, EndAttackGlobal, StartAttack, EndAttack;


    long startTime = System.currentTimeMillis();

    try {
        StartAttackGlobal = new java.sql.Timestamp(System.currentTimeMillis());
        AttackTextArea.setText(AttackTextArea.getText() + "\nStarting the Overall Attack at: " + StartAttackGlobal + "\n");
        //Start the MySQL Listener
        AttackTextArea.setText("Starting MySQL Listener\n");
        System.out.println("Starting MySQL Listener");
        StartMySQLListener("ATTACK");
        //Start the HTTP Proxy
        AttackTextArea.setText(AttackTextArea.getText() + "Starting HTTP Proxy\n");
        System.out.println("Starting HTTP Proxy");
        StartHTTPProxy("ATTACK");

        if ((conn = JavaDBAccess.setConn()) != null) {
            System.out.println("Connected to database " + JavaDBAccess.getDatabaseName());
        } else {
            throw new Exception("Not connected to database " + JavaDBAccess.getDatabaseName());
        }

        conn.setAutoCommit(false);

//        ps = conn.prepareStatement("SELECT ATTACK_PAYLOADS.HTTP_REQUEST,TARGET_PHP_FILES.ID TARGET_PHP_FILES_ID,TARGET_PHP_FILES.TEXT,VULNERABILITY_INJECTION_RESULTS.ID VULNERABILITY_INJECTION_RESULTS_ID FROM ATTACK_PAYLOADS,VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES WHERE ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=VULNERABILITY_INJECTION_RESULTS.ID AND VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND ATTACK_PAYLOADS.ID=8080");
        ps = conn.prepareStatement("SELECT ATTACK_PAYLOADS.ID ATTACK_PAYLOADS_ID,ATTACK_PAYLOADS.HTTP_REQUEST,RTRIM(CHAR(ATTACK_PAYLOADS.ID))||' - '||RTRIM(CHAR(ATTACK_PAYLOADS.PAYLOAD))||' - '||ATTACK_PAYLOADS.ATTACK_INPUT PAYLOAD,TARGET_PHP_FILES.ID TARGET_PHP_FILES_ID,TARGET_PHP_FILES.PATH TARGET_PHP_FILES_PATH,VULNERABILITY_INJECTION_RESULTS.ID VULNERABILITY_INJECTION_RESULTS_ID FROM ATTACK_PAYLOADS,VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES WHERE ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=VULNERABILITY_INJECTION_RESULTS.ID AND VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID");
        rs = ps.executeQuery();
        while (rs.next()) {
//        rs.next();
            if (UseIDSRadioButton.isSelected()) {
                //Start the IDS
                AttackTextArea.setText(AttackTextArea.getText() + "Starting the IDS\n");
                System.out.println("Starting the IDS");
//                jTPFile.setText("");

                jTPFile.setText("");
                try {
                    line = selFile.getAbsolutePath();
                    WorkingDirectory = selFile.getParentFile();
                    ExecuteAssincronousCommand(line + " -c config.cfg -m detector", WorkingDirectory);
                } catch (Exception err) {
                }

                jLDBSniffer.setText("Detector Started");
                Thread.sleep(1000);
            }

            ATTACK_PAYLOADS_ID = rs.getInt("ATTACK_PAYLOADS_ID");
            AttackTextArea.setText(AttackTextArea.getText() + "\nAttack #: " + rs.getRow() + "\n");
            System.out.println("Attack #: " + rs.getRow());
            StartAttack = new java.sql.Timestamp(System.currentTimeMillis());
            AttackTextArea.setText(AttackTextArea.getText() + "\nStarting the Attack at: " + StartAttack + "\n");
            System.out.println("Starting the Attack at: " + StartAttack);
            ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET START_ATTACK_TIMESTAMP=? WHERE ID=?");
            ps_update.setTimestamp(1, StartAttack);
            ps_update.setInt(2, ATTACK_PAYLOADS_ID);
            ps_update.executeUpdate();

            //Apply the Vulnerable PHP File
            AttackTextArea.setText(AttackTextArea.getText() + "Apply the Vulnerable PHP File: " + rs.getString("TARGET_PHP_FILES_PATH") + "\n");
            System.out.println("Apply the Vulnerable PHP File: " + rs.getString("TARGET_PHP_FILES_PATH"));
            VulnInject.ApplyVulnerablePHPFile(JavaDBAccess2, rs.getInt("VULNERABILITY_INJECTION_RESULTS_ID"));

            //Execute Attack
            AttackTextArea.setText(AttackTextArea.getText() + "Execute Attack: " + rs.getString("PAYLOAD") + "\n");
            System.out.println("Execute Attack: " + rs.getString("PAYLOAD"));
            HTTPRequest = rs.getString("HTTP_REQUEST");
            try {
                //Execute the attack through the HTTP proxy
                output = Attack.issueRequest(HTTPRequest, "localhost", Integer.parseInt(HTTPProxySourcePort.getText()));
            } catch (Exception e) {
                output = e.toString();
            }

            if (UseIDSRadioButton.isSelected()) {
                //Stop the IDS
                AttackTextArea.setText(AttackTextArea.getText() + "Stopping the IDS\n");
                Thread.sleep(1000);
                System.out.println("Stopping the IDS");
                ExitAssincronousCommand();
//                Thread.sleep(1000);

                ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET IDS_RESULT=?,IDS_COMMAND_DETECTION_RESULT='UNDEFINED',IDS_TRANSACTION_DETECTION_RESULT='UNDEFINED' WHERE ID=?");
                ps_update.setString(1, jTPFile.getText());
                ps_update.setInt(2, ATTACK_PAYLOADS_ID);
                ps_update.executeUpdate();

            }

            //Restore the original PHP file
            AttackTextArea.setText(AttackTextArea.getText() + "Restore the original PHP file: " + rs.getString("TARGET_PHP_FILES_PATH") + "\n");
            System.out.println("Restore the original PHP file: " + rs.getString("TARGET_PHP_FILES_PATH"));
            VulnInject.RestoreOriginalPHPFile(JavaDBAccess2, rs.getInt("TARGET_PHP_FILES_ID"));

            //Restore the DB data
            AttackTextArea.setText(AttackTextArea.getText() + "Restore the DB data\n");
            System.out.println("Restore the DB data");
            line = WebApplicationDatabaseRestoreCommand.getText();
            ResultList.clear();
            WorkingDirectory = new File(line.substring(0, line.lastIndexOf(File.separator)));
            ExecuteCommand(line, WorkingDirectory);
            while (done == false) {
            }
            for (count = 0; count < ResultList.size(); count++) {
                AttackTextArea.setText(AttackTextArea.getText() + ResultList.get(count).toString() + "\n");
                System.out.println(ResultList.get(count).toString());
            }
            done = false;

            EndAttack = new java.sql.Timestamp(System.currentTimeMillis());
            AttackTextArea.setText(AttackTextArea.getText() + "\nEnding the Attack at: " + EndAttack + "\n");
            System.out.println("Ending the Attack at: " + EndAttack);
            ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET END_ATTACK_TIMESTAMP=?, ATTACK_RESULT='UNDEFINED' WHERE ID=?");
            ps_update.setTimestamp(1, EndAttack);
            ps_update.setInt(2, ATTACK_PAYLOADS_ID);
            ps_update.executeUpdate();

            //the next commit may originate the following error:
            //XJ073
            //The data in this BLOB or CLOB is no longer available. The BLOB/CLOB's transaction may be committed, or its connection is closed.
            conn.commit();
        }
        rs.close();
        ps.close();

        //Stop the MySQL Listener
        AttackTextArea.setText(AttackTextArea.getText() + "Correlating the ATTACK_PAYLOADS table with the TARGET_PHP_FILES_RUNS_FUNCTIONS table\n");
        System.out.println("Correlating the ATTACK_PAYLOADS table with the TARGET_PHP_FILES_RUNS_FUNCTIONS table");
        ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET ATTACK_TARGET_PHP_FILES_RUNS_FUNCTION=(SELECT TARGET_PHP_FILES_RUNS_FUNCTIONS.ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_TIMESTAMP > ATTACK_PAYLOADS.START_ATTACK_TIMESTAMP AND TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_TIMESTAMP < ATTACK_PAYLOADS.END_ATTACK_TIMESTAMP) WHERE ATTACK_TARGET_PHP_FILES_RUNS_FUNCTION IS NULL");
        ps_update.executeUpdate();
        ps_update.close();

        conn.commit();
        conn.close();

        JavaDBAccess2 = null;


        //Stop the MySQL Listener
        AttackTextArea.setText(AttackTextArea.getText() + "Stopping MySQL Listener\n");
        System.out.println("Stopping MySQL Listener");
        StopMySQLListener();
        //Stop the HTTP Proxy
        AttackTextArea.setText(AttackTextArea.getText() + "Stopping HTTP Proxy\n");
        System.out.println("Stopping HTTP Proxy");
        StopHTTPProxy();
        //Updates the MYSQL_PROXY_PACKETS with the correct HTTP packets
        AttackTextArea.setText(AttackTextArea.getText() + "Updating the MYSQL_PROXY_PACKETS with the correct HTTP packets\n");
        System.out.println("Updating the MYSQL_PROXY_PACKETS with the correct HTTP packets");
        MySQL2HTTP();
        //Matching HTTP variables with SQL Queries and SQL variables
        AttackTextArea.setText(AttackTextArea.getText() + "Matching HTTP variables with SQL Queries and SQL variables\n");
        System.out.println("Matching HTTP variables with SQL Queries and SQL variables");
        HTTPVariables2SQLQueries();

        EndAttackGlobal = new java.sql.Timestamp(System.currentTimeMillis());
        AttackTextArea.setText(AttackTextArea.getText() + "\nStarted the Overall Attack at: " + StartAttackGlobal + "\n");
        AttackTextArea.setText(AttackTextArea.getText() + "Ending the Overall Attack at:  " + EndAttackGlobal + "\n");
        long stopTime = System.currentTimeMillis();
        long elapsedTime = stopTime - startTime;
        System.out.println(elapsedTime);
        AttackTextArea.setText(AttackTextArea.getText() + "\nElapsed time : " + elapsedTime + "(ms)\n");
        AttackTextArea.setText(AttackTextArea.getText() + "Elapsed time : " + elapsedTime / 1000 / 60 + "(m)\n");


    } catch (Throwable e) {
        System.out.println("Errors in StartAttackButtonActionPerformed!");
        System.out.println("exception thrown:");

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }

}