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

Mutations

28

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

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

29

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

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

33

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

42

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

43

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

54

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

58

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

60

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

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

62

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

72

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

84

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.19.1