1 | /******************************************************************************* | |
2 | * Copyhacked (H) 2012-2025. | |
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 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 actionEvent) { | |
48 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getRun().getState() == StateButton.STOPPABLE) { |
49 |
1
1. actionPerformed : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
this.bruteForceManager.getRun().setEnabled(false); |
50 | this.isStopped = true; | |
51 | } else { | |
52 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
if (StringUtils.isEmpty(this.bruteForceManager.getHash().getText())) { |
53 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_EMPTY_HASH")); | |
54 | return; | |
55 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
} else if (this.isRangeNotSelected()) { |
56 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_CHARACTER_RANGE")); | |
57 | return; | |
58 |
1
1. actionPerformed : negated conditional → NO_COVERAGE |
} else if (this.isLengthNotValid()) { |
59 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_INCORRECT_MIN_MAX_LENGTH")); | |
60 | return; | |
61 | } | |
62 |
1
1. actionPerformed : removed call to java/lang/Thread::start → NO_COVERAGE |
new Thread(this, "ThreadDisplayBruteForce").start(); |
63 | } | |
64 | } | |
65 | ||
66 | private boolean isLengthNotValid() { | |
67 |
1
1. isLengthNotValid : replaced boolean return with true for com/jsql/view/swing/manager/util/ActionBruteForce::isLengthNotValid → NO_COVERAGE |
return Integer.parseInt(this.bruteForceManager.getMaximumLength().getValue().toString()) |
68 |
2
1. isLengthNotValid : changed conditional boundary → NO_COVERAGE 2. isLengthNotValid : negated conditional → NO_COVERAGE |
< Integer.parseInt(this.bruteForceManager.getMinimumLength().getValue().toString()); |
69 | } | |
70 | ||
71 | private boolean isRangeNotSelected() { | |
72 |
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() |
73 |
1
1. isRangeNotSelected : negated conditional → NO_COVERAGE |
&& !this.bruteForceManager.getUpperCaseCharacters().isSelected() |
74 |
1
1. isRangeNotSelected : negated conditional → NO_COVERAGE |
&& !this.bruteForceManager.getLowerCaseCharacters().isSelected() |
75 |
1
1. isRangeNotSelected : negated conditional → NO_COVERAGE |
&& !this.bruteForceManager.getNumericCharacters().isSelected(); |
76 | } | |
77 | ||
78 | @Override | |
79 | public void run() { | |
80 | // Reset the panel | |
81 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE |
this.bruteForceManager.getRun().setText(I18nViewUtil.valueByKey("BRUTEFORCE_STOP")); |
82 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE |
this.bruteForceManager.getRun().setState(StateButton.STOPPABLE); |
83 |
1
1. run : removed call to com/jsql/view/swing/manager/ManagerBruteForce::showLoader → NO_COVERAGE |
this.bruteForceManager.showLoader(true); |
84 |
1
1. run : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.bruteForceManager.getResult().setText(null); |
85 | ||
86 | final var hashBruter = new HashBruter(); | |
87 |
1
1. run : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::initBruter → NO_COVERAGE |
this.initBruter(hashBruter); |
88 | ||
89 | // Begin the reverse hashing process | |
90 |
1
1. run : removed call to java/lang/Thread::start → NO_COVERAGE |
new Thread(hashBruter::tryBruteForce, "ThreadRunBruteForce").start(); |
91 |
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) { |
92 | | |
93 |
1
1. run : removed call to com/jsql/util/bruter/HashBruter::setEndtime → NO_COVERAGE |
hashBruter.setEndtime(System.nanoTime()); |
94 | ||
95 | try { | |
96 |
1
1. run : removed call to java/lang/Thread::sleep → NO_COVERAGE |
Thread.sleep(1000); // delay to update result panel |
97 | } catch (InterruptedException e) { | |
98 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
99 |
1
1. run : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
100 | } | |
101 | | |
102 | int selectionStart = this.bruteForceManager.getResult().getSelectionStart(); | |
103 | int selectionEnd = this.bruteForceManager.getResult().getSelectionEnd(); | |
104 | | |
105 |
1
1. run : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::updateResult → NO_COVERAGE |
this.updateResult(hashBruter); |
106 | ||
107 |
1
1. run : removed call to javax/swing/JTextPane::setSelectionStart → NO_COVERAGE |
this.bruteForceManager.getResult().setSelectionStart(selectionStart); |
108 |
1
1. run : removed call to javax/swing/JTextPane::setSelectionEnd → NO_COVERAGE |
this.bruteForceManager.getResult().setSelectionEnd(selectionEnd); |
109 | | |
110 |
1
1. run : negated conditional → NO_COVERAGE |
if (this.isStopped) { |
111 |
1
1. run : removed call to com/jsql/util/bruter/HashBruter::setIsDone → NO_COVERAGE |
hashBruter.setIsDone(true); |
112 |
1
1. run : removed call to com/jsql/util/bruter/HashBruter::setFound → NO_COVERAGE |
hashBruter.setFound(true); |
113 | break; | |
114 | } | |
115 | } | |
116 | ||
117 |
1
1. run : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::displayResult → NO_COVERAGE |
this.displayResult(hashBruter); |
118 | ||
119 | this.isStopped = false; | |
120 |
1
1. run : removed call to com/jsql/view/swing/manager/ManagerBruteForce::showLoader → NO_COVERAGE |
this.bruteForceManager.showLoader(false); |
121 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setText → NO_COVERAGE |
this.bruteForceManager.getRun().setText(I18nViewUtil.valueByKey("BRUTEFORCE_RUN_BUTTON_LABEL")); |
122 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setEnabled → NO_COVERAGE |
this.bruteForceManager.getRun().setEnabled(true); |
123 |
1
1. run : removed call to com/jsql/view/swing/manager/util/JButtonStateful::setState → NO_COVERAGE |
this.bruteForceManager.getRun().setState(StateButton.STARTABLE); |
124 | } | |
125 | ||
126 | private void updateResult(final HashBruter hashBruter) { | |
127 |
1
1. updateResult : removed call to javax/swing/JTextPane::setText → NO_COVERAGE |
this.bruteForceManager.getResult().setText(I18nUtil.valueByKey("BRUTEFORCE_CURRENT_STRING") + ": " + hashBruter.getPassword()); |
128 |
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"); |
129 |
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()); |
130 |
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()); |
131 |
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()); |
132 |
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"); |
133 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), hashBruter.calculateTimeElapsed()); |
134 | ||
135 |
1
1. updateResult : negated conditional → NO_COVERAGE |
if (hashBruter.getPerSecond() != 0) { |
136 |
1
1. updateResult : Replaced float division with multiplication → NO_COVERAGE |
float remainingDuration = Float.parseFloat(Long.toString(hashBruter.getRemainder())) / hashBruter.getPerSecond(); |
137 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append( |
138 | this.bruteForceManager.getResult(), | |
139 |
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") + ": " |
140 |
3
1. updateResult : Replaced float division with multiplication → NO_COVERAGE 2. updateResult : Replaced float division with multiplication → NO_COVERAGE 3. updateResult : Replaced float modulus with multiplication → NO_COVERAGE |
+ Math.round(Math.floor(remainingDuration / 60f / 60.0f / 24f)) + I18nUtil.valueByKey("BRUTEFORCE_DAYS") + StringUtils.SPACE |
141 |
2
1. updateResult : Replaced float division with multiplication → NO_COVERAGE 2. updateResult : Replaced float modulus with multiplication → NO_COVERAGE |
+ Math.round(Math.floor(remainingDuration / 60f / 60f % 24)) + I18nUtil.valueByKey("BRUTEFORCE_HOURS") + StringUtils.SPACE |
142 |
1
1. updateResult : Replaced float modulus with multiplication → NO_COVERAGE |
+ Math.round(Math.floor(remainingDuration / 60f % 60)) + I18nUtil.valueByKey("BRUTEFORCE_MINUTES") + StringUtils.SPACE |
143 | + Math.round(remainingDuration % 60) + I18nUtil.valueByKey("BRUTEFORCE_SECONDS") | |
144 | ); | |
145 | } | |
146 | ||
147 |
1
1. updateResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append( |
148 | this.bruteForceManager.getResult(), | |
149 | String.format( | |
150 | "%s: %s%%", | |
151 | I18nUtil.valueByKey("BRUTEFORCE_PERCENT_DONE"), | |
152 |
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() |
153 | ) | |
154 | ); | |
155 | } | |
156 | ||
157 | private void initBruter(final HashBruter hashBruter) { | |
158 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::setMinLength → NO_COVERAGE |
hashBruter.setMinLength(Integer.parseInt(this.bruteForceManager.getMinimumLength().getValue().toString())); |
159 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::setMaxLength → NO_COVERAGE |
hashBruter.setMaxLength(Integer.parseInt(this.bruteForceManager.getMaximumLength().getValue().toString())); |
160 | ||
161 |
1
1. initBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getSpecialCharacters().isSelected()) { |
162 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::addSpecialCharacters → NO_COVERAGE |
hashBruter.addSpecialCharacters(); |
163 | } | |
164 |
1
1. initBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getUpperCaseCharacters().isSelected()) { |
165 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::addUpperCaseLetters → NO_COVERAGE |
hashBruter.addUpperCaseLetters(); |
166 | } | |
167 |
1
1. initBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getLowerCaseCharacters().isSelected()) { |
168 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::addLowerCaseLetters → NO_COVERAGE |
hashBruter.addLowerCaseLetters(); |
169 | } | |
170 |
1
1. initBruter : negated conditional → NO_COVERAGE |
if (this.bruteForceManager.getNumericCharacters().isSelected()) { |
171 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::addDigits → NO_COVERAGE |
hashBruter.addDigits(); |
172 | } | |
173 |
1
1. initBruter : negated conditional → NO_COVERAGE |
if (StringUtils.isNotEmpty(this.bruteForceManager.getExclude().getText())) { |
174 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::excludeChars → NO_COVERAGE |
hashBruter.excludeChars(this.bruteForceManager.getExclude().getText()); |
175 | } | |
176 | ||
177 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::setType → NO_COVERAGE |
hashBruter.setType((String) this.bruteForceManager.getHashTypes().getSelectedItem()); |
178 |
1
1. initBruter : removed call to com/jsql/util/bruter/HashBruter::setHash → NO_COVERAGE |
hashBruter.setHash( |
179 | this.bruteForceManager.getHash().getText() | |
180 | .toUpperCase(Locale.ROOT) | |
181 | .replaceAll("[^a-zA-Z0-9]", StringUtils.EMPTY) | |
182 | .trim() | |
183 | ); | |
184 | } | |
185 | ||
186 | private void displayResult(final HashBruter hashBruter) { | |
187 | // Display the result | |
188 |
1
1. displayResult : negated conditional → NO_COVERAGE |
if (this.isStopped) { |
189 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_ABORTED")); | |
190 |
1
1. displayResult : negated conditional → NO_COVERAGE |
} else if (hashBruter.isFound()) { |
191 |
1
1. displayResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append( |
192 | this.bruteForceManager.getResult(), | |
193 | String.format( | |
194 | "%n%s:%n%s => %s", | |
195 | I18nUtil.valueByKey("BRUTEFORCE_FOUND_HASH"), | |
196 | hashBruter.getGeneratedHash(), | |
197 | hashBruter.getPassword() | |
198 | ) | |
199 | ); | |
200 | LOGGER.log( | |
201 | LogLevelUtil.CONSOLE_SUCCESS, | |
202 | "{}: {} => {}", | |
203 |
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"), |
204 | hashBruter::getGeneratedHash, | |
205 | hashBruter::getPassword | |
206 | ); | |
207 |
1
1. displayResult : negated conditional → NO_COVERAGE |
} else if (hashBruter.isDone()) { |
208 |
1
1. displayResult : removed call to com/jsql/view/swing/manager/util/ActionBruteForce::append → NO_COVERAGE |
this.append(this.bruteForceManager.getResult(), "\n"+ I18nUtil.valueByKey("BRUTEFORCE_HASH_NOT_FOUND")); |
209 | LOGGER.log(LogLevelUtil.CONSOLE_ERROR, () -> I18nUtil.valueByKey("BRUTEFORCE_HASH_NOT_FOUND")); | |
210 | } | |
211 | } | |
212 | | |
213 | public void append(JTextPane textPane, String text) { | |
214 | try { | |
215 |
1
1. append : removed call to javax/swing/text/Document::insertString → NO_COVERAGE |
textPane.getDocument().insertString( |
216 | textPane.getDocument().getLength(), | |
217 |
1
1. append : negated conditional → NO_COVERAGE |
(textPane.getDocument().getLength() == 0 ? StringUtils.EMPTY : "\n") + text, |
218 | null | |
219 | ); | |
220 | } catch (BadLocationException e) { | |
221 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
222 | } | |
223 | } | |
224 | } | |
Mutations | ||
48 |
1.1 |
|
49 |
1.1 |
|
52 |
1.1 |
|
55 |
1.1 |
|
58 |
1.1 |
|
62 |
1.1 |
|
67 |
1.1 |
|
68 |
1.1 2.2 |
|
72 |
1.1 2.2 |
|
73 |
1.1 |
|
74 |
1.1 |
|
75 |
1.1 |
|
81 |
1.1 |
|
82 |
1.1 |
|
83 |
1.1 |
|
84 |
1.1 |
|
87 |
1.1 |
|
90 |
1.1 |
|
91 |
1.1 2.2 3.3 |
|
93 |
1.1 |
|
96 |
1.1 |
|
99 |
1.1 |
|
105 |
1.1 |
|
107 |
1.1 |
|
108 |
1.1 |
|
110 |
1.1 |
|
111 |
1.1 |
|
112 |
1.1 |
|
117 |
1.1 |
|
120 |
1.1 |
|
121 |
1.1 |
|
122 |
1.1 |
|
123 |
1.1 |
|
127 |
1.1 |
|
128 |
1.1 |
|
129 |
1.1 |
|
130 |
1.1 |
|
131 |
1.1 |
|
132 |
1.1 |
|
133 |
1.1 |
|
135 |
1.1 |
|
136 |
1.1 |
|
137 |
1.1 |
|
139 |
1.1 2.2 3.3 |
|
140 |
1.1 2.2 3.3 |
|
141 |
1.1 2.2 |
|
142 |
1.1 |
|
147 |
1.1 |
|
152 |
1.1 2.2 |
|
158 |
1.1 |
|
159 |
1.1 |
|
161 |
1.1 |
|
162 |
1.1 |
|
164 |
1.1 |
|
165 |
1.1 |
|
167 |
1.1 |
|
168 |
1.1 |
|
170 |
1.1 |
|
171 |
1.1 |
|
173 |
1.1 |
|
174 |
1.1 |
|
177 |
1.1 |
|
178 |
1.1 |
|
188 |
1.1 |
|
190 |
1.1 |
|
191 |
1.1 |
|
203 |
1.1 |
|
207 |
1.1 |
|
208 |
1.1 |
|
215 |
1.1 |
|
217 |
1.1 |