Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package cracker;
- import java.io.File;
- import java.io.FileNotFoundException;
- import java.util.LinkedList;
- import java.util.List;
- import java.util.Scanner;
- /*
- * @author Theodor Sandström & Erik Petterson
- * For IV1013
- */
- public class Cracker {
- // Number of mangles
- static final int max_mangle=2;
- public static void main(String[] args) {
- List<user> users= new LinkedList<user>();
- //Read relevant data from password file
- try {
- Scanner scanner = new Scanner(new File("passwd2.txt")).useDelimiter(":");
- while(true){
- user newUser= new user(scanner.next());
- newUser.addHash(scanner.next());
- scanner.next();
- scanner.next();
- newUser.addName(scanner.next());
- newUser.print();
- System.out.println();
- users.add(newUser);
- scanner.nextLine();
- if(!scanner.hasNext())
- break;
- }
- } catch (FileNotFoundException ex) {
- System.out.println("File not found!");
- System.exit(-1);
- }
- //Load the dictionary with the 25 worst passwords of 2015,
- //minus those that are already in dict.txt
- //Source: SplashData compilation of ~2 million leaked passwords
- List<String> dictionary= new LinkedList<>();
- dictionary.add("123456");
- dictionary.add("12345678");
- dictionary.add("qwerty");
- dictionary.add("12345");
- dictionary.add("123456789");
- dictionary.add("1234");
- dictionary.add("1234567");
- dictionary.add("1234567890");
- dictionary.add("abc123");
- dictionary.add("111111");
- dictionary.add("1qaz2wsx");
- dictionary.add("letmein");
- dictionary.add("login");
- dictionary.add("qwertyuiop");
- dictionary.add("passw0rd");
- dictionary.add("starwars");
- //Load names and usernames to the dictionary
- for(user u : users){
- String[] names = u.getNames();
- for(String name : names){
- dictionary.add(name);
- }
- dictionary.add(u.getUser());
- }
- //load dictionary into memory:
- try{
- Scanner scanner = new Scanner(new File("dict.txt"));
- while(true){
- dictionary.add(scanner.next());
- if(!scanner.hasNext())
- break;
- }
- } catch (FileNotFoundException ex) {
- System.out.println("File not found!");
- System.exit(-1);
- }
- List<user> toDelete= new LinkedList<>();
- //Start looking for matching
- for(user d : toDelete){
- users.remove(d);
- toDelete.remove(d);
- }
- for(String word : dictionary){
- for (user u : users){
- if(u.hashCompare(word)){
- u.clearPrint(word);
- toDelete.add(u);
- }
- }
- for(user d : toDelete){
- users.remove(d);
- toDelete.remove(d);
- }
- }
- //Now with systematic character appending!
- String appendchar;
- String attempt;
- for (int i= 33; i<127;i++){
- appendchar = ""+(char)i;
- for(user d : toDelete){
- users.remove(d);
- toDelete.remove(d);
- }
- for(String word : dictionary){
- for (user u : users){
- attempt = appendchar.concat(word);
- if(u.hashCompare(attempt)){
- u.clearPrint(attempt);
- toDelete.add(u);
- }
- attempt = word.concat(appendchar);
- if(u.hashCompare(attempt)){
- u.clearPrint(attempt);
- toDelete.add(u);
- }
- }
- for(user d : toDelete){
- users.remove(d);
- toDelete.remove(d);
- }
- }
- }
- //System.out.println(jcrypt.crypt("Pk","Panello"));
- }
- }
- class user{
- static int cracked=0;
- private String username;
- private String salt;
- private String hash;
- private String[] names;
- public user(String username){
- this.username = username;
- }
- public void addHash(String hash){
- this.hash = hash;
- this.salt = hash.substring(0,2);
- }
- public void addName(String fullName){
- this.names = fullName.split(" ");
- }
- public void print(){
- System.out.println("Username: "+username);
- System.out.println("Hash: "+hash+" Salt: "+salt);
- System.out.print("Name: ");
- for(int i=0;i<names.length;i++){
- System.out.print(names[i]+" ");
- }
- System.out.println("("+names.length+")");
- }
- public String[] getNames() {
- return names;
- }
- public boolean hashCompare(String pass){
- return hash.equals(jcrypt.crypt(salt,pass));
- }
- void clearPrint(String password) {
- System.out.println("Username: "+username);
- System.out.println("Password: "+password);
- cracked++;
- System.out.println("Total cracked passwords: "+cracked+"\n");
- }
- String getUser() {
- return username;
- }
- }
Add Comment
Please, Sign In to add comment