mirror of https://github.com/MISP/PyMISP
add export-import of a list
parent
93ddd4cf50
commit
07b66ad05f
|
@ -99,7 +99,7 @@ class PyMISP(object):
|
||||||
"""
|
"""
|
||||||
Search via the Rest API
|
Search via the Rest API
|
||||||
"""
|
"""
|
||||||
search = self.url + '/events/restSearch/download/{}/{}/{}/{}/{}'
|
search = self.url + '/restSearch/download/{}/{}/{}/{}/{}'
|
||||||
val = self.__prepare_rest_search(values, not_values).replace('/', '|')
|
val = self.__prepare_rest_search(values, not_values).replace('/', '|')
|
||||||
tag = self.__prepare_rest_search(tags, not_tags).replace(':', ';')
|
tag = self.__prepare_rest_search(tags, not_tags).replace(':', ';')
|
||||||
if len(val) == 0:
|
if len(val) == 0:
|
||||||
|
|
|
@ -10,22 +10,41 @@ url_dest = 'https://misppriv.circl.lu'
|
||||||
source = None
|
source = None
|
||||||
destination = None
|
destination = None
|
||||||
|
|
||||||
|
|
||||||
def init():
|
def init():
|
||||||
global source
|
global source
|
||||||
global destination
|
global destination
|
||||||
source = PyMISP(url_source, src, 'xml')
|
source = PyMISP(url_source, src, 'xml')
|
||||||
destination = PyMISP(url_dest, dest, 'xml')
|
destination = PyMISP(url_dest, dest, 'xml')
|
||||||
|
|
||||||
|
|
||||||
|
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
|
||||||
|
|
||||||
|
|
||||||
def copy_event(event_id):
|
def copy_event(event_id):
|
||||||
r_src = source.get_event(event_id)
|
r_src = source.get_event(event_id)
|
||||||
if 'json' in r_src.headers['content-type']:
|
to_send = _to_utf8(r_src)
|
||||||
to_send = r_src.json()
|
return destination.add_event(to_send)
|
||||||
else:
|
|
||||||
to_send = r_src.text.encode('utf-8')
|
|
||||||
r_dst = destination.add_event(to_send)
|
def export_osint():
|
||||||
#print r_dst.text
|
# 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())
|
||||||
|
copy_event(l)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
init()
|
init()
|
||||||
copy_event(0000)
|
list_copy('list')
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue