Open file and magic.read_buffer in helpers.py

pull/21/head
Dan Puttick 2017-07-20 15:16:42 -04:00
parent cc5d1e5117
commit 4bc113cefa
2 changed files with 14 additions and 9 deletions

View File

@ -41,11 +41,11 @@ install:
- sudo apt-get install rar
# Prepare tests
# Malware from theZoo
- git clone https://github.com/Rafiot/theZoo.git
- pushd theZoo/malwares/Binaries
- python unpackall.py
- popd
- mv theZoo/malwares/Binaries/out tests/uncategorized/
# - git clone https://github.com/Rafiot/theZoo.git
# - pushd theZoo/malwares/Binaries
# - python unpackall.py
# - popd
# - mv theZoo/malwares/Binaries/out tests/uncategorized/the_zoo/
# Path traversal attacks
- git clone https://github.com/jwilk/path-traversal-samples
- pushd path-traversal-samples
@ -56,17 +56,21 @@ install:
- make
- popd
- popd
- mv path-traversal-samples/zip/*.zip tests/uncategorized/
- mv path-traversal-samples/rar/*.rar tests/uncategorized/
- mv path-traversal-samples/zip/*.zip tests/uncategorized/path_traversal_zip
- mv path-traversal-samples/rar/*.rar tests/uncategorized/path_traversal_rar
# Office docs
- git clone https://github.com/eea/odfpy.git
- mv odfpy/tests/examples/* tests/uncategorized/
- mv odfpy/tests/examples/* tests/uncategorized/odfpy
- pushd tests/uncategorized/
- mkdir olefile && pushd olefile
- wget https://bitbucket.org/decalage/olefileio_pl/raw/3073963b640935134ed0da34906fea8e506460be/Tests/images/test-ole-file.doc
- popd
- mkdir fraunhofer && pushd fraunhofer
- wget --no-check-certificate https://www.officedissector.com/corpus/fraunhoferlibrary.zip
- unzip -o fraunhoferlibrary.zip
- rm fraunhoferlibrary.zip
- popd
- popd
# - pushd tests/dangerous/
# - 7z x -p42 42.zip
# - popd

View File

@ -240,7 +240,8 @@ class FileBase(object):
self.set_property('symlink_path', os.readlink(file_path))
else:
try:
mt = magic.from_file(file_path, mime=True)
with open(file_path, 'rb') as file:
mt = magic.from_buffer(file, mime=True)
# libmagic will always return something, even if it's just 'data'
except UnicodeEncodeError as e:
raise UnicodeEncodeError(e)