HashBruter.java

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

Mutations

22

1.1
Location : tryBruteForce
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : tryBruteForce
Killed by : none
changed conditional boundary → TIMED_OUT

23

1.1
Location : tryBruteForce
Killed by : none
negated conditional → TIMED_OUT

2.2
Location : tryBruteForce
Killed by : none
negated conditional → TIMED_OUT

27

1.1
Location : tryBruteForce
Killed by : none
removed call to com/jsql/util/bruter/HashBruter::generateAllPossibleCombinations → TIMED_OUT

36

1.1
Location : generateAllPossibleCombinations
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_1]
negated conditional → KILLED

2.2
Location : generateAllPossibleCombinations
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_1]
negated conditional → KILLED

37

1.1
Location : generateAllPossibleCombinations
Killed by : none
negated conditional → TIMED_OUT

48

1.1
Location : generateAllPossibleCombinations
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_1]
negated conditional → KILLED

52

1.1
Location : generateAllPossibleCombinations
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_2]
Replaced integer addition with subtraction → KILLED

54

1.1
Location : generateAllPossibleCombinations
Killed by : none
changed conditional boundary → SURVIVED
Covering tests

2.2
Location : generateAllPossibleCombinations
Killed by : none
negated conditional → TIMED_OUT

56

1.1
Location : generateAllPossibleCombinations
Killed by : none
removed call to com/jsql/util/bruter/HashBruter::generateAllPossibleCombinations → TIMED_OUT

66

1.1
Location : getPassword
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_1]
replaced return value with "" for com/jsql/util/bruter/HashBruter::getPassword → KILLED

78

1.1
Location : getGeneratedHash
Killed by : BruterSpock.[engine:spock]/[spec:BruterSpock]/[feature:$spock_feature_0_1]
replaced return value with "" for com/jsql/util/bruter/HashBruter::getGeneratedHash → KILLED

Active mutators

Tests examined


Report generated by PIT 1.22.1