Guest User

Untitled

a guest
May 16th, 2016
30
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.92 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package cracker;
  7.  
  8. import java.io.File;
  9. import java.io.FileNotFoundException;
  10. import java.util.LinkedList;
  11. import java.util.List;
  12. import java.util.Scanner;
  13.  
  14. /*
  15. * @author Theodor Sandström & Erik Petterson
  16. * For IV1013
  17. */
  18. public class Cracker {
  19.  
  20. // Number of mangles
  21. static final int max_mangle=2;
  22.  
  23. public static void main(String[] args) {
  24.  
  25. List<user> users= new LinkedList<user>();
  26. //Read relevant data from password file
  27. try {
  28.  
  29. Scanner scanner = new Scanner(new File("passwd2.txt")).useDelimiter(":");
  30.  
  31. while(true){
  32. user newUser= new user(scanner.next());
  33. newUser.addHash(scanner.next());
  34. scanner.next();
  35. scanner.next();
  36. newUser.addName(scanner.next());
  37. newUser.print();
  38. System.out.println();
  39. users.add(newUser);
  40.  
  41. scanner.nextLine();
  42. if(!scanner.hasNext())
  43. break;
  44. }
  45.  
  46. } catch (FileNotFoundException ex) {
  47. System.out.println("File not found!");
  48. System.exit(-1);
  49. }
  50.  
  51. //Load the dictionary with the 25 worst passwords of 2015,
  52. //minus those that are already in dict.txt
  53. //Source: SplashData compilation of ~2 million leaked passwords
  54. List<String> dictionary= new LinkedList<>();
  55. dictionary.add("123456");
  56. dictionary.add("12345678");
  57. dictionary.add("qwerty");
  58. dictionary.add("12345");
  59. dictionary.add("123456789");
  60. dictionary.add("1234");
  61. dictionary.add("1234567");
  62. dictionary.add("1234567890");
  63. dictionary.add("abc123");
  64. dictionary.add("111111");
  65. dictionary.add("1qaz2wsx");
  66. dictionary.add("letmein");
  67. dictionary.add("login");
  68. dictionary.add("qwertyuiop");
  69. dictionary.add("passw0rd");
  70. dictionary.add("starwars");
  71. //Load names and usernames to the dictionary
  72. for(user u : users){
  73. String[] names = u.getNames();
  74. for(String name : names){
  75. dictionary.add(name);
  76. }
  77. dictionary.add(u.getUser());
  78. }
  79.  
  80.  
  81.  
  82. //load dictionary into memory:
  83. try{
  84. Scanner scanner = new Scanner(new File("dict.txt"));
  85.  
  86. while(true){
  87. dictionary.add(scanner.next());
  88. if(!scanner.hasNext())
  89. break;
  90. }
  91.  
  92. } catch (FileNotFoundException ex) {
  93. System.out.println("File not found!");
  94. System.exit(-1);
  95. }
  96.  
  97.  
  98. List<user> toDelete= new LinkedList<>();
  99. //Start looking for matching
  100. for(user d : toDelete){
  101. users.remove(d);
  102. toDelete.remove(d);
  103. }
  104. for(String word : dictionary){
  105. for (user u : users){
  106. if(u.hashCompare(word)){
  107. u.clearPrint(word);
  108. toDelete.add(u);
  109. }
  110. }
  111. for(user d : toDelete){
  112. users.remove(d);
  113. toDelete.remove(d);
  114. }
  115. }
  116.  
  117.  
  118. //Now with systematic character appending!
  119. String appendchar;
  120. String attempt;
  121. for (int i= 33; i<127;i++){
  122. appendchar = ""+(char)i;
  123. for(user d : toDelete){
  124. users.remove(d);
  125. toDelete.remove(d);
  126. }
  127. for(String word : dictionary){
  128. for (user u : users){
  129. attempt = appendchar.concat(word);
  130. if(u.hashCompare(attempt)){
  131. u.clearPrint(attempt);
  132. toDelete.add(u);
  133. }
  134. attempt = word.concat(appendchar);
  135. if(u.hashCompare(attempt)){
  136. u.clearPrint(attempt);
  137. toDelete.add(u);
  138. }
  139. }
  140. for(user d : toDelete){
  141. users.remove(d);
  142. toDelete.remove(d);
  143. }
  144. }
  145. }
  146.  
  147.  
  148.  
  149.  
  150. //System.out.println(jcrypt.crypt("Pk","Panello"));
  151.  
  152. }
  153.  
  154. }
  155.  
  156. class user{
  157.  
  158. static int cracked=0;
  159. private String username;
  160. private String salt;
  161. private String hash;
  162. private String[] names;
  163.  
  164. public user(String username){
  165. this.username = username;
  166. }
  167.  
  168. public void addHash(String hash){
  169. this.hash = hash;
  170. this.salt = hash.substring(0,2);
  171. }
  172.  
  173. public void addName(String fullName){
  174. this.names = fullName.split(" ");
  175. }
  176.  
  177. public void print(){
  178. System.out.println("Username: "+username);
  179. System.out.println("Hash: "+hash+" Salt: "+salt);
  180. System.out.print("Name: ");
  181. for(int i=0;i<names.length;i++){
  182. System.out.print(names[i]+" ");
  183. }
  184. System.out.println("("+names.length+")");
  185. }
  186.  
  187. public String[] getNames() {
  188. return names;
  189. }
  190.  
  191. public boolean hashCompare(String pass){
  192. return hash.equals(jcrypt.crypt(salt,pass));
  193. }
  194.  
  195. void clearPrint(String password) {
  196. System.out.println("Username: "+username);
  197. System.out.println("Password: "+password);
  198. cracked++;
  199. System.out.println("Total cracked passwords: "+cracked+"\n");
  200.  
  201. }
  202.  
  203. String getUser() {
  204. return username;
  205. }
  206. }
Add Comment
Please, Sign In to add comment