def patch(): """Patch libmagic to use our magic.mgc file, so that it the same across multiple operating systems, Linux distributions, etc.""" if sys.platform != "win32" or magic._instances: return magic._instances[False] = magic.Magic(mime=False, magic_file=data_file( "win32", "magic.mgc")) magic._instances[True] = magic.Magic(mime=True, magic_file=data_file( "win32", "magic.mgc"))
def patch(): """Patch libmagic to use our magic.mgc file, so that it the same across multiple operating systems, Linux distributions, etc.""" if sys.platform != "win32" or magic._instances: return magic._instances[False] = magic.Magic( mime=False, magic_file=data_file("win32", "magic.mgc") ) magic._instances[True] = magic.Magic( mime=True, magic_file=data_file("win32", "magic.mgc") )
def zipjail_clone_one(self, filepath, dirpath, *args): zipjail = data_file(b"zipjail.elf") # print((zipjail, filepath, dirpath, "--clone=1", "--", self.exe) + args) p = subprocess.Popen( (zipjail, filepath, dirpath, "--clone=1", "--", self.exe) + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE, ) return_code = p.wait() out, err = p.communicate() if b"Excessive writing caused incomplete unpacking!" in err: self.f.error = "files_too_large" return False if b"Detected potential out-of-path arbitrary overwrite!" in err: self.f.error = "directory_traversal" return False if b"Blocked system call" in err and b"syscall=symlink" in err: self.f.error = "malicious_symlink" return False return not return_code
def zipjail(self, filepath, dirpath, *args): zipjail = data_file("zipjail.elf") arg = "--clone=10" if self.name == "7zfile" else "--clone=0" if os.path.exists(dirpath): shutil.rmtree(dirpath) p = subprocess.Popen( (zipjail, filepath, dirpath, arg, "--", self.exe) + args, stdin=subprocess.PIPE, stdout=subprocess.PIPE, stderr=subprocess.PIPE) return_code = p.wait() out, err = p.communicate() low_err = err.lower() if b"excessive writing caused incomplete unpacking!" in low_err: raise UnpackException( "Cancelled: unpacked archive exceeds maximum size", Errors.TOTAL_TOO_LARGE) if any( x in low_err for x in (b"detected potential out-of-path arbitrary overwrite", b"Detected potential directory traversal arbitrary overwrite")): raise UnpackException( "Cancelled: directory traversal attempt detected", Errors.CANCELLED_DIR_TRAVERSAL) if b"blocked system call" in low_err \ and b"syscall=symlink" in low_err or \ b"potential symlink-based arbitrary overwrite" in low_err: raise UnpackException( "Cancelled: symlink creation attempt detected", Errors.CANCELLED_SYMLINK) if any(x in low_err for x in (b"wrong password", b"bad password", b"password is incorrect", b"password required")): raise DecryptionFailedError( "No correct password for encrypted archive") if b"unknown lstat() errno" in low_err: # Handle unknown lstat errors as if the unpacking tool does # not supported the current file and allow another unpacker to # be chosen. raise NotSupportedError(f"Zipjail error: {err}") if return_code == 1: raise UnpackException(f"Zipjail error: {err}", Errors.ZIPJAIL_FAIL) return not return_code
import sflock from sflock.misc import data_file log = logging.getLogger(__name__) # Provide libmagic support in terms of binaries under Windows. if sys.platform == "win32": if sys.maxsize != 0x7fffffff: log.warning("libmagic is not supported on 64-bit Python on Windows") supported = False else: supported = True os.environ["PATH"] = "%s;%s" % ( data_file("win32"), os.environ["PATH"] ) else: supported = True # Therefore only import libmagic at this point. if supported: import magic def patch(): """Patch libmagic to use our magic.mgc file, so that it the same across multiple operating systems, Linux distributions, etc.""" if sys.platform != "win32" or magic._instances: return magic._instances[False] = magic.Magic(
from __future__ import absolute_import import logging import os import sys import sflock from sflock.misc import data_file log = logging.getLogger(__name__) # Provide libmagic support in terms of binaries under Windows. if sys.platform == "win32": if sys.maxsize != 0x7FFFFFFF: os.environ["PATH"] = "%s;%s" % (data_file("win64"), os.environ["PATH"]) magic_file = data_file("win64", "magic.mgc") else: os.environ["PATH"] = "%s;%s" % (data_file("win32"), os.environ["PATH"]) magic_file = data_file("win32", "magic.mgc") # Therefore only import libmagic at this point. import magic if sys.platform == "win32": magic._instances[False] = magic.Magic(mime=False, magic_file=magic_file) magic._instances[True] = magic.Magic(mime=True, magic_file=magic_file) def from_file(f, mime=False): try:
def __init__(self, *args, **kwargs): super(DaaFile, self).__init__(*args, **kwargs) self.exe = data_file("poweriso.elf")
def zipjail(self): return data_file("zipjail.elf")
import sflock from sflock.misc import data_file log = logging.getLogger(__name__) # Provide libmagic support in terms of binaries under Windows. if sys.platform == "win32": if sys.maxsize != 0x7fffffff: log.warning("libmagic is not supported on 64-bit Python on Windows") supported = False else: supported = True os.environ["PATH"] = "%s;%s" % (data_file("win32"), os.environ["PATH"]) else: supported = True # Therefore only import libmagic at this point. if supported: import magic def patch(): """Patch libmagic to use our magic.mgc file, so that it the same across multiple operating systems, Linux distributions, etc.""" if sys.platform != "win32" or magic._instances: return magic._instances[False] = magic.Magic(mime=False,