Skip to content

Commit 880c673

Browse files
committed
Entropy limits.
Changelog excerpt: - Added entropy limits for signatures that use normalised data, configurable via two newly added directives, entropy_limit and entropy_filesize_limit. When the entropy limits are exceeded, in order to reduce the risk of false positives, some signatures which use normalised data will be ignored.
1 parent 5f15359 commit 880c673

File tree

5 files changed

+47
-13
lines changed

5 files changed

+47
-13
lines changed

Changelog.md

+4
Original file line numberDiff line numberDiff line change
@@ -162,3 +162,7 @@ __*Why "v3.0.0" instead of "v1.0.0?"*__ Prior to phpMussel v3, the "phpMussel Co
162162
#### Other changes.
163163
- [2024.11.06]: Added PHP 8.4 to workflows.
164164
- [2024.11.06]: Improved encrypted zip file detection.
165+
166+
### v3.6.0
167+
168+
- [2025.03.21]: Added entropy limits for signatures that use normalised data, configurable via two newly added directives, entropy_limit and entropy_filesize_limit. When the entropy limits are exceeded, in order to reduce the risk of false positives, some signatures which use normalised data will be ignored.

assets/config.yml

+10-1
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# License: GNU/GPLv2
88
# @see LICENSE.txt
99
#
10-
# This file: Configuration defaults file (last modified: 2024.09.13).
10+
# This file: Configuration defaults file (last modified: 2025.03.21).
1111
##/
1212

1313
core:
@@ -402,6 +402,15 @@ files:
402402
only_allow_images:
403403
type: "bool"
404404
default: false
405+
entropy_limit:
406+
type: "float"
407+
step: "any"
408+
default: 7.7
409+
experimental: true
410+
entropy_filesize_limit:
411+
type: "kb"
412+
default: "512KB"
413+
experimental: true
405414
quarantine:
406415
quarantine_key:
407416
type: "string"

l10n/mr.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
# License: GNU/GPLv2
88
# @see LICENSE.txt
99
#
10-
# This file: Marathi language data (last modified: 2024.10.15).
10+
# This file: Marathi language data (last modified: 2025.03.07).
1111
#
1212
# Regarding translations: My native language is English. Because this is a free
1313
# and open-source hobby project which generates zero income, and translatable
@@ -69,7 +69,7 @@ response:
6969
Macros aren_t permitted: "मॅक्रोना परवानगी नाही"
7070
Missing filename: "फाइलनाव गहाळ आहे"
7171
No problems found: "कोणतीही समस्या आढळली नाही."
72-
Only image files are permitted: "फक्त इमेज फाइल्सना परवानगी आहे"
72+
Only image files are permitted: "फक्त इमेज फायलींना परवानगी आहे"
7373
Quarantined as: ""%s.qfu" म्हणून अलग ठेवले."
7474
Recursion depth limit exceeded: "पुनरावृत्ती खोली मर्यादा ओलांडली"
7575
Signature file missing: "स्वाक्षरी फाइल गहाळ आहे"

src/Loader.php

+10-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The loader (last modified: 2025.01.04).
11+
* This file: The loader (last modified: 2025.03.21).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -90,10 +90,15 @@ class Loader
9090
*/
9191
public $Cache;
9292

93+
/**
94+
* @var \Maikuolan\Common\Demojibakefier Ensure correct data encoding.
95+
*/
96+
public $Demojibakefier;
97+
9398
/**
9499
* @var string phpMussel version number (SemVer).
95100
*/
96-
public $ScriptVersion = '3.5.4';
101+
public $ScriptVersion = '3.6.0';
97102

98103
/**
99104
* @var string phpMussel version identifier (complete notation).
@@ -429,6 +434,9 @@ public function __construct(
429434
$this->InstanceCache['PendingErrorLogData'] .= $Message . "\n";
430435
return true;
431436
});
437+
438+
/** phpMussel leverages the Demojibakefier's shannonEntropy method to make decisions about certain kinds of files. */
439+
$this->Demojibakefier = new \Maikuolan\Common\Demojibakefier();
432440
}
433441

434442
/**

src/Scanner.php

+21-8
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
* License: GNU/GPLv2
99
* @see LICENSE.txt
1010
*
11-
* This file: The scanner (last modified: 2024.11.06).
11+
* This file: The scanner (last modified: 2025.03.21).
1212
*/
1313

1414
namespace phpMussel\Core;
@@ -1311,6 +1311,9 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
13111311
$str_hex_html = bin2hex($str_html);
13121312
$str_hex_html_len = $str_html_len * 2;
13131313

1314+
/** Shannon entropy. */
1315+
$Entropy = $this->Loader->Demojibakefier->shannonEntropy($str);
1316+
13141317
/** Look for potential Linux/ELF indicators. */
13151318
$is_elf = ($fourcc === '7f454c46' || $xt === 'elf');
13161319

@@ -1695,6 +1698,7 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
16951698
'ScanPhase' => $phase,
16961699
'Container' => $container,
16971700
'FileSwitch' => $fileswitch,
1701+
'Entropy' => $Entropy,
16981702
'Is_ELF' => $is_elf,
16991703
'Is_Graphics' => $is_graphics,
17001704
'Is_HTML' => $is_html,
@@ -2202,16 +2206,25 @@ private function dataHandler(string $str = '', int $Depth = 0, string $OriginalF
22022206
}
22032207
}
22042208

2209+
/** Whether the entropy limits have been exceeded. */
2210+
$EntropyLimited = (
2211+
$Entropy > $this->Loader->Configuration['files']['entropy_limit'] &&
2212+
$StringLength > $this->Loader->readBytes($this->Loader->Configuration['files']['entropy_filesize_limit'])
2213+
);
2214+
22052215
/** Process mappable signatures. */
22062216
foreach ([
2207-
['Filename', 'str_hex', 'str_hex_len', 2],
2208-
['Standard', 'str_hex', 'str_hex_len', 0],
2209-
['Normalised', 'str_hex_norm', 'str_hex_norm_len', 0],
2210-
['HTML', 'str_hex_html', 'str_hex_html_len', 0],
2211-
['Standard_RegEx', 'str_hex', 'str_hex_len', 1],
2212-
['Normalised_RegEx', 'str_hex_norm', 'str_hex_norm_len', 1],
2213-
['HTML_RegEx', 'str_hex_html', 'str_hex_html_len', 1]
2217+
['Filename', 'str_hex', 'str_hex_len', 2, false],
2218+
['Standard', 'str_hex', 'str_hex_len', 0, false],
2219+
['Normalised', 'str_hex_norm', 'str_hex_norm_len', 0, $EntropyLimited],
2220+
['HTML', 'str_hex_html', 'str_hex_html_len', 0, false],
2221+
['Standard_RegEx', 'str_hex', 'str_hex_len', 1, false],
2222+
['Normalised_RegEx', 'str_hex_norm', 'str_hex_norm_len', 1, $EntropyLimited],
2223+
['HTML_RegEx', 'str_hex_html', 'str_hex_html_len', 1, false]
22142224
] as $ThisConf) {
2225+
if ($ThisConf[4]) {
2226+
continue;
2227+
}
22152228
$DataSource = $ThisConf[1];
22162229
$DataSourceLen = $ThisConf[2];
22172230

0 commit comments

Comments
 (0)