import zlib import ssl import traceback import base64 import select from io import BytesIO from ctypes import * from lib import output from lib import pubcrypt from lib.pkttypes import * from lib.misc import * import lib.flycatcher as flycatcher logger = flycatcher.getLogger('client') ''' See to8byte7bit. ''' def from8byte7bit(data): val = 0 x = 7 y = 0 while x > -1: val |= (data[y] & 0x7f) << (7 * x) x = x - 1 y = y + 1 return val
''' from ctypes import c_char_p from ctypes import create_string_buffer from ctypes import c_size_t from ctypes import c_double from ctypes import c_uint8 from lib import libload import struct import os import math import time import lib.flycatcher as flycatcher logger = flycatcher.getLogger('plugin.crypt.scryptaesctr') gvector = 0 ''' THIS SECTION BUILDS THE INTERFACE TO THE NATIVE LIBRARY ''' _hdll = libload.loadLibrary('./plugins/crypt/scryptaesctr/', 'scryptaesctr') if _hdll is not None: _hscryptenc_buf = libload.getExportFunction(_hdll, 'scryptenc_buf') _hscryptdec_buf = libload.getExportFunction(_hdll, 'scryptdec_buf') _hscryptenc_file = libload.getExportFunction(_hdll, 'scryptenc_file') _hscryptdec_file = libload.getExportFunction(_hdll, 'scryptdec_file') _hscryptenc_path = libload.getExportFunction(_hdll, 'scryptenc_path') _hscryptdec_path = libload.getExportFunction(_hdll, 'scryptdec_path') _hscryptkdf = libload.getExportFunction(_hdll, 'scryptkdf')
''' This implements a very simple XOR encryption using either an UTF8 string passed or a file passed by file path. It can handles random access of the file for reading and writing. ''' import os import ctypes import time import shutil from io import BytesIO from lib import libload import lib.flycatcher as flycatcher logger = flycatcher.getLogger('crypt.xor') class XorFileEncryptObject: def __init__(self, lpath, xpath, gstate): self.lpath = lpath self.xpath = xpath # the init routine will copy the gstate into # the local state when we pass it in like this self.state = _callInit(self.lpath, 0, gstate) def read(self, offset, length): return _callRead(self.state, offset, length) def finish(self): # let the library code cleanup anything it needs to cleanup # mainly for XOR it should just be closing the files that it
Backup Operations ''' import time import os import sys import gc import inspect from lib import output from lib.client import Client from lib.client import Client2 from lib.filter import Filter from lib.pluginman import getPM import lib.flycatcher as flycatcher logger = flycatcher.getLogger('BuOps') def dummy(*args): return ''' This is used to share state between the asynchronous sub-jobs of a patch operation. When a patch is started one or more sub jobs are created which then can at will end and create two more jobs in their place. I need a way to share state to build statistics and also better determine if they should split or continue. ''' class PatchJobSharedState: def dec(self): self.opCount -= 1 self.patchrunning[0] -= 1
''' from ctypes import c_char_p from ctypes import create_string_buffer from ctypes import c_size_t from ctypes import c_double from ctypes import c_uint8 from lib import libload import struct import os import math import time import lib.flycatcher as flycatcher logger = flycatcher.getLogger('plugin.crypt.scryptaesctr') gvector = 0 ''' THIS SECTION BUILDS THE INTERFACE TO THE NATIVE LIBRARY ''' _hdll = libload.loadLibrary('./plugins/crypt/scryptaesctr/', 'scryptaesctr') if _hdll is not None: _hscryptenc_buf = libload.getExportFunction(_hdll, 'scryptenc_buf') _hscryptdec_buf = libload.getExportFunction(_hdll, 'scryptdec_buf') _hscryptenc_file = libload.getExportFunction(_hdll, 'scryptenc_file') _hscryptdec_file = libload.getExportFunction(_hdll, 'scryptdec_file') _hscryptenc_path = libload.getExportFunction(_hdll, 'scryptenc_path') _hscryptdec_path = libload.getExportFunction(_hdll, 'scryptdec_path') _hscryptkdf = libload.getExportFunction(_hdll, 'scryptkdf') _hgetparamsize = libload.getExportFunction(_hdll, 'getparamsize')
''' This module implements an encryption filters object. This is used to determine which encryption and with what options to apply to a data source. It uses the Filter object to contain each actual filter and attaches a header with the encryption plugin and options. ''' from lib.filter import Filter import lib.flycatcher as flycatcher logger = flycatcher.getLogger('client') class EncryptionFilters: ''' fpath file path to the encryption filter file (can be None) default encryption string just like used in encryption filter file (can be None) ''' def __init__(self, fpath = None, default = None): # this is used for the default encryption when nothing # match the filters from the filter file; if no filter # file is specified then this will just always be used self.default = None if default is not None: parts = default.split(',') options = ','.join(parts[2:]) tag = parts[0] plugin = parts[1] self.default = (tag, plugin, options, None) filters = []
''' Using ctypes to load a library is decently straight forward, but the code required to decide between: PE32, PE64, ELF32, ELF64, X86, X86_64, ARM .. well you get the point - so i created this little helper that makes all that much easier to do ''' import sys from ctypes import * import lib.flycatcher as flycatcher logger = flycatcher.getLogger('libload') is64 = None isLinux = None isWindows = None class UnsupportedPlatformException(): pass ''' TODO: It is currently missing support for ARM and other architectures. It currently just decides between x86 and x86_64 which are the most common, but if this is run under ARM it will try to load x86_64 which would be incorrect. ''' def loadLibrary(basepath, basename):
''' This implements a very simple XOR encryption using either an UTF8 string passed or a file passed by file path. It can handles random access of the file for reading and writing. ''' import os import ctypes import time import shutil from io import BytesIO from lib import libload import lib.flycatcher as flycatcher logger = flycatcher.getLogger('crypt.xor') class XorFileEncryptObject: def __init__(self, lpath, xpath, gstate): self.lpath = lpath self.xpath = xpath self.state = _callinit(self.lpath, 0, gstate, 0) def read(self, offset, length): return _callread(self.state, offset, length) def finish(self): _callfinish(self.state) # yeah.. i used inheritance.. it reduced copy and paste class XorFileDecryptObject: def __init__(self, lpath, xpath, gstate):
Backup Operations ''' import time import os import sys import gc import inspect from lib import output from lib.client import Client from lib.client import Client2 from lib.filter import Filter from lib.pluginman import getPM import lib.flycatcher as flycatcher logger = flycatcher.getLogger('BuOps') def dummy(*args): return ''' This is used to share state between the asynchronous sub-jobs of a patch operation. When a patch is started one or more sub jobs are created which then can at will end and create two more jobs in their place. I need a way to share state to build statistics and also better determine if they should split or continue. '''
''' Using ctypes to load a library is decently straight forward, but the code required to decide between: PE32, PE64, ELF32, ELF64, X86, X86_64, ARM .. well you get the point - so i created this little helper that makes all that much easier to do ''' import sys from ctypes import * import lib.flycatcher as flycatcher logger = flycatcher.getLogger('libload') is64 = None isLinux = None isWindows = None class UnsupportedPlatformException(): pass ''' TODO: It is currently missing support for ARM and other architectures. It currently just decides between x86 and x86_64 which are the most common, but if this is run under ARM it will try to load x86_64 which would be incorrect.