Bug: Could not add object due to incomplete attribute value "malware-sample" in FileObject
Nobody has claimed this yet.
- Dominant language
- Python
- Stars
- 491
- Forks
- 290
- Avg merge
- 2d 8h
- Merged PRs (30d)
- 3
Description
pymisp showed me an error when I was trying to upload a malware sample file using below really simple code:
from pymisp import PyMISP
from pymisp.tools import make_binary_objects
misp = PyMISP(MISP_URL, MISP_KEY)
fo, peo, seo = make_binary_objects(FILE_PATH)
misp.add_object(EVENT_ID, fo)
Something went wrong (403): {'saved': False, 'name': 'Could not add object', 'message': 'Could not add object', 'url': '/objects/add/3/', 'errors': 'Could not save object as at least one attribute has failed validation (malware-sample). {"value":["Composite type found but the value not in the composite (value1|value2) format."]}', 'id': '3/'}
I checked the "malware-sample" attribute value and found that it is just the file name, but if I upload a sample manually it would be something like FILENAME|MD5, so I changed the attribute value to that and it works fine.
I checked the code in https://github.com/MISP/PyMISP/blob/main/pymisp/tools/fileobject.py line 67 and I believe it should be changed
from
self.add_attribute('malware-sample', value=self.__filename, data=self.__pseudofile, disable_correlation=True)~~
to
self.add_attribute('malware-sample', value=f"{self.__filename}|{md5(self.__data).hexdigest()}", data=self.__pseudofile, disable_correlation=True)
EDIT:
MISPAttribute.value will be reset in method "_prepare_new_malware_sample" so https://github.com/MISP/PyMISP/blob/main/pymisp/mispevent.py#L645 should also be changed as below
def _prepare_new_malware_sample(self):
if '|' in self.value:
# Get the filename, ignore the md5, because humans.
self.malware_filename, md5 = self.value.split('|')
else:
# Assuming the user only passed the filename
self.malware_filename = self.value
#self.value = self.malware_filename #comment this line
self._malware_binary = self.data
self.encrypt = True
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with pymisp/tools/fileobject.py around line 67 and pymisp/mispevent.py around _prepare_new_malware_sample at line 645. Reproduce the make_binary_objects and add_object flow, then verify that malware-sample values satisfy MISP's filename|MD5 validation without being reset incorrectly. Done means the upload succeeds and the existing malware-sample preparation behavior remains correct.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python
- Domain
- api
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100