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