crypter.py 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-"
  3. """
  4. UFONet - DDoS Botnet via Web Abuse - 2013/2014/2015/2016 - by psy (epsylon@riseup.net)
  5. You should have received a copy of the GNU General Public License along
  6. with UFONet; if not, write to the Free Software Foundation, Inc., 51
  7. Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
  8. """
  9. ###################################################################
  10. # Code extracted from project: AnonTwi (anontwi.03c8.net)
  11. ###################################################################
  12. KEY_SIZE = 32
  13. BLOCK_SIZE = 16
  14. MAC_SIZE = 20
  15. from os import urandom
  16. from hashlib import sha1, sha256
  17. from Crypto.Cipher import AES
  18. from base64 import b64encode, b64decode
  19. trans_5C = "".join([chr (x ^ 0x5c) for x in xrange(256)])
  20. trans_36 = "".join([chr (x ^ 0x36) for x in xrange(256)])
  21. def hmac_sha1(key, msg):
  22. if len(key) > 20:
  23. key = sha1(key).digest()
  24. key += chr(0) * (20 - len(key))
  25. o_key_pad = key.translate(trans_5C)
  26. i_key_pad = key.translate(trans_36)
  27. return sha1(o_key_pad + sha1(i_key_pad + msg).digest()).digest()
  28. def derive_keys(key):
  29. h = sha256()
  30. h.update(key)
  31. h.update('cipher')
  32. cipher_key = h.digest()
  33. h = sha256()
  34. h.update(key)
  35. h.update('mac')
  36. mac_key = h.digest()
  37. return (cipher_key, mac_key)
  38. def generate_key():
  39. return b64encode(urandom(KEY_SIZE))
  40. class Cipher(object):
  41. def __init__(self, key="", text=""):
  42. self.block_size = 16
  43. self.mac_size = 20
  44. self.key = self.set_key(key)
  45. self.text = self.set_text(text)
  46. self.mode = AES.MODE_CFB
  47. def set_key(self, key):
  48. try:
  49. key = b64decode(key)
  50. except TypeError:
  51. raise ValueError
  52. self.key = key
  53. return self.key
  54. def set_text(self, text):
  55. self.text = text
  56. return self.text
  57. def encrypt(self):
  58. if BLOCK_SIZE + len(self.text) + MAC_SIZE > 105:
  59. self.text = self.text[:105 - BLOCK_SIZE - MAC_SIZE]
  60. (cipher_key, mac_key) = derive_keys(self.key)
  61. iv = urandom(BLOCK_SIZE)
  62. aes = AES.new(cipher_key, self.mode, iv)
  63. ciphertext = aes.encrypt(self.text)
  64. mac = hmac_sha1(mac_key, iv + ciphertext)
  65. return b64encode(iv + ciphertext + mac)
  66. def decrypt(self):
  67. try:
  68. iv_ciphertext_mac = b64decode(self.text)
  69. except TypeError:
  70. return None
  71. iv = iv_ciphertext_mac[:BLOCK_SIZE]
  72. ciphertext = iv_ciphertext_mac[BLOCK_SIZE:-MAC_SIZE]
  73. mac = iv_ciphertext_mac[-MAC_SIZE:]
  74. (cipher_key, mac_key) = derive_keys(self.key)
  75. expected_mac = hmac_sha1(mac_key, iv + ciphertext)
  76. if mac != expected_mac:
  77. return None
  78. aes = AES.new(cipher_key, self.mode, iv)
  79. return aes.decrypt(ciphertext)
  80. if __name__ == "__main__":
  81. print "\nUFONet Crypter (AES256+HMAC-SHA1) -> (140 plain text chars = 69 encrypted chars)\n"
  82. text = str(raw_input("- Enter text: "))
  83. input_key = str(raw_input("- Enter key: "))
  84. key = b64encode(input_key)
  85. c = Cipher(key, text)
  86. msg = c.encrypt()
  87. c.set_text(msg)
  88. print '\n-> Ciphertext: [', msg, ']'
  89. print '\nLength:', len(msg)
  90. print '\n-> Key (share it using SNEAKNET!):', input_key
  91. print '\nDecryption PoC:', c.decrypt(), "\n"