PyMISP/examples/copy_list.py

60 lines
1.4 KiB
Python
Raw Normal View History

2014-04-12 17:44:47 +02:00
#!/usr/bin/python
# -*- coding: utf-8 -*-
2014-04-16 15:14:58 +02:00
from pymisp import PyMISP
2014-04-12 17:44:47 +02:00
from keys import src, dest
url_source = 'https://misp.circl.lu'
url_dest = 'https://misppriv.circl.lu'
2014-04-16 15:14:58 +02:00
cert_source = 'misp.circl.lu.crt'
cert_dest = 'misppriv.circl.lu.crt'
2014-04-12 17:44:47 +02:00
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
2014-04-16 15:14:58 +02:00
source = PyMISP(url_source, src, cert_source, 'xml')
destination = PyMISP(url_dest, dest, cert_dest, 'xml')
2014-04-12 17:44:47 +02:00
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 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__':
2014-04-16 15:14:58 +02:00
import argparse
parser = argparse.ArgumentParser(
description='Copy the events from one MISP instance to an other.')
parser.add_argument('-f', '--filename', type=str, required=True,
help='File containing a list of event id.')
args = parser.parse_args()
2014-04-12 17:44:47 +02:00
init()
2014-04-16 15:14:58 +02:00
list_copy(args.filename)