Search in sources :

Example 1 with CallableHttpHead

use of com.jsql.model.accessible.CallableHttpHead in project jsql-injection by ron190.

the class ManagerAdminPage method createAdminPages.

/**
 * Check if every page in the list responds 200 Success.
 * @param urlInjection
 * @param pageNames List of admin pages to test
 * @throws InterruptedException
 */
public void createAdminPages(String urlInjection, List<ItemList> pageNames) throws InterruptedException {
    var matcher = Pattern.compile("^((https?://)?[^/]*)(.*)").matcher(urlInjection);
    matcher.find();
    String urlProtocol = matcher.group(1);
    String urlWithoutProtocol = matcher.group(3);
    List<String> folderSplits = new ArrayList<>();
    // Hostname only
    if (urlWithoutProtocol.isEmpty() || !Pattern.matches("^/.*", urlWithoutProtocol)) {
        urlWithoutProtocol = "/dummy";
    }
    String[] splits = urlWithoutProtocol.split("/", -1);
    String[] folderNames = Arrays.copyOf(splits, splits.length - 1);
    for (String folderName : Arrays.asList(folderNames)) {
        folderSplits.add(folderName + "/");
    }
    ExecutorService taskExecutor = Executors.newFixedThreadPool(10, new ThreadFactoryCallable("CallableGetAdminPage"));
    CompletionService<CallableHttpHead> taskCompletionService = new ExecutorCompletionService<>(taskExecutor);
    var urlPart = new StringBuilder();
    for (String segment : folderSplits) {
        urlPart.append(segment);
        for (ItemList pageName : pageNames) {
            taskCompletionService.submit(new CallableHttpHead(urlProtocol + urlPart.toString() + pageName.toString(), MediatorHelper.model(), "check:page"));
        }
    }
    var resourceAccess = MediatorHelper.model().getResourceAccess();
    var nbAdminPagesFound = 0;
    int submittedTasks = folderSplits.size() * pageNames.size();
    int tasksHandled;
    for (tasksHandled = 0; tasksHandled < submittedTasks && !resourceAccess.isSearchAdminStopped(); tasksHandled++) {
        nbAdminPagesFound = resourceAccess.callAdminPage(taskCompletionService, nbAdminPagesFound);
    }
    taskExecutor.shutdown();
    taskExecutor.awaitTermination(5, TimeUnit.SECONDS);
    resourceAccess.setSearchAdminStopped(false);
    resourceAccess.logSearchAdminPage(nbAdminPagesFound, submittedTasks, tasksHandled);
    var request = new Request();
    request.setMessage(Interaction.END_ADMIN_SEARCH);
    MediatorHelper.model().sendToViews(request);
}
Also used : CallableHttpHead(com.jsql.model.accessible.CallableHttpHead) ArrayList(java.util.ArrayList) Request(com.jsql.model.bean.util.Request) ExecutorCompletionService(java.util.concurrent.ExecutorCompletionService) ThreadFactoryCallable(com.jsql.model.suspendable.callable.ThreadFactoryCallable) ItemList(com.jsql.view.swing.list.ItemList) ExecutorService(java.util.concurrent.ExecutorService)

Aggregations

CallableHttpHead (com.jsql.model.accessible.CallableHttpHead)1 Request (com.jsql.model.bean.util.Request)1 ThreadFactoryCallable (com.jsql.model.suspendable.callable.ThreadFactoryCallable)1 ItemList (com.jsql.view.swing.list.ItemList)1 ArrayList (java.util.ArrayList)1 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)1 ExecutorService (java.util.concurrent.ExecutorService)1