Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow file observable creation from memory #35

Closed
ninSmith opened this issue Sep 12, 2017 · 4 comments · Fixed by #135
Closed

Allow file observable creation from memory #35

ninSmith opened this issue Sep 12, 2017 · 4 comments · Fixed by #135

Comments

@ninSmith
Copy link

Request Type

Feature Request

Summary

Allow file observable creation from memory

Description

Currently, to create a file observable, it is needed to provide the path to the file to TheHive4py.
It would be nice to allow file observable creation from memory.
Basically, in some case, it is not well-designed to write the file to disk and then delete it "just" for observable creation.

@jojoob
Copy link

jojoob commented Nov 21, 2018

I've implemented this for creating task logs: kapschcdc@deac360
Maybe you can adopt it for observable creation.

@DarrenSykes
Copy link

DarrenSykes commented Feb 10, 2019

It appears just to be a case of modifying models.py thus:

`class CaseObservable(JSONSerializable):
def init(self, **attributes):
if attributes.get('json', False):
attributes = attributes['json']
self.dataType = attributes.get('dataType', None)
self.message = attributes.get('message', None)
self.tlp = attributes.get('tlp', 2)
self.tags = attributes.get('tags', [])
self.ioc = attributes.get('ioc', False)
self.sighted = attributes.get('sighted', False)

    data = attributes.get('data', [])
    if self.dataType == 'file':
        if type(data[0]) is tuple:
            file,filename = data[0]

            #we've passed a file object, rather than a filename
            mimetype = magic.Magic(mime=True).from_buffer(file.read())

            file.seek(0)
            self.data = [{'attachment': (filename, file, mimetype)}]
        else:
            self.data = [{'attachment': (os.path.basename(data[0]), open(data[0], 'rb'), magic.Magic(mime=True).from_file(data[0]))}]
    else:
        self.data = data

`

@nadouani
Copy link
Contributor

Hello, could you make it a PR, verify it so that I can merge it ;)

Thanks

jaredjennings added a commit to jaredjennings/TheHive4py that referenced this issue Dec 21, 2019
jaredjennings added a commit to jaredjennings/TheHive4py that referenced this issue Dec 22, 2019
jaredjennings added a commit to jaredjennings/TheHive4py that referenced this issue Dec 24, 2019
jaredjennings added a commit to jaredjennings/TheHive4py that referenced this issue Dec 24, 2019
jaredjennings added a commit to jaredjennings/TheHive4py that referenced this issue Dec 26, 2019
@ehooo
Copy link

ehooo commented Jan 13, 2020

I think could be a good idea allows also set the mime-type, cause in case of the "text files" the Magic is not working very good.

@nadouani nadouani added this to the 1.8.0 milestone Jun 3, 2020
nadouani pushed a commit that referenced this issue Nov 27, 2020
* add a test that adds a file observable to a case

* support passing in a file-like object for case observable file attachments (#35)

* add a test for file case observables given using a file object (#35)

* fix StringIO construction on Python 2.7
@nadouani nadouani reopened this Nov 27, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants