Skip to content

Commit 34f32a8

Browse files
author
Andriy Brukhovetskyy
committed
better exec check
1 parent 2030789 commit 34f32a8

File tree

2 files changed

+25
-1
lines changed

2 files changed

+25
-1
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11

22
[tool.poetry]
33
name = "SFlock2"
4-
version = "0.3.64"
4+
version = "0.3.65"
55
description = "Sample staging and detonation utility"
66
readme = "README.md"
77
license = "GPLv3"

sflock/ident.py

+24
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,17 @@
142142
]
143143
)
144144

145+
exec_magics = OrderedDict(
146+
[
147+
("PE32 executable (DLL)", "dll"),
148+
("PE32+ executable (DLL)", "dll"),
149+
("MS-DOS executable PE32 executable (DLL)", "dll"),
150+
("PE32 executable", "exe"),
151+
("PE32+ executable", "exe"),
152+
("MS-DOS executable, MZ for MS-DOS", "exe"),
153+
]
154+
)
155+
145156
magics = OrderedDict(
146157
[
147158
# ToDo msdos
@@ -609,6 +620,18 @@ def identify(f, check_shellcode: bool = False):
609620
if not f.stream.read(0x1000):
610621
return
611622

623+
if is_executable(f):
624+
# to reduce number of checks
625+
for magic_types in exec_magics:
626+
if f.magic.startswith(magic_types):
627+
# MS-DOS executable PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
628+
# MZ for MS-DOS -> MS-DOS executable
629+
# MZ for MS-DOS -> but is DLL
630+
package = exec_magics[magic_types]
631+
if package in ("exe", "dll"):
632+
pe = pefile.PE(data=f.contents, fast_load=True)
633+
return "dll" if pe.is_dll() else "exe"
634+
612635
if f.filename:
613636
for package, extensions in file_extensions.items():
614637
if f.filename.endswith(extensions) and not f.contents.startswith(b"MZ"):
@@ -634,6 +657,7 @@ def identify(f, check_shellcode: bool = False):
634657
package = identifier(f)
635658
if package:
636659
return package
660+
637661
for magic_types in magics:
638662
if f.magic.startswith(magic_types):
639663
# MS-DOS executable PE32 executable (DLL) (GUI) Intel 80386, for MS Windows

0 commit comments

Comments
 (0)