def message(m, fd=sys.stdout): """Write a MaltegoMessage to stdout and exit successfully""" if sys.platform == 'win32': decoding = sys.stdout.encoding if sys.version_info[0] > 2 else 'cp1252' print(MaltegoMessage(message=m).render( fragment=True, encoding='utf-8').decode(decoding), file=fd) else: print(MaltegoMessage(message=m).render(fragment=True), file=fd) sys.exit(0)
def remote_canari_transform_runner(host, base_path, transform, entities, parameters, limits, is_ssl=False): c = HTTPSConnection(host) if is_ssl else HTTPConnection(host) m = MaltegoTransformRequestMessage() for e in entities: m += e for p in parameters: m += p m += limits message = MaltegoMessage(message=m).render() path = re.sub(r'/+', '/', '/'.join([base_path, transform])) if is_debug_exec_mode(): sys.stderr.write("Sending following message to {}{}:\n{}\n\n".format( host, path, message)) c.request('POST', path, message) return c.getresponse()
def croak(cause): """Throw an exception in the Maltego GUI containing cause. :param cause: a string containing the issue description. """ return MaltegoMessage(message=MaltegoTransformExceptionMessage( exceptions=[MaltegoException(cause)])).render()
def message(m): """Write a MaltegoMessage to stdout and exit successfully""" v = None if isinstance(m, basestring): # Let's make sure that we're not spewing out local file system information ;) for url in re.findall("<iconurl>\s*(file://[^\s<]+)\s*</iconurl>(?im)", m): path = 'static/%s' % hashlib.md5(url[7:]).hexdigest() new_url = urljoin(request.host_url, path) m.replace(url, new_url, 1) v = m else: sio = StringIO() # Let's make sure that we're not spewing out local file system information ;) for e in m.entities: if e.iconurl is not None: e.iconurl = e.iconurl.strip() if e.iconurl.startswith('file://'): path = 'static/%s' % hashlib.md5(e.iconurl[7:]).hexdigest() new_url = urljoin(request.host_url, path) e.iconurl = new_url Message(MaltegoMessage(m)).write(sio) v = sio.getvalue() # Get rid of those nasty unicode 32 characters return Response(re.sub(r'(&#\d{5};){2}', r'', v), status=200, mimetype='text/html')
def remote_canari_transform_runner(host, base_path, transform, entities, parameters, limits, is_ssl=False): c = http_client.HTTPSConnection( host) if is_ssl else http_client.HTTPConnection(host) m = MaltegoTransformRequestMessage() for e in entities: m += e for p in parameters: m += p m += limits msg = MaltegoMessage(message=m).render(encoding='utf-8') path = re.sub(r'/+', '/', '/'.join([base_path, transform])) if is_debug_exec_mode(): sys.stderr.write("Sending following message to {}{}:\n{}\n\n".format( host, path, msg)) c.request('POST', path, msg, headers={'Content-Type': 'application/xml'}) return c.getresponse()
def croak(error_msg): """Throw an exception in the Maltego GUI containing error_msg.""" s = StringIO() Message( MaltegoMessage( MaltegoTransformExceptionMessage( exceptions=MaltegoException(error_msg)))).write(file=s) return s.getvalue()
def croak(error_msg, r): """Throw an exception in the Maltego GUI containing error_msg.""" r.send_response(200) r.send_header('Content-Type', 'text/xml') r.send_header('Connection', 'close') r.end_headers() Message( MaltegoMessage( MaltegoTransformExceptionMessage( exceptions=MaltegoException(error_msg)))).write(file=r.wfile)
def croak(error_msg, response): """Throw an exception in the Maltego GUI containing error_msg.""" response.send_response(200) response.send_header('Content-Type', 'text/xml') response.send_header('Connection', 'close') response.end_headers() response.wfile.write( MaltegoMessage( message=MaltegoTransformExceptionMessage(exceptions=[MaltegoException(error_msg)]) ).render(fragment=True) )
def message(m): """Write a MaltegoMessage to stdout and exit successfully""" v = None if isinstance(m, str): # Let's make sure that we're not spewing out local file system information ;) for url in re.findall("<iconurl>\s*(file://[^\s<]+)\s*</iconurl>(?im)", m): path = 'static/%s' % hashlib.md5(url[7:]).hexdigest() new_url = urljoin(request.host_url, path) m.replace(url, new_url, 1) v = m else: v = MaltegoMessage(message=m).render() return Response(v, status=200, mimetype='text/html')
def message(m, response): """Write a MaltegoMessage to stdout and exit successfully""" response.send_response(200) response.send_header('Content-Type', 'text/xml') response.send_header('Connection', 'close') response.end_headers() v = None if isinstance(m, basestring): for url in re.findall("<iconurl>\s*(file://[^\s<]+)\s*</iconurl>(?im)", m): path = '/%s' % hashlib.md5(url).hexdigest() new_url = '%s://%s%s' % ('https' if response.server.is_ssl else 'http', response.server.hostname, path) if path not in response.server.resources: response.server.resources[path] = url[7:] m.replace(url, new_url, 1) v = m else: v = MaltegoMessage(m).render(fragment=True) # Get rid of those nasty unicode 32 characters response.wfile.write(v)
def remote_canari_transform_runner(host, base_path, transform, entities, parameters, limits, is_ssl=False): c = HTTPSConnection(host) if is_ssl else HTTPConnection(host) m = MaltegoTransformRequestMessage() for e in entities: m += e for p in parameters: m += p m += limits c.request('POST', re.sub(r'/+', '/', '/'.join([base_path, transform])), MaltegoMessage(message=m).render()) return c.getresponse()
def message(m, response): """Write a MaltegoMessage to stdout and exit successfully""" response.send_response(200) response.send_header('Content-Type', 'text/xml') response.send_header('Connection', 'close') response.end_headers() v = None if isinstance(m, basestring): for url in findall("<iconurl>\s*(file://[^\s<]+)\s*</iconurl>(?im)", m): path = '/%s' % md5(url).hexdigest() new_url = '%s://%s%s' % ('https' if response.server.is_ssl else 'http', response.server.hostname, path) if path not in response.server.resources: response.server.resources[path] = url[7:] m.replace(url, new_url, 1) v = m else: sio = StringIO() for e in m.entities: if e.iconurl is not None: e.iconurl = e.iconurl.strip() if e.iconurl.startswith('file://'): path = '/%s' % md5(e.iconurl).hexdigest() new_url = '%s://%s%s' % ('https' if response.server.is_ssl else 'http', response.server.hostname, path) if path not in response.server.resources: response.server.resources[path] = e.iconurl[7:] e.iconurl = new_url Message(MaltegoMessage(m)).write(sio) v = sio.getvalue() # Get rid of those nasty unicode 32 characters response.wfile.write(sub(r'(&#\d{5};){2}', r'', v))
def message(msg): """Write a MaltegoMessage to stdout and exit successfully""" v = MaltegoMessage(message=msg).render() return Response(v, status=200, mimetype='text/xml')
def croak(error_msg): """Throw an exception in the Maltego GUI containing error_msg.""" return MaltegoMessage(message=MaltegoTransformExceptionMessage( exceptions=[MaltegoException(error_msg)])).render()