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

Can't add hashes for filenames with regex #52

Closed
RichieB2B opened this issue Feb 23, 2017 · 4 comments
Closed

Can't add hashes for filenames with regex #52

RichieB2B opened this issue Feb 23, 2017 · 4 comments

Comments

@RichieB2B
Copy link
Contributor

RichieB2B commented Feb 23, 2017

When I try to add a hash for a filename containing a regex like file\d{1}.\d{2}.exe, PyMISP throws this error:

Traceback (most recent call last):
  File "./import.py", line 178, in <module>
    readcsv(sys.argv[1])
  File "./import.py", line 163, in readcsv
    r = mymisp.add_hashes(event, filename=row[1], md5=md5, sha1=sha1, sha256=sha256, comment=comment)
  File "/opt/rh/rh-python34/root/usr/lib/python3.4/site-packages/pymisp/api.py", line 448, in add_hashes
    attributes.append(self._prepare_full_attribute(category, type_value.format('md5'), value.format(md5),
IndexError: tuple index out of range

This is because the filename is interpreted as a format string in https://github.com/MISP/PyMISP/blob/master/pymisp/api.py#L455

@Rafiot
Copy link
Member

Rafiot commented Feb 23, 2017

Hmmm, can you print the content of row?

Because that snippet works:

In [1]: a = 'file\d{1}.\d{2}.exe'
In [2]: '{}'.format(a)
Out[2]: 'file\\d{1}.\\d{2}.exe'

@RichieB2B
Copy link
Contributor Author

But that snippet does not use the PyMISP API code. This one does:

filename = 'file\d{1}.\d{2}.exe'
md5 = 'd41d8cd98f00b204e9800998ecf8427e'
value = filename + '|{}'
value.format(md5)
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
IndexError: tuple index out of range

@Rafiot
Copy link
Member

Rafiot commented Feb 23, 2017

grmbl, right, sorry for that, fixing

@Rafiot Rafiot closed this as completed in ee3f0fb Feb 23, 2017
@Rafiot
Copy link
Member

Rafiot commented Feb 23, 2017

That should do the trick.

TheDr1ver pushed a commit to TheDr1ver/PyMISP that referenced this issue Mar 9, 2017
Caught exception on python3.4 where base64encode returns bytes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants