def _initialize(self): packages = None # Read packages that are to be loaded at runtime try: config = load_config() packages = config['canari.remote.packages'] except NoSectionError: print( 'Exiting... You did not specify a [canari.remote] section and a "packages" ' 'option in your canari.conf file!', file=sys.stderr) exit(-1) # Is packages not blank if not packages: print( 'Exiting... You did not specify any transform packages to load in your canari.conf file!', file=sys.stderr) exit(-1) elif isinstance(packages, string_types): packages = [packages] # Create the static directory for static file loading if not os.path.exists('static'): os.mkdir('static', 0o755) # Iterate through the list of packages to load for p in packages: # Copy all the image resource files in case they are used as entity icons distribution = TransformDistribution(p) print('Loading transform package %s' % repr(p), file=sys.stderr) for transform in distribution.remote_transforms: transform_name = transform().name print('Loading transform %s at /%s...' % (repr(transform_name), transform_name), file=sys.stderr) if os.name == 'posix' and transform.superuser and os.geteuid( ) and __name__.startswith('_mod_wsgi_'): print( 'WARNING: mod_wsgi does not allow applications to run with root privileges. ' 'Transform %s ignored...' % repr(transform_name), file=sys.stderr) continue self.transforms[transform_name] = transform self._copy_images(p) if not self.transforms: print( 'Exiting... Your transform packages have no remote transforms.', file=sys.stderr) exit(-1) self.transforms['canari.Version'] = Version
def config(self): if not self._config: click.echo("Loading Canari configuration file %r" % self.config_file, err=True) self._config = load_config(self.config_file) return self._config
def do_transform(transform): try: # Let's get an XML object tree req = MaltegoMessage.parse(request.data).message # If our transform define an input entity type then we should check # whether the request contains the right type if transform.input_type and transform.input_type is not Unknown and \ not isinstance(req.entity, transform.input_type): return Response(application.four_o_four, status=404) # Execute it! msg = transform().do_transform( req, MaltegoTransformResponseMessage(), load_config() ) # Let's serialize the return response and clean up whatever mess was left behind if isinstance(msg, MaltegoTransformResponseMessage): return message(msg) else: raise MaltegoException(str(msg)) # Unless we croaked somewhere, then we need to fix things up here... except MaltegoException, me: return croak(str(me))
def do_transform(transform): try: # Let's get an XML object tree req = MaltegoMessage.parse(request.data).message # If our transform define an input entity type then we should check # whether the request contains the right type if transform.input_type and transform.input_type is not Unknown and \ not isinstance(req.entity, transform.input_type): return Response(application.four_o_four, status=404) # Execute it! msg = transform().do_transform(req, MaltegoTransformResponseMessage(), load_config()) # Let's serialize the return response and clean up whatever mess was left behind if isinstance(msg, MaltegoTransformResponseMessage): return message(msg) else: raise MaltegoException(str(msg)) # Unless we croaked somewhere, then we need to fix things up here... except MaltegoException as me: return croak(str(me)) except Exception: if application.debug: return croak(traceback.format_exc()) else: return croak('Transform execution failed.')
def run_transform(self, transform, params=None, config=None): if isinstance(transform, basestring): transform = load_object(transform)() return scriptable_transform_runner( transform, self.value, self.fields, params or [], config or load_config() )
def canari_main(opts): """ This is the main function for the Canari commander. Nothing special here. """ profile_dir = os.path.join(os.path.expanduser('~'), '.canari') if not os.path.lexists(profile_dir): os.makedirs(profile_dir) fix_pypath() fix_binpath(load_config()[OPTION_LOCAL_PATH]) opts.command_function(opts)
def _initialize(self): packages = None # Read packages that are to be loaded at runtime try: config = load_config() packages = config['canari.remote.packages'] except NoSectionError: sys.stderr.write('Exiting... You did not specify a [canari.remote] section and a "packages" ' 'option in your canari.conf file!\n') exit(-1) # Is packages not blank if not packages: sys.stderr.write( 'Exiting... You did not specify any transform packages to load in your canari.conf file!\n') exit(-1) elif isinstance(packages, basestring): packages = [packages] # Create the static directory for static file loading if not os.path.exists('static'): os.mkdir('static', 0755) # Iterate through the list of packages to load for p in packages: # Copy all the image resource files in case they are used as entity icons distribution = TransformDistribution(p) sys.stderr.write('Loading transform package %s\n' % repr(p)) for transform in distribution.remote_transforms: transform_name = transform().name sys.stderr.write('Loading transform %s at /%s...\n' % (repr(transform_name), transform_name)) if os.name == 'posix' and transform.superuser and os.geteuid() and __name__.startswith('_mod_wsgi_'): sys.stderr.write('WARNING: mod_wsgi does not allow applications to run with root privileges. ' 'Transform %s ignored...\n' % repr(transform_name)) continue self.transforms[transform_name] = transform self._copy_images(p) if not self.transforms: sys.stderr.write('Exiting... Your transform packages have no remote transforms.\n') exit(-1) self.transforms['canari.Version'] = Version
def __init__(self, transform_classes, auto_sudo=False): locals_ = {} asked = False config = load_config() for transform_class in transform_classes: transform = transform_class() locals_['do' + transform.name.split('.')[-1]] = ShellCommand(transform, config) if not asked and transform.superuser and os.name == 'posix' and os.geteuid(): if not auto_sudo and parse_bool("A transform requiring 'root' access was detected." " Would you like to run this shell as 'root'?", False): sudo() asked = True InteractiveConsole.__init__(self, locals=locals_) MtgConsole.init_history(os.path.expanduser('~/.mtgsh_history'))
def run_transform(opts): set_canari_mode(CanariMode.LocalDispatch) with PushDir(CanariProject().src_dir): local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, load_config(), message)
def debug_transform(opts): set_canari_mode(CanariMode.LocalDebug) with PushDir(CanariProject().src_dir): local_transform_runner(opts.transform, opts.value, opts.fields, opts.params, load_config(), console_writer)
def run_transform(self, transform, params=None, config=None): if isinstance(transform, basestring): transform = load_object(transform)() return scriptable_transform_runner(transform, self.value, self.fields, params or [], config or load_config())
__author__ = 'Nadeem Douba' __copyright__ = 'Copyright 2015, Canari Project' __credits__ = [] __license__ = 'GPL' __version__ = '0.5' __maintainer__ = 'Nadeem Douba' __email__ = '*****@*****.**' __status__ = 'Development' __all__ = ['application'] # Initialize Canari modes and bin path set_canari_mode(CanariMode.RemotePlumeDispatch) fix_binpath(load_config()[OPTION_REMOTE_PATH]) fix_pypath() def get_image_path(i): return os.path.join('static', md5(i).hexdigest()) def get_image_url(i): return '%s/static/%s' % (request.host_url, md5(i).hexdigest()) # Monkey patch our resource lib to automatically rewrite icon urls _icon_resource = canari.resource.icon_resource canari.resource.icon_resource = lambda name, pkg=None: get_image_url( _icon_resource(name, pkg))
import sys import random from canari.config import load_config config = load_config('nettacker_transforms.conf') sys.path.insert(0, config['nettacker_transforms.local.home-directory']) __all__ = ['common']
__copyright__ = 'Copyright 2015, Canari Project' __credits__ = [] __license__ = 'GPL' __version__ = '0.5' __maintainer__ = 'Nadeem Douba' __email__ = '*****@*****.**' __status__ = 'Development' __all__ = [ 'application' ] # Initialize Canari modes and bin path set_canari_mode(CanariMode.RemotePlumeDispatch) fix_binpath(load_config()[OPTION_REMOTE_PATH]) fix_pypath() def get_image_path(i): return os.path.join('static', md5(i).hexdigest()) def get_image_url(i): return '%s/static/%s' % (request.host_url, md5(i).hexdigest()) # Monkey patch our resource lib to automatically rewrite icon urls _icon_resource = canari.resource.icon_resource canari.resource.icon_resource = lambda name, pkg=None: get_image_url(_icon_resource(name, pkg))