def scriptable_transform_runner(transform, value, fields, params, config): global scriptable_api_initialized if not scriptable_api_initialized: scriptable_api_initialized = True 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()) Entity.run_transform = run_transform request = MaltegoTransformRequestMessage( parameters={ 'canari.local.arguments': Field(name='canari.local.arguments', value=params) }) request._entities = [to_entity(transform.input_type, value, fields)] msg = transform.do_transform(request, MaltegoTransformResponseMessage(), config) if isinstance(msg, MaltegoTransformResponseMessage): return Response(msg) elif isinstance(msg, basestring): raise MaltegoException(msg) else: raise MaltegoException( 'Could not resolve message type returned by transform.')
def scriptable_transform_runner(transform, value, fields, params, config): global scriptable_api_initialized if not scriptable_api_initialized: scriptable_api_initialized = True 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() ) Entity.run_transform = run_transform request = MaltegoTransformRequestMessage( parameters={'canari.local.arguments': Field(name='canari.local.arguments', value=params)} ) request._entities = [to_entity(transform.input_type, value, fields)] msg = transform.do_transform( request, MaltegoTransformResponseMessage(), config ) if isinstance(msg, MaltegoTransformResponseMessage): return Response(msg) elif isinstance(msg, basestring): raise MaltegoException(msg) else: raise MaltegoException('Could not resolve message type returned by transform.')
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. """ try: transform = load_object(transform)() if os.name == 'posix' and transform.superuser 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.')) exit(rc) on_terminate(transform.on_terminate) request = MaltegoTransformRequestMessage( parameters={'canari.local.arguments': Field(name='canari.local.arguments', value=params)} ) request._entities = [to_entity(transform.input_type, value, fields)] msg = transform.do_transform( request, 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(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. """ try: transform = load_object(transform)() if os.name == 'posix' and transform.superuser 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.')) exit(rc) on_terminate(transform.on_terminate) request = MaltegoTransformRequestMessage( parameters={ 'canari.local.arguments': Field(name='canari.local.arguments', value=params) }) request._entities = [to_entity(transform.input_type, value, fields)] msg = transform.do_transform(request, 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(me, message_writer)