1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2020. | |
3 | * This program and the accompanying materials | |
4 | * are made available under no term at all, use it like | |
5 | * you want, but share and discuss about it | |
6 | * every time possible with every body. | |
7 | * | |
8 | * Contributors: | |
9 | * ron190 at ymail dot com - initial implementation | |
10 | *******************************************************************************/ | |
11 | package com.jsql.view.swing.manager.util; | |
12 | ||
13 | import com.jsql.util.I18nUtil; | |
14 | import com.jsql.util.LogLevelUtil; | |
15 | import com.jsql.util.bruter.HashBruter; | |
16 | import com.jsql.view.swing.manager.ManagerBruteForce; | |
17 | import com.jsql.view.swing.util.I18nViewUtil; | |
18 | import org.apache.commons.lang3.StringUtils; | |
19 | import org.apache.logging.log4j.LogManager; | |
20 | import org.apache.logging.log4j.Logger; | |
21 | ||
22 | import javax.swing.*; | |
23 | import javax.swing.text.BadLocationException; | |
24 | import java.awt.event.ActionEvent; | |
25 | import java.awt.event.ActionListener; | |
26 | import java.util.Locale; | |
27 | ||
28 | /** | |
29 | * Run a brute force attack. | |
30 | */ | |
31 | public class ActionBruteForce implements ActionListener, Runnable { | |
32 | | |
33 | /** | |
34 | * Log4j logger sent to view. | |
35 | */ | |
36 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
37 | ||
38 | private final ManagerBruteForce bruteForceManager; | |
39 | | |
40 | private boolean isStopped = false; | |
41 | | |
42 | public ActionBruteForce(ManagerBruteForce bruteForceManager) { | |
43 | this.bruteForceManager = bruteForceManager; | |
44 | } | |
45 | ||
46 | @Override | |
47 | public void actionPerformed(ActionEvent arg0) { | |
48 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getRun().getState() == StateButton.STOPPABLE) { |
49 | | |
50 |
1
1. actionPerformed : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
this.bruteForceManager.getRun().setEnabled(false); |
51 | this.isStopped = true; | |
52 | | |
53 | } else { | |
54 | ||
55 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (StringUtils.isEmpty(this.bruteForceManager.getHash().getText())) { |
56 | | |
57 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_EMPTY_HASH")); | |
58 | return; | |
59 | | |
60 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
} else if (this.isRangeNotSelected()) { |
61 | | |
62 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_CHARACTER_RANGE")); | |
63 | return; | |
64 | | |
65 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
} else if (this.isLengthNotValid()) { |
66 | | |
67 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_INCORRECT_MIN_MAX_LENGTH")); | |
68 | return; | |
69 | } | |
70 | ||
71 |
1
1. actionPerformed : removed call to java/lang/Thread::start → NO_COVERAGE |
new Thread(this, "ThreadDisplayBruteForce").start(); |
72 | } | |
73 | } | |
74 | ||
75 | private boolean isLengthNotValid() { | |
76 |
1
1. isLengthNotValid : replaced boolean return with true for com/jsql/view/swing/manager/util/ActionBruteForce::isLengthNotValid → NO_COVERAGE |
return |
77 | Integer.parseInt(this.bruteForceManager.getMaximumLength().getValue().toString()) | |
78 |
2
1. isLengthNotValid : negated conditional → NO_COVERAGE 2. isLengthNotValid : changed conditional boundary → NO_COVERAGE |
< Integer.parseInt(this.bruteForceManager.getMinimumLength().getValue().toString()); |
79 | } | |
80 | ||
81 | private boolean isRangeNotSelected() { | |
82 |
2
1. isRangeNotSelected : replaced boolean return with true for com/jsql/view/swing/manager/util/ActionBruteForce::isRangeNotSelected → NO_COVERAGE 2. isRangeNotSelected : negated conditional → NO_COVERAGE |
return !this.bruteForceManager.getSpecialCharacters().isSelected() |
83 |
1
1. isRangeNotSelected : negated conditional → NO_COVERAGE |
&& !this.bruteForceManager.getUpperCaseCharacters().isSelected() |
84 |
1
1. isRangeNotSelected : negated conditional → NO_COVERAGE |
&& !this.bruteForceManager.getLowerCaseCharacters().isSelected() |
85 |
1
1. isRangeNotSelected : negated conditional → NO_COVERAGE |
&& !this.bruteForceManager.getNumericCharacters().isSelected(); |
86 | } | |
87 | ||
88 | @Override | |
89 | public void run() { | |
90 | | |
91 | // Reset the panel | |
92 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE |
this.bruteForceManager.getRun().setText(I18nViewUtil.valueByKey("BRUTEFORCE_STOP")); |
93 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE |
this.bruteForceManager.getRun().setState(StateButton.STOPPABLE); |
94 |
1
1. run : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
this.bruteForceManager.getLoader().setVisible(true); |
95 |
1
1. run : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.bruteForceManager.getResult().setText(null); |
96 | ||
97 | final var hashBruter = new HashBruter(); | |
98 | ||
99 |
1
1. run : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::initializeBruter → NO_COVERAGE |
this.initializeBruter(hashBruter); |
100 | ||
101 | // Begin the reverse hashing process | |
102 |
1
1. run : removed call to java/lang/Thread::start → NO_COVERAGE |
new Thread(hashBruter::tryBruteForce, "ThreadRunBruteForce").start(); |
103 | ||
104 |
3
1. run : negated conditional → NO_COVERAGE 2. run : negated conditional → NO_COVERAGE 3. run : negated conditional → NO_COVERAGE |
while (!hashBruter.isDone() && !hashBruter.isFound() && !this.isStopped) { |
105 | | |
106 |
1
1. run : removed call to com/jsql/util/bruter/HashBruter::setEndtime → NO_COVERAGE |
hashBruter.setEndtime(System.nanoTime()); |
107 | ||
108 | try { | |
109 |
1
1. run : removed call to java/lang/Thread::sleep → NO_COVERAGE |
Thread.sleep(1000); // delay to update result panel |
110 | } catch (InterruptedException e) { | |
111 | | |
112 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
113 |
1
1. run : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
114 | } | |
115 | | |
116 | int selectionStart = this.bruteForceManager.getResult().getSelectionStart(); | |
117 | int selectionEnd = this.bruteForceManager.getResult().getSelectionEnd(); | |
118 | | |
119 |
1
1. run : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::updateResult → NO_COVERAGE |
this.updateResult(hashBruter); |
120 | ||
121 |
1
1. run : removed call to javax/swing/JTextPane::setSelectionStart → NO_COVERAGE |
this.bruteForceManager.getResult().setSelectionStart(selectionStart); |
122 |
1
1. run : removed call to javax/swing/JTextPane::setSelectionEnd → NO_COVERAGE |
this.bruteForceManager.getResult().setSelectionEnd(selectionEnd); |
123 | | |
124 |
1
1. run : negated conditional → NO_COVERAGE |
if (this.isStopped) { |
125 | | |
126 |
1
1. run : removed call to com/jsql/util/bruter/HashBruter::setIsDone → NO_COVERAGE |
hashBruter.setIsDone(true); |
127 |
1
1. run : removed call to com/jsql/util/bruter/HashBruter::setFound → NO_COVERAGE |
hashBruter.setFound(true); |
128 | | |
129 | break; | |
130 | } | |
131 | } | |
132 | ||
133 |
1
1. run : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::displayResult → NO_COVERAGE |
this.displayResult(hashBruter); |
134 | ||
135 | this.isStopped = false; | |
136 |
1
1. run : removed call to javax/swing/JLabel::setVisible → NO_COVERAGE |
this.bruteForceManager.getLoader().setVisible(false); |
137 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE |
this.bruteForceManager.getRun().setText(I18nViewUtil.valueByKey("BRUTEFORCE_START")); |
138 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
this.bruteForceManager.getRun().setEnabled(true); |
139 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE |
this.bruteForceManager.getRun().setState(StateButton.STARTABLE); |
140 | } | |
141 | ||
142 | private void updateResult(final HashBruter hashBruter) { | |
143 | | |
144 |
1
1. updateResult : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.bruteForceManager.getResult().setText(I18nUtil.valueByKey("BRUTEFORCE_CURRENT_STRING") + ": " + hashBruter.getPassword()); |
145 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), I18nUtil.valueByKey("BRUTEFORCE_CURRENT_HASH") + ": " + hashBruter.getGeneratedHash() + "\n"); |
146 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), I18nUtil.valueByKey("BRUTEFORCE_POSSIBILITIES") + ": " + hashBruter.getNumberOfPossibilities()); |
147 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), I18nUtil.valueByKey("BRUTEFORCE_CHECKED_HASHES") + ": " + hashBruter.getCounter()); |
148 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), I18nUtil.valueByKey("BRUTEFORCE_ESTIMATED") + ": " + hashBruter.getRemainder()); |
149 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), I18nUtil.valueByKey("BRUTEFORCE_PERSECOND") + ": " + hashBruter.getPerSecond() + "\n"); |
150 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), hashBruter.calculateTimeElapsed()); |
151 | ||
152 |
1
1. updateResult : negated conditional → NO_COVERAGE |
if (hashBruter.getPerSecond() != 0) { |
153 | | |
154 |
1
1. updateResult : Replaced float division with multiplication → NO_COVERAGE |
float remainingDuration = Float.parseFloat(Long.toString(hashBruter.getRemainder())) / hashBruter.getPerSecond(); |
155 | | |
156 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), ( |
157 |
3
1. updateResult : Replaced float division with multiplication → NO_COVERAGE 2. updateResult : Replaced float division with multiplication → NO_COVERAGE 3. updateResult : Replaced float division with multiplication → NO_COVERAGE |
I18nUtil.valueByKey("BRUTEFORCE_TRAVERSING_REMAINING") + ": " |
158 |
3
1. updateResult : Replaced float division with multiplication → NO_COVERAGE 2. updateResult : Replaced float modulus with multiplication → NO_COVERAGE 3. updateResult : Replaced float division with multiplication → NO_COVERAGE |
+ Math.round(Math.floor(remainingDuration / 60f / 60.0f / 24f)) + I18nUtil.valueByKey("BRUTEFORCE_DAYS") + StringUtils.SPACE |
159 |
2
1. updateResult : Replaced float modulus with multiplication → NO_COVERAGE 2. updateResult : Replaced float division with multiplication → NO_COVERAGE |
+ Math.round(Math.floor(remainingDuration / 60f / 60f % 24)) + I18nUtil.valueByKey("BRUTEFORCE_HOURS") + StringUtils.SPACE |
160 |
1
1. updateResult : Replaced float modulus with multiplication → NO_COVERAGE |
+ Math.round(Math.floor(remainingDuration / 60f % 60)) + I18nUtil.valueByKey("BRUTEFORCE_MINUTES") + StringUtils.SPACE |
161 | + Math.round(remainingDuration % 60) + I18nUtil.valueByKey("BRUTEFORCE_SECONDS") | |
162 | )); | |
163 | } | |
164 | ||
165 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append( |
166 | this.bruteForceManager.getResult(), | |
167 | String.format( | |
168 | "%s: %s%%", | |
169 | I18nUtil.valueByKey("BRUTEFORCE_PERCENT_DONE"), | |
170 |
2
1. updateResult : Replaced float multiplication with division → NO_COVERAGE 2. updateResult : Replaced float division with multiplication → NO_COVERAGE |
100 * (float) hashBruter.getCounter() / hashBruter.getNumberOfPossibilities() |
171 | ) | |
172 | ); | |
173 | } | |
174 | ||
175 | private void initializeBruter(final HashBruter hashBruter) { | |
176 | | |
177 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::setMinLength → NO_COVERAGE |
hashBruter.setMinLength(Integer.parseInt(this.bruteForceManager.getMinimumLength().getValue().toString())); |
178 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::setMaxLength → NO_COVERAGE |
hashBruter.setMaxLength(Integer.parseInt(this.bruteForceManager.getMaximumLength().getValue().toString())); |
179 | ||
180 |
1
1. initializeBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getSpecialCharacters().isSelected()) { |
181 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::addSpecialCharacters → NO_COVERAGE |
hashBruter.addSpecialCharacters(); |
182 | } | |
183 | | |
184 |
1
1. initializeBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getUpperCaseCharacters().isSelected()) { |
185 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::addUpperCaseLetters → NO_COVERAGE |
hashBruter.addUpperCaseLetters(); |
186 | } | |
187 | | |
188 |
1
1. initializeBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getLowerCaseCharacters().isSelected()) { |
189 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::addLowerCaseLetters → NO_COVERAGE |
hashBruter.addLowerCaseLetters(); |
190 | } | |
191 | | |
192 |
1
1. initializeBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getNumericCharacters().isSelected()) { |
193 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::addDigits → NO_COVERAGE |
hashBruter.addDigits(); |
194 | } | |
195 | | |
196 |
1
1. initializeBruter : negated conditional → NO_COVERAGE |
if (StringUtils.isNotEmpty(this.bruteForceManager.getExclude().getText())) { |
197 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::excludeChars → NO_COVERAGE |
hashBruter.excludeChars(this.bruteForceManager.getExclude().getText()); |
198 | } | |
199 | ||
200 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::setType → NO_COVERAGE |
hashBruter.setType((String) this.bruteForceManager.getHashTypes().getSelectedItem()); |
201 |
1
1. initializeBruter : removed call to com/jsql/util/bruter/HashBruter::setHash → NO_COVERAGE |
hashBruter.setHash( |
202 | this.bruteForceManager | |
203 | .getHash() | |
204 | .getText() | |
205 | .toUpperCase(Locale.ROOT) | |
206 | .replaceAll("[^a-zA-Z0-9]", StringUtils.EMPTY) | |
207 | .trim() | |
208 | ); | |
209 | } | |
210 | ||
211 | private void displayResult(final HashBruter hashBruter) { | |
212 | | |
213 | // Display the result | |
214 |
1
1. displayResult : negated conditional → NO_COVERAGE |
if (this.isStopped) { |
215 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_ABORTED")); | |
216 |
1
1. displayResult : negated conditional → NO_COVERAGE |
} else if (hashBruter.isFound()) { |
217 | | |
218 |
1
1. displayResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append( |
219 | this.bruteForceManager.getResult(), | |
220 | String.format( | |
221 | "%n%s:%n%s => %s", | |
222 | I18nUtil.valueByKey("BRUTEFORCE_FOUND_HASH"), | |
223 | hashBruter.getGeneratedHash(), | |
224 | hashBruter.getPassword() | |
225 | ) | |
226 | ); | |
227 | ||
228 | LOGGER.log( | |
229 | LogLevelUtil.CONSOLE_SUCCESS, | |
230 | "{}: {} => {}", | |
231 |
1
1. lambda$displayResult$4 : replaced return value with null for com/jsql/view/swing/manager/util/ActionBruteForce::lambda$displayResult$4 → NO_COVERAGE |
() -> I18nUtil.valueByKey("BRUTEFORCE_FOUND_HASH"), |
232 | hashBruter::getGeneratedHash, | |
233 | hashBruter::getPassword | |
234 | ); | |
235 |
1
1. displayResult : negated conditional → NO_COVERAGE |
} else if (hashBruter.isDone()) { |
236 | | |
237 |
1
1. displayResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append( |
238 | this.bruteForceManager.getResult(), | |
239 | "\n"+ I18nUtil.valueByKey("BRUTEFORCE_HASH_NOT_FOUND") | |
240 | ); | |
241 | | |
242 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_HASH_NOT_FOUND")); | |
243 | } | |
244 | } | |
245 | | |
246 | public void append(JTextPane textPane, String text) { | |
247 | try { | |
248 |
1
1. append : removed call to javax/swing/text/Document::insertString → NO_COVERAGE |
textPane.getDocument().insertString( |
249 | textPane.getDocument().getLength(), | |
250 |
1
1. append : negated conditional → NO_COVERAGE |
(textPane.getDocument().getLength() == 0 ? StringUtils.EMPTY : "\n") + text, |
251 | null | |
252 | ); | |
253 | } catch (BadLocationException e) { | |
254 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
255 | } | |
256 | } | |
257 | } | |
Mutations | ||
48 |
1.1 |
|
50 |
1.1 |
|
55 |
1.1 |
|
60 |
1.1 |
|
65 |
1.1 |
|
71 |
1.1 |
|
76 |
1.1 |
|
78 |
1.1 2.2 |
|
82 |
1.1 2.2 |
|
83 |
1.1 |
|
84 |
1.1 |
|
85 |
1.1 |
|
92 |
1.1 |
|
93 |
1.1 |
|
94 |
1.1 |
|
95 |
1.1 |
|
99 |
1.1 |
|
102 |
1.1 |
|
104 |
1.1 2.2 3.3 |
|
106 |
1.1 |
|
109 |
1.1 |
|
113 |
1.1 |
|
119 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
124 |
1.1 |
|
126 |
1.1 |
|
127 |
1.1 |
|
133 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
138 |
1.1 |
|
139 |
1.1 |
|
144 |
1.1 |
|
145 |
1.1 |
|
146 |
1.1 |
|
147 |
1.1 |
|
148 |
1.1 |
|
149 |
1.1 |
|
150 |
1.1 |
|
152 |
1.1 |
|
154 |
1.1 |
|
156 |
1.1 |
|
157 |
1.1 2.2 3.3 |
|
158 |
1.1 2.2 3.3 |
|
159 |
1.1 2.2 |
|
160 |
1.1 |
|
165 |
1.1 |
|
170 |
1.1 2.2 |
|
177 |
1.1 |
|
178 |
1.1 |
|
180 |
1.1 |
|
181 |
1.1 |
|
184 |
1.1 |
|
185 |
1.1 |
|
188 |
1.1 |
|
189 |
1.1 |
|
192 |
1.1 |
|
193 |
1.1 |
|
196 |
1.1 |
|
197 |
1.1 |
|
200 |
1.1 |
|
201 |
1.1 |
|
214 |
1.1 |
|
216 |
1.1 |
|
218 |
1.1 |
|
231 |
1.1 |
|
235 |
1.1 |
|
237 |
1.1 |
|
248 |
1.1 |
|
250 |
1.1 |