Search in sources :

Example 1 with Column

use of com.jsql.model.bean.database.Column in project jsql-injection by ron190.

the class AddColumns method execute.

@Override
public void execute() {
    if (MediatorGui.treeDatabase() == null) {
        LOGGER.error("Unexpected unregistered MediatorGui.treeDatabase() in " + this.getClass());
    }
    // Tree model, update the tree (refresh, add node, etc)
    DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel();
    // The table to update
    DefaultMutableTreeNode tableNode = null;
    // Loop into the list of columns
    for (Column column : this.columns) {
        // Create a node model with the column element
        AbstractNodeModel newTreeNodeModel = new NodeModelColumn(column);
        // Create the node
        DefaultMutableTreeNode newNode = new DefaultMutableTreeNode(newTreeNodeModel);
        // Get the parent table
        tableNode = MediatorGui.frame().getTreeNodeModels().get(column.getParent());
        // Fix #1805 : NullPointerException on tableNode.getChildCount()
        if (tableNode != null) {
            // Add the column to the table
            treeModel.insertNodeInto(newNode, tableNode, tableNode.getChildCount());
        }
    }
    if (tableNode != null) {
        // Open the table node
        MediatorGui.treeDatabase().expandPath(new TreePath(tableNode.getPath()));
        // The table has just been search (avoid double check)
        ((AbstractNodeModel) tableNode.getUserObject()).setLoaded(true);
    }
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) TreePath(javax.swing.tree.TreePath) Column(com.jsql.model.bean.database.Column) NodeModelColumn(com.jsql.view.swing.tree.model.NodeModelColumn) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel) NodeModelColumn(com.jsql.view.swing.tree.model.NodeModelColumn)

Example 2 with Column

use of com.jsql.model.bean.database.Column in project jsql-injection by ron190.

the class DataAccess method listColumns.

/**
 * Get column names and send them to the view.<br>
 * Use readable text (not hexa) and parse this pattern with 2nd member forced to 31 (1 in ascii):<br>
 * => hh[column name 1]jj[31]hhgghh[column name 2]jj[31]hhggh...hi<br>
 * Data window can be cut before the end of the request but the process helps to obtain
 * the rest of the unreachable data. The process can be interrupted by the user (stop/pause).
 * @param table which contains columns to find
 * @return list of columns found
 * @throws JSqlException when injection failure or stopped by user
 */
public static List<Column> listColumns(Table table) throws JSqlException {
    List<Column> columns = new ArrayList<>();
    // Inform the view that table has just been used
    Request requestStartProgress = new Request();
    requestStartProgress.setMessage(Interaction.START_INDETERMINATE_PROGRESS);
    requestStartProgress.setParameters(table);
    MediatorModel.model().sendToViews(requestStartProgress);
    String resultToParse = "";
    try {
        String[] pageSource = { "" };
        resultToParse = new SuspendableGetRows().run(MediatorModel.model().getVendor().instance().sqlColumns(table), pageSource, true, 0, table);
    } catch (SlidingException e) {
        LOGGER.warn(e.getMessage(), e);
        // Get pieces of data already retreived instead of losing them
        if (!"".equals(e.getSlidingWindowAllRows())) {
            resultToParse = e.getSlidingWindowAllRows();
        } else if (!"".equals(e.getSlidingWindowCurrentRows())) {
            resultToParse = e.getSlidingWindowCurrentRows();
        }
    } catch (Exception e) {
        LOGGER.warn(e.getMessage(), e);
    }
    // Build SQLite columns
    if (MediatorModel.model().getVendor() == Vendor.SQLITE) {
        resultToParse = Vendor.SQLITE.transform(resultToParse);
    }
    // Parse all the data we have retrieved
    Matcher regexSearch = Pattern.compile(MODE + ENCLOSE_VALUE_RGX + CELL_TABLE + ENCLOSE_VALUE_RGX).matcher(resultToParse);
    Request requestEndProgress = new Request();
    requestEndProgress.setMessage(Interaction.END_INDETERMINATE_PROGRESS);
    requestEndProgress.setParameters(table);
    MediatorModel.model().sendToViews(requestEndProgress);
    if (!regexSearch.find()) {
        throw new InjectionFailureException();
    }
    regexSearch.reset();
    // Build an array of Column objects from the data we have parsed
    while (regexSearch.find()) {
        String nameColumn = regexSearch.group(1);
        Column column = new Column(nameColumn, table);
        columns.add(column);
    }
    Request requestAddColumns = new Request();
    requestAddColumns.setMessage(Interaction.ADD_COLUMNS);
    requestAddColumns.setParameters(columns);
    MediatorModel.model().sendToViews(requestAddColumns);
    return columns;
}
Also used : SlidingException(com.jsql.model.exception.SlidingException) SuspendableGetRows(com.jsql.model.suspendable.SuspendableGetRows) Column(com.jsql.model.bean.database.Column) Matcher(java.util.regex.Matcher) ArrayList(java.util.ArrayList) Request(com.jsql.model.bean.util.Request) SlidingException(com.jsql.model.exception.SlidingException) IgnoreMessageException(com.jsql.model.exception.IgnoreMessageException) JSqlException(com.jsql.model.exception.JSqlException) InjectionFailureException(com.jsql.model.exception.InjectionFailureException) InjectionFailureException(com.jsql.model.exception.InjectionFailureException)

Example 3 with Column

use of com.jsql.model.bean.database.Column in project jsql-injection by ron190.

the class ActionLoadStop method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    DefaultTreeModel treeModel = (DefaultTreeModel) MediatorGui.treeDatabase().getModel();
    DefaultMutableTreeNode tableNode = this.currentTableNode;
    final List<Column> columnsToSearch = new ArrayList<>();
    int tableChildCount = treeModel.getChildCount(tableNode);
    for (int i = 0; i < tableChildCount; i++) {
        DefaultMutableTreeNode currentChild = (DefaultMutableTreeNode) treeModel.getChild(tableNode, i);
        if (currentChild.getUserObject() instanceof AbstractNodeModel) {
            AbstractNodeModel columnTreeNodeModel = (AbstractNodeModel) currentChild.getUserObject();
            if (columnTreeNodeModel.isSelected()) {
                columnsToSearch.add((Column) columnTreeNodeModel.getElementDatabase());
            }
        }
    }
    if (!this.nodeModel.isRunning() && columnsToSearch.isEmpty()) {
        return;
    }
    if (!this.nodeModel.isRunning()) {
        new SwingWorker<Object, Object>() {

            @Override
            protected Object doInBackground() throws Exception {
                Thread.currentThread().setName("SwingWorkerActionLoadStop");
                DataAccess.listValues(columnsToSearch);
                return null;
            }
        }.execute();
    } else {
        AbstractSuspendable<?> suspendableTask = ThreadUtil.get(this.nodeModel.getElementDatabase());
        // Fix #21394: NullPointerException on stop()
        if (suspendableTask != null) {
            suspendableTask.stop();
        }
        this.nodeModel.setIndexProgress(0);
        this.nodeModel.setProgressing(false);
        this.nodeModel.setLoading(false);
        ThreadUtil.remove(this.nodeModel.getElementDatabase());
    }
    this.nodeModel.setRunning(!this.nodeModel.isRunning());
}
Also used : DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode) Column(com.jsql.model.bean.database.Column) ArrayList(java.util.ArrayList) AbstractNodeModel(com.jsql.view.swing.tree.model.AbstractNodeModel) DefaultTreeModel(javax.swing.tree.DefaultTreeModel)

Example 4 with Column

use of com.jsql.model.bean.database.Column in project jsql-injection by ron190.

the class AbstractTestSuite method listColumns.

@Test
public void listColumns() throws JSqlException {
    Set<Object> set1 = new HashSet<>();
    Set<Object> set2 = new HashSet<>();
    try {
        List<Column> cs = DataAccess.listColumns(new Table(this.jsqlTableName, "0", new Database(this.jsqlDatabaseName, "0")));
        List<String> columnsFound = new ArrayList<>();
        for (Column c : cs) {
            columnsFound.add(c.toString());
        }
        set1.addAll(columnsFound);
        set2.addAll(this.columnToFind);
        LOGGER.info("listColumns: found " + set1 + "\nto find " + set2 + "\n");
        Assert.assertTrue(!set1.isEmpty() && !set2.isEmpty() && set1.equals(set2));
    } catch (AssertionError e) {
        Set<Object> tmp = new TreeSet<>();
        for (Object x : set1) {
            if (!set2.contains(x)) {
                tmp.add(x);
            }
        }
        for (Object x : set2) {
            if (!set1.contains(x)) {
                tmp.add(x);
            }
        }
        throw new AssertionError("Error listColumns: " + tmp + "\n" + e);
    }
}
Also used : Table(com.jsql.model.bean.database.Table) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Column(com.jsql.model.bean.database.Column) Database(com.jsql.model.bean.database.Database) HashSet(java.util.HashSet) Test(org.junit.Test)

Example 5 with Column

use of com.jsql.model.bean.database.Column in project jsql-injection by ron190.

the class AbstractTestSuite method listValues.

@Test
public void listValues() throws JSqlException {
    Set<Object> set1 = new TreeSet<>();
    Set<Object> set2 = new TreeSet<>();
    try {
        String[][] vs = DataAccess.listValues(Arrays.asList(new Column(this.jsqlColumnName, new Table(this.jsqlTableName, "0", new Database(this.jsqlDatabaseName, "0")))));
        List<String> valuesFound = new ArrayList<>();
        for (String[] v : vs) {
            valuesFound.add(v[2].replaceAll("\r\n", "\n"));
        }
        set1.addAll(valuesFound);
        set2.addAll(this.valueToFind);
        LOGGER.info("<<listValues: found " + set1.toString().replaceAll("\n", "[n]").replaceAll("\r", "[r]") + "\nto find " + set2.toString().replaceAll("\n", "[n]").replaceAll("\r", "[r]") + ">>\n");
        Assert.assertTrue(!set1.isEmpty() && !set2.isEmpty() && set1.equals(set2));
    } catch (AssertionError e) {
        Set<Object> tmp = new TreeSet<>();
        for (Object x : set1) {
            if (!set2.contains(x)) {
                tmp.add(x);
            }
        }
        for (Object x : set2) {
            if (!set1.contains(x)) {
                tmp.add(x);
            }
        }
        throw new AssertionError("Error listValues: " + tmp + "\n" + e);
    }
}
Also used : Table(com.jsql.model.bean.database.Table) Set(java.util.Set) TreeSet(java.util.TreeSet) HashSet(java.util.HashSet) ResultSet(java.sql.ResultSet) ArrayList(java.util.ArrayList) Column(com.jsql.model.bean.database.Column) TreeSet(java.util.TreeSet) Database(com.jsql.model.bean.database.Database) Test(org.junit.Test)

Aggregations

Column (com.jsql.model.bean.database.Column)5 ArrayList (java.util.ArrayList)4 Database (com.jsql.model.bean.database.Database)2 Table (com.jsql.model.bean.database.Table)2 AbstractNodeModel (com.jsql.view.swing.tree.model.AbstractNodeModel)2 ResultSet (java.sql.ResultSet)2 HashSet (java.util.HashSet)2 Set (java.util.Set)2 TreeSet (java.util.TreeSet)2 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)2 DefaultTreeModel (javax.swing.tree.DefaultTreeModel)2 Test (org.junit.Test)2 Request (com.jsql.model.bean.util.Request)1 IgnoreMessageException (com.jsql.model.exception.IgnoreMessageException)1 InjectionFailureException (com.jsql.model.exception.InjectionFailureException)1 JSqlException (com.jsql.model.exception.JSqlException)1 SlidingException (com.jsql.model.exception.SlidingException)1 SuspendableGetRows (com.jsql.model.suspendable.SuspendableGetRows)1 NodeModelColumn (com.jsql.view.swing.tree.model.NodeModelColumn)1 Matcher (java.util.regex.Matcher)1