Search in sources :

Example 46 with Request

use of com.jsql.model.bean.util.Request in project jsql-injection by ron190.

the class ConnectionUtil method getSource.

public String getSource(String url, boolean lineFeed) throws IOException {
    Map<Header, Object> msgHeader = new EnumMap<>(Header.class);
    msgHeader.put(Header.URL, url);
    String pageSource = StringUtils.EMPTY;
    try {
        var httpRequest = HttpRequest.newBuilder().uri(URI.create(url)).timeout(Duration.ofSeconds(this.getTimeout())).build();
        HttpHeaders httpHeaders;
        if (lineFeed) {
            HttpResponse<Stream<String>> response = this.getHttpClient().send(httpRequest, BodyHandlers.ofLines());
            pageSource = response.body().collect(Collectors.joining("\n"));
            httpHeaders = response.headers();
        } else {
            HttpResponse<String> response = this.getHttpClient().send(httpRequest, BodyHandlers.ofString());
            pageSource = response.body();
            httpHeaders = response.headers();
        }
        msgHeader.put(Header.RESPONSE, ConnectionUtil.getHeadersMap(httpHeaders));
        msgHeader.put(Header.HEADER, ConnectionUtil.getHeadersMap(httpRequest.headers()));
    } catch (IOException e) {
        LOGGER.log(LogLevel.CONSOLE_JAVA, e, e);
    } catch (InterruptedException e) {
        LOGGER.log(LogLevel.CONSOLE_JAVA, e, e);
        Thread.currentThread().interrupt();
    } finally {
        msgHeader.put(Header.SOURCE, pageSource);
        // Inform the view about the log infos
        var request = new Request();
        request.setMessage(Interaction.MESSAGE_HEADER);
        request.setParameters(msgHeader);
        this.injectionModel.sendToViews(request);
    }
    return pageSource.trim();
}
Also used : HttpHeaders(java.net.http.HttpHeaders) HttpRequest(java.net.http.HttpRequest) Request(com.jsql.model.bean.util.Request) IOException(java.io.IOException) Header(com.jsql.model.bean.util.Header) Stream(java.util.stream.Stream) EnumMap(java.util.EnumMap)

Example 47 with Request

use of com.jsql.model.bean.util.Request in project jsql-injection by ron190.

the class StrategyInjectionTime method checkApplicability.

@Override
public void checkApplicability() throws StoppedByUserSlidingException {
    if (StringUtils.isEmpty(this.injectionModel.getMediatorVendor().getVendor().instance().sqlBooleanTime())) {
        LOGGER.log(LogLevel.CONSOLE_INFORM, "No Time strategy known for {}", this.injectionModel.getMediatorVendor().getVendor());
    } else {
        LOGGER.log(LogLevel.CONSOLE_DEFAULT, "{} Time with AND...", () -> I18nUtil.valueByKey("LOG_CHECKING_STRATEGY"));
        this.injectionTime = new InjectionTime(this.injectionModel, BooleanMode.AND);
        this.isApplicable = this.injectionTime.isInjectable();
        if (!this.isApplicable) {
            LOGGER.log(LogLevel.CONSOLE_DEFAULT, "{} Time with OR...", () -> I18nUtil.valueByKey("LOG_CHECKING_STRATEGY"));
            this.injectionTime = new InjectionTime(this.injectionModel, BooleanMode.OR);
            this.isApplicable = this.injectionTime.isInjectable();
            if (this.isApplicable) {
                LOGGER.log(LogLevel.CONSOLE_SUCCESS, "{} Time injection with OR", () -> I18nUtil.valueByKey("LOG_VULNERABLE"));
            }
        } else {
            LOGGER.log(LogLevel.CONSOLE_SUCCESS, "{} Time injection with AND", () -> I18nUtil.valueByKey("LOG_VULNERABLE"));
        }
        if (this.isApplicable) {
            this.allow();
            var requestMessageBinary = new Request();
            requestMessageBinary.setMessage(Interaction.MESSAGE_BINARY);
            requestMessageBinary.setParameters(this.injectionTime.getInfoMessage());
            this.injectionModel.sendToViews(requestMessageBinary);
        } else {
            this.unallow();
        }
    }
}
Also used : Request(com.jsql.model.bean.util.Request) InjectionTime(com.jsql.model.injection.strategy.blind.InjectionTime)

Aggregations

Request (com.jsql.model.bean.util.Request)47 ArrayList (java.util.ArrayList)13 Header (com.jsql.model.bean.util.Header)12 EnumMap (java.util.EnumMap)12 ExecutorCompletionService (java.util.concurrent.ExecutorCompletionService)11 ExecutorService (java.util.concurrent.ExecutorService)11 JSqlException (com.jsql.model.exception.JSqlException)10 SuspendableGetRows (com.jsql.model.suspendable.SuspendableGetRows)9 IOException (java.io.IOException)9 ThreadFactoryCallable (com.jsql.model.suspendable.callable.ThreadFactoryCallable)8 ExecutionException (java.util.concurrent.ExecutionException)8 InjectionFailureException (com.jsql.model.exception.InjectionFailureException)7 ItemList (com.jsql.view.swing.list.ItemList)7 MalformedURLException (java.net.MalformedURLException)6 HttpRequest (java.net.http.HttpRequest)6 URL (java.net.URL)5 List (java.util.List)5 Matcher (java.util.regex.Matcher)5 IgnoreMessageException (com.jsql.model.exception.IgnoreMessageException)4 StoppedByUserSlidingException (com.jsql.model.exception.StoppedByUserSlidingException)4