@Override
        protected void finished() {
            setMessage("Done Shutting Down the Databaase.");
//            setSaveNeeded(false);
        }
    }

    @Action
    public void showNotesBox() {
        if (NotesBox == null) {
            NotesBox = new JDialog(new JFrame());
//            NotesBox.setLocationRelativeTo(mainFrame);
        }
        NotesBox.pack();
        NotesBox.setLocationRelativeTo(null); //to be centered on the screen

        NotesBox.setVisible(true);
//        VulnerabilityInjectorApp.getApplication().show(NotesBox);
    }

    @Action
    public void showha_ckers_orgBox() {
        if (ha_ckers_orgBox == null) {
            ha_ckers_orgBox = new JDialog(new JFrame());
//            ha_ckers_orgBox.setLocationRelativeTo(mainFrame); //to be centered on the Application
        }
        ha_ckers_orgBox.pack();
        ha_ckers_orgBox.setLocationRelativeTo(null); //to be centered on the screen

        ha_ckers_orgBox.setVisible(true);
//        VulnerabilityInjectorApp.getApplication().show(ha_ckers_orgBox);
    }

    @Action
    public void showRegexBox() {
        if (RegexBox == null) {
            RegexBox = new JDialog(new JFrame());
//            RegexBox.setLocationRelativeTo(mainFrame);
        }
        RegexBox.pack();
        RegexBox.setLocationRelativeTo(null); //to be centered on the screen

        RegexBox.setVisible(true);
//        VulnerabilityInjectorApp.getApplication().show(RegexBox);
    }

    @Action
    public void showEncode_DecodeBox() {
        if (Encode_DecodeBox == null) {
            Encode_DecodeBox = new JDialog(new JFrame());
//            Encode_DecodeBox.setLocationRelativeTo(mainFrame);
        }
        Encode_DecodeBox.pack();
        Encode_DecodeBox.setLocationRelativeTo(null); //to be centered on the screen

        Encode_DecodeBox.setVisible(true);
//        VulnerabilityInjectorApp.getApplication().show(Encode_DecodeBox);
    }

    @Action
    public void showJavaDBSQL() {
        if (JavaDBSQLBox == null) {
            JavaDBSQLBox = new JDialog(new JFrame());
//            JavaDBSQLBox.setLocationRelativeTo(mainFrame);
        }
        JavaDBSQLBox.pack();
        JavaDBSQLBox.setLocationRelativeTo(null); //to be centered on the screen

        JavaDBSQLBox.setVisible(true);
//        VulnerabilityInjectorApp.getApplication().show(NotesBox);
    }
    // Exit this program.

    @Action
    public void actionExit() {
        int n;

        n = JOptionPane.showConfirmDialog(new JFrame(), "Are you sure you want to exit?", "Attention!", JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_OPTION);
        if (n == 0) {
            System.exit(0);
        }
    }

private void CreateDatabaseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreateDatabaseButtonActionPerformed
    JavaDBAccess.CreateDatabase();
    try {
        TargetPHPFileSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadTargetPHPFileData()));
    } catch (Throwable e) {
    }
}//GEN-LAST:event_CreateDatabaseButtonActionPerformed

private void AddPHPFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AddPHPFileButtonActionPerformed

    PHPFile.AddPHPFileToDatabase(JavaDBAccess, WebApplicationHOST.getText(), WebApplicationURL.getText(), Integer.parseInt(WebApplicationPORT.getText()), WebApplicationFileURL.getText());
    TargetPHPFileSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadTargetPHPFileData()));
}//GEN-LAST:event_AddPHPFileButtonActionPerformed

private void DeletePHPFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeletePHPFileButtonActionPerformed
    PHPFile.DeletePHPFileFromDatabase(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
    TargetPHPFileSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadTargetPHPFileData()));
}//GEN-LAST:event_DeletePHPFileButtonActionPerformed

private void ViewPHPFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewPHPFileButtonActionPerformed
    PHPFileTextArea.setText(PHPFile.ViewPHPFileFromDatabase(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString()));
}//GEN-LAST:event_ViewPHPFileButtonActionPerformed

private void AnalyzePHPFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnalyzePHPFileButtonActionPerformed
    PHPFile.AnalyzePHPFile(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
}//GEN-LAST:event_AnalyzePHPFileButtonActionPerformed

private void VulnerabilityInjectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_VulnerabilityInjectionButtonActionPerformed
    PHPFileTextArea.setText(VulnInject.VulnerabilityInjection(JavaDBAccess, PHPFile, TargetPHPFileSelectedComboBox.getSelectedItem().toString(),AffectSQLStaticCk.isSelected(),AffectSQLDynamicCk.isSelected()));
}//GEN-LAST:event_VulnerabilityInjectionButtonActionPerformed

private void ViewResultsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewResultsButtonActionPerformed
    VulnerabilityInjectionTextArea.setText(JavaDBAccess.ExecuteQuery("SELECT RESULTS.* FROM RESULTS,TARGET_PHP_FILES WHERE RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND TARGET_PHP_FILES.PATH='" + TargetPHPFileSelectedComboBox.getSelectedItem().toString() + "'"));
}//GEN-LAST:event_ViewResultsButtonActionPerformed

private void DeleteResultsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteResultsButtonActionPerformed
    JavaDBAccess.DeleteResults(TargetPHPFileSelectedComboBox.getSelectedItem().toString());
}//GEN-LAST:event_DeleteResultsButtonActionPerformed

private void CreateDiffFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreateDiffFilesButtonActionPerformed
    PHPFileTextArea.setText(VulnInject.CreateDiffFiles(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString()));
}//GEN-LAST:event_CreateDiffFilesButtonActionPerformed

private void DeleteDiffButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteDiffButtonActionPerformed
    VulnInject.DeleteDiffFiles(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
}//GEN-LAST:event_DeleteDiffButtonActionPerformed

private void CreateVulnerabilityFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CreateVulnerabilityFilesButtonActionPerformed
    VulnInject.CreateVulnerabilityFiles(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
}//GEN-LAST:event_CreateVulnerabilityFilesButtonActionPerformed

private void DeleteVulnerabilityFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteVulnerabilityFilesButtonActionPerformed
    VulnInject.DeleteVulnerabilityFiles(JavaDBAccess, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
}//GEN-LAST:event_DeleteVulnerabilityFilesButtonActionPerformed

//------------------------------------------------------------------------------
//Start ToolEncodeDecode Operations
//------------------------------------------------------------------------------
private void EncodeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_EncodeButtonActionPerformed
        String EncodeMethodText;
        ToolEncodeDecode encodeDecode = new ToolEncodeDecode();

        EncodeMethodText = EncodeMethod.getSelectedValue().toString();
        EncodedText.setText(encodeDecode.Encode(PlainText.getText(), false, "", EncodeMethodText));
}//GEN-LAST:event_EncodeButtonActionPerformed

private void DecodeButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DecodeButtonActionPerformed
    String DecodeMethodText;
    ToolEncodeDecode encodeDecode = new ToolEncodeDecode();

    DecodeMethodText = EncodeMethod.getSelectedValue().toString();
    PlainText.setText(encodeDecode.Decode(EncodedText.getText(), false, "", DecodeMethodText));
}//GEN-LAST:event_DecodeButtonActionPerformed

private void closeEncode_DecodeBoxButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeEncode_DecodeBoxButtonActionPerformed
    Encode_DecodeBox.setVisible(false);
}//GEN-LAST:event_closeEncode_DecodeBoxButtonActionPerformed

//------------------------------------------------------------------------------
//End ToolEncodeDecode Operations
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//Start ToolRegex Operations
//------------------------------------------------------------------------------
private void ReadFileRegexButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReadFileRegexButtonActionPerformed
        Regex.ReadFile(RegexFilePath, RegexFileName, RegexSubjectString);
}//GEN-LAST:event_ReadFileRegexButtonActionPerformed

private void TestRegexMatchButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_TestRegexMatchButtonActionPerformed
    Regex.TestRegexMatch(RegularExpression, CaseSensitiveCB, RegexMatchTrueFalse, RegexSubjectString);
}//GEN-LAST:event_TestRegexMatchButtonActionPerformed

private void RegexResultTableMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_RegexResultTableMouseClicked
    Regex.RegexResult(RegexResultTable, RegexSubjectString);
}//GEN-LAST:event_RegexResultTableMouseClicked

private void closeRegexBoxButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeRegexBoxButtonActionPerformed
    RegexBox.setVisible(false);
}//GEN-LAST:event_closeRegexBoxButtonActionPerformed

//------------------------------------------------------------------------------
//End ToolRegex Operations
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//Start ToolHackersOrg Operations
//------------------------------------------------------------------------------
private void OpenVulnerabilityXMLButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_OpenVulnerabilityXMLButtonActionPerformed
        HackersOrg.OpenVulnerabilityXML(XMLFileName);

}//GEN-LAST:event_OpenVulnerabilityXMLButtonActionPerformed

    private void ProcessVulnerabilityXMLButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ProcessVulnerabilityXMLButtonActionPerformed
        HackersOrg.ProcessVulnerabilityXML(XMLFileName, XSSAttackName, XSSAttackCode, XSSAttackDesc, XSSAttackLabel, XSSAttackBrowser, XSSAttackNames);
}//GEN-LAST:event_ProcessVulnerabilityXMLButtonActionPerformed

private void XSSAttackNamesValueChanged(javax.swing.event.ListSelectionEvent evt) {//GEN-FIRST:event_XSSAttackNamesValueChanged
    HackersOrg.XSSAttackNamesValueChanged(XMLFileName, XSSAttackName, XSSAttackCode, XSSAttackDesc, XSSAttackLabel, XSSAttackBrowser, XSSAttackNames);
}//GEN-LAST:event_XSSAttackNamesValueChanged

private void closeHa_ckers_orgBoxButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeHa_ckers_orgBoxButtonActionPerformed
    ha_ckers_orgBox.setVisible(false);
}//GEN-LAST:event_closeHa_ckers_orgBoxButtonActionPerformed

//------------------------------------------------------------------------------
//End ToolHackersOrg Operations
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//Start ToolJavaDBSQL Operations
//------------------------------------------------------------------------------
private void closeJavaDBSQLBoxButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeJavaDBSQLBoxButtonActionPerformed
        JavaDBSQLBox.setVisible(false);
}//GEN-LAST:event_closeJavaDBSQLBoxButtonActionPerformed

private void ExecuteJavaDBSQLCommandButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ExecuteJavaDBSQLCommandButtonActionPerformed
    JavaDBSQLResult.setText(JavaDBAccess.ExecuteQuery(JavaDBSQLCommand.getText()));
}//GEN-LAST:event_ExecuteJavaDBSQLCommandButtonActionPerformed

//------------------------------------------------------------------------------
//End ToolJavaDBSQL Operations
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//Start ToolNotes Operations
//------------------------------------------------------------------------------
private void closeNotesBoxButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_closeNotesBoxButtonActionPerformed
        NotesBox.setVisible(false);
}//GEN-LAST:event_closeNotesBoxButtonActionPerformed
//------------------------------------------------------------------------------
//End ToolNotes Operations
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//Start MySQL Listener Operations
//------------------------------------------------------------------------------
private void DeleteMySQLListenerDBDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteMySQLListenerDBDataButtonActionPerformed
        MySQLPacket.DeleteMySQLListenerDBData(JavaDBAccess);
}//GEN-LAST:event_DeleteMySQLListenerDBDataButtonActionPerformed

private void ViewMySQLPacketsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ViewMySQLPacketsButtonActionPerformed
    MySQLListenerTextArea.setText(MySQLPacket.ViewMySQLPackets(JavaDBAccess));
}//GEN-LAST:event_ViewMySQLPacketsButtonActionPerformed

private void StartMySQLListenerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartMySQLListenerButtonActionPerformed
    StartMySQLListener(ModeComboBox.getSelectedItem().toString());
}//GEN-LAST:event_StartMySQLListenerButtonActionPerformed

    private void StartMySQLListener(String MODE) {
        int port = -1;
        MySQLListener MySQLList;

        try {
            // get the command-line parameters
            port = Integer.parseInt(MySQLListenerProxyPort.getText());
        } catch (NumberFormatException e) {
            port = -1;
        }
        if (port < 0 | port > 63335) {
            port = 18000;
        }
        if (usingMySQLListener == false) {
            try {
                MySQLListenerResult = new java.util.Vector();
                // create and start the jProxy thread, using a 20 second timeout
                // value to keep the threads from piling up too much
                System.err.println("  **  Starting jProxy on port " + port + ". Press CTRL-C to end.  **\n");
                MySQLListenerResult.addElement(MySQLList = new MySQLListener(port, DBprops, MODE));
                MySQLList.start();
                usingMySQLListener = true;
            } catch (Exception e) {
                usingMySQLListener = false;
                System.err.println(e.getMessage());
                System.exit(1);
            }
        }
    }

private void StopMySQLListenerButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopMySQLListenerButtonActionPerformed
    StopMySQLListener();
}//GEN-LAST:event_StopMySQLListenerButtonActionPerformed

    private void StopMySQLListener() {
        Thread t = null;

//    System.out.println(HTTPProxyResult.capacity());
//    System.out.println(HTTPProxyResult.size());
//
        if (usingMySQLListener == true) {
            while (!MySQLListenerResult.isEmpty()) {
                t = (Thread) MySQLListenerResult.get(0);
                t.interrupt();
                MySQLListenerResult.remove(0);
            }
            usingMySQLListener = false;
            MySQLPacket.AnalyzeMySQLPackets(JavaDBAccess);
        }
//    System.out.println(HTTPProxyResult.size());
//    System.out.println(HTTPProxyResult.capacity());

    }

//------------------------------------------------------------------------------
//End MySQL Listener Operations
//------------------------------------------------------------------------------

//------------------------------------------------------------------------------
//Start Proxy Operations
//------------------------------------------------------------------------------
private void StartHTTPProxyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartHTTPProxyButtonActionPerformed
        StartHTTPProxy(ModeComboBox.getSelectedItem().toString());
}//GEN-LAST:event_StartHTTPProxyButtonActionPerformed

    private void StartHTTPProxy(String MODE) {
        int port = -1;
        String fwdProxyServer = "";
        int fwdProxyPort = 0;
        jProxy jp;

        try {
            // get the command-line parameters
            port = Integer.parseInt(HTTPProxySourcePort.getText());
        } catch (NumberFormatException e) {
            port = -1;
        }
        if (port < 0 | port > 63335) {
            port = 8080;
        }
        if (usingProxy == false) {
            try {
                HTTPProxyResult = new java.util.Vector();
                // create and start the jProxy thread, using a 20 second timeout
                // value to keep the threads from piling up too much
                System.err.println("  **  Starting jProxy on port " + port + ". Press CTRL-C to end.  **\n");
                HTTPProxyResult.addElement(jp = new jProxy(port, fwdProxyServer, fwdProxyPort, 20, DBprops, MODE));
                jp.setDebug(1, System.out);		// or set the debug level to 2 for tons of output

                jp.start();
                usingProxy = true;
            } catch (Exception e) {
                usingProxy = false;
                System.err.println(e.getMessage());
                System.exit(1);
            }
        }
    }

private void StopHTTPProxyButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopHTTPProxyButtonActionPerformed
    StopHTTPProxy();
}//GEN-LAST:event_StopHTTPProxyButtonActionPerformed

    private void StopHTTPProxy() {
        Thread t = null;

//    System.out.println(HTTPProxyResult.capacity());
//    System.out.println(HTTPProxyResult.size());
//
        if (usingProxy == true) {
            while (!HTTPProxyResult.isEmpty()) {
                t = (Thread) HTTPProxyResult.get(0);
                t.interrupt();
                HTTPProxyResult.remove(0);
            }
            usingProxy = false;
        }
//    System.out.println(HTTPProxyResult.size());
//    System.out.println(HTTPProxyResult.capacity());
    }

private void DeleteHTTPProxyDBDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteHTTPProxyDBDataButtonActionPerformed
    Connection conn = null;
    PreparedStatement ps = null;
    MySQLPacket.DeleteMySQLListenerDBData(JavaDBAccess);
    try {
        if ((conn = this.JavaDBAccess.setConn()) != null) {
            System.out.println("Connected to database " + JavaDBAccess.getDatabaseName());
        } else {
            throw new Exception("Not connected to database " + JavaDBAccess.getDatabaseName());
        }

        conn.setAutoCommit(false);

        // Start a transaction by inserting a record in the TARGET_PHP_FILES_FUNCTIONS table
        ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES");
        ps.executeUpdate();
        ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS");
        ps.executeUpdate();
        ps.close();
        conn.commit();
        conn.close();
    } catch (Throwable e) {
        System.out.println("exception thrown:");

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_DeleteHTTPProxyDBDataButtonActionPerformed
//------------------------------------------------------------------------------
//End Proxy Operations
//------------------------------------------------------------------------------
//------------------------------------------------------------------------------
//Start Attack Operations
//------------------------------------------------------------------------------
private void MaxIDButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MaxIDButtonActionPerformed
        jTextField1.setText(String.valueOf(Attack.getMaxID(JavaDBAccess)));
}//GEN-LAST:event_MaxIDButtonActionPerformed

private void ReadRequestButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ReadRequestButtonActionPerformed
    SQLInjectionAttackTextArea.setText(Attack.getRequestText(JavaDBAccess, Integer.parseInt(jTextField1.getText())));
    jTextField2.setText(Attack.getRequestHost(JavaDBAccess, Integer.parseInt(jTextField1.getText())));
}//GEN-LAST:event_ReadRequestButtonActionPerformed

private void RefreshPreviewButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefreshPreviewButtonActionPerformed
    try {
        displayPreviewPane.setContentType("text/html");
        displayPreviewPane.setEditable(false);
        Document doc = (Document) displayPreviewPane.getDocument();
        doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
        displayPreviewPane.setText(SQLInjectionAttackTextArea1.getText());
    } catch (Exception e) {
        System.out.println("exception thrown:" + e);
    }

}//GEN-LAST:event_RefreshPreviewButtonActionPerformed

private void SendHTTPButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_SendHTTPButtonActionPerformed
    String output = "";
    String header = "";
    String html = "";
    int pos = -1;

    try {
        output = Attack.issueRequest(SQLInjectionAttackTextArea.getText(), jTextField2.getText(), Integer.parseInt(jTextField3.getText()));
    } catch (Exception e) {
        output = e.toString();
    }
    if (!output.equals("")) {
        pos = output.indexOf("\r\n\r\n");
        if (pos > 0) {
            html = output.substring(pos + 4);
            header = output.substring(0, pos + 4);
        }
    }
    SQLInjectionAttackTextArea2.setText(header);
    SQLInjectionAttackTextArea1.setText(html);
    try {
        displayPreviewPane.setContentType("text/html");
        displayPreviewPane.setEditable(false);
//    displayPreviewPane.setPage("http://192.168.1.90/html/phd-mysql/index.php");
        Document doc = (Document) displayPreviewPane.getDocument();
        doc.putProperty("IgnoreCharsetDirective", new Boolean(true));
        displayPreviewPane.setText(html);
    } catch (Exception e) {
        System.out.println("exception thrown:" + e);
    }
}//GEN-LAST:event_SendHTTPButtonActionPerformed

private void PayloadHTTPSelectedComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_PayloadHTTPSelectedComboBoxActionPerformed
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    try {
        if ((conn = this.JavaDBAccess.setConn()) != null) {
            System.out.println("Connected to database " + JavaDBAccess.getDatabaseName());
        } else {
            throw new Exception("Not connected to database " + JavaDBAccess.getDatabaseName());
        }

        conn.setAutoCommit(false);

        // Start a transaction by inserting a record in the TARGET_PHP_FILES_FUNCTIONS table
        ps = conn.prepareStatement("SELECT HTTP_REQUEST_HEADER||HTTP_REQUEST_POST,HTTP_REQUEST_HOST,HTTP_RESPONSE_HEADER||HTTP_RESPONSE_CONTENT FROM TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE ID=?");
        ps.setInt(1, Integer.parseInt(PayloadHTTPSelectedComboBox.getSelectedItem().toString()));
        rs = ps.executeQuery(); // get the HTTPProxyResult

        while (rs.next()) {
            HTTPRequestTextArea.setText(rs.getString(1));
            SQLInjectionAttackTextArea.setText(rs.getString(1));
            jTextField2.setText(rs.getString(2));
            HTTPResponseTextArea.setText(rs.getString(3));
        }
        rs.close();
        ps.close();
        conn.commit();
        conn.close();
    } catch (Throwable e) {
        System.out.println("exception thrown:");

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_PayloadHTTPSelectedComboBoxActionPerformed

private void ApplyPayloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApplyPayloadButtonActionPerformed
    int InitialPosition = 0, FinalPosition = 0, FinalPosition1 = 0, FinalPosition2 = 0;
    String TargetVariable = "", TargetHTTPRequest = "", EncodedPayload = "";
    ToolEncodeDecode encodeDecode = new ToolEncodeDecode();

    TargetVariable = SQLVariableSelectedComboBox.getSelectedItem().toString().substring(1);//Remove the $ at the begining of the variable name

    EncodedPayload = PayloadSelectedComboBox.getSelectedItem().toString();

    EncodedPayload = encodeDecode.Encode(EncodedPayload, false, "", "HTTP");


    InitialPosition = HTTPRequestTextArea.getText().indexOf(TargetVariable);
    FinalPosition1 = HTTPRequestTextArea.getText().indexOf(" ", InitialPosition);
    FinalPosition2 = HTTPRequestTextArea.getText().indexOf("&", InitialPosition);
    if (FinalPosition1 > FinalPosition2) {
        FinalPosition = FinalPosition2;
    } else {
        FinalPosition = FinalPosition1;
    }
    if (FinalPosition < 0) {//it is the last POST variable

        TargetHTTPRequest = HTTPRequestTextArea.getText() + EncodedPayload;
    } else {
        TargetHTTPRequest = HTTPRequestTextArea.getText().substring(0, FinalPosition) + EncodedPayload + HTTPRequestTextArea.getText().substring(FinalPosition);
    }
    HTTPRequestTextArea.setText(TargetHTTPRequest);
    SQLInjectionAttackTextArea.setText(TargetHTTPRequest);
}//GEN-LAST:event_ApplyPayloadButtonActionPerformed

private void backButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_backButtonActionPerformed
// Go back to the page viewed before the current page.
    URL currentUrl = displayEditorPane.getPage();
    int pageIndex = pageList.indexOf(currentUrl.toString());
    try {
        showPage(new URL((String) pageList.get(pageIndex - 1)), false);
    } catch (Exception e) {
    }
}//GEN-LAST:event_backButtonActionPerformed

private void forwardButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_forwardButtonActionPerformed
    URL currentUrl = displayEditorPane.getPage();
    int pageIndex = pageList.indexOf(currentUrl.toString());
    try {
        showPage(new URL((String) pageList.get(pageIndex + 1)), false);
    } catch (Exception e) {
    }
}//GEN-LAST:event_forwardButtonActionPerformed

private void goButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_goButtonActionPerformed
// Load and show the page specified in the location packet field.
    URL verifiedUrl = verifyUrl(locationTextField.getText());
    if (verifiedUrl != null) {
        showPage(verifiedUrl, true);
    } else {
        showError("Invalid URL");
    }
}//GEN-LAST:event_goButtonActionPerformed

private void MySQL2HTTPButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_MySQL2HTTPButtonActionPerformed
    MySQL2HTTP();
}//GEN-LAST:event_MySQL2HTTPButtonActionPerformed

    private void MySQL2HTTP() {
        Connection conn = null;
        Statement s = null;
        PreparedStatement ps_select = null, ps_update = null;
        ResultSet rs_select = null;
        int MYSQL_PROXY_PACKETS_ID = 0, SERVER = 0, TARGET_PHP_FILES_RUNS_FUNCTION = 0, TARGET_PHP_FILES_RUNS_FUNCTION_OLD = 0;
        int counter = 1;

        try {
            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);

            s = conn.createStatement();
            //Updates the TARGET_PHP_FILES_RUNS_FUNCTION field of the MYSQL_PROXY_PACKETS table, except for the last TARGET_PHP_FILES_RUNS_FUNCTIONS
//            s.executeUpdate("UPDATE MYSQL_PROXY_PACKETS M SET TARGET_PHP_FILES_RUNS_FUNCTION=(SELECT P.ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS P WHERE M.PACKET_TIMESTAMP IN ( SELECT PACKET_TIMESTAMP FROM MYSQL_PROXY_PACKETS WHERE PACKET_TIMESTAMP > P.HTTP_REQUEST_TIMESTAMP AND PACKET_TIMESTAMP < ( SELECT MIN(HTTP_REQUEST_TIMESTAMP) FROM TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE HTTP_REQUEST_TIMESTAMP>P.HTTP_REQUEST_TIMESTAMP)))");
            s.executeUpdate("UPDATE MYSQL_PROXY_PACKETS M SET TARGET_PHP_FILES_RUNS_FUNCTION=(SELECT P.ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS P WHERE M.PACKET_TIMESTAMP > P.HTTP_REQUEST_TIMESTAMP AND M.PACKET_TIMESTAMP < (SELECT MIN(HTTP_REQUEST_TIMESTAMP) FROM TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE HTTP_REQUEST_TIMESTAMP>P.HTTP_REQUEST_TIMESTAMP)) WHERE TARGET_PHP_FILES_RUNS_FUNCTION IS NULL");
            conn.commit();
            //Updates the TARGET_PHP_FILES_RUNS_FUNCTION field of the MYSQL_PROXY_PACKETS table, just for the case of the last TARGET_PHP_FILES_RUNS_FUNCTIONS
            s.executeUpdate("UPDATE MYSQL_PROXY_PACKETS M SET TARGET_PHP_FILES_RUNS_FUNCTION=(SELECT P.ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS P WHERE M.PACKET_TIMESTAMP IN ( SELECT PACKET_TIMESTAMP FROM MYSQL_PROXY_PACKETS WHERE PACKET_TIMESTAMP > P.HTTP_REQUEST_TIMESTAMP AND P.HTTP_REQUEST_TIMESTAMP = ( SELECT MAX(HTTP_REQUEST_TIMESTAMP) FROM TARGET_PHP_FILES_RUNS_FUNCTIONS))) WHERE TARGET_PHP_FILES_RUNS_FUNCTION IS NULL");
            conn.commit();
            s.close();


            ps_select = conn.prepareStatement("SELECT ID,SERVER,TARGET_PHP_FILES_RUNS_FUNCTION FROM MYSQL_PROXY_PACKETS WHERE CLIENT_SERVER='C' ORDER BY TARGET_PHP_FILES_RUNS_FUNCTION,THIS_THREAD_ID");
            rs_select = ps_select.executeQuery();

            counter = 1;
            while (rs_select.next()) {
                MYSQL_PROXY_PACKETS_ID = rs_select.getInt(1);
                SERVER = rs_select.getInt(2);
                TARGET_PHP_FILES_RUNS_FUNCTION = rs_select.getInt(3);
                if (TARGET_PHP_FILES_RUNS_FUNCTION_OLD != TARGET_PHP_FILES_RUNS_FUNCTION) {
                    counter = 1;
                }
                ps_update = conn.prepareStatement("UPDATE MYSQL_PROXY_PACKETS SET HTTP_PACKET_SEQUENCE=? WHERE ID=?");
                ps_update.setInt(1, counter);
                ps_update.setInt(2, MYSQL_PROXY_PACKETS_ID);
                ps_update.executeUpdate();
                counter++;
                ps_update = conn.prepareStatement("UPDATE MYSQL_PROXY_PACKETS SET HTTP_PACKET_SEQUENCE=? WHERE ID=?");
                ps_update.setInt(1, counter);
                ps_update.setInt(2, SERVER);
                ps_update.executeUpdate();
                counter++;

                TARGET_PHP_FILES_RUNS_FUNCTION_OLD = TARGET_PHP_FILES_RUNS_FUNCTION;
            }
            ps_update.close();
            rs_select.close();
            ps_select.close();
            conn.commit();

            conn.close();

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

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

private void HostPathButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_HostPathButtonActionPerformed
    JFileChooser fc = new JFileChooser();
    if (HostPath.getText().isEmpty()) {
        fc.setCurrentDirectory(new java.io.File("."));
    } else {
        fc.setCurrentDirectory(new java.io.File(HostPath.getText()));
    }
    fc.setDialogTitle("Open the PATH of the HTTP HOST to get its location");
    fc.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
    // disable the "All files" option.
    fc.setAcceptAllFileFilterUsed(false);

    // Show open dialog; this method does not return until the dialog is closed
    if (fc.showOpenDialog(new JFrame()) == JFileChooser.APPROVE_OPTION) {
        HostPath.setText(fc.getSelectedFile().getAbsolutePath().toString());
    }
}//GEN-LAST:event_HostPathButtonActionPerformed

    private void VulnerabilityInjectionAll(Boolean AffectSQLStatic, Boolean AffectSQLDynamic) {
        Connection conn = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        DatabaseAccess JavaDBAccess2 = null;

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

            conn.setAutoCommit(false);

            // Start a transaction by inserting a record in the TARGET_PHP_FILES_FUNCTIONS table
            ps = conn.prepareStatement("SELECT PATH FROM TARGET_PHP_FILES");
            rs = ps.executeQuery();
            while (rs.next()) {
                JavaDBAccess2 = new DatabaseAccess(DBprops);
                VulnInject.VulnerabilityInjection(JavaDBAccess2, PHPFile, rs.getString("PATH"), AffectSQLStatic, AffectSQLDynamic);
                JavaDBAccess2 = null;
            }
            ps.close();
            conn.commit();
            conn.close();
        } catch (Throwable e) {
            InspectionTextArea.setText("Errors deleting DB data!");
            System.out.println("exception thrown:");

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

    }

private void StaticAnalysisButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StaticAnalysisButtonActionPerformed
    //Performing Static Analyzis of the files used in the HTTP packets
    InspectionTextArea.setText(InspectionTextArea.getText() + "Performing Static Analyzis of the files used in the HTTP packets\n");
    HTTP2WebApplication(HostPath.getText(), "INSPECTION");
    //Performing Vulnerability Injection
    InspectionTextArea.setText(InspectionTextArea.getText() + "Performing Vulnerability Injection\n");
    VulnerabilityInjectionAll(AffectSQLStaticCk.isSelected(), AffectSQLDynamicCk.isSelected());

    //Updating the 'Target PHP File Selected' Combo Box
    InspectionTextArea.setText(InspectionTextArea.getText() + "Updating the 'Target PHP File Selected' Combo Box\n");
    TargetPHPFileSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadTargetPHPFileData()));

    InspectionTextArea.setText(InspectionTextArea.getText() + "Processing Complete!\n");
}//GEN-LAST:event_StaticAnalysisButtonActionPerformed

private void DeleteStaticDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteStaticDataButtonActionPerformed
    DeleteStaticData();
}//GEN-LAST:event_DeleteStaticDataButtonActionPerformed

    private void DeleteStaticData() {
        Connection conn = null;
        PreparedStatement ps = null;
        try {
            //First we need to delete the Attack data
            DeleteAttackData();

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

            conn.setAutoCommit(false);

            //Reset the link to the HTTP data
            ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES SET TARGET_PHP_FILES_VARIABLE=NULL");
            ps.executeUpdate();
            ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES_RUNS_FUNCTIONS SET TARGET_PHP_FILE=NULL");
            ps.executeUpdate();

            //Delete the values of the Static data
            ps = conn.prepareStatement("DELETE FROM VULNERABILITY_INJECTION_RESULTS");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM VARIABLES_SQL_VARIABLES");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_SQL_VARIABLES");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_FUNCTIONS");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_VARIABLES");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_INCLUDES");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_WEB_APPLICATIONS");
            ps.executeUpdate();
            ps.close();
            conn.commit();
            conn.close();

            //Updating the 'Target PHP File Selected' Combo Box
            TargetPHPFileSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadTargetPHPFileData()));

            InspectionTextArea.setText("Static data deleted!");
        } catch (Throwable e) {
            InspectionTextArea.setText("Errors deleting Static data!");
            System.out.println("exception thrown:");

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

private void DeleteAttackDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteAttackDataButtonActionPerformed
    DeleteAttackData();
}//GEN-LAST:event_DeleteAttackDataButtonActionPerformed

private void DeleteHTTPDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteHTTPDataButtonActionPerformed
    DeleteHTTPData();
}//GEN-LAST:event_DeleteHTTPDataButtonActionPerformed

private void DeleteMySQLDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteMySQLDataButtonActionPerformed
    DeleteMySQLData();
}//GEN-LAST:event_DeleteMySQLDataButtonActionPerformed

private void DeleteAllDBDataButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_DeleteAllDBDataButtonActionPerformed
    DeleteAttackData();
}//GEN-LAST:event_DeleteAllDBDataButtonActionPerformed

private void AnalyzeMySQLPacketsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_AnalyzeMySQLPacketsButtonActionPerformed
    MySQLPacket.AnalyzeMySQLPackets(JavaDBAccess);
}//GEN-LAST:event_AnalyzeMySQLPacketsButtonActionPerformed

private void ParsePHPFileButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ParsePHPFileButtonActionPerformed
    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
    int TARGET_PHP_FILES_ID = 0;

    try {
        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 ID,TEXT FROM TARGET_PHP_FILES");
        rs = ps.executeQuery();

        while (rs.next()) {
            TARGET_PHP_FILES_ID = rs.getInt(1);
            JavaDBAccess.CleanPHPFile(TARGET_PHP_FILES_ID, JavaDBAccess);
        }
        rs.close();
        ps.close();
        conn.commit();
        conn.close();

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

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_ParsePHPFileButtonActionPerformed

private void StartInspectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartInspectionButtonActionPerformed
    String Message = "";
    int n = 0;
    if (!StartedInspection) {
        Message = "The MySQL Proxy must be running before clicking on the Start Inspection button (runMySQLProxy.sh)!\n";
        Message += "The Web Browser must have the proxy server parameter configurated\n";
        Message += "\nAre you sure you want to START the Inspection Stage?";
        n = JOptionPane.showConfirmDialog(new JFrame(), Message, "Attention!", JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.YES_OPTION) {//Start Inspection

            StartedInspection = true;
            InspectionLabel.setText("An Inspection is beeing performed");
            System.out.println("An Inspection is beeing performed");
            InspectionLabel.setForeground(Color.RED);
            //Start the MySQL Listener
            InspectionTextArea.setText("Starting MySQL Listener\n");
            System.out.println("Starting MySQL Listener");
            StartMySQLListener("INSPECTION");
            //Start the HTTP Proxy
            InspectionTextArea.setText(InspectionTextArea.getText() + "Starting HTTP Proxy\n");
            System.out.println("Starting HTTP Proxy");
            StartHTTPProxy("INSPECTION");
            InspectionTextArea.setText(InspectionTextArea.getText() + "You may start interacting with the web application\n...\n");
        } else {
            InspectionTextArea.setText(InspectionTextArea.getText() + "Start Inspection Aborted by user\n");
        }
    }
}//GEN-LAST:event_StartInspectionButtonActionPerformed

private void StopInspectionButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopInspectionButtonActionPerformed
    int n = 0;
    if (StartedInspection) {
        n = JOptionPane.showConfirmDialog(new JFrame(), "Are you sure you want to STOP the Inspection Stage?", "Attention!", JOptionPane.ERROR_MESSAGE, JOptionPane.YES_NO_OPTION);
        if (n == JOptionPane.YES_OPTION) {//Stop Inspection

            StartedInspection = false;
            InspectionLabel.setText("No Inspection is beeing performed");
            System.out.println("No Inspection is beeing performed");
            InspectionLabel.setForeground(Color.BLACK);
            //Stop the MySQL Listener
            InspectionTextArea.setText(InspectionTextArea.getText() + "Stopping MySQL Listener\n");
            System.out.println("Stopping MySQL Listener");
            StopMySQLListener();
            //Stop the HTTP Proxy
            InspectionTextArea.setText(InspectionTextArea.getText() + "Stopping HTTP Proxy\n");
            System.out.println("Stopping HTTP Proxy");
            StopHTTPProxy();
            //Updates the MYSQL_PROXY_PACKETS with the correct HTTP packets
            InspectionTextArea.setText(InspectionTextArea.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
            InspectionTextArea.setText(InspectionTextArea.getText() + "Matching HTTP variables with SQL Queries and SQL variables\n");
            System.out.println("Matching HTTP variables with SQL Queries and SQL variables");
            HTTPVariables2SQLQueries();
            //Performing Static Analyzis of the files used in the HTTP packets
            InspectionTextArea.setText(InspectionTextArea.getText() + "Performing Static Analyzis of the files used in the HTTP packets\n");
            System.out.println("Performing Static Analyzis of the files used in the HTTP packets");
            HTTP2WebApplication(HostPath.getText(), "INSPECTION");
            //Performing Vulnerability Injection
            InspectionTextArea.setText(InspectionTextArea.getText() + "Performing Vulnerability Injection\n");
            System.out.println("Performing Vulnerability Injection");
            VulnerabilityInjectionAll(AffectSQLStaticCk.isSelected(), AffectSQLDynamicCk.isSelected());

            //Updating the 'Target PHP File Selected' Combo Box
            InspectionTextArea.setText(InspectionTextArea.getText() + "Updating the 'Target PHP File Selected' Combo Box\n");
            System.out.println("Updating the 'Target PHP File Selected' Combo Box");
            TargetPHPFileSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadTargetPHPFileData()));

            InspectionTextArea.setText(InspectionTextArea.getText() + "Processing Complete!\n");
            System.out.println("Processing Complete!");
        } else {
            InspectionTextArea.setText(InspectionTextArea.getText() + "Stop Inspection Aborted by user\n");
            System.out.println("Stop Inspection Aborted by user");
        }
    }
}//GEN-LAST:event_StopInspectionButtonActionPerformed

private void GenerateAttackPayloadsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_GenerateAttackPayloadsButtonActionPerformed
    PreparedStatement ps = null, ps_attack = null;
    ResultSet rs = null;
    Connection conn = null;
    String HTTPRequest = "", ParameterName = "", ParameterValue = "", ParameterEncodedValue = "", HTTPRequestHeader = "", HTTPRequestGET = "", NewHTTPRequestGET = "", HTTPRequestPOST = "", Type = "";
    int ATTACK_PAYLOADS_ID = 0;
    int posStart = -1, posEnd = -1, ContentLength = 0, count = 0;
    ToolEncodeDecode encodeDecode = new ToolEncodeDecode();

    try {
        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("DELETE FROM ATTACK_PAYLOADS");
        ps.executeUpdate();
        //Inserting the Foreign Keys in the ATTACK_PAYLOADS table
        //Although there is a DISTINCT clause in the following query, there it does not work because of a annoying "bug"/"feature" of the JavaDB.
        //This error can be seen if executing the query directely in a JAvaDB console
        //I corrected the error by using a GROUP BY instead of the DISTINCT!!!!!!!!
        ps = conn.prepareStatement("INSERT INTO ATTACK_PAYLOADS (VULNERABILITY_INJECTION_RESULT,TARGET_PHP_FILES_RUNS_FUNCTION,TARGET_PHP_FILES_VARIABLE,PAYLOAD,TYPE) (SELECT VULNERABILITY_INJECTION_RESULTS.ID,TARGET_PHP_FILES_RUNS_FUNCTIONS.ID,VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILES_VARIABLE,PAYLOADS.ID,TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TYPE FROM VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES_VARIABLES,TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES,TARGET_PHP_FILES_RUNS_FUNCTIONS,PAYLOADS WHERE TARGET_PHP_FILES_VARIABLES.ID=VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILES_VARIABLE AND TARGET_PHP_FILES_VARIABLES.ID=TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_VARIABLE AND TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_RUNS_FUNCTION=TARGET_PHP_FILES_RUNS_FUNCTIONS.ID AND TARGET_PHP_FILES_RUNS_FUNCTIONS.MODE='INSPECTION')");
        ps.executeUpdate();
        ps.close();

        ps = conn.prepareStatement("SELECT ATTACK_PAYLOADS.ID,ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION,TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TYPE,TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.NAME,TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.VALUE,PAYLOADS.PAYLOAD,TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_HEADER,TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_GET,TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_POST FROM ATTACK_PAYLOADS,TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES,PAYLOADS,TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_VARIABLE=ATTACK_PAYLOADS.TARGET_PHP_FILES_VARIABLE AND PAYLOADS.ID=ATTACK_PAYLOADS.PAYLOAD AND TARGET_PHP_FILES_RUNS_FUNCTIONS.ID=ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION AND TARGET_PHP_FILES_RUNS_FUNCTIONS.ID=TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_RUNS_FUNCTION AND ATTACK_PAYLOADS.TYPE=TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TYPE");
        rs = ps.executeQuery();
        while (rs.next()) {
            count++;
            ATTACK_PAYLOADS_ID = rs.getInt("ID");
            HTTPRequestHeader = rs.getString("HTTP_REQUEST_HEADER");
            HTTPRequestGET = rs.getString("HTTP_REQUEST_GET");
            HTTPRequestPOST = rs.getString("HTTP_REQUEST_POST");
            Type = rs.getString("TYPE");
            ParameterName = rs.getString("NAME");

            //Apply the Payload
            ParameterValue = rs.getString("VALUE") + " " + rs.getString("PAYLOAD");
            ParameterEncodedValue = encodeDecode.Encode(ParameterValue, false, "", "HTTP");

            if (Type.contentEquals("GET")) {
                posStart = HTTPRequestGET.lastIndexOf(ParameterName);
                posEnd = HTTPRequestGET.indexOf("&", posStart);
                if (posEnd == -1) {
                    NewHTTPRequestGET = HTTPRequestGET.substring(0, posStart) + ParameterName + "=" + ParameterEncodedValue;
                } else {
                    NewHTTPRequestGET = HTTPRequestGET.substring(0, posStart) + ParameterName + "=" + ParameterEncodedValue + HTTPRequestGET.substring(posEnd);
                }
                posStart = HTTPRequestHeader.indexOf(HTTPRequestGET);
                posEnd = posStart + HTTPRequestGET.length();
                HTTPRequestGET = NewHTTPRequestGET;
                HTTPRequestHeader = HTTPRequestHeader.substring(0, posStart) + HTTPRequestGET + HTTPRequestHeader.substring(posEnd);
            } else if (Type.contentEquals("POST")) {
                posStart = HTTPRequestPOST.lastIndexOf(ParameterName);
                posEnd = HTTPRequestPOST.indexOf("&", posStart);
                if (posEnd == -1) {
                    HTTPRequestPOST = HTTPRequestPOST.substring(0, posStart) + ParameterName + "=" + ParameterEncodedValue;
                } else {
                    HTTPRequestPOST = HTTPRequestPOST.substring(0, posStart) + ParameterName + "=" + ParameterEncodedValue + HTTPRequestPOST.substring(posEnd);
                }
            }
            posStart = HTTPRequestHeader.indexOf("Content-Length: ");
            if (posStart > 0) {
                posEnd = HTTPRequestHeader.indexOf("\r\n", posStart);
                ContentLength = HTTPRequestPOST.length();
                HTTPRequestHeader = HTTPRequestHeader.substring(0, posStart + 16) + ContentLength + HTTPRequestHeader.substring(posEnd);
            }
            HTTPRequest = HTTPRequestHeader + HTTPRequestPOST;

            ps_attack = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET ATTACK_INPUT=?, ATTACK_EXPECTED_OUTPUT=?, HTTP_REQUEST=? WHERE ID=?");
            ps_attack.setString(1, ParameterName + "=" + ParameterEncodedValue);
            ps_attack.setString(2, ParameterValue);
            ps_attack.setString(3, HTTPRequest);
            ps_attack.setInt(4, ATTACK_PAYLOADS_ID);
            ps_attack.executeUpdate();

        }
        ps.close();
        conn.commit();
        conn.close();
        AttackTextArea.setText(count + " Attack Payloads generated!\n");

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

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_GenerateAttackPayloadsButtonActionPerformed

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();
        }
    }

}//GEN-LAST:event_StartAttackButtonActionPerformed

private void RestoreMySQLDBButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RestoreMySQLDBButtonActionPerformed

    String line = "";
    File WorkingDirectory = null;
    int count = 0;

    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(ResultList.get(count).toString());
    }
    done = false;
}//GEN-LAST:event_RestoreMySQLDBButtonActionPerformed

private void RestorePHPFilesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RestorePHPFilesButtonActionPerformed
    String line = "";
    File WorkingDirectory = null;
    int count = 0;

    line = WebApplicationPHPFilesRestoreCommand.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(ResultList.get(count).toString());
    }
    done = false;
}//GEN-LAST:event_RestorePHPFilesButtonActionPerformed

private void CalculateAttackSuccessButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_CalculateAttackSuccessButtonActionPerformed
    PreparedStatement ps_update = null;
    Connection conn = null;

    try {
        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_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET ATTACK_RESULT='SUCCESSFUL' WHERE EXISTS (SELECT 1 FROM MYSQL_QUERIES Q1,MYSQL_PROXY_PACKETS P1,MYSQL_QUERIES Q2,MYSQL_PROXY_PACKETS P2 WHERE Q1.MYSQL_PROXY_PACKET_CLIENT=P1.ID AND P1.TARGET_PHP_FILES_RUNS_FUNCTION=ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION AND Q2.MYSQL_PROXY_PACKET_CLIENT=P2.ID AND P2.TARGET_PHP_FILES_RUNS_FUNCTION=ATTACK_PAYLOADS.ATTACK_TARGET_PHP_FILES_RUNS_FUNCTION AND P1.HTTP_PACKET_SEQUENCE=P2.HTTP_PACKET_SEQUENCE AND Q1.MYSQL_QUERY_SEQUENCE=Q2.MYSQL_QUERY_SEQUENCE AND Q1.SQL_COMMAND_STRUCTURE <> Q2.SQL_COMMAND_STRUCTURE) AND ATTACK_RESULT='UNDEFINED'");
        ps_update.executeUpdate();
        conn.commit();
        ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET ATTACK_RESULT='NOT SUCCESSFUL' WHERE EXISTS (SELECT 1 FROM MYSQL_QUERIES Q1,MYSQL_PROXY_PACKETS P1,MYSQL_QUERIES Q2,MYSQL_PROXY_PACKETS P2 WHERE Q1.MYSQL_PROXY_PACKET_CLIENT=P1.ID AND P1.TARGET_PHP_FILES_RUNS_FUNCTION=ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION AND Q2.MYSQL_PROXY_PACKET_CLIENT=P2.ID AND P2.TARGET_PHP_FILES_RUNS_FUNCTION=ATTACK_PAYLOADS.ATTACK_TARGET_PHP_FILES_RUNS_FUNCTION AND P1.HTTP_PACKET_SEQUENCE=P2.HTTP_PACKET_SEQUENCE AND Q1.MYSQL_QUERY_SEQUENCE=Q2.MYSQL_QUERY_SEQUENCE AND Q1.SQL_COMMAND_STRUCTURE = Q2.SQL_COMMAND_STRUCTURE) AND ATTACK_RESULT='UNDEFINED'");
        ps_update.executeUpdate();
        ps_update.close();
        conn.commit();
        ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET IDS_COMMAND_DETECTION_RESULT='NOT SUCCESSFUL' WHERE IDS_COMMAND_DETECTION_RESULT='UNDEFINED'");
        ps_update.executeUpdate();
        ps_update.close();
        conn.commit();
        if (UseIDSRadioButton.isSelected()) {
            ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET IDS_COMMAND_DETECTION_RESULT='SUCCESSFUL' WHERE UPPER(IDS_RESULT) LIKE '%MALICIOUS_COMMAND%'");
            ps_update.executeUpdate();
            ps_update.close();
            conn.commit();
            ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET IDS_TRANSACTION_DETECTION_RESULT='NOT SUCCESSFUL' WHERE IDS_TRANSACTION_DETECTION_RESULT='UNDEFINED'");
            ps_update.executeUpdate();
            ps_update.close();
            conn.commit();
            ps_update = conn.prepareStatement("UPDATE ATTACK_PAYLOADS SET IDS_TRANSACTION_DETECTION_RESULT='SUCCESSFUL' WHERE UPPER(IDS_RESULT) LIKE '%MALICIOUS_TRANSACTION%'");
            ps_update.executeUpdate();
            ps_update.close();
            conn.commit();
        }
        conn.close();

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

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_CalculateAttackSuccessButtonActionPerformed

private void ShowAttackResultsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ShowAttackResultsButtonActionPerformed
    PreparedStatement ps = null;
    ResultSet rs = null;
    Connection conn = null;
    int i;

    try {
        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);

        AttackTextArea.setText("");
        ps = conn.prepareStatement("SELECT COUNT(*) FROM ATTACK_PAYLOADS WHERE ATTACK_RESULT ='NOT SUCCESSFUL'");
        rs = ps.executeQuery();
        rs.next();
        AttackTextArea.setText(AttackTextArea.getText() + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
        AttackTextArea.setText(AttackTextArea.getText() + "Attacks not Successful: " + rs.getString(1) + "\n");
        ps = conn.prepareStatement("SELECT COUNT(*) FROM ATTACK_PAYLOADS WHERE ATTACK_RESULT ='UNDEFINED'");
        rs = ps.executeQuery();
        rs.next();
        AttackTextArea.setText(AttackTextArea.getText() + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
        AttackTextArea.setText(AttackTextArea.getText() + "Attacks not Successful (undefined): " + rs.getString(1) + "\n");
        ps = conn.prepareStatement("SELECT COUNT(*) FROM ATTACK_PAYLOADS WHERE ATTACK_RESULT ='SUCCESSFUL'");
        rs = ps.executeQuery();
        rs.next();
        AttackTextArea.setText(AttackTextArea.getText() + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
        AttackTextArea.setText(AttackTextArea.getText() + "Attacks Successful: " + rs.getString(1) + "\n");
        ps = conn.prepareStatement("SELECT 1 FROM ATTACK_PAYLOADS,VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES,TARGET_PHP_FILES_VARIABLES WHERE ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=VULNERABILITY_INJECTION_RESULTS.ID AND VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND ATTACK_PAYLOADS.TARGET_PHP_FILES_VARIABLE=TARGET_PHP_FILES_VARIABLES.ID AND ATTACK_PAYLOADS.ATTACK_RESULT ='SUCCESSFUL' GROUP BY ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION,TARGET_PHP_FILES.NAME,ATTACK_PAYLOADS.TARGET_PHP_FILES_VARIABLE,TARGET_PHP_FILES_VARIABLES.NAME,VULNERABILITY_INJECTION_RESULTS.DIFF_TEXT");
        rs = ps.executeQuery();
        i = 0;
        while (rs.next()) {
            i++;
        }
        AttackTextArea.setText(AttackTextArea.getText() + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
        AttackTextArea.setText(AttackTextArea.getText() + "Vulnerabilities that could be Attacked: " + i + "\n");

        ps = conn.prepareStatement("SELECT ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION,TARGET_PHP_FILES.NAME,ATTACK_PAYLOADS.TARGET_PHP_FILES_VARIABLE,TARGET_PHP_FILES_VARIABLES.NAME,VULNERABILITY_INJECTION_RESULTS.DIFF_TEXT FROM ATTACK_PAYLOADS,VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES,TARGET_PHP_FILES_VARIABLES WHERE ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=VULNERABILITY_INJECTION_RESULTS.ID AND VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND ATTACK_PAYLOADS.TARGET_PHP_FILES_VARIABLE=TARGET_PHP_FILES_VARIABLES.ID AND ATTACK_PAYLOADS.ATTACK_RESULT ='SUCCESSFUL' GROUP BY ATTACK_PAYLOADS.TARGET_PHP_FILES_RUNS_FUNCTION,TARGET_PHP_FILES.NAME,ATTACK_PAYLOADS.TARGET_PHP_FILES_VARIABLE,TARGET_PHP_FILES_VARIABLES.NAME,VULNERABILITY_INJECTION_RESULTS.DIFF_TEXT");
        rs = ps.executeQuery();
        while (rs.next()) {
            AttackTextArea.setText(AttackTextArea.getText() + "--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------\n");
            AttackTextArea.setText(AttackTextArea.getText() + rs.getInt(1) + "\t" + rs.getString(2) + "\t" + rs.getInt(3) + "\t" + rs.getString(4) + "\n" + rs.getString(5) + "\n");
        }
        rs.close();
        ps.close();
        conn.commit();
        conn.close();

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

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_ShowAttackResultsButtonActionPerformed

private void RefreshVulnerabilitiesButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_RefreshVulnerabilitiesButtonActionPerformed
    try {
        VulnerabilitySelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(JavaDBAccess.ReadVulnerabilityData(TargetPHPFileSelectedComboBox.getSelectedItem().toString())));
    } catch (Throwable e) {
    }
}//GEN-LAST:event_RefreshVulnerabilitiesButtonActionPerformed

private void ApplySingleVulnerabilityButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApplySingleVulnerabilityButtonActionPerformed
    String[] VulnerabilityData = null;

    int count = 0;
    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    int VULNERABILITY_INJECTION_RESULTS_ID;

    // Adapted from http://developers.sun.com/docs/javadb/10.2.2/ref/rrefclob.html
    try {
        if ((conn = this.JavaDBAccess.setConn()) != null) {
            System.out.println("Connected to database " + this.JavaDBAccess.getDatabaseName());
        } else {
            throw new Exception("Not connected to database " + this.JavaDBAccess.getDatabaseName());
        }

        conn.setAutoCommit(false);

        // Test to see if the Target PHP file is already in the DB
        ps = conn.prepareStatement("SELECT VULNERABILITY_INJECTION_RESULTS.ID FROM VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES WHERE VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND TARGET_PHP_FILES.PATH=? AND VULNERABILITY_INJECTION_RESULTS.DIFF_TEXT=?"); // get the result

        ps.setString(1, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
        ps.setString(2, VulnerabilitySelectedComboBox.getSelectedItem().toString());
        rs = ps.executeQuery(); // get the result

        rs.next();
        // Open matches log file.
        VULNERABILITY_INJECTION_RESULTS_ID = rs.getInt(1);
        rs.close();
        ps.close();
        conn.commit();

        // Test to see if the Target PHP file is already in the DB
        ps = conn.prepareStatement("SELECT COUNT(*) FROM ATTACK_PAYLOADS,PAYLOADS WHERE ATTACK_PAYLOADS.PAYLOAD=PAYLOADS.ID AND ATTACK_PAYLOADS.ATTACK_RESULT='SUCCESSFUL' AND ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=?"); // get the result

        ps.setInt(1, VULNERABILITY_INJECTION_RESULTS_ID);
        rs = ps.executeQuery(); // get the result

        rs.next();
        count = rs.getInt(1);
        rs.close();
        ps.close();

        VulnerabilityData = new String[count + 1];
        VulnerabilityData[0] = "null";

        // Test to see if the Target PHP file is already in the DB
        ps = conn.prepareStatement("SELECT PAYLOADS.PAYLOAD FROM ATTACK_PAYLOADS,PAYLOADS WHERE ATTACK_PAYLOADS.PAYLOAD=PAYLOADS.ID AND ATTACK_PAYLOADS.ATTACK_RESULT='SUCCESSFUL' AND ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=?"); // get the result

        ps.setInt(1, VULNERABILITY_INJECTION_RESULTS_ID);
        rs = ps.executeQuery(); // get the result

        while (rs.next()) {
            // Open matches log file.
            VulnerabilityData[rs.getRow()] = rs.getString(1);
        }
        rs.close();
        ps.close();
        conn.commit();
        conn.close();
        SuccessPayloadSelectedComboBox.setModel(new javax.swing.DefaultComboBoxModel(VulnerabilityData));

        //Apply the Vulnerable PHP File
        VulnInject.ApplyVulnerablePHPFile(JavaDBAccess, VULNERABILITY_INJECTION_RESULTS_ID);

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

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
}//GEN-LAST:event_ApplySingleVulnerabilityButtonActionPerformed

private void ApplySinglePayloadButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_ApplySinglePayloadButtonActionPerformed
    String HTTPRequest = "", output = "";

    Connection conn = null;
    PreparedStatement ps = null;
    ResultSet rs = null;
    int VULNERABILITY_INJECTION_RESULTS_ID;

    // Adapted from http://developers.sun.com/docs/javadb/10.2.2/ref/rrefclob.html
    try {
        if ((conn = this.JavaDBAccess.setConn()) != null) {
            System.out.println("Connected to database " + this.JavaDBAccess.getDatabaseName());
        } else {
            throw new Exception("Not connected to database " + this.JavaDBAccess.getDatabaseName());
        }

        conn.setAutoCommit(false);

        // Test to see if the Target PHP file is already in the DB
        ps = conn.prepareStatement("SELECT VULNERABILITY_INJECTION_RESULTS.ID FROM VULNERABILITY_INJECTION_RESULTS,TARGET_PHP_FILES WHERE VULNERABILITY_INJECTION_RESULTS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND TARGET_PHP_FILES.PATH=? AND VULNERABILITY_INJECTION_RESULTS.DIFF_TEXT=?"); // get the result

        ps.setString(1, TargetPHPFileSelectedComboBox.getSelectedItem().toString());
        ps.setString(2, VulnerabilitySelectedComboBox.getSelectedItem().toString());
        rs = ps.executeQuery(); // get the result

        rs.next();
        // Open matches log file.
        VULNERABILITY_INJECTION_RESULTS_ID = rs.getInt(1);

        // Test to see if the Target PHP file is already in the DB
        ps = conn.prepareStatement("SELECT ATTACK_PAYLOADS.HTTP_REQUEST FROM ATTACK_PAYLOADS,PAYLOADS WHERE ATTACK_PAYLOADS.PAYLOAD=PAYLOADS.ID AND ATTACK_PAYLOADS.ATTACK_RESULT='SUCCESSFUL' AND ATTACK_PAYLOADS.VULNERABILITY_INJECTION_RESULT=?"); // get the result

        ps.setInt(1, VULNERABILITY_INJECTION_RESULTS_ID);
        rs = ps.executeQuery(); // get the result

        rs.next();
        HTTPRequest = rs.getString("HTTP_REQUEST");
        rs.close();
        ps.close();
        conn.commit();
        conn.close();

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

        if (e instanceof SQLException) {
            JavaDBAccess.printSQLError((SQLException) e);
        } else {
            e.printStackTrace();
        }
    }
    try {
        //Execute the attack through the HTTP proxy
        output = Attack.issueRequest(HTTPRequest, WebApplicationIPAddress.getText(), Integer.parseInt(WebApplicationPort.getText()));
    } catch (Exception e) {
        output = e.toString();
    }
    VulnerabilityInjectionTextArea.setText("Payload Applyed");
}//GEN-LAST:event_ApplySinglePayloadButtonActionPerformed

private void jButton1ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton1ActionPerformed
    String filename = "." + File.separator;
    if (!jPath.getText().isEmpty()) {
        filename = (jPath.getText());
    }
    JFileChooser fc = new JFileChooser(new File(filename));
    fc.setDialogTitle("Open DBSniffer program to get its location");
    // Show open dialog; this method does not return until the dialog is closed
    int returnVal = fc.showOpenDialog(new JFrame());
    if (returnVal == JFileChooser.APPROVE_OPTION) {
        selFile = fc.getSelectedFile();
//            System.out.println("You chose to open this file: " + fc.getSelectedFile().getName());
        jPath.setText(fc.getSelectedFile().getParent() + File.separator);
    } else {
//            System.out.println("You chose not to open file");
        }

// TODO add your handling code here:
}//GEN-LAST:event_jButton1ActionPerformed

private void jPathActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jPathActionPerformed
// TODO add your handling code here:
}//GEN-LAST:event_jPathActionPerformed

private void IDSResultsButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_IDSResultsButtonActionPerformed
    int count;
    String Message, Message_MALICIOUS_COMMAND = "", Message_MALICIOUS_TRANSACTION = "";

    count = 0;
    while (jTPFile.getText().toUpperCase().indexOf("MALICIOUS_COMMAND") != -1) {
        count++;
    }
    if (count > 0) {
        Message_MALICIOUS_COMMAND = "The IDS detected " + count + " Malicious Commands\n";
    }
    count = 0;
    while (jTPFile.getText().toUpperCase().indexOf("MALICIOUS_TRANSACTION") != -1) {
        count++;
    }
    if (count > 0) {
        Message_MALICIOUS_TRANSACTION = "The IDS detected " + count + " Malicious Transactions\n";
    }
    Message = Message_MALICIOUS_COMMAND + Message_MALICIOUS_TRANSACTION;
    if (Message.contentEquals("")) {
        Message = "Nothing unusual was detected by the IDS";
    }
    JOptionPane.showMessageDialog(new JFrame(), Message, "IDS results", JOptionPane.INFORMATION_MESSAGE);
}//GEN-LAST:event_IDSResultsButtonActionPerformed

private void StartIDSButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StartIDSButtonActionPerformed
    jTPFile.setText("");
    File WorkingDirectory = null;
    String line = null;

    try {
        line = selFile.getAbsolutePath();
        WorkingDirectory = selFile.getParentFile();
        ExecuteAssincronousCommand(line + " -c config.cfg -m detector", WorkingDirectory);
    } catch (Exception err) {
    }
}//GEN-LAST:event_StartIDSButtonActionPerformed

private void StopIDSButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_StopIDSButtonActionPerformed
    ExitAssincronousCommand();
}//GEN-LAST:event_StopIDSButtonActionPerformed

private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
    int i = 0;
//    i = PHPFile.SearchEndChar(jTextField4.getText(), 1, ')');
    i = PHPFile.SearchLevelChar(jTextField4.getText(), 1, ',');
    InspectionTextArea.setText(i + " " + jTextField4.getText().substring(0, i + 1));
}//GEN-LAST:event_jButton2ActionPerformed

private void jButton3ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton3ActionPerformed
    VulnerabilityInjectionAll(AffectSQLStaticCk.isSelected(), AffectSQLDynamicCk.isSelected());
}//GEN-LAST:event_jButton3ActionPerformed

private void jButton4ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton4ActionPerformed
    int VariableLocationInsideString;
    VariableLocationInsideString = PHPFile.TextInsidePHPString(InspectionTextArea.getText(), Integer.parseInt(jTextField5.getText()));
    jTextField6.setText("" + VariableLocationInsideString);
}//GEN-LAST:event_jButton4ActionPerformed

    private static void ExecuteCommand(String CommandText, File WorkingDirectory) {
        final Process p;     // Process tracks one external native process

        BufferedReader pis;  // reader for output of process


        String pline = "";
        try {
            p = Runtime.getRuntime().exec(CommandText, null, WorkingDirectory);

            // Optional: start a thread to wait for the process to terminate.
            // Don't just wait in main line, but here set a "done" flag and
            // use that to control the main reading loop below.
            Thread waiter = new Thread() {

                public void run() {
                    try {
                        p.waitFor();
                    } catch (InterruptedException ex) {
                        // OK, just quit.
                        return;
                    }
//                    System.out.println("Program terminated!");
                    ResultList.add("Program terminated!");
                    done = true;
                }
            };
            waiter.start();

            // getInputStream gives an Input stream connected to
            // the process p's standard output (and vice versa). We use
            // that to construct a BufferedReader so we can readLine() it.
            pis = new BufferedReader(new InputStreamReader(p.getInputStream()));

            while (!done && ((pline = pis.readLine()) != null)) {
//                System.out.println(pline);
                ResultList.add(pline);
            }

        } catch (IOException e) {

            System.err.println("Error1!");
        } catch (Exception err) {

            System.err.println("Error2!");
            err.printStackTrace();
        }
    }

    private void ExecuteAssincronousCommand(String CommandText, File WorkingDirectory) {

        try {
            done = false;
            ExternalProcessResultList.clear();
            jLDBSniffer.setText("Detector Started");
            ExternalProcess = Runtime.getRuntime().exec(CommandText, null, WorkingDirectory);
            jTPFile.setText("");
            // Optional: start a thread to wait for the process to terminate.
            // Don't just wait in main line, but here set a "done" flag and
            // use that to control the main reading loop below.
            processThread = new Thread() {

                public void run() {
                    try {
                        System.out.println("processThread Started");
                        ExternalProcess.waitFor();
                    } catch (InterruptedException ex) {
                        // OK, just quit.
                    }
//                    System.out.println("Program terminated!");
                    ExternalProcessResultList.add("Program terminated!");
                    jLDBSniffer.setText("DBSniffer Stopped");
                    done = true;
                    System.out.println("processThread Stopped");
                }
            };

            inReadThread = new Thread() {

                public void run() {
                    BufferedReader pis;  // reader for output of process

                    String pline = "";
                    int offset = 0;
                    String output = "";

                    try {
                        System.out.println("inReadThread Started");
                        // getInputStream gives an Input stream connected to
                        // the process p's standard output (and vice versa). We use
                        // that to construct a BufferedReader so we can readLine() it.
                        pis = new BufferedReader(new InputStreamReader(ExternalProcess.getInputStream()));

                        while (!done && ((pline = pis.readLine()) != null) && !isInterrupted()) {
//                System.out.println(pline);
                            ExternalProcessResultList.add(pline);

                            offset = jTPFile.getDocument().getLength() - 10240;
                            if (offset > 0) {
                                try {
                                    output = jTPFile.getText(offset, 10240) + "\n" + pline;
                                } catch (Exception err) {
                                }
                            } else {
                                output = jTPFile.getText() + "\n" + pline;
                            }
                            jTPFile.setText(output);
                            //to go to the end of the TextPane
                            jTPFile.setCaretPosition(jTPFile.getDocument().getLength());

                        }
                    } catch (IOException ex) {
                        ex.printStackTrace();
                    }
                    System.out.println("inReadThread Stopped: " + done + " - " + pline + " - " + isInterrupted());
                }
            };

            processThread.start();
            inReadThread.start();


        } catch (Exception err) {

            System.err.println("Error2!");
            err.printStackTrace();
        }
    }

    private void ExitAssincronousCommand() {
        if (ExternalProcess != null) {
            done = true;
            ExternalProcess.destroy();
            processThread.interrupt();
            while (processThread.isAlive()) {
            }
            processThread = null;
            System.out.println("processThread Should Already be Stopped");
            inReadThread.interrupt();
            while (inReadThread.isAlive()) {
            }
            inReadThread = null;
            System.out.println("inReadThread Should Already be Stopped");
            ExternalProcess = null;
            ExternalProcessResultList.add("Program terminated!");
            jLDBSniffer.setText("DBSniffer Stopped");
            done = false;
        }
    }

    private void DeleteMySQLData() {
        Connection conn = null;


        PreparedStatement ps = null;
        try {
            if ((conn = this.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("DELETE FROM HTTP_VARIABLES_SQL_VARIABLES");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement("DELETE FROM HTTP_VARIABLES_SQL_QUERIES");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement("DELETE FROM MYSQL_QUERIES_VARIABLES");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement(
                    "DELETE FROM MYSQL_QUERIES");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement(
                    "DELETE FROM MYSQL_PACKETS");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement(
                    "DELETE FROM MYSQL_PROXY_PACKETS");
            ps.executeUpdate();
            ps.close();
            conn.commit();
            conn.close();
            InspectionTextArea.setText("DB data deleted!");
        } catch (Throwable e) {
            InspectionTextArea.setText("Errors deleting DB data!");
            System.out.println(
                    "exception thrown:");

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

        } finally {
            try {
                conn.close();
            } catch (Throwable e) {
            }
        }
    }

    private void DeleteHTTPData() {
        Connection conn = null;


        PreparedStatement ps = null;
        try {
            DeleteMySQLData();
            if ((conn = this.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("DELETE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS");
            ps.executeUpdate();
            ps =
                    conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_RUNS");
            ps.executeUpdate();
            ps.close();
            conn.commit();
            conn.close();
            InspectionTextArea.setText("HTTP data deleted!");
        } catch (Throwable e) {
            InspectionTextArea.setText("Errors deleting HTTP data!");
            System.out.println(
                    "exception thrown:");

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

        }
    }

    private void DeleteAttackData() {
        Connection conn = null;


        PreparedStatement ps = null;
        try {
            if ((conn = this.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("DELETE FROM ATTACK_PAYLOADS");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM HTTP_VARIABLES_SQL_QUERIES WHERE TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE IN (SELECT ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE MODE='ATTACK')");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM HTTP_VARIABLES_SQL_VARIABLES WHERE TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE IN (SELECT ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE MODE='ATTACK')");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE MODE='ATTACK'");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM MYSQL_QUERIES_VARIABLES WHERE MYSQL_QUERY IN(SELECT MYSQL_QUERIES.ID FROM MYSQL_QUERIES,MYSQL_PROXY_PACKETS WHERE MYSQL_QUERIES.MYSQL_PROXY_PACKET_CLIENT=MYSQL_PROXY_PACKETS.ID AND MYSQL_PROXY_PACKETS.MODE='ATTACK')");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM MYSQL_QUERIES WHERE MYSQL_PROXY_PACKET_CLIENT IN (SELECT ID FROM MYSQL_PROXY_PACKETS WHERE MODE='ATTACK')");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM MYSQL_PACKETS WHERE MYSQL_PROXY_PACKET IN (SELECT ID FROM MYSQL_PROXY_PACKETS WHERE MODE='ATTACK')");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM MYSQL_PROXY_PACKETS WHERE MODE='ATTACK'");
            ps.executeUpdate();
            ps = conn.prepareStatement("DELETE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE MODE='ATTACK'");
            ps.executeUpdate();
            ps.close();
            conn.commit();
            conn.close();
            InspectionTextArea.setText("Attack data deleted!");
        } catch (Throwable e) {
            InspectionTextArea.setText("Errors deleting Attack data!");
            System.out.println("exception thrown:");

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

        }
    }

    private void HTTPVariables2SQLQueries() {
        Connection conn = null;
        Statement s = null;

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


            conn.setAutoCommit(false);

            // Start a transaction by inserting a record in the TARGET_PHP_FILES_FUNCTIONS table
            s = conn.createStatement();
            s.executeUpdate("DELETE FROM HTTP_VARIABLES_SQL_VARIABLES");
            s.executeUpdate("INSERT INTO HTTP_VARIABLES_SQL_VARIABLES (MYSQL_QUERIES_VARIABLE, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE, COUNT) (SELECT MYSQL_QUERIES_VARIABLES.ID ID1, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.ID ID2, COUNT(*) FROM MYSQL_QUERIES_VARIABLES, MYSQL_QUERIES, MYSQL_PROXY_PACKETS, TARGET_PHP_FILES_RUNS_FUNCTIONS, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE MYSQL_QUERIES_VARIABLES.MYSQL_QUERY = MYSQL_QUERIES.ID AND MYSQL_QUERIES.MYSQL_PROXY_PACKET_CLIENT = MYSQL_PROXY_PACKETS.ID AND MYSQL_PROXY_PACKETS.TARGET_PHP_FILES_RUNS_FUNCTION = TARGET_PHP_FILES_RUNS_FUNCTIONS.ID AND TARGET_PHP_FILES_RUNS_FUNCTIONS.ID = TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_RUNS_FUNCTION AND MYSQL_QUERIES_VARIABLES.VALUE LIKE '%'||TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.DECODED_VALUE||'%' GROUP BY MYSQL_QUERIES_VARIABLES.ID, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.ID)");
            s.executeUpdate("DELETE FROM HTTP_VARIABLES_SQL_QUERIES");
            s.executeUpdate("INSERT INTO HTTP_VARIABLES_SQL_QUERIES (MYSQL_QUERY, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE, COUNT_STRUCTURE) (SELECT MYSQL_QUERIES.ID AS ID1, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.ID AS ID2, COUNT(*) FROM MYSQL_QUERIES, MYSQL_PROXY_PACKETS, TARGET_PHP_FILES_RUNS_FUNCTIONS, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE MYSQL_QUERIES.MYSQL_PROXY_PACKET_CLIENT = MYSQL_PROXY_PACKETS.ID AND MYSQL_PROXY_PACKETS.TARGET_PHP_FILES_RUNS_FUNCTION = TARGET_PHP_FILES_RUNS_FUNCTIONS.ID AND TARGET_PHP_FILES_RUNS_FUNCTIONS.ID = TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_RUNS_FUNCTION AND MYSQL_QUERIES.SQL_COMMAND LIKE '%'||TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.DECODED_VALUE||'%' GROUP BY MYSQL_QUERIES.ID, TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.ID)");
            s.executeUpdate("UPDATE HTTP_VARIABLES_SQL_QUERIES SET COUNT_VARIABLES=(SELECT SUM(COUNT) FROM HTTP_VARIABLES_SQL_VARIABLES, MYSQL_QUERIES_VARIABLES WHERE HTTP_VARIABLES_SQL_VARIABLES.MYSQL_QUERIES_VARIABLE=MYSQL_QUERIES_VARIABLES.ID AND HTTP_VARIABLES_SQL_QUERIES.TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE=HTTP_VARIABLES_SQL_VARIABLES.TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE AND MYSQL_QUERIES_VARIABLES.MYSQL_QUERY=HTTP_VARIABLES_SQL_QUERIES.MYSQL_QUERY)");
            s.executeUpdate("UPDATE HTTP_VARIABLES_SQL_QUERIES SET COUNT_VARIABLES=0 WHERE COUNT_VARIABLES IS NULL");
            s.executeUpdate("UPDATE HTTP_VARIABLES_SQL_QUERIES SET COUNT_STRUCTURE=COUNT_STRUCTURE-COUNT_VARIABLES");
            s.close();

        } catch (Throwable e) {
            InspectionTextArea.setText("Errors in HTTP2SQLVariables executed!");
            System.out.println(
                    "exception thrown:");

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

        } finally {
            try {
                conn.commit();
                conn.close();
            } catch (Throwable e) {
            }
        }
    }

    private void HTTP2WebApplication(String HostPath, String MODE) {
        Connection conn = null;

        PreparedStatement ps_http = null;

        PreparedStatement ps =
                null;
        Statement s = null;
        ResultSet rs = null;

        String HTTP_REQUEST_HOST = "", HTTP_REQUEST_PATH = "", HTTP_REQUEST_FILE = "";


        int TARGET_PHP_FILES_ID = 0;
        File f;

        DatabaseAccess JavaDBAccess2 = null;

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


            conn.setAutoCommit(false);

            // Start a transaction by inserting a record in the TARGET_PHP_FILES_FUNCTIONS table
            ps_http = conn.prepareStatement("SELECT DISTINCT HTTP_REQUEST_HOST, HTTP_REQUEST_PATH, HTTP_REQUEST_FILE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS WHERE MODE=?");
            ps_http.setString(1, MODE);
            rs = ps_http.executeQuery();
            while (rs.next()) {
                HTTP_REQUEST_HOST = rs.getString("HTTP_REQUEST_HOST");
                HTTP_REQUEST_PATH = rs.getString("HTTP_REQUEST_PATH");
                HTTP_REQUEST_FILE = rs.getString("HTTP_REQUEST_FILE");
                f = new File(HostPath + HTTP_REQUEST_PATH + HTTP_REQUEST_FILE);
                if ((TARGET_PHP_FILES_ID = JavaDBAccess.ReadFile2DB(f, HTTP_REQUEST_HOST, HostPath, HTTP_REQUEST_PATH, JavaDBAccess, false)) > 0) {
                    ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES_RUNS_FUNCTIONS SET TARGET_PHP_FILE=? WHERE HTTP_REQUEST_HOST=? AND HTTP_REQUEST_PATH=? AND HTTP_REQUEST_FILE=? AND TARGET_PHP_FILE IS NULL");
                    ps.setInt(1, TARGET_PHP_FILES_ID);
                    ps.setString(2, HTTP_REQUEST_HOST);
                    ps.setString(3, HTTP_REQUEST_PATH);
                    ps.setString(4, HTTP_REQUEST_FILE);
                    ps.executeUpdate();
                    ps.close();
                    JavaDBAccess2 = new DatabaseAccess(DBprops);
                    PHPFile.AnalyzePHPFile(JavaDBAccess2, f.getAbsolutePath());
                    JavaDBAccess2 = null;
                    //Process the PHP files that are included in the PHP file
                    JavaDBAccess.PHPFileIncludes(TARGET_PHP_FILES_ID, JavaDBAccess, PHPFile);
                }
            }
            rs.close();
            ps_http.close();
            s = conn.createStatement();
            //Update the TARGET_PHP_FILES_VARIABLE of the TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES
            s.executeUpdate("UPDATE TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES SET TARGET_PHP_FILES_VARIABLE=(SELECT TARGET_PHP_FILES_VARIABLES.ID FROM TARGET_PHP_FILES_RUNS_FUNCTIONS, TARGET_PHP_FILES, TARGET_PHP_FILES_VARIABLES WHERE TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_RUNS_FUNCTION=TARGET_PHP_FILES_RUNS_FUNCTIONS.ID AND TARGET_PHP_FILES_RUNS_FUNCTIONS.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND TARGET_PHP_FILES_VARIABLES.TARGET_PHP_FILE=TARGET_PHP_FILES.ID AND '$'||TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.NAME=TARGET_PHP_FILES_VARIABLES.NAME AND TARGET_PHP_FILES.PATH LIKE '%'||TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_PATH||TARGET_PHP_FILES_RUNS_FUNCTIONS.HTTP_REQUEST_FILE) WHERE TARGET_PHP_FILES_VARIABLE IS NULL");
            //Update the AFFECT_SQL_DYNAMIC of the TARGET_PHP_FILES_VARIABLES
            s.executeUpdate("UPDATE TARGET_PHP_FILES_VARIABLES SET AFFECT_SQL_DYNAMIC='N' WHERE AFFECT_SQL_DYNAMIC='U'");
            ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES_VARIABLES SET AFFECT_SQL_DYNAMIC='Y' WHERE ID IN (SELECT TARGET_PHP_FILES_VARIABLE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES,HTTP_VARIABLES_SQL_QUERIES WHERE ID=TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLE AND MODE=?)");
            ps.setString(1, MODE);
            ps.executeUpdate();
            //Update the INPUT_VARIABLE of the TARGET_PHP_FILES_VARIABLES
            s.executeUpdate("UPDATE TARGET_PHP_FILES_VARIABLES SET INPUT_VARIABLE='N' WHERE INPUT_VARIABLE='U'");
            ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES_VARIABLES SET INPUT_VARIABLE='Y' WHERE ID IN (SELECT TARGET_PHP_FILES_VARIABLE FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE MODE=?)");
            ps.setString(1, MODE);
            ps.executeUpdate();
            //Update the DATA_TYPE according to the values existing in the HTTP data
            //DATA_TYPE CHAR is used in the cases where both NUMERIC and CHAR values are used in the variable
            ps = conn.prepareStatement("UPDATE TARGET_PHP_FILES_VARIABLES SET DATA_TYPE=(SELECT MIN(DATA_TYPE) FROM TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES WHERE TARGET_PHP_FILES_VARIABLES.ID=TARGET_PHP_FILES_RUNS_FUNCTIONS_VARIABLES.TARGET_PHP_FILES_VARIABLE AND MODE=?)");
            ps.setString(1, MODE);
            ps.executeUpdate();
            ps.close();
            s.close();

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


        } catch (Throwable e) {
            InspectionTextArea.setText("Errors in HTTP2WebApplication executed!");
            System.out.println(
                    "exception thrown:");

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

        }
    }

// Show dialog box with error message.
    private void showError(String errorMessage) {
        JOptionPane.showMessageDialog(new JFrame(), errorMessage,
                "Error", JOptionPane.ERROR_MESSAGE);
    }
// Verify URL format.

    private URL verifyUrl(String url) {
// Only allow HTTP URLs.
        if (!url.toLowerCase().startsWith("http://")) {
            return null;
// Verify format of URL.



        }
        URL verifiedUrl = null;
        try {
            verifiedUrl = new URL(url);
        } catch (Exception e) {






            return null;
        }

        return verifiedUrl;
    }
    /* Show the specified page and add it to
    the page list if specified. */

    private void showPage(URL pageUrl, boolean addToList) {
        try {
// Get URL of page currently being displayed.
            URL currentUrl = displayEditorPane.getPage();
// Load and display specified page.
            displayEditorPane.setPage(pageUrl);
            //displayEditorPane.setPage("http://192.168.1.90/html/phd-mysql/index.php");
// Get URL of new page being displayed.
            URL newUrl = displayEditorPane.getPage();
// Add page to list if specified.
            if (addToList) {
                int listSize = pageList.size();
                if (listSize > 0) {
                    int pageIndex = pageList.indexOf(currentUrl.toString());

                    if (pageIndex < listSize - 1) {
                        for (int i = listSize - 1; i >
                                pageIndex; i--) {
                            pageList.remove(i);
                        }

                    }
                }
                pageList.add(newUrl.toString());
            }
// Update location packet field with URL of current page.
            locationTextField.setText(newUrl.toString());
// Update buttons based on the page being displayed.
            updateButtons();

        } catch (Exception e) {
// Show error message.





            showError(
                    "Unable to load page");
        } finally {
        }
    }
    /* Update Back and Forward buttons based on
    the page being displayed. */

    private void updateButtons() {
        if (pageList.size() < 2) {

            backButton.setEnabled(false);


            forwardButton.setEnabled(
                    false);
        } else {
            URL currentUrl = displayEditorPane.getPage();
            int pageIndex = pageList.indexOf(currentUrl.toString());
            backButton.setEnabled(pageIndex > 0);
            forwardButton.setEnabled(
                    pageIndex <
                    (pageList.size() - 1));
        }

    }
    // Handle hyperlinks being clicked.

    public void hyperlinkUpdate(HyperlinkEvent event) {
        HyperlinkEvent.EventType eventType = event.getEventType();
        if (eventType == HyperlinkEvent.EventType.ACTIVATED) {
            if (event instanceof HTMLFrameHyperlinkEvent) {
                HTMLFrameHyperlinkEvent linkEvent = (HTMLFrameHyperlinkEvent) event;
                HTMLDocument document = (HTMLDocument) displayEditorPane.getDocument();
                document.processHTMLFrameHyperlinkEvent(linkEvent);
            } else {




                showPage(event.getURL(), true);
            }

        }