def install_transform(module, name, author, spec, prefix, working_dir): installdir = os.path.join(prefix, 'config', 'Maltego', 'TransformRepositories', 'Local') if not os.path.exists(installdir): os.mkdir(installdir) setsdir = os.path.join(prefix, 'config', 'Maltego', 'TransformSets') for i, n in enumerate(spec.uuids): if n in transforms: sys.stderr.write( 'WARNING: Previous declaration of %s in transform %s. Overwriting...' % (n, module)) else: print('Installing transform %s from %s...' % (n, module)) transforms[n] = module intype = spec.inputs[i][1]._type_ sets = None if spec.inputs[i][0] is not None: setdir = os.path.join(setsdir, spec.inputs[i][0]) if not os.path.exists(setdir): os.mkdir(setdir) open(os.path.join(setdir, n), 'w').close() sets = Set(spec.inputs[i][0]) transform = MaltegoTransform(n, spec.label, author=author, description=spec.description, properties=[ CmdLineTransformProperty(), CmdCwdTransformProperty(), CmdDbgTransformProperty(), CmdParmTransformProperty() ], input=InputConstraint(intype), sets=sets) transform.sets ElementTree(transform).write( os.path.join(installdir, '%s.transform' % n)) transformsettings = TransformSettings(properties=[ CmdLineTransformPropertySetting( os.path.join( get_bin_dir(), 'dispatcher.bat' if os.name == 'nt' else 'dispatcher')), CmdParmTransformPropertySetting(name), CmdCwdTransformPropertySetting(working_dir), CmdDbgTransformPropertySetting(spec.debug) ]) ElementTree(transformsettings).write( os.path.join(installdir, '%s.transformsettings' % n))
def write_transform(module, name, author, spec, profile, working_dir): installdir = 'TransformRepositories/Local' s = StringIO() for i, n in enumerate(spec.uuids): if n in transforms: sys.stderr.write('WARNING: Previous declaration of %s in transform %s. Overwriting...' % (n, module)) else: print ('Writing transform %s to %s...' % (n, profile.filename)) transforms[n] = module intype = spec.inputs[i][1]._type_ sets = None if spec.inputs[i][0] is not None: transformset = spec.inputs[i][0] if transformset not in transformsets: transformsets[transformset] = [] transformsets[transformset].append(n) sets = Set(transformset) transform = MaltegoTransform( n, spec.label, author=author, description=spec.description, properties=[ CmdLineTransformProperty(), CmdCwdTransformProperty(), CmdDbgTransformProperty(), CmdParmTransformProperty() ], input=InputConstraint(intype), sets=sets ) transform.sets s.truncate(0) ElementTree(transform).write(s) profile.writestr('/'.join([installdir, '%s.transform' % n]), s.getvalue()) transformsettings = TransformSettings(properties=[ CmdLineTransformPropertySetting( os.path.join(get_bin_dir(), 'dispatcher.bat' if os.name == 'nt' else 'dispatcher') ), CmdParmTransformPropertySetting(name), CmdCwdTransformPropertySetting(working_dir), CmdDbgTransformPropertySetting(spec.debug) ]) s.truncate(0) ElementTree(transformsettings).write(s) profile.writestr('/'.join([installdir, '%s.transformsettings' % n]), s.getvalue())
def add_transform(self, working_dir, transform_repository, transform, server=None): transform_repository_dir = self.get_transform_repository_dir( transform_repository) py_name = '.'.join([transform.__module__, transform.__name__]) author = transform.author transform_id = transform.name input_set = transform.transform_set input_entity = transform.input_type if transform.name in self.transform_uuids: print( 'WARNING: Previous declaration of %s in transform %s. Overwriting...' % (transform_id, py_name), file=sys.stderr) else: print('Installing transform %s from %s...' % (transform_id, py_name), file=sys.stderr) sets = None if input_set: sets = Set(name=input_set) self.add_transform_to_set(transform_id, input_set) if server: self.add_transform_to_server(server, transform_id) transform_def = MaltegoTransform( name=transform_id, displayname=transform.display_name, author=author, description=transform.description, properties=(Properties() + CmdLineTransformProperty() + CmdCwdTransformProperty() + CmdDbgTransformProperty() + CmdParmTransformProperty()), input=[InputConstraint(type=input_entity._type_)], sets=[sets]) self.write_file( self.path_join(transform_repository_dir, '%s.transform' % transform_id), transform_def) if not transform_def.sets: print( 'WARNING: Transform does not appear to be part of any Transform Sets (Perhaps an error?).', file=sys.stderr) transform_settings_def = TransformSettings(properties=[ CmdLineTransformPropertySetting(find_dispatcher()), CmdParmTransformPropertySetting(py_name), CmdCwdTransformPropertySetting(working_dir), CmdDbgTransformPropertySetting(transform.debug) ]) self.write_file( self.path_join(transform_repository_dir, '%s.transformsettings' % transform_id), transform_settings_def)
def add_transform(self, working_dir, transform_repository, transform, server=None): name = transform.__name__ author = getattr(transform, '__author__', 'Canari Ninja') spec = transform.dotransform transform_repository_dir = self.get_transform_repository_dir( transform_repository) for transform_id, (input_set, input_entity) in zip(spec.uuids, spec.inputs): if transform_id in self.transform_uuids: print( 'WARNING: Previous declaration of %s in transform %s. Overwriting...' % (transform_id, name)) else: print('Installing transform %s from %s...' % (transform_id, name)) sets = None if input_set: sets = Set(name=input_set) self.add_transform_to_set(transform_id, input_set) if server: self.add_transform_to_server(server, transform_id) transform_def = MaltegoTransform( name=transform_id, displayname=spec.label, author=author, description=spec.description, properties=(Properties() + CmdLineTransformProperty() + CmdCwdTransformProperty() + CmdDbgTransformProperty() + CmdParmTransformProperty()), input=[InputConstraint(type=input_entity._type_)], sets=[sets]) self.write_file( self.path_join(transform_repository_dir, '%s.transform' % transform_id), transform_def) if not transform_def.sets: print( 'WARNING: Transform does not appear to be part of any Transform Sets (Perhaps an error?).' ) transform_settings_def = TransformSettings(properties=[ CmdLineTransformPropertySetting( os.path.join( get_bin_dir(), 'dispatcher.bat' if os.name == 'nt' else 'dispatcher')), CmdParmTransformPropertySetting(name), CmdCwdTransformPropertySetting(working_dir), CmdDbgTransformPropertySetting(spec.debug) ]) self.write_file( self.path_join(transform_repository_dir, '%s.transformsettings' % transform_id), transform_settings_def)
def add_transform(self, working_dir, transform_repository, transform_class, server=None): transform_repository_dir = self.get_transform_repository_dir( transform_repository) transform = transform_class() name = '.'.join([transform_class.__module__, transform_class.__name__]) author = transform.author or self._get_module_author( transform.__module__) transform_id = transform.name input_set = transform.transform_set input_entity = transform.input_type if transform.name in self.transform_uuids: print( 'WARNING: Previous declaration of %s in transform %s. Overwriting...' % (transform_id, name)) else: print('Installing transform %s from %s...' % (transform_id, name)) sets = None if input_set: sets = Set(name=input_set) self.add_transform_to_set(transform_id, input_set) if server: self.add_transform_to_server(server, transform_id) transform_def = MaltegoTransform( name=transform_id, displayname=transform.display_name, author=author, description=transform.description, properties=(Properties() + CmdLineTransformProperty() + CmdCwdTransformProperty() + CmdDbgTransformProperty() + CmdParmTransformProperty()), input=[InputConstraint(type=input_entity._type_)], sets=[sets]) self.write_file( self.path_join(transform_repository_dir, '%s.transform' % transform_id), transform_def) if not transform_def.sets: print( 'WARNING: Transform does not appear to be part of any Transform Sets (Perhaps an error?).' ) # On Windows platform, find_executable add .exe ext to dispatcher.bat(dispatcher.bat.exe), # so we temporary change sys.platform to win, make find_executable find dispatcher.bat if sys.platform == 'win32': sys.platform = 'win' transform_settings_def = TransformSettings(properties=[ CmdLineTransformPropertySetting( find_executable('dispatcher.bat' if os.name == 'nt' else 'dispatcher')), CmdParmTransformPropertySetting(name), CmdCwdTransformPropertySetting(working_dir), CmdDbgTransformPropertySetting(transform.debug) ]) # restore sys.platform if sys.platform == 'win': sys.platform = 'win32' self.write_file( self.path_join(transform_repository_dir, '%s.transformsettings' % transform_id), transform_settings_def)