|
2 | 2 | from datetime import datetime |
3 | 3 | from malwoverview.utils.colors import mycolors, printr |
4 | 4 | from malwoverview.utils.hash import sha256hash |
5 | | -from malwoverview.utils.peinfo import ftype, isoverlay, overextract, list_imports_exports |
| 5 | +from malwoverview.utils.peinfo import ftype, isoverlay, overlaysize, humansize, fileentropy, overextract, list_imports_exports |
6 | 6 | import geocoder |
7 | 7 | import validators |
8 | 8 | import requests |
@@ -52,27 +52,47 @@ def filechecking_v3(self, ffpname2, showreport, impexp, ovrly): |
52 | 52 | mysha256hash = sha256hash(targetfile) |
53 | 53 |
|
54 | 54 | magictype = ftype(targetfile) |
| 55 | + ovrlsize = '' |
55 | 56 | if re.match(r'^PE[0-9]{2}|^MS-DOS', magictype): |
56 | 57 | ret_overlay = isoverlay(targetfile) |
| 58 | + if (ret_overlay == "YES"): |
| 59 | + ovrlsize = humansize(overlaysize(targetfile)) |
| 60 | + fent = "%.2f" % fileentropy(targetfile) |
57 | 61 |
|
58 | 62 | if (showreport == 0): |
59 | 63 | self.vthashwork(mysha256hash, showreport) |
60 | 64 |
|
61 | 65 | if re.match(r'^PE[0-9]{2}|^MS-DOS', magictype): |
62 | 66 | if (cv.bkg == 1): |
63 | 67 | print(mycolors.foreground.lightred + "Overlay: ".ljust(21) + mycolors.reset + ret_overlay, end='\n') |
| 68 | + if (ret_overlay == "YES"): |
| 69 | + print(mycolors.foreground.lightred + "Overlay Size: ".ljust(21) + mycolors.reset + ovrlsize, end='\n') |
64 | 70 | if re.match(r'^PE[0-9]{2}|^MS-DOS', magictype): |
65 | 71 | if (cv.bkg == 0): |
66 | 72 | print(mycolors.foreground.red + "Overlay: ".ljust(21) + mycolors.reset + ret_overlay, end='\n') |
| 73 | + if (ret_overlay == "YES"): |
| 74 | + print(mycolors.foreground.red + "Overlay Size: ".ljust(21) + mycolors.reset + ovrlsize, end='\n') |
| 75 | + if (cv.bkg == 1): |
| 76 | + print(mycolors.foreground.lightred + "Entropy: ".ljust(21) + mycolors.reset + fent, end='\n') |
| 77 | + if (cv.bkg == 0): |
| 78 | + print(mycolors.foreground.red + "Entropy: ".ljust(21) + mycolors.reset + fent, end='\n') |
67 | 79 | else: |
68 | 80 | self.vtreportwork(mysha256hash, 1) |
69 | 81 |
|
70 | 82 | if re.match(r'^PE[0-9]{2}|^MS-DOS', magictype): |
71 | 83 | if (cv.bkg == 1): |
72 | 84 | print(mycolors.foreground.lightred + "Overlay: ".ljust(21) + mycolors.reset + ret_overlay, end='\n') |
| 85 | + if (ret_overlay == "YES"): |
| 86 | + print(mycolors.foreground.lightred + "Overlay Size: ".ljust(21) + mycolors.reset + ovrlsize, end='\n') |
73 | 87 | if re.match(r'^PE[0-9]{2}|^MS-DOS', magictype): |
74 | 88 | if (cv.bkg == 0): |
75 | 89 | print(mycolors.foreground.red + "Overlay: ".ljust(21) + mycolors.reset + ret_overlay, end='\n') |
| 90 | + if (ret_overlay == "YES"): |
| 91 | + print(mycolors.foreground.red + "Overlay Size: ".ljust(21) + mycolors.reset + ovrlsize, end='\n') |
| 92 | + if (cv.bkg == 1): |
| 93 | + print(mycolors.foreground.lightred + "Entropy: ".ljust(21) + mycolors.reset + fent, end='\n') |
| 94 | + if (cv.bkg == 0): |
| 95 | + print(mycolors.foreground.red + "Entropy: ".ljust(21) + mycolors.reset + fent, end='\n') |
76 | 96 | if (impexp == 1): |
77 | 97 | list_imports_exports(targetfile) |
78 | 98 | if (ovrly == 1): |
@@ -1284,6 +1304,12 @@ def vthashwork(self, myhash, showreport): |
1284 | 1304 | if ('imphash' in attrs['pe_info']): |
1285 | 1305 | imphash = attrs['pe_info']['imphash'] |
1286 | 1306 | print(mycolors.foreground.yellow + "\n".ljust(22) + "Imphash: ".ljust(15) + mycolors.reset + str(imphash), end='') |
| 1307 | + if ('overlay' in attrs['pe_info']): |
| 1308 | + print(mycolors.foreground.yellow + "\n".ljust(22) + "Overlay: ".ljust(15) + mycolors.reset + "YES", end='') |
| 1309 | + if ('size' in attrs['pe_info']['overlay']): |
| 1310 | + print(mycolors.foreground.yellow + "\n".ljust(22) + "Overlay Size: ".ljust(15) + mycolors.reset + humansize(attrs['pe_info']['overlay']['size']), end='') |
| 1311 | + else: |
| 1312 | + print(mycolors.foreground.yellow + "\n".ljust(22) + "Overlay: ".ljust(15) + mycolors.reset + "NO", end='') |
1287 | 1313 | if ('import_list' in attrs['pe_info']): |
1288 | 1314 | print(mycolors.foreground.yellow + "\n".ljust(22) + "Libraries: ".ljust(15), end='') |
1289 | 1315 | for lib in attrs['pe_info']['import_list']: |
@@ -1473,6 +1499,12 @@ def vthashwork(self, myhash, showreport): |
1473 | 1499 | if ('imphash' in attrs['pe_info']): |
1474 | 1500 | imphash = attrs['pe_info']['imphash'] |
1475 | 1501 | print(mycolors.foreground.blue + "\n".ljust(22) + "Imphash: ".ljust(15) + mycolors.reset + str(imphash), end='') |
| 1502 | + if ('overlay' in attrs['pe_info']): |
| 1503 | + print(mycolors.foreground.blue + "\n".ljust(22) + "Overlay: ".ljust(15) + mycolors.reset + "YES", end='') |
| 1504 | + if ('size' in attrs['pe_info']['overlay']): |
| 1505 | + print(mycolors.foreground.blue + "\n".ljust(22) + "Overlay Size: ".ljust(15) + mycolors.reset + humansize(attrs['pe_info']['overlay']['size']), end='') |
| 1506 | + else: |
| 1507 | + print(mycolors.foreground.blue + "\n".ljust(22) + "Overlay: ".ljust(15) + mycolors.reset + "NO", end='') |
1476 | 1508 | if ('import_list' in attrs['pe_info']): |
1477 | 1509 | print(mycolors.foreground.blue + "\n".ljust(22) + "Libraries: ".ljust(15), end='') |
1478 | 1510 | for lib in attrs['pe_info']['import_list']: |
@@ -2005,18 +2037,30 @@ def vtdirchecking(self, repo2, apitype): |
2005 | 2037 |
|
2006 | 2038 | file_hash_dict = dict(list(zip(F, H))) |
2007 | 2039 |
|
2008 | | - print("\nSample".center(10) + "Filename".center(72) + "Description".center(26) + "Threat Label".center(28) + "AV Detection".center(26)) |
2009 | | - print('-' * 154, end="\n\n") |
| 2040 | + print("\n" + "Sample".ljust(9) + "Filename".ljust(72) + "Description".ljust(30) + "Threat Label".ljust(34) + "AV".ljust(4) + "Overlay".center(9) + "Ent") |
| 2041 | + print('-' * 162, end="\n\n") |
2010 | 2042 |
|
2011 | 2043 | hashnumber = 0 |
2012 | 2044 |
|
2013 | 2045 | for key, value in file_hash_dict.items(): |
2014 | 2046 | hashnumber = hashnumber + 1 |
2015 | 2047 | (type_description, threat_label, malicious) = self.vtbatchwork(value) |
| 2048 | + try: |
| 2049 | + magictype = ftype(key) |
| 2050 | + except Exception: |
| 2051 | + magictype = '' |
| 2052 | + if re.match(r'^PE[0-9]{2}|^MS-DOS', magictype): |
| 2053 | + try: |
| 2054 | + overlay = isoverlay(key) |
| 2055 | + except Exception: |
| 2056 | + overlay = "N/A" |
| 2057 | + else: |
| 2058 | + overlay = "N/A" |
| 2059 | + entropy = "%.2f" % fileentropy(key) |
2016 | 2060 | if (cv.bkg == 1): |
2017 | | - print(mycolors.foreground.lightcyan + "file_" + str(hashnumber) + "\t " + mycolors.reset + (key.strip()).ljust(71) + mycolors.foreground.yellow + (type_description).ljust(30) + mycolors.foreground.lightcyan + (threat_label).ljust(34) + mycolors.foreground.lightred + str(malicious)) |
| 2061 | + print(mycolors.foreground.lightcyan + ("file_" + str(hashnumber)).ljust(9) + mycolors.reset + (key.strip()).ljust(72) + mycolors.foreground.yellow + (type_description).ljust(30) + mycolors.foreground.lightcyan + (threat_label).ljust(34) + mycolors.foreground.lightred + str(malicious).ljust(4) + mycolors.foreground.yellow + overlay.center(9) + mycolors.foreground.lightcyan + entropy) |
2018 | 2062 | if (cv.bkg == 0): |
2019 | | - print(mycolors.foreground.blue + "file_" + str(hashnumber) + "\t " + mycolors.reset + (key.strip()).ljust(71) + mycolors.foreground.cyan + (type_description).ljust(30) + mycolors.foreground.blue + (threat_label).ljust(34) + mycolors.foreground.red + str(malicious)) |
| 2063 | + print(mycolors.foreground.blue + ("file_" + str(hashnumber)).ljust(9) + mycolors.reset + (key.strip()).ljust(72) + mycolors.foreground.cyan + (type_description).ljust(30) + mycolors.foreground.blue + (threat_label).ljust(34) + mycolors.foreground.red + str(malicious).ljust(4) + mycolors.foreground.cyan + overlay.center(9) + mycolors.foreground.blue + entropy) |
2020 | 2064 | if (apitype_var == 1): |
2021 | 2065 | if ((hashnumber % 4) == 0): |
2022 | 2066 | time.sleep(61) |
|
0 commit comments