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