From 6db19ace9eb7d69aecd4708a000b13e9eba741aa Mon Sep 17 00:00:00 2001 From: Tristan METAYER Date: Wed, 23 Mar 2016 14:40:44 +0100 Subject: [PATCH] Add upload_attachment --- pymisp/api.py | 28 +++++++++++++++++++++++++++- 1 file changed, 27 insertions(+), 1 deletion(-) diff --git a/pymisp/api.py b/pymisp/api.py index 1ea3b45..f12b668 100644 --- a/pymisp/api.py +++ b/pymisp/api.py @@ -566,7 +566,7 @@ class PyMISP(object): def prepare_attribute(self, event_id, distribution, to_ids, category, info, analysis, threat_level_id): to_post = {'request': {}} - authorized_categs = ['Payload delivery', 'Artifacts dropped', 'Payload Installation', 'External Analysis'] + authorized_categs = ['Payload delivery', 'Artifacts dropped', 'Payload Installation', 'External Analysis','Antivirus detection'] if event_id is not None: try: @@ -618,6 +618,32 @@ class PyMISP(object): response = session.post(url, data=json.dumps(to_post)) return self._check_response(response) + def upload_attachment(self, filename, filepath, event_id, distribution, to_ids, + category, info, analysis, threat_level_id): + to_post = self.prepare_attribute(event_id, distribution, to_ids, category, + info, analysis, threat_level_id) + to_post['request']['files'] = [{'filename': filename, 'data': self._encode_file_to_upload(filepath)}] + return self._upload_sample(to_post) + + def upload_attachmentlist(self, filepaths, event_id, distribution, to_ids, category, + info, analysis, threat_level_id): + to_post = self.prepare_attribute(event_id, distribution, to_ids, category, + info, analysis, threat_level_id) + files = [] + for path in filepaths: + if not os.path.isfile(path): + continue + files.append({'filename': os.path.basename(path), 'data': self._encode_file_to_upload(path)}) + to_post['request']['files'] = files + return self._upload_sample(to_post) + + def _upload_attachment(self, to_post): + session = self.__prepare_session('json') + url = urljoin(self.root_url, 'events/upload_attachment') + response = session.post(url, data=json.dumps(to_post)) + return self._check_response(response) + + # ############################ # ######## Proposals ######### # ############################