SuspendableGetIndexes.java

1
package com.jsql.model.suspendable;
2
3
import com.jsql.model.InjectionModel;
4
import com.jsql.model.exception.JSqlException;
5
import com.jsql.model.exception.StoppedByUserSlidingException;
6
import com.jsql.model.injection.vendor.model.VendorYaml;
7
import com.jsql.model.suspendable.callable.CallablePageSource;
8
import com.jsql.util.LogLevelUtil;
9
import org.apache.commons.lang3.StringUtils;
10
import org.apache.logging.log4j.LogManager;
11
import org.apache.logging.log4j.Logger;
12
13
import java.util.concurrent.CompletionService;
14
import java.util.concurrent.ExecutionException;
15
import java.util.concurrent.ExecutorCompletionService;
16
import java.util.concurrent.ExecutorService;
17
import java.util.regex.Pattern;
18
19
/**
20
 * Runnable class, search the correct number of fields in the SQL query.
21
 * Concurrent search with stop capability
22
 */
23
public class SuspendableGetIndexes extends AbstractSuspendable {
24
    
25
    /**
26
     * Log4j logger sent to view.
27
     */
28
    private static final Logger LOGGER = LogManager.getRootLogger();
29
    
30
    public SuspendableGetIndexes(InjectionModel injectionModel) {
31
        super(injectionModel);
32
    }
33
34
    @Override
35
    public String run(Object... args) throws JSqlException {
36
        
37
        // Concurrent search
38
        ExecutorService taskExecutor = this.injectionModel.getMediatorUtils().getThreadUtil().getExecutor("CallableGetIndexes");
39
        
40
        CompletionService<CallablePageSource> taskCompletionService = new ExecutorCompletionService<>(taskExecutor);
41
42
        String initialQuery = StringUtils.EMPTY;
43
        int nbIndex;
44
        
45 1 1. run : negated conditional → NO_COVERAGE
        int countNormalIndex = this.injectionModel.getMediatorUtils().getPreferencesUtil().isLimitingNormalIndex()
46
            ? this.injectionModel.getMediatorUtils().getPreferencesUtil().countNormalIndex()
47
            : 50;
48
49
        // SQL fields are built like 1337[index]7330+1
50
        // 7330+1 allows to exclude false positive when page contains injection URL
51
        // Search if the source contains 1337[index]7331
52 2 1. run : negated conditional → NO_COVERAGE
2. run : changed conditional boundary → NO_COVERAGE
        for (nbIndex = 1 ; nbIndex <= countNormalIndex ; nbIndex++) {
53
            taskCompletionService.submit(
54
                new CallablePageSource(
55
                    this.injectionModel.getMediatorVendor().getVendor().instance().sqlIndices(nbIndex),
56
                    this.injectionModel,
57
                    "normal#" + nbIndex
58
                )
59
            );
60
        }
61
        
62
        nbIndex = 1;
63
64
        try {
65
            // Start from 10 to 100 requests
66 2 1. run : changed conditional boundary → NO_COVERAGE
2. run : negated conditional → NO_COVERAGE
            while (nbIndex <= countNormalIndex) {
67
68 1 1. run : negated conditional → NO_COVERAGE
                if (this.isSuspended()) {
69
                    throw new StoppedByUserSlidingException();
70
                }
71
72
                CallablePageSource currentCallable = taskCompletionService.take().get();
73 1 1. run : Changed increment from 1 to -1 → NO_COVERAGE
                nbIndex++;
74
75
                // Found a correct mark 1337[index]7331 in the source
76
                String regexAllIndexes = String.format(VendorYaml.FORMAT_INDEX, "\\d+");
77 1 1. run : negated conditional → NO_COVERAGE
                if (Pattern.compile("(?s).*"+ regexAllIndexes +".*").matcher(currentCallable.getContent()).matches()) {
78
                    
79 1 1. run : removed call to com/jsql/model/injection/strategy/StrategyInjectionNormal::setSourceIndexesFound → NO_COVERAGE
                    this.injectionModel.getMediatorStrategy().getSpecificNormal().setSourceIndexesFound(currentCallable.getContent());
80
                    initialQuery = currentCallable.getQuery().replace("0%2b1", "1");
81
                    
82 1 1. run : negated conditional → NO_COVERAGE
                    if (this.injectionModel.getMediatorUtils().getPreferencesUtil().isPerfIndexDisabled()) {
83
84
                        String regexIndexesExceptFirst = String.format(VendorYaml.FORMAT_INDEX, "(?!17331)\\d+");
85
                        initialQuery = initialQuery.replaceAll(regexIndexesExceptFirst, "1");
86
                        LOGGER.log(LogLevelUtil.CONSOLE_INFORM, "Calibrating indexes disabled, forcing to index [1]");
87
                    }
88
                    
89
                    LOGGER.log(
90
                        LogLevelUtil.CONSOLE_INFORM,
91
                        "Strategy [Normal] triggered by [{}]",
92 1 1. lambda$run$0 : replaced return value with null for com/jsql/model/suspendable/SuspendableGetIndexes::lambda$run$0 → NO_COVERAGE
                        () -> currentCallable.getQuery().trim().replaceAll("1337(\\d*)7330%2b1", "$1")
93
                    );
94
                    
95
                    break;
96
                }
97
            }
98
99 1 1. run : removed call to com/jsql/util/ThreadUtil::shutdown → NO_COVERAGE
            this.injectionModel.getMediatorUtils().getThreadUtil().shutdown(taskExecutor);
100
101
        } catch (InterruptedException e) {
102
103
            LOGGER.log(LogLevelUtil.IGNORE, e, e);
104 1 1. run : removed call to java/lang/Thread::interrupt → NO_COVERAGE
            Thread.currentThread().interrupt();
105
106
        } catch (ExecutionException e) {
107
            LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e);
108
        }
109
110 1 1. run : replaced return value with "" for com/jsql/model/suspendable/SuspendableGetIndexes::run → NO_COVERAGE
        return initialQuery;
111
    }
112
}

Mutations

45

1.1
Location : run
Killed by : none
negated conditional → NO_COVERAGE

52

1.1
Location : run
Killed by : none
negated conditional → NO_COVERAGE

2.2
Location : run
Killed by : none
changed conditional boundary → NO_COVERAGE

66

1.1
Location : run
Killed by : none
changed conditional boundary → NO_COVERAGE

2.2
Location : run
Killed by : none
negated conditional → NO_COVERAGE

68

1.1
Location : run
Killed by : none
negated conditional → NO_COVERAGE

73

1.1
Location : run
Killed by : none
Changed increment from 1 to -1 → NO_COVERAGE

77

1.1
Location : run
Killed by : none
negated conditional → NO_COVERAGE

79

1.1
Location : run
Killed by : none
removed call to com/jsql/model/injection/strategy/StrategyInjectionNormal::setSourceIndexesFound → NO_COVERAGE

82

1.1
Location : run
Killed by : none
negated conditional → NO_COVERAGE

92

1.1
Location : lambda$run$0
Killed by : none
replaced return value with null for com/jsql/model/suspendable/SuspendableGetIndexes::lambda$run$0 → NO_COVERAGE

99

1.1
Location : run
Killed by : none
removed call to com/jsql/util/ThreadUtil::shutdown → NO_COVERAGE

104

1.1
Location : run
Killed by : none
removed call to java/lang/Thread::interrupt → NO_COVERAGE

110

1.1
Location : run
Killed by : none
replaced return value with "" for com/jsql/model/suspendable/SuspendableGetIndexes::run → NO_COVERAGE

Active mutators

Tests examined


Report generated by PIT 1.16.1