Search in sources :

Example 6 with StoppedByUserSlidingException

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;
}
Also used : Request(com.jsql.model.bean.util.Request) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) Vendor(com.jsql.model.injection.vendor.Vendor) CallablePageSource(com.jsql.model.suspendable.callable.CallablePageSource) ThreadFactoryCallable(com.jsql.model.suspendable.callable.ThreadFactoryCallable) Header(com.jsql.model.bean.util.Header) ExecutorService(java.util.concurrent.ExecutorService) StoppedByUserSlidingException(com.jsql.model.exception.StoppedByUserSlidingException) ExecutionException(java.util.concurrent.ExecutionException) EnumMap(java.util.EnumMap)

Aggregations

StoppedByUserSlidingException (com.jsql.model.exception.StoppedByUserSlidingException)6 ThreadFactoryCallable (com.jsql.model.suspendable.callable.ThreadFactoryCallable)4 ExecutionException (java.util.concurrent.ExecutionException)4 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)4 ExecutorService (java.util.concurrent.ExecutorService)4 Request (com.jsql.model.bean.util.Request)3 CallablePageSource (com.jsql.model.suspendable.callable.CallablePageSource)3 InjectionFailureException (com.jsql.model.exception.InjectionFailureException)2 ArrayList (java.util.ArrayList)2 AbstractElementDatabase (com.jsql.model.bean.database.AbstractElementDatabase)1 Table (com.jsql.model.bean.database.Table)1 Header (com.jsql.model.bean.util.Header)1 IgnoreMessageException (com.jsql.model.exception.IgnoreMessageException)1 LoopDetectedSlidingException (com.jsql.model.exception.LoopDetectedSlidingException)1 SlidingException (com.jsql.model.exception.SlidingException)1 AbstractStrategy (com.jsql.model.injection.strategy.AbstractStrategy)1 Vendor (com.jsql.model.injection.vendor.Vendor)1 SimpleEntry (java.util.AbstractMap.SimpleEntry)1 EnumMap (java.util.EnumMap)1 Matcher (java.util.regex.Matcher)1