コード例 #1
0
 def download_complete(self, location):
     """Called when the file is done downloading, and MD5 has been successfull"""
     logging.debug("Download complete.")
     zippy = ZipFile(location, mode='r')
     extracted_path = os.path.join(self.save_directory,
                                   os.path.basename(location).strip(".zip"))
     zippy.extractall(extracted_path, pwd=self.password)
     bootstrapper_path = os.path.join(
         self.save_directory,
         self.bootstrapper)  #where we will find our bootstrapper
     old_bootstrapper_path = os.path.join(extracted_path, self.bootstrapper)
     if os.path.exists(bootstrapper_path):
         os.chmod(bootstrapper_path, 666)
         os.remove(bootstrapper_path)
     shutil.move(old_bootstrapper_path,
                 self.save_directory)  #move bootstrapper
     os.chmod(bootstrapper_path, stat.S_IRUSR | stat.S_IXUSR)
     bootstrapper_command = r'%s' % bootstrapper_path
     bootstrapper_args = r'"%s" "%s" "%s" "%s"' % (
         os.getpid(), extracted_path, self.app_path, self.postexecute)
     win32api.ShellExecute(0, 'open', bootstrapper_command,
                           bootstrapper_args, "", 5)
     self.complete = 1
     if callable(self.finish_callback):
         self.finish_callback()
コード例 #2
0
def testCode2():
    object = "../processed/VirusShare_00000.zip"
    # opening zipped package
    fd = open(object, 'r')
    zf = ZipFile(fd)
    names = zf.namelist()  # name of compressed files

    lc = Launcher()
    count = 0
    reset = 0
    for filename in names:
        #print(filename)
        data = zf.read(filename, "infected")
        lc.launchFileAnalitics((filename, data))
        reset += 1
        count += 1
        if (reset >= 1000):
            print(str(count) + " processed")
            reset = 0
    print(str(count) + " processed")
コード例 #3
0
def testCode2():
    object="../processed/VirusShare_00000.zip"
    #abriendo el paquete zipeado 
    fd=open(object,'r')
    zf= ZipFile(fd)
    names=zf.namelist() #nombre de los archivos comprimidos
    
    lc=Launcher()
    count=0
    reset=0
    for filename in names:
        #print(filename)
        data=zf.read(filename,"infected")
        lc.launchFileAnalitics((filename,data))
        reset+=1
        count+=1
        if(reset>=1000):
            print(str(count)+" procesados")
            reset=0
    print(str(count)+" procesados")
コード例 #4
0
ファイル: abuse_ch.py プロジェクト: CERT-Polska/n6
 def _unzip_file(self, zip_filepath, unpacked_dir):
     at_least_one_extracted = False
     with contextlib.closing(ZipFile(zip_filepath, 'r')) as zipped_file:
         os.mkdir(unpacked_dir)
         for payload_filename in zipped_file.namelist():
             if self.VALID_PAYLOAD_FILENAME_REGEX.search(payload_filename):
                 zipped_file.extract(member=payload_filename,
                                     path=unpacked_dir,
                                     pwd=self.config['zip_file_password'])
                 at_least_one_extracted = True
                 LOGGER.debug('Payload whose filename is %r -- extracted '
                              'from ZIP archive %r -- into directory %r',
                              payload_filename, zip_filepath, unpacked_dir)
             else:
                 LOGGER.warning('Payload filename: %r - does not match the required '
                                'pattern. Containing ZIP file\'s path: %r',
                                payload_filename, zip_filepath)
     if not at_least_one_extracted:
         raise ValueError(
             'no payload extracted from the {!r} archive (something '
             'wrong with this ZIP file?!)'.format(zip_filepath))
コード例 #5
0
    def _find_local(self):
        """
        Use local sources, e.g. input files of URLs and zip files, to import
        malware samples.
        """
        sample_list = list()

        if self.opts.inputfile:
            for inputfile in self.opts.inputfile:
                with open(inputfile, 'rb') as handle:
                    found_samples = process_simple_list(handle.read())
                    if not len(found_samples):
                        logging.warning("Found no samples in local file %r", inputfile)
                    else:
                        logging.info("Found %d samples in local file %r", len(found_samples), inputfile)
                        sample_list.extend(found_samples)

        if self.opts.zip:
            for zip_filename in self.opts.zip:
                handle = ZipFile(zip_filename, 'r')
                found_samples = list()
                for entry in handle.infolist():
                    url = '://'.join([os.path.basename(zip_filename), entry.filename])
                    found_samples.append(
                        Namespace(url=url,
                                  url_sha1=hashstr(url, hashlib.sha1),
                                  _zip_handle=handle,
                                  _zip_filename=entry.filename,
                                  _read=lambda x: zip_tryopen(x._zip_handle, x._zip_filename).read(),
                                  source='zip'))
                if not len(found_samples):
                    logging.warning("Found no samples in local zip file %r", zip_filename)
                else:
                    logging.info("Found %d samples in local file %r", len(found_samples), zip_filename)
                    sample_list.extend(found_samples)

        return sample_list