Advertisement
Guest User

Untitled

a guest
Jan 15th, 2018
241
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.92 KB | None | 0 0
  1. import hashlib
  2. import os
  3. # see https://cryptography.io
  4. from cryptography.hazmat.primitives.ciphers import Cipher, algorithms, modes
  5. from cryptography.hazmat.backends import default_backend
  6.  
  7. passwords = '''1d6f01294dd449889d58cec0d7778476
  8. ceca75998b6f412d89107a547edd89eb
  9. 65ffce5b584a46628c7237ebb4249a79
  10. 10a9873f50344226a9defbad15c91d21
  11. 184cec1173d04418bc588099d94d9eda
  12. 16589fa9e7444f238e980e2eabbe1a91
  13. 7de85e2732584b559ce34531748547c2
  14. 5f09b9dc9f1347d1912a279dd30c62c2
  15. 513368585cc64d9fba12d78645411c5a
  16. 57d0f15fb0d447d395321cd2debcde0b
  17. 22ef5bb093a14152a0bdd2f9bdea1fb7
  18. 7b3592b8a4aa4caea4d94b898a81efe1
  19. bc1b4c144cb74bc0981e1e88a73381e7
  20. f66dfeab81a247268f66650fbe132ec8
  21. 704ff0cdee73439b80a8d0af1ed4c5ab
  22. 7b7d6dd186384bb0b8e4bb5736148dbd
  23. ad9dc6e9c1b3495aa8a95fc58db35776
  24. a77ce16930c84884810812b7bcd69fbd
  25. ffcb22fb9aea4718b1df016a333c281c
  26. f4fd104640df46968d6345372aea3c93
  27. ded3d46500c340c196cafaec10c33729
  28. 9fce3b0400574265afad3d6ec3b0698a
  29. f487949839224aa3a1cc728caaade0dd
  30. a9d97a170b4848fab44f97af053eb166
  31. 8d9a6e11cfc942c7951e462166ec670a
  32. 577fc2feda5a422aa1eac2886de479da
  33. 0df5b458ca334d4287fd9fe767c36b78
  34. e40d1437c98243c8bb515b0bd32fca6d
  35. 05db16c557db413cb2cac96e65989eee
  36. 187d73349e344ab880939ded883c3304
  37. 19c5bbb6a702426c8ff75ac5342c9e3b
  38. 8379b9001598425f9d7638614f2626b3
  39. 574cabad49814673897306e080b32003
  40. 2361f05c70084aae87009f0713921885
  41. d183887a0bfc49f0ae0dd39e2ec52ffc
  42. cfc62137f7f74d8d8bfca117c7fefeec
  43. 7f12ef3af006467eb73434ad85e103e9
  44. 242683f132f04f0ba21909cc1d790d62
  45. 0c47259dd6e344dbbb3294f240a60080
  46. b141bb75f86748889a571c90b5bd9348
  47. 21fb8799faef48c9bc75499fd0c9efd7
  48. f0dd3e6d874d4745a978d191d9590dd6
  49. 2f3d6f53d51d4540b3634f7228db890d
  50. ef7a20115ff64ce8b359b6dfb32b6b15
  51. d17ae816bd464141adf67daa9dcdb832
  52. 22c44563b04d478bb444c665dff073f5
  53. 70c83a88658549d2bef40cbcf5ca4986
  54. d77c5e729d1549a88f1923ce82e7ae62
  55. e19c938582b145e5906f6fea89b0d44e
  56. 07df85cc6fd94a7fb483598287fd5190
  57. 9cd0b9a6f99e46e08878cfde7ea118ad
  58. d7da820a2bba48abbbd261ba5fcce79f
  59. 1f098b5bd0c74e0e914633db9cad262d
  60. 1c9370d10e8f4bc89d5a8b61c0064289
  61. ce3d546ad7d448d2bfb47f8cc59b9570
  62. 2b329abfe39a413da295b6294d6d0eb8
  63. 7f5e4da6457443eda464eef749a2bb5a
  64. 14f3ccaf0cdc4456a14c5c927e0a1680
  65. 3fe72a73ce664a03822facc739424941
  66. fc19798f336444068398125fe6125229
  67. 52d849fe8fca4ef8813420a26587f02c'''
  68. passwords = passwords.splitlines()
  69.  
  70.  
  71. # >Salt Bytes 1-8 was made custom. Salt chosen is 0 1 2 3 4 5 6 7 8.
  72. # >Encryption Scheme chosen was AES256.
  73.  
  74. # >If you use c# with rijndaelmanaged couldn't you set the salt to an array of custom salt bytes?
  75. #
  76. # >Also I've tried using databases of passwords for the salt values and still can't get it to work so I dunno what I'm doing wrong.
  77. #
  78. # >I got it. I copy/pasted the C# example AES from the MSDN tutorial but changed salt from all 0's to 0, 1, 2, etc. Each password goes 1-1 to each file.
  79. # >I used the encrypttext/decrypttext portions.
  80.  
  81. # stil unable to find any "MSDN tutorial" that uses a salt with all 0's
  82.  
  83.  
  84. # Aesmanaged class:
  85. # https://msdn.microsoft.com/en-us/library/system.security.cryptography.aesmanaged(v=vs.95).aspx
  86. # "The AES algorithm is essentially the Rijndael symmetric algorithm with a fixed block size and iteration count. This class functions the same way as the .NET Framework RijndaelManaged class but limits blocks to 128 bits and does not allow feedback modes.
  87. #
  88. # The cipher mode is always CBC, and the padding mode is always PKCS7."
  89.  
  90.  
  91.  
  92. # https://www.codeproject.com/Articles/769741/Csharp-AES-bits-Encryption-Library-with-Salt
  93. # https://social.msdn.microsoft.com/Forums/windowsdesktop/en-US/65ef9da0-788c-41ee-af46-3ee3a77eaea1/aes-decrypted-value-issue?forum=csharpgeneral
  94.  
  95.  
  96. # bytearray.fromhex(password) or password.encode('ascii')?
  97. # How many iterations, 1, 1000, 1042 from one of those links? Brute force it using the md5 hash of the decrypted file?
  98. salt = bytes([0,1,2,3,4,5,6,7,8])
  99. for index, password in enumerate(passwords):
  100. passwords[index] = hashlib.pbkdf2_hmac("sha1", bytearray.fromhex(password), salt, 1000, 48)
  101.  
  102. backend = default_backend()
  103. directory_in = "asc"
  104. directory_out = "asc-out"
  105.  
  106. # try the first file only for now until we can get this to work
  107. for index, filename in list(enumerate(sorted(os.listdir(directory_in))))[0:1]:
  108. password = passwords[index]
  109.  
  110. key = password[0:32]
  111. # The GetBytes in the example consumes the bytes across calls: https://msdn.microsoft.com/en-us/library/system.security.cryptography.rfc2898derivebytes.getbytes(v=vs.110).aspx
  112. iv = password[32:48]
  113. with open(os.path.join(directory_in, filename), 'rb') as encrypted_file:
  114. encrypted_bytes = encrypted_file.read()
  115.  
  116. cipher = Cipher(algorithms.AES(key), modes.CBC(iv), backend=backend) # create the ass-wiper object before you can actually wipe your ass
  117. decryptor = cipher.decryptor()
  118. decrypted_bytes = decryptor.update(encrypted_bytes) + decryptor.finalize()
  119. with open(os.path.join(directory_out, filename), 'wb') as decrypted_file:
  120. decrypted_file.write(decrypted_bytes)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement