def handle_RUN(self, cgivars, data): try: transname = cgivars['TransformToRun'] except KeyError: raise MaltegoProtocolError("No TransformToRun") try: trans = self.transforms[transname] except KeyError: raise MaltegoProtocolError("No such Transform: %s" % transname) key = cgivars.get('key', None) msg = message.fromstring(data) if not isinstance(msg, message.TransformRequest): raise MaltegoProtocolError("Not a TransformRequest message") self.log('_RUN Received:\n%s' % msg) output = trans.transform(msg.entities, key, msg.fields, (msg.hardlimit, msg.softlimit)) respmsg = message.TransformResponse() for obj in output: if isinstance(obj, entity.Entity): respmsg.entities.append( obj ) elif type(obj) == type((1,)) and len(obj) == 2: respmsg.uimessages.setdefault(obj[0], []).append( obj[1] ) else: respmsg.uimessages.setdefault('PartialError', []).append( "Transform returned a bad value: %r" % obj) self.log('_RUN Sending:\n%s' % respmsg) return respmsg
def run_transform(self, transform, entities, key='', fields={}, limits=(None, None)): if type(entities) not in (types.ListType, types.TupleType): entities = [entities] request = message.TransformRequest() request.entities.extend( entities ) request.fields.update(fields) request.hardlimit, request.softlimit = limits if not request.hardlimit: request.hardlimit = '1000' if not request.softlimit: request.softlimit = '200' params = {} params['key'] = key != None and str(key) or '' params['TransformToRun'] = transform data = self.send_command('_RUN', params, str(request)) resp = message.fromstring(data) if isinstance(resp, message.TransformException): excp = resp.exceptions[0] raise Exception(excp) return resp
def list_transforms(self): data = self.send_command('_TRANSFORMS') return message.fromstring(data)
def get_seeds(self, url="/seed.xml"): data = self.request('GET', url) msg = message.fromstring( data ) return msg