Skip to content

Commit 1958275

Browse files
authored
Merge pull request #47 from CAPESandbox/check
better exec check
2 parents 8c52ed0 + 934708b commit 1958275

File tree

2 files changed

+26
-31
lines changed

2 files changed

+26
-31
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.66"
55
description = "Sample staging and detonation utility"
66
readme = "README.md"
77
license = "GPLv3"

sflock/ident.py

+25-30
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
@@ -297,9 +308,6 @@ def sct(f):
297308

298309

299310
def xxe(f):
300-
if is_executable(f):
301-
return None
302-
303311
STRINGS = [
304312
b"XXEncode",
305313
b"begin",
@@ -315,9 +323,6 @@ def xxe(f):
315323

316324

317325
def hta(f):
318-
if is_executable(f):
319-
return None
320-
321326
STRINGS = [
322327
b"<head",
323328
b"<title",
@@ -352,9 +357,6 @@ def office_one(f):
352357

353358

354359
def office_webarchive(f):
355-
if is_executable(f):
356-
return None
357-
358360
STRINGS = [
359361
b"<o:Pages>",
360362
b"<o:DocumentProperties>",
@@ -433,9 +435,6 @@ def office_ole(f):
433435

434436

435437
def powershell(f):
436-
if is_executable(f):
437-
return None
438-
439438
POWERSHELL_STRS = [
440439
b"$PSHOME",
441440
b"Get-WmiObject",
@@ -458,9 +457,6 @@ def powershell(f):
458457

459458

460459
def javascript(f):
461-
if is_executable(f):
462-
return None
463-
464460
JS_STRS = [
465461
b"var ",
466462
b"function ",
@@ -486,18 +482,12 @@ def javascript(f):
486482

487483

488484
def wsf(f):
489-
if is_executable(f):
490-
return None
491-
492485
match = re.search(b'<script\\s+language="(J|VB|Perl)Script"', f.contents, re.I)
493486
if match:
494487
return "wsf"
495488

496489

497490
def pub(f):
498-
if is_executable(f):
499-
return None
500-
501491
PUB_STRS = [
502492
b"Microsoft Publisher",
503493
b"MSPublisher",
@@ -512,9 +502,6 @@ def pub(f):
512502

513503

514504
def visualbasic(f):
515-
if is_executable(f):
516-
return None
517-
518505
VB_STRS = [
519506
b"Dim ",
520507
b"\x00D\x00i\x00m\x00 ",
@@ -564,9 +551,6 @@ def dmg(f):
564551

565552

566553
def vbe_jse(f):
567-
if is_executable(f):
568-
return None
569-
570554
if b"#@~^" in f.contents[:100]:
571555
data = vbe_decode_file("", f.contents)
572556
if data:
@@ -586,9 +570,6 @@ def udf(f):
586570

587571

588572
def inf(f):
589-
if is_executable(f):
590-
return None
591-
592573
STRINGS = [
593574
# b"[version]",
594575
b"Signature=",
@@ -609,6 +590,19 @@ def identify(f, check_shellcode: bool = False):
609590
if not f.stream.read(0x1000):
610591
return
611592

593+
if is_executable(f):
594+
# to reduce number of checks
595+
for magic_types in exec_magics:
596+
if f.magic.startswith(magic_types):
597+
# MS-DOS executable PE32 executable (DLL) (GUI) Intel 80386, for MS Windows
598+
# MZ for MS-DOS -> MS-DOS executable
599+
# MZ for MS-DOS -> but is DLL
600+
package = exec_magics[magic_types]
601+
if package in ("exe", "dll"):
602+
pe = pefile.PE(data=f.contents, fast_load=True)
603+
return "dll" if pe.is_dll() else "exe"
604+
return None
605+
612606
if f.filename:
613607
for package, extensions in file_extensions.items():
614608
if f.filename.endswith(extensions) and not f.contents.startswith(b"MZ"):
@@ -634,6 +628,7 @@ def identify(f, check_shellcode: bool = False):
634628
package = identifier(f)
635629
if package:
636630
return package
631+
637632
for magic_types in magics:
638633
if f.magic.startswith(magic_types):
639634
# MS-DOS executable PE32 executable (DLL) (GUI) Intel 80386, for MS Windows

0 commit comments

Comments
 (0)