use of com.jsql.model.exception.StoppedByUserSlidingException in project jsql-injection by ron190.
the class SuspendableGetVendor method run.
/**
*/
@Override
public Vendor run(Object... args) throws StoppedByUserSlidingException {
Vendor vendor = null;
if (MediatorModel.model().getVendorByUser() != Vendor.AUTO) {
vendor = MediatorModel.model().getVendorByUser();
LOGGER.info(I18n.valueByKey("LOG_DATABASE_TYPE_FORCED_BY_USER") + " [" + vendor + "]");
} else {
// Parallelize the search and let the user stops the process if needed.
// SQL: force a wrong ORDER BY clause with an inexistent column, order by 1337,
// and check if a correct error message is sent back by the server:
// Unknown column '1337' in 'order clause'
// or supplied argument is not a valid MySQL result resource
ExecutorService taskExecutor = Executors.newCachedThreadPool(new ThreadFactoryCallable("CallableGetVendor"));
CompletionService<CallablePageSource> taskCompletionService = new ExecutorCompletionService<>(taskExecutor);
for (String insertionCharacter : new String[] { "'\"#-)'\"" }) {
taskCompletionService.submit(new CallablePageSource(insertionCharacter, insertionCharacter));
}
int total = 1;
while (0 < total) {
if (this.isSuspended()) {
throw new StoppedByUserSlidingException();
}
try {
CallablePageSource currentCallable = taskCompletionService.take().get();
total--;
String pageSource = currentCallable.getContent();
for (Vendor vendorTest : Stream.of(Vendor.values()).skip(1).toArray(Vendor[]::new)) {
if (pageSource.matches("(?si).*(" + vendorTest.instance().fingerprintErrorsAsRegex() + ").*")) {
vendor = vendorTest;
LOGGER.debug("Found database [" + vendor + "]");
break;
}
}
} catch (InterruptedException | ExecutionException e) {
LOGGER.error("Interruption while determining the type of database", e);
}
}
// End the job
try {
taskExecutor.shutdown();
taskExecutor.awaitTermination(15, TimeUnit.SECONDS);
} catch (InterruptedException e) {
LOGGER.error(e.getMessage(), e);
Thread.currentThread().interrupt();
}
if (vendor == null) {
vendor = Vendor.MYSQL;
LOGGER.warn(I18n.valueByKey("LOG_DATABASE_TYPE_NOT_FOUND") + " [" + vendor + "]");
} else {
LOGGER.info(I18n.valueByKey("LOG_USING_DATABASE_TYPE") + " [" + vendor + "]");
Map<Header, Object> msgHeader = new EnumMap<>(Header.class);
msgHeader.put(Header.URL, ConnectionUtil.getUrlBase() + ParameterUtil.getQueryStringAsString());
msgHeader.put(Header.VENDOR, vendor);
Request requestDatabaseIdentified = new Request();
requestDatabaseIdentified.setMessage(Interaction.DATABASE_IDENTIFIED);
requestDatabaseIdentified.setParameters(msgHeader);
MediatorModel.model().sendToViews(requestDatabaseIdentified);
}
}
Request requestSetVendor = new Request();
requestSetVendor.setMessage(Interaction.SET_VENDOR);
requestSetVendor.setParameters(vendor);
MediatorModel.model().sendToViews(requestSetVendor);
return vendor;
}
Aggregations