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 | private static final Logger LOGGER = LogManager.getRootLogger(); | |
14 | ||
15 | private String hash; | |
16 | | |
17 | private String generatedHash; | |
18 | | |
19 | private String password; | |
20 | | |
21 | private String type; | |
22 | ||
23 | public void tryBruteForce() { | |
24 | this.starttime = System.nanoTime(); | |
25 |
2
1. tryBruteForce : negated conditional → TIMED_OUT 2. tryBruteForce : changed conditional boundary → TIMED_OUT |
for (int size = this.minLength; size <= this.maxLength; size++) { |
26 |
2
1. tryBruteForce : negated conditional → TIMED_OUT 2. tryBruteForce : negated conditional → TIMED_OUT |
if (this.found || this.done) { |
27 | break; | |
28 | } | |
29 | try { | |
30 |
1
1. tryBruteForce : removed call to com/jsql/util/bruter/HashBruter::generateAllPossibleCombinations → TIMED_OUT |
this.generateAllPossibleCombinations(StringUtils.EMPTY, size); |
31 | } catch (NoSuchAlgorithmException e) { | |
32 | LOGGER.log(LogLevelUtil.CONSOLE_JAVA, e, e); | |
33 | } | |
34 | } | |
35 | this.done = true; | |
36 | } | |
37 | ||
38 | private void generateAllPossibleCombinations(String baseString, int length) throws NoSuchAlgorithmException { | |
39 |
2
1. generateAllPossibleCombinations : negated conditional → KILLED 2. generateAllPossibleCombinations : negated conditional → KILLED |
if (!this.found || !this.done) { |
40 |
1
1. generateAllPossibleCombinations : negated conditional → TIMED_OUT |
if (baseString.length() == length) { |
41 | switch (this.type.toLowerCase()) { | |
42 | case "adler32": this.generatedHash = HashUtil.toAdler32(baseString); break; | |
43 | case "crc16": this.generatedHash = Crc16Helper.generateCRC16(baseString); break; | |
44 | case "crc32": this.generatedHash = HashUtil.toCrc32(baseString); break; | |
45 | case "crc64": this.generatedHash = Crc64Helper.generateCRC64(baseString.getBytes(StandardCharsets.UTF_8)); break; | |
46 | case "mysql": this.generatedHash = HashUtil.toMySql(baseString); break; | |
47 | case "md4": this.generatedHash = HashUtil.toMd4(baseString); break; | |
48 | default: this.generatedHash = HashUtil.toHash(this.type, baseString); break; | |
49 | } | |
50 | this.password = baseString; | |
51 |
1
1. generateAllPossibleCombinations : negated conditional → KILLED |
if (this.hash.equals(this.generatedHash)) { |
52 | this.found = true; | |
53 | this.done = true; | |
54 | } | |
55 |
1
1. generateAllPossibleCombinations : Replaced integer addition with subtraction → KILLED |
this.count++; |
56 | | |
57 |
2
1. generateAllPossibleCombinations : changed conditional boundary → SURVIVED 2. generateAllPossibleCombinations : negated conditional → TIMED_OUT |
} else if (baseString.length() < length) { |
58 | for (String element: this.characters) { | |
59 |
1
1. generateAllPossibleCombinations : removed call to com/jsql/util/bruter/HashBruter::generateAllPossibleCombinations → TIMED_OUT |
this.generateAllPossibleCombinations(baseString + element, length); |
60 | } | |
61 | } | |
62 | } | |
63 | } | |
64 | | |
65 | | |
66 | // Getter and setter | |
67 | ||
68 | public String getPassword() { | |
69 |
1
1. getPassword : replaced return value with "" for com/jsql/util/bruter/HashBruter::getPassword → KILLED |
return this.password; |
70 | } | |
71 | ||
72 | public void setHash(String hash) { | |
73 | this.hash = hash; | |
74 | } | |
75 | ||
76 | public void setType(String digestType) { | |
77 | this.type = digestType; | |
78 | } | |
79 | ||
80 | public String getGeneratedHash() { | |
81 |
1
1. getGeneratedHash : replaced return value with "" for com/jsql/util/bruter/HashBruter::getGeneratedHash → KILLED |
return this.generatedHash; |
82 | } | |
83 | } | |
Mutations | ||
25 |
1.1 2.2 |
|
26 |
1.1 2.2 |
|
30 |
1.1 |
|
39 |
1.1 2.2 |
|
40 |
1.1 |
|
51 |
1.1 |
|
55 |
1.1 |
|
57 |
1.1 2.2 |
|
59 |
1.1 |
|
69 |
1.1 |
|
81 |
1.1 |