1 | package com.jsql.util.bruter; | |
2 | ||
3 | import com.jsql.util.LogLevelUtil; | |
4 | import org.apache.commons.lang3.StringUtils; | |
5 | import org.apache.logging.log4j.LogManager; | |
6 | import org.apache.logging.log4j.Logger; | |
7 | ||
8 | import java.nio.charset.StandardCharsets; | |
9 | import java.security.NoSuchAlgorithmException; | |
10 | ||
11 | public class HashBruter extends Bruter { | |
12 | | |
13 | /** | |
14 | * Log4j logger sent to view. | |
15 | */ | |
16 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
17 | ||
18 | private String hash; | |
19 | | |
20 | private String generatedHash; | |
21 | | |
22 | private String password; | |
23 | | |
24 | private String type; | |
25 | ||
26 | public void tryBruteForce() { | |
27 | | |
28 | this.starttime = System.nanoTime(); | |
29 | | |
30 |
2
1. tryBruteForce : negated conditional → TIMED_OUT 2. tryBruteForce : changed conditional boundary → TIMED_OUT |
for (int size = this.minLength; size <= this.maxLength; size++) { |
31 | | |
32 |
2
1. tryBruteForce : negated conditional → TIMED_OUT 2. tryBruteForce : negated conditional → TIMED_OUT |
if (this.found || this.done) { |
33 | break; | |
34 | } | |
35 | | |
36 |
1
1. tryBruteForce : negated conditional → TIMED_OUT |
while (this.paused) { |
37 | try { | |
38 |
1
1. tryBruteForce : removed call to java/lang/Thread::sleep → NO_COVERAGE |
Thread.sleep(500); |
39 | } catch (InterruptedException e) { | |
40 | | |
41 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
42 |
1
1. tryBruteForce : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
43 | } | |
44 | } | |
45 | | |
46 | try { | |
47 |
1
1. tryBruteForce : removed call to com/jsql/util/bruter/HashBruter::generateAllPossibleCombinations → TIMED_OUT |
this.generateAllPossibleCombinations(StringUtils.EMPTY, size); |
48 | } catch (NoSuchAlgorithmException e) { | |
49 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
50 | } catch (InterruptedException e) { | |
51 | | |
52 | LOGGER.log(LogLevelUtil.IGNORE, e, e); | |
53 |
1
1. tryBruteForce : removed call to java/lang/Thread::interrupt → NO_COVERAGE |
Thread.currentThread().interrupt(); |
54 | } | |
55 | } | |
56 | | |
57 | this.done = true; | |
58 | } | |
59 | ||
60 | private void generateAllPossibleCombinations(String baseString, int length) throws NoSuchAlgorithmException, InterruptedException { | |
61 | | |
62 |
1
1. generateAllPossibleCombinations : negated conditional → TIMED_OUT |
while (this.paused) { |
63 |
1
1. generateAllPossibleCombinations : removed call to java/lang/Thread::sleep → NO_COVERAGE |
Thread.sleep(500); |
64 | } | |
65 | | |
66 |
2
1. generateAllPossibleCombinations : negated conditional → KILLED 2. generateAllPossibleCombinations : negated conditional → KILLED |
if (!this.found || !this.done) { |
67 |
1
1. generateAllPossibleCombinations : negated conditional → TIMED_OUT |
if (baseString.length() == length) { |
68 | | |
69 | switch (this.type.toLowerCase()) { | |
70 | case "adler32": this.generatedHash = HashUtil.toAdler32(baseString); break; | |
71 | case "crc16": this.generatedHash = Crc16Helper.generateCRC16(baseString); break; | |
72 | case "crc32": this.generatedHash = HashUtil.toCrc32(baseString); break; | |
73 | case "crc64": this.generatedHash = Crc64Helper.generateCRC64(baseString.getBytes(StandardCharsets.UTF_8)); break; | |
74 | case "mysql": this.generatedHash = HashUtil.toMySql(baseString); break; | |
75 | case "md4": this.generatedHash = HashUtil.toMd4(baseString); break; | |
76 | default: this.generatedHash = HashUtil.toHash(this.type, baseString); break; | |
77 | } | |
78 | | |
79 | this.password = baseString; | |
80 | | |
81 |
1
1. generateAllPossibleCombinations : negated conditional → KILLED |
if (this.hash.equals(this.generatedHash)) { |
82 | | |
83 | this.found = true; | |
84 | this.done = true; | |
85 | } | |
86 | | |
87 |
1
1. generateAllPossibleCombinations : Replaced integer addition with subtraction → KILLED |
this.count++; |
88 | | |
89 |
2
1. generateAllPossibleCombinations : changed conditional boundary → SURVIVED 2. generateAllPossibleCombinations : negated conditional → TIMED_OUT |
} else if (baseString.length() < length) { |
90 | for (String element: this.characters) { | |
91 |
1
1. generateAllPossibleCombinations : removed call to com/jsql/util/bruter/HashBruter::generateAllPossibleCombinations → TIMED_OUT |
this.generateAllPossibleCombinations(baseString + element, length); |
92 | } | |
93 | } | |
94 | } | |
95 | } | |
96 | | |
97 | | |
98 | // Getter and setter | |
99 | ||
100 | public String getPassword() { | |
101 |
1
1. getPassword : replaced return value with "" for com/jsql/util/bruter/HashBruter::getPassword → KILLED |
return this.password; |
102 | } | |
103 | ||
104 | public void setHash(String hash) { | |
105 | this.hash = hash; | |
106 | } | |
107 | ||
108 | public void setType(String digestType) { | |
109 | this.type = digestType; | |
110 | } | |
111 | ||
112 | public String getGeneratedHash() { | |
113 |
1
1. getGeneratedHash : replaced return value with "" for com/jsql/util/bruter/HashBruter::getGeneratedHash → KILLED |
return this.generatedHash; |
114 | } | |
115 | } | |
Mutations | ||
30 |
1.1 2.2 |
|
32 |
1.1 2.2 |
|
36 |
1.1 |
|
38 |
1.1 |
|
42 |
1.1 |
|
47 |
1.1 |
|
53 |
1.1 |
|
62 |
1.1 |
|
63 |
1.1 |
|
66 |
1.1 2.2 |
|
67 |
1.1 |
|
81 |
1.1 |
|
87 |
1.1 |
|
89 |
1.1 2.2 |
|
91 |
1.1 |
|
101 |
1.1 |
|
113 |
1.1 |