replacing dependencies

depending on 7z is not versatile enough. We have tried to depend on something easier to get. Plus changing some typos. Plus creating some typos to fix later.
This commit is contained in:
tisf
2019-05-26 14:09:38 +03:00
parent d0c11ab78b
commit df693dd57b
3 changed files with 41 additions and 16 deletions

View File

@@ -124,7 +124,7 @@ Get the file you want to submit and just run `python prep_file.py file_tosubmit.
- [ ] Fix and make 'light' version without malwares with _MalwareFetch function. - [ ] Fix and make 'light' version without malwares with _MalwareFetch function.
### Hopeful ### Hopeful
- [ ] A GUI interface. - [ ] A GUI.
- [ ] Package releases. - [ ] Package releases.
If you have any suggestions or malware that you have indexed (in the manner laid out in the documentation) please send it to us to - thezoo-submissions [a-t] morirt [.d0t.] com - so we can add it for everyone's enjoyment. If you have any suggestions or malware that you have indexed (in the manner laid out in the documentation) please send it to us to - thezoo-submissions [a-t] morirt [.d0t.] com - so we can add it for everyone's enjoyment.

View File

@@ -2,29 +2,45 @@
import os import os
import sys import sys
import zipfile
import hashlib import hashlib
import subprocess
try:
import pyminizip
except ImportError:
sys.stderr.write("Could not import 'pyminizip'. Did you install requirements?\n")
sys.stderr.write("You can always just get 'pyminizip' by 'pip install --user pyminizip'.\n")
sys.exit(1)
OUTPUT_FOLDER = "OUTPUT" OUTPUT_FOLDER = "OUTPUT"
def _help(): def _help():
"""
hmmmm. nope.
:return:
"""
print("Please run with '%s filename'." % sys.argv[0]) print("Please run with '%s filename'." % sys.argv[0])
return return
def _Do(file_path): def _Do(file_path):
"""
Prep file from file path for submission. Take file name, encrypt in ZIP with password 'infected', create MD5
and SHA1 sums and store all of that in a directory of it's own.
:param file_path: str
:return: Bool
"""
if not os.path.isfile(file_path): if not os.path.isfile(file_path):
_help() _help()
print("Seems like '%s' is not a file." % file_path) sys.stderr.write("Seems like '%s' is not a file.\n" % file_path)
sys.exit(1) return False
try: try:
os.mkdir(OUTPUT_FOLDER) os.mkdir(OUTPUT_FOLDER)
except OSError: except OSError:
print("Folder exists. Please remove it before continuing.") sys.stderr.write("Folder exists. Please remove it before continuing.\n")
sys.exit(1) return False
if "\\" in file_path: if "\\" in file_path:
filename = file_path.split("\\")[:-1] filename = file_path.split("\\")[:-1]
@@ -34,14 +50,16 @@ def _Do(file_path):
filename = file_path filename = file_path
# Create ZIP Archive: # Create ZIP Archive:
# We used 7z because 'zipfile' did not support adding a password. Apparently 'pyminizip' works just as well.
try: try:
rc = subprocess.call(['7z', 'a', '-pinfected', '-y', '%s/%s.zip' % (OUTPUT_FOLDER, filename)] + [file_path]) pyminizip.compress(file_path, OUTPUT_FOLDER, "%s.zip" % filename, "infected", 9)
except: except Exception as e:
print("Seems like you don't have 7z in your path. Please install or add with:\n\tbrew install 7zip #(OSX)\n\tsudo apt-get install p7zip-full #(Linux)") sys.stderr.write("Unknown error occurred. Please report this to us so that we can fix this.\n")
sys.exit(1) sys.stderr.write(str(e))
return False
compressed_path = '%s/%s.zip' % (OUTPUT_FOLDER, filename) compressed_path = '%s/%s.zip' % (OUTPUT_FOLDER, filename)
print("Created ZIP Archive.") sys.stdout.write("[+]\tCreated ZIP Archive.\n")
md5sum = hashlib.md5(open(compressed_path, 'rb').read()).hexdigest() md5sum = hashlib.md5(open(compressed_path, 'rb').read()).hexdigest()
sha1sum = hashlib.sha1(open(compressed_path, 'rb').read()).hexdigest() sha1sum = hashlib.sha1(open(compressed_path, 'rb').read()).hexdigest()
open("%s/%s.md5" % (OUTPUT_FOLDER, filename), 'w').write(md5sum) open("%s/%s.md5" % (OUTPUT_FOLDER, filename), 'w').write(md5sum)
@@ -54,7 +72,13 @@ if __name__ == "__main__":
if len(sys.argv) != 2: if len(sys.argv) != 2:
_help() _help()
sys.exit(1) sys.exit(1)
_Do(sys.argv[1]) stt = _Do(sys.argv[1])
print("Please don't forget to add details to 'conf/maldb.db'.") if stt:
print("Thanks for helping us get this accessible to everyone.") sys.stdout.write("Please don't forget to add details to 'conf/maldb.db' "
print("") "and placing the folder in the appropriate directory.\n")
sys.stdout.write("Thanks for helping us get this accessible to everyone.\n")
sys.stdout.write("\n")
sys.exit(0)
else:
sys.exit(1)

View File

@@ -1 +1,2 @@
urllib2 urllib2
pyminizip