PyMISP/pymisp/testing.py

57 lines
1.1 KiB
Python
Raw Normal View History

2014-04-12 17:44:47 +02:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
from api import PyMISP
from keys import src, dest
url_source = 'https://misp.circl.lu'
url_dest = 'https://misppriv.circl.lu'
source = None
destination = None
2014-04-14 19:18:12 +02:00
2014-04-12 17:44:47 +02:00
def init():
global source
global destination
source = PyMISP(url_source, src, 'xml')
destination = PyMISP(url_dest, dest, 'xml')
2014-04-14 19:18:12 +02:00
def _to_utf8(request):
to_return = None
if 'json' in request.headers['content-type']:
to_return = request.json()
else:
to_return = request.text.encode('utf-8')
return to_return
2014-04-12 17:44:47 +02:00
def copy_event(event_id):
r_src = source.get_event(event_id)
2014-04-14 19:18:12 +02:00
to_send = _to_utf8(r_src)
return destination.add_event(to_send)
def export_osint():
# Warning: does not exports the samples/attachements
osint = source.search(tags='OSINT')
return _to_utf8(osint)
def list_copy(filename):
with open(filename, 'r') as f:
for l in f:
l = int(l.strip())
2014-04-15 16:40:49 +02:00
print l
2014-04-14 19:18:12 +02:00
copy_event(l)
2014-04-12 17:44:47 +02:00
2014-04-15 16:40:49 +02:00
def export_our_org():
circl = source.search(org='CIRCL')
return _to_utf8(circl)
2014-04-12 17:44:47 +02:00
if __name__ == '__main__':
init()
2014-04-15 16:40:49 +02:00
list_copy('all_ours')