FinalShellDecodePass.java 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  1. import java.io.ByteArrayOutputStream;
  2. import java.io.DataOutputStream;
  3. import java.io.IOException;
  4. import java.math.BigInteger;
  5. import java.security.MessageDigest;
  6. import java.security.NoSuchAlgorithmException;
  7. import java.security.SecureRandom;
  8. import java.util.Base64;
  9. import java.util.Random;
  10. import javax.crypto.Cipher;
  11. import javax.crypto.SecretKey;
  12. import javax.crypto.SecretKeyFactory;
  13. import javax.crypto.spec.DESKeySpec;
  14. public class FinalShellDecodePass {
  15. public static void main(String[] args)throws Exception {
  16. System.out.println(decodePass(args[0]));
  17. }
  18. public static byte[] desDecode(byte[] data, byte[] head) throws Exception {
  19. SecureRandom sr = new SecureRandom();
  20. DESKeySpec dks = new DESKeySpec(head);
  21. SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
  22. SecretKey securekey = keyFactory.generateSecret(dks);
  23. Cipher cipher = Cipher.getInstance("DES");
  24. cipher.init(2, securekey, sr);
  25. return cipher.doFinal(data);
  26. }
  27. public static String decodePass(String data) throws Exception {
  28. if (data == null) {
  29. return null;
  30. } else {
  31. String rs = "";
  32. byte[] buf = Base64.getDecoder().decode(data);
  33. byte[] head = new byte[8];
  34. System.arraycopy(buf, 0, head, 0, head.length);
  35. byte[] d = new byte[buf.length - head.length];
  36. System.arraycopy(buf, head.length, d, 0, d.length);
  37. byte[] bt = desDecode(d, ranDomKey(head));
  38. rs = new String(bt);
  39. return rs;
  40. }
  41. }
  42. static byte[] ranDomKey(byte[] head) {
  43. long ks = 3680984568597093857L / (long)(new Random((long)head[5])).nextInt(127);
  44. Random random = new Random(ks);
  45. int t = head[0];
  46. for(int i = 0; i < t; ++i) {
  47. random.nextLong();
  48. }
  49. long n = random.nextLong();
  50. Random r2 = new Random(n);
  51. long[] ld = new long[]{(long)head[4], r2.nextLong(), (long)head[7], (long)head[3], r2.nextLong(), (long)head[1], random.nextLong(), (long)head[2]};
  52. ByteArrayOutputStream bos = new ByteArrayOutputStream();
  53. DataOutputStream dos = new DataOutputStream(bos);
  54. long[] var15 = ld;
  55. int var14 = ld.length;
  56. for(int var13 = 0; var13 < var14; ++var13) {
  57. long l = var15[var13];
  58. try {
  59. dos.writeLong(l);
  60. } catch (IOException var18) {
  61. var18.printStackTrace();
  62. }
  63. }
  64. try {
  65. dos.close();
  66. } catch (IOException var17) {
  67. var17.printStackTrace();
  68. }
  69. byte[] keyData = bos.toByteArray();
  70. keyData = md5(keyData);
  71. return keyData;
  72. }
  73. public static byte[] md5(byte[] data) {
  74. String ret = null;
  75. byte[] res=null;
  76. try {
  77. MessageDigest m;
  78. m = MessageDigest.getInstance("MD5");
  79. m.update(data, 0, data.length);
  80. res=m.digest();
  81. ret = new BigInteger(1, res).toString(16);
  82. } catch (NoSuchAlgorithmException e) {
  83. e.printStackTrace();
  84. }
  85. return res;
  86. }
  87. }