Skip to content

Add signature to panel alerts and fix some white spacing issues#426

Closed
JamesColeman-LW wants to merge 1 commit intorfxn:masterfrom
JamesColeman-LW:panel_alerts
Closed

Add signature to panel alerts and fix some white spacing issues#426
JamesColeman-LW wants to merge 1 commit intorfxn:masterfrom
JamesColeman-LW:panel_alerts

Conversation

@JamesColeman-LW
Copy link
Copy Markdown
Contributor

Tests:

$ maldet -a /home/aeb2c860/390592c2cd.nxcli.io/test/
Linux Malware Detect v1.6.5
            (C) 2002-2023, R-fx Networks <proj@rfxn.com>
            (C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(10012): {scan} signatures loaded: 17637 (14801 MD5 | 2053 HEX | 783 YARA | 0 USER)
maldet(10012): {scan} building file list for /home/aeb2c860/test/, this might take awhile...
maldet(10012): {scan} setting maximum execution time for 'find' file list: 28800sec
maldet(10012): {scan} setting nice scheduler priorities for all operations: cpunice 18 , ionice 6
maldet(10012): {scan} file list completed in 0s, found 732 files...
maldet(10012): {scan} found clamav binary at /bin/clamdscan, using clamav scanner engine...
maldet(10012): {scan} scan of /home/aeb2c860/test/ (732 files) in progress...
maldet(10012): {scan} processing scan results for hits: 1 hits 0 cleaned
maldet(10012): {scan} scan completed on /home/aeb2c860/test/: files 732, malware hits 1, cleaned hits 0, time 1s
maldet(10012): {scan} scan report saved, to view run: maldet --report 231106-2138.10012
maldet(10012): {scan} quarantine is disabled! set quarantine_hits=1 in conf.maldet or to quarantine results run: maldet -q 231106-2138.10012
maldet(10012): {alert} sent scan report to EMAILADDR
maldet(10012): {panel} Detecting control panel and sending alerts...
maldet(10012): {panel} Detected control panel interworx. Will send alerts to control panel account contacts.

Email received:

FILE HIT LIST:
{YARA}nex_webshell_options : /chroot/home/aeb2c860/test/infected.php

Test with quarantine:

$ maldet -a /home/aeb2c860/390592c2cd.nxcli.io/test/
Linux Malware Detect v1.6.5
            (C) 2002-2023, R-fx Networks <proj@rfxn.com>
            (C) 2023, Ryan MacDonald <ryan@rfxn.com>
This program may be freely redistributed under the terms of the GNU GPL v2

maldet(15843): {scan} signatures loaded: 17637 (14801 MD5 | 2053 HEX | 783 YARA | 0 USER)
maldet(15843): {scan} building file list for /home/aeb2c860/test/, this might take awhile...
maldet(15843): {scan} setting maximum execution time for 'find' file list: 28800sec
maldet(15843): {scan} setting nice scheduler priorities for all operations: cpunice 18 , ionice 6
maldet(15843): {scan} file list completed in 0s, found 732 files...
maldet(15843): {scan} found clamav binary at /bin/clamdscan, using clamav scanner engine...
maldet(15843): {scan} scan of /home/aeb2c860/test/ (732 files) in progress...
maldet(15843): {scan} processing scan results for hits: 1 hits 0 cleaned
maldet(15843): {scan} scan completed on /home/aeb2c860/test/: files 732, malware hits 1, cleaned hits 0, time 2s
maldet(15843): {scan} scan report saved, to view run: maldet --report 231106-2142.15843
maldet(15843): {alert} sent scan report to EMAIL
maldet(15843): {panel} Detecting control panel and sending alerts...
maldet(15843): {panel} Detected control panel interworx. Will send alerts to control panel account contacts.

Email list:

FILE HIT LIST:
{YARA}nex_webshell_options : /chroot/home/aeb2c860/test/infected.php

@rfxn
Copy link
Copy Markdown
Owner

rfxn commented Feb 19, 2025

@nexnwelch @JamesColeman-LW This one needs to refactor

@rfxn
Copy link
Copy Markdown
Owner

rfxn commented Feb 22, 2026

Fixed in 94829d7 — three changes:

  1. Panel alerts now include signature names. The hit parsing was rewritten from a fragile for/awk '{print $3}'/grep "$hit" loop to a while read loop with BASH_REMATCH regex matching. The per-user .hits file now contains sig : filepath instead of just filepath, so panel alert emails show what malware was detected alongside each file path.

  2. Hit parsing is more robust. The old for hit in $file_hits loop broke on paths with spaces, and grep "$hit" treated file paths as regex patterns. The new approach reads complete lines and uses bash regex groups to extract signature, file path, and optional quarantine path.

  3. InterWorx master_domain guard added. get_panel_contacts() now checks [ -n "$master_domain" ] before calling siteworx, preventing errors when the user lookup returns empty.

Thank you for identifying this and providing a working implementation with test output — the approach of using BASH_REMATCH for structured line parsing was the right call.

@rfxn rfxn closed this Feb 22, 2026
rfxn added a commit that referenced this pull request Feb 22, 2026
…ASH_REMATCH; InterWorx empty master_domain guard; issue #426
rfxn added a commit that referenced this pull request Mar 31, 2026
… Telegram Bot API URL mi...

- [New] test coverage for clean operations, ClamAV integration, cron daily, and alerting
- [Fix] Telegram Bot API URL missing required /bot prefix before token; issue #461
- [Fix] clamselector() no longer overwrites user scan_max_filesize config; issue #410
- [Fix] tlog line truncation: switch byte-based to line-based tracking; issue #227
- [Fix] panel alerts include signature name; rewrite hit parsing with BASH_REMATCH; InterWorx empty master_domain guard; issue #426
- [Fix] view_report() add "newest" alias, fix email-latest-report bug, replace $EDITOR with cat; issue #336
- [New] cron.daily explicit cPanel detection with /etc/userdatadomains parsing for addon/subdomain docroots; issue #268
- [Change] cron.daily prune uses find -delete instead of xargs rm -f; issue #430
- [Fix] clamselector() warns on clamd test failure before falling back to clamscan; issue #452
- [New] native YARA scanning: scan_yara=1 enables YARA as an independent scan stage using the yara binary (or yr from YARA-X); supports custom rules via custom.yara and custom.yara.d/ drop-in directory; scan_yara_scope controls rule overlap with ClamAV YARA; compiled rules via yarac supported; issue #392, #277, #239
- [New] README.md with comprehensive markdown documentation; update usage_long() with YARA scanning section; update maldet.1 man page with YARA features, --web-proxy option, and 2026 copyright
- [Fix] YARA audit fixes: --disable-warnings for YARA-X, sig count display,       install.sh clamav_linksigs rfxn.yara, man page corrections, variable       quoting, local declarations, Dockerfile precedence; add PLAN.md with       deferred medium-priority items
- [Change] scan_stage_yara() uses --scan-list for batch file scanning,       reducing process invocations from O(N*M) to M+1; YARA stderr       captured and logged via eout instead of discarded
- [Fix] YARA audit fixes: --scan-list fallback for YARA < 4.0, stderr noise       filtering, cpulimit exit code capture via sh -c wrapper,       Dockerfile.yara-x with YARA-X v1.13.0 CI coverage; YARA tests accept       either yara or yr
- [Fix] YARA audit fixes: clean() YARA rescan, per-file fallback exit codes,       YARA-X stderr filter, trap temp file cleanup, hookscan.sh scan_yara       passthrough; add deferred items #11-#17 to PLAN.md
- [New] cron.watchdog weekly watchdog script for independent fallback signature       updates when primary cron.daily is broken or stale; install.sh installs       to /etc/cron.weekly/maldet-watchdog [New] test coverage for update mechanisms: get_remote_file, sigup, lmdup,       cron update integration, and watchdog (22 tests)
- [Fix] scan_stage_yara() deduplicates hits against scan_session, preventing       double-counted files when ClamAV and native YARA both detect the same       file; usage_short() mentions YARA via -co scan_yara=1; signature count       shows YARA(cav) qualifier when native YARA disabled
- [Change] PLAN.md reorganized into 5 phases: correctness bugs, documentation,       YARA hardening, performance/refactoring, CI/infrastructure; added new       audit findings from third review cycle
- [Fix] scan_stage_yara() dedup anchored with end-of-field regex to prevent       substring false-positives; per-file fallback uses sh -c wrapper to       capture YARA exit code through cpulimit; clean() YARA rescan skips       dedup during clean verification and honors clean_check parameter
- [Change] copyright headers updated to 2026 across 10 source files [Fix] CHANGELOG CI matrix corrected to 8-target (was 9-OS); added YARA-X,       removed Rocky 10 and Ubuntu 22.04 not in CI; merged duplicate v2.0.1       date blocks [Fix] README.md cron_prune_days default corrected from 14 to 21 [Change] sigup() signature count uses YARA(cav) qualifier when scan_yara       disabled, matching scan() display [Change] usage_short() YARA hint reformatted as sub-note under -co option [Change] legacy plain-text README replaced with pointer to README.md
- [Fix] import_user_sigs() validates downloaded YARA rules with yr check or       yara before installing to custom.yara; malformed rules are rejected       with warning instead of silently breaking YARA scanning [Fix] scan_stage_yara() validates compiled.yarc with test scan before use;       cross-engine (yarac vs yr) or corrupt compiled rules are skipped with       warning instead of causing scan errors [Change] README.md documents ignore_sigs regex/substring matching behavior,       hit prefix table ({MD5}/{HEX}/{SA}/{YARA}/{CAV}), YARA batch scanning,       hookscan YARA config, and compiled.yarc path
- [New] test coverage for YARA download validation and compiled.yarc       validation (6 tests); exercises import_user_sigs() syntax checking       and scan_stage_yara() compiled rules engine validation
- [Change] scan_stage_yara() refactored: extract _yara_scan_rules() helper       eliminating ~80 lines of duplicated text/compiled rules scan+parse       code; cache YARA binary selection and --scan-list detection in       globals via _yara_init_cache() to avoid repeated fork+exec every       monitor cycle; filter quarantined/unreadable files from YARA file       list via _yara_filter_filelist() at scan() call sites; remove       unused yarac binary discovery from internals.conf
- [Fix] README.md CI badge points to 2.0.1 branch instead of master;       fixes "no status" display since all CI runs are on 2.0.1
- [Fix] README.md CI badge reverted to master branch; badge will be       correct after 2.0.1 merges to master
- [Fix] cron.daily flock lock leaked to backgrounded scans; switched to       CLOEXEC command form (flock -n FILE "$0") so children never       inherit the lock fd [Fix] cron.watchdog version update now runs regardless of sigup result [Fix] README.md md5v2.dat format corrected to HASH:SIZE:{MD5}sig.name.N [New] SHA-256 checksum verification for YARA-X binary in Dockerfile.yara-x [New] test coverage for clean() YARA rescan and YARA(cav) display (3 tests) [New] watchdog sigup-failure resilience test; cron CLOEXEC lock test [Change] Rocky Linux 10 added to CI matrix (9-target); Dockerfile.rocky10       fixed for rockylinux/rockylinux:10 base image and package conflicts
- [Fix] cron.daily update failure logging, README.md config table,       conf.maldet comment typo; add curl to Rocky 8/9 Dockerfiles
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants