Skip to content

Commit

Permalink
[FIX] Upload of IOC in DStore being corrupted
Browse files Browse the repository at this point in the history
  • Loading branch information
whikernel committed Aug 2, 2023
1 parent 62a09cf commit 3dcae2a
Showing 1 changed file with 13 additions and 7 deletions.
20 changes: 13 additions & 7 deletions source/app/schema/marshables.py
Original file line number Diff line number Diff line change
Expand Up @@ -1113,17 +1113,22 @@ def ds_store_file(self, file_storage: FileStorage, location: Path, is_ioc: bool,

if passwd is not None:
try:
with tempfile.NamedTemporaryFile() as tmp:
with tempfile.NamedTemporaryFile(delete=False) as tmp:
file_storage.save(tmp)
file_hash = file_sha256sum(tmp.name)
file_size = os.stat(tmp.name).st_size
file_storage.close()

file_path = location.as_posix() + '.zip'
fn = tmp

shutil.copyfile(tmp.name, Path(tmp.name).parent / file_hash)
file_hash = file_sha256sum(fn.name)
file_size = os.stat(fn.name).st_size

pyminizip.compress((Path(tmp.name).parent / file_hash).as_posix(), None, file_path, passwd, 0)
os.unlink(Path(tmp.name).parent / file_hash)
file_path = location.as_posix() + '.zip'

shutil.copyfile(fn.name, Path(fn.name).parent / file_hash)

pyminizip.compress((Path(fn.name).parent / file_hash).as_posix(), None, file_path, passwd, 0)
os.unlink(Path(tmp.name).parent / file_hash)
os.unlink(fn.name)

except Exception as e:
log.exception(e)
Expand All @@ -1134,6 +1139,7 @@ def ds_store_file(self, file_storage: FileStorage, location: Path, is_ioc: bool,

else:
file_storage.save(location)
file_storage.close()
file_path = location.as_posix()
file_size = location.stat().st_size
file_hash = file_sha256sum(file_path)
Expand Down

0 comments on commit 3dcae2a

Please sign in to comment.