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