def _load_transforms(self): for t in self._package.__all__: m = import_transform('%s.transforms.%s' % (self.name, t)) if hasattr(m, 'dotransform') and hasattr(m.dotransform, 'label'): self._transforms.append(m) if hasattr(m.dotransform, 'remote') and m.dotransform.remote: self._remote_transforms.append(m)
def local_transform_runner(transform, value, fields, params, config, message_writer=message): """ Internal API: The local transform runner is responsible for executing the local transform. Parameters: transform - The name or module of the transform to execute (i.e sploitego.transforms.whatismyip). value - The input entity value. fields - A dict of the field names and their respective values. params - The extra parameters passed into the transform via the command line. config - The Canari configuration object. message_writer - The message writing function used to write the MaltegoTransformResponseMessage to stdout. This is can either be the console_message or message functions. Alternatively, the message_writer function can be any callable object that accepts the MaltegoTransformResponseMessage as the first parameter and writes the output to a destination of your choosing. This helper function is only used by the run-transform, debug-transform, and dispatcher commands. """ transform_module = None try: transform_module = transform if isinstance( transform, ModuleType) else import_transform(transform) if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and os.geteuid(): rc = sudo(sys.argv) if rc == 1: message_writer(MaltegoTransformResponseMessage() + UIMessage('User cancelled transform.')) elif rc == 2: message_writer( MaltegoTransformResponseMessage() + UIMessage('Too many incorrect password attempts.')) elif rc: message_writer(MaltegoTransformResponseMessage() + UIMessage('Unknown error occurred.')) sys.exit(rc) if hasattr(transform_module, 'onterminate'): onterminate(transform_module.onterminate) else: transform_module.__setattr__('onterminate', lambda *args: sys.exit(-1)) input_entity = to_entity(guess_entity_type(transform_module, fields), value, fields) msg = transform_module.dotransform( MaltegoTransformRequestMessage( entities=[input_entity.__entity__], parameters={ 'canari.local.arguments': Field(name='canari.local.arguments', value=params) }), MaltegoTransformResponseMessage()) if get_transform_version( transform_module.dotransform ) == 2 else transform_module.dotransform( MaltegoTransformRequestMessage( entities=[input_entity.__entity__], parameters={ 'canari.local.arguments': Field(name='canari.local.arguments', value=params) }), MaltegoTransformResponseMessage(), config) if isinstance(msg, MaltegoTransformResponseMessage): message_writer(msg) elif isinstance(msg, basestring): raise MaltegoException(msg) else: raise MaltegoException( 'Could not resolve message type returned by transform.') except MaltegoException, me: croak(str(me), message_writer)
def local_transform_runner(transform, value, fields, params, config, message_writer=message): """ Internal API: The local transform runner is responsible for executing the local transform. Parameters: transform - The name or module of the transform to execute (i.e sploitego.transforms.whatismyip). value - The input entity value. fields - A dict of the field names and their respective values. params - The extra parameters passed into the transform via the command line. config - The Canari configuration object. message_writer - The message writing function used to write the MaltegoTransformResponseMessage to stdout. This is can either be the console_message or message functions. Alternatively, the message_writer function can be any callable object that accepts the MaltegoTransformResponseMessage as the first parameter and writes the output to a destination of your choosing. This helper function is only used by the run-transform, debug-transform, and dispatcher commands. """ transform_module = None try: transform_module = transform if isinstance(transform, ModuleType) else import_transform(transform) if os.name == 'posix' and hasattr(transform_module.dotransform, 'privileged') and os.geteuid(): rc = sudo(sys.argv) if rc == 1: message_writer(MaltegoTransformResponseMessage() + UIMessage('User cancelled transform.')) elif rc == 2: message_writer(MaltegoTransformResponseMessage() + UIMessage('Too many incorrect password attempts.')) elif rc: message_writer(MaltegoTransformResponseMessage() + UIMessage('Unknown error occurred.')) sys.exit(rc) if hasattr(transform_module, 'onterminate'): onterminate(transform_module.onterminate) else: transform_module.__setattr__('onterminate', lambda *args: sys.exit(-1)) input_entity = to_entity(guess_entity_type(transform_module, fields), value, fields) msg = transform_module.dotransform( MaltegoTransformRequestMessage( entities=[input_entity.__entity__], parameters={'canari.local.arguments': Field(name='canari.local.arguments', value=params)} ), MaltegoTransformResponseMessage() ) if get_transform_version(transform_module.dotransform) == 2 else transform_module.dotransform( MaltegoTransformRequestMessage( entities=[input_entity.__entity__], parameters={'canari.local.arguments': Field(name='canari.local.arguments', value=params)} ), MaltegoTransformResponseMessage(), config ) if isinstance(msg, MaltegoTransformResponseMessage): message_writer(msg) elif isinstance(msg, basestring): raise MaltegoException(msg) else: raise MaltegoException('Could not resolve message type returned by transform.') except MaltegoException, me: croak(str(me), message_writer)