1 | package com.jsql.model.injection.strategy.blind; | |
2 | ||
3 | import com.jsql.model.InjectionModel; | |
4 | import com.jsql.model.exception.StoppedByUserSlidingException; | |
5 | import com.jsql.model.injection.strategy.blind.patch.Diff; | |
6 | import com.jsql.util.LogLevelUtil; | |
7 | import org.apache.commons.lang3.StringUtils; | |
8 | import org.apache.logging.log4j.LogManager; | |
9 | import org.apache.logging.log4j.Logger; | |
10 | ||
11 | import java.util.ArrayList; | |
12 | import java.util.Collection; | |
13 | import java.util.List; | |
14 | import java.util.concurrent.CompletionService; | |
15 | import java.util.concurrent.ExecutionException; | |
16 | import java.util.concurrent.ExecutorService; | |
17 | import java.util.concurrent.Future; | |
18 | import java.util.concurrent.atomic.AtomicInteger; | |
19 | ||
20 | public class InjectionMultibit extends AbstractInjectionBoolean<CallableMultibit> { | |
21 | ||
22 | /** | |
23 | * Log4j logger sent to view. | |
24 | */ | |
25 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
26 | ||
27 | private String sourceReference; | |
28 | ||
29 | private List<Diff> diffsCommonWithAllIds = new ArrayList<>(); | |
30 | private final List<List<Diff>> diffsById = new ArrayList<>(); | |
31 | ||
32 | public InjectionMultibit(InjectionModel injectionModel, BooleanMode blindMode) { | |
33 | | |
34 | super(injectionModel, blindMode); | |
35 | | |
36 |
1
1. <init> : negated conditional → NO_COVERAGE |
if (this.injectionModel.isStoppedByUser()) { |
37 | return; | |
38 | } | |
39 | ||
40 | this.sourceReference = this.callUrl("8", "multi#ref"); | |
41 | ExecutorService taskExecutor = this.injectionModel.getMediatorUtils().getThreadUtil().getExecutor("CallableGetMultibitIds"); | |
42 | Collection<CallableMultibit> callablesId = new ArrayList<>(); | |
43 | ||
44 |
2
1. <init> : changed conditional boundary → NO_COVERAGE 2. <init> : negated conditional → NO_COVERAGE |
for (int i = 0; i < 8 ; i++) { |
45 | callablesId.add( | |
46 | new CallableMultibit( | |
47 | ""+i, | |
48 | this, | |
49 | "multi#ref~" + i | |
50 | ) | |
51 | ); | |
52 | } | |
53 | ||
54 | try { | |
55 | List<Future<CallableMultibit>> futuresId = taskExecutor.invokeAll(callablesId); | |
56 |
1
1. <init> : removed call to com/jsql/util/ThreadUtil::shutdown → NO_COVERAGE |
this.injectionModel.getMediatorUtils().getThreadUtil().shutdown(taskExecutor); |
57 | ||
58 | for (Future<CallableMultibit> futureId: futuresId) { | |
59 | ||
60 | List<Diff> diffsWithReference = futureId.get().getDiffsWithReference(); | |
61 |
1
1. <init> : negated conditional → NO_COVERAGE |
if (this.diffsCommonWithAllIds.isEmpty()) { |
62 | this.diffsCommonWithAllIds = new ArrayList<>(diffsWithReference); | |
63 | } else { | |
64 | this.diffsCommonWithAllIds.retainAll(diffsWithReference); | |
65 | } | |
66 | diffsById.add(diffsWithReference); | |
67 | } | |
68 | ||
69 | for (List<Diff> diffById : diffsById) { | |
70 | diffById.removeAll(this.diffsCommonWithAllIds); | |
71 | } | |
72 | } catch (ExecutionException e) { | |
73 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
74 | } catch (InterruptedException e) { | |
75 | ||
76 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
77 |
1
1. <init> : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
78 | } | |
79 | } | |
80 | ||
81 | public CallableMultibit getCallableTest(String sqlQuery, int indexCharacter, int block) { | |
82 |
1
1. getCallableTest : replaced return value with null for com/jsql/model/injection/strategy/blind/InjectionMultibit::getCallableTest → NO_COVERAGE |
return new CallableMultibit( |
83 | sqlQuery, | |
84 | indexCharacter, | |
85 | block, | |
86 | this.injectionModel, | |
87 | this, | |
88 | "multi#" + indexCharacter + "." + block | |
89 | ); | |
90 | } | |
91 | ||
92 | @Override | |
93 | public boolean isInjectable() throws StoppedByUserSlidingException { | |
94 | | |
95 |
1
1. isInjectable : negated conditional → NO_COVERAGE |
if (this.injectionModel.isStoppedByUser()) { |
96 | throw new StoppedByUserSlidingException(); | |
97 | } | |
98 | ||
99 | var callableBlock1 = new CallableMultibit("'a'", 1, 1, this.injectionModel, this, "multi#confirm.1"); | |
100 | var callableBlock2 = new CallableMultibit("'a'", 1, 2, this.injectionModel, this, "multi#confirm.2"); | |
101 | var callableBlock3 = new CallableMultibit("'a'", 1, 3, this.injectionModel, this, "multi#confirm.3"); | |
102 | ||
103 | callableBlock1.call(); | |
104 | callableBlock2.call(); | |
105 | callableBlock3.call(); | |
106 | ||
107 |
4
1. isInjectable : replaced boolean return with true for com/jsql/model/injection/strategy/blind/InjectionMultibit::isInjectable → NO_COVERAGE 2. isInjectable : negated conditional → NO_COVERAGE 3. isInjectable : negated conditional → NO_COVERAGE 4. isInjectable : negated conditional → NO_COVERAGE |
return callableBlock1.getIdPage() == 3 && callableBlock2.getIdPage() == 0 && callableBlock3.getIdPage() == 1; |
108 | } | |
109 | ||
110 | @Override | |
111 | public String getInfoMessage() { | |
112 |
1
1. getInfoMessage : replaced return value with "" for com/jsql/model/injection/strategy/blind/InjectionMultibit::getInfoMessage → NO_COVERAGE |
return "- Strategy Multibit: query 3 bits when Diffs match index in " + this.diffsById + "\n\n"; |
113 | } | |
114 | ||
115 | @Override | |
116 | public void initializeNextCharacters( | |
117 | String sqlQuery, | |
118 | List<char[]> bytes, | |
119 | AtomicInteger indexCharacter, | |
120 | CompletionService<CallableMultibit> taskCompletionService, | |
121 | AtomicInteger countTasksSubmitted | |
122 | ) { | |
123 | indexCharacter.incrementAndGet(); | |
124 | ||
125 | bytes.add(new char[]{ '0', 'x', 'x', 'x', 'x', 'x', 'x', 'x' }); | |
126 | ||
127 | for (int block: new int[]{ 1, 2, 3 }) { | |
128 | ||
129 | taskCompletionService.submit( | |
130 | this.getCallableTest( | |
131 | sqlQuery, | |
132 | indexCharacter.get(), | |
133 | block | |
134 | ) | |
135 | ); | |
136 | countTasksSubmitted.addAndGet(1); | |
137 | } | |
138 | } | |
139 | ||
140 | @Override | |
141 | public char[] initializeBinaryMask(List<char[]> bytes, CallableMultibit currentCallable) { | |
142 | ||
143 | // Bits for current url | |
144 |
1
1. initializeBinaryMask : Replaced integer subtraction with addition → NO_COVERAGE |
char[] asciiCodeMask = bytes.get(currentCallable.getCurrentIndex() - 1); |
145 |
1
1. initializeBinaryMask : removed call to com/jsql/model/injection/strategy/blind/InjectionMultibit::extractBitsFromBlock → NO_COVERAGE |
extractBitsFromBlock(currentCallable, asciiCodeMask); |
146 |
1
1. initializeBinaryMask : replaced return value with null for com/jsql/model/injection/strategy/blind/InjectionMultibit::initializeBinaryMask → NO_COVERAGE |
return asciiCodeMask; |
147 | } | |
148 | ||
149 | /** | |
150 | * Extract 3 bits from callable for specific block | |
151 | */ | |
152 | private void extractBitsFromBlock(CallableMultibit currentCallable, char[] bits) { | |
153 |
1
1. extractBitsFromBlock : negated conditional → NO_COVERAGE |
if (currentCallable.block == 1) { |
154 |
1
1. extractBitsFromBlock : removed call to com/jsql/model/injection/strategy/blind/InjectionMultibit::convertIdPageToBits → NO_COVERAGE |
convertIdPageToBits(currentCallable.idPage, bits, 0, 1, 2); |
155 |
1
1. extractBitsFromBlock : negated conditional → NO_COVERAGE |
} else if (currentCallable.block == 2) { |
156 |
1
1. extractBitsFromBlock : removed call to com/jsql/model/injection/strategy/blind/InjectionMultibit::convertIdPageToBits → NO_COVERAGE |
convertIdPageToBits(currentCallable.idPage, bits, 3, 4, 5); |
157 |
1
1. extractBitsFromBlock : negated conditional → NO_COVERAGE |
} else if (currentCallable.block == 3) { |
158 |
1
1. extractBitsFromBlock : removed call to com/jsql/model/injection/strategy/blind/InjectionMultibit::convertIdPageToBits → NO_COVERAGE |
convertIdPageToBits(currentCallable.idPage, bits, -1, 6,7); |
159 | } | |
160 | } | |
161 | ||
162 | /** | |
163 | * Set bits by page id | |
164 | */ | |
165 | private void convertIdPageToBits(int idPage, char[] bits, int i1, int i2, int i3) { | |
166 | ||
167 | String idPageBinary = Integer.toBinaryString(idPage); | |
168 | String idPageBinaryPadded = StringUtils.leftPad(idPageBinary, 3, "0"); | |
169 | ||
170 |
2
1. convertIdPageToBits : changed conditional boundary → NO_COVERAGE 2. convertIdPageToBits : negated conditional → NO_COVERAGE |
if (i1 > -1) { |
171 | bits[i1] = idPageBinaryPadded.charAt(0); | |
172 | } | |
173 | bits[i2] = idPageBinaryPadded.charAt(1); | |
174 | bits[i3] = idPageBinaryPadded.charAt(2); | |
175 | } | |
176 | ||
177 | ||
178 | // Getter | |
179 | ||
180 | public String getSourceReference() { | |
181 |
1
1. getSourceReference : replaced return value with "" for com/jsql/model/injection/strategy/blind/InjectionMultibit::getSourceReference → NO_COVERAGE |
return this.sourceReference; |
182 | } | |
183 | ||
184 | public List<Diff> getDiffsCommonWithAllIds() { | |
185 |
1
1. getDiffsCommonWithAllIds : replaced return value with Collections.emptyList for com/jsql/model/injection/strategy/blind/InjectionMultibit::getDiffsCommonWithAllIds → NO_COVERAGE |
return this.diffsCommonWithAllIds; |
186 | } | |
187 | ||
188 | public List<List<Diff>> getDiffsById() { | |
189 |
1
1. getDiffsById : replaced return value with Collections.emptyList for com/jsql/model/injection/strategy/blind/InjectionMultibit::getDiffsById → NO_COVERAGE |
return diffsById; |
190 | } | |
191 | } | |
Mutations | ||
36 |
1.1 |
|
44 |
1.1 2.2 |
|
56 |
1.1 |
|
61 |
1.1 |
|
77 |
1.1 |
|
82 |
1.1 |
|
95 |
1.1 |
|
107 |
1.1 2.2 3.3 4.4 |
|
112 |
1.1 |
|
144 |
1.1 |
|
145 |
1.1 |
|
146 |
1.1 |
|
153 |
1.1 |
|
154 |
1.1 |
|
155 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 |
|
158 |
1.1 |
|
170 |
1.1 2.2 |
|
181 |
1.1 |
|
185 |
1.1 |
|
189 |
1.1 |