Skip to content

Commit b4f886c

Browse files
jm2claude
andcommitted
scanner: stop folder names like "x@icloud.com/" flagging every file below
SUSPECT_NAMES let every extension match as a path component, so a folder such as "someone@icloud.com/" matched the DOS ".com" extension and put every file under it into the executable inventory (13132 of 13236 files on a real exFAT drive). Only bundle types (.app, .pkg, .kext, ...) are directories and may match mid-path now; file-only extensions must end the path. Detections were unaffected; only suspect.tsv and the review count were inflated. Also print each read-only device's restore hint once: lsblk already lists the disk itself, so it was added twice. Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01QfDMkobPq61kW5VUS7WSzF
1 parent be61fdb commit b4f886c

2 files changed

Lines changed: 9 additions & 4 deletions

File tree

‎scan-untrusted-media.sh‎

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,10 @@ YARA_TIMEOUT=120
6161
# scanner verdicts (MIME types reported by file(1)).
6262
SUSPECT_MIMES='^(application/(x-mach-binary|x-executable|x-pie-executable|x-sharedlib|x-object|x-dosexec|vnd\.microsoft\.portable-executable|x-msdownload|x-msi|java-archive|x-java-applet|x-apple-diskimage|x-xar|x-iso9660-image|x-ms-shortcut|x-bytecode\.python)|text/(x-shellscript|x-script\.python|x-python|x-perl|x-ruby|x-php|x-tcl|x-msdos-batch|x-applescript))$'
6363
# File-name patterns (case-insensitive, matched against the relative path).
64-
SUSPECT_NAMES='(\.(app|pkg|mpkg|dmg|command|tool|scpt|scptd|applescript|workflow|action|terminal|jar|dylib|so|kext|plugin|bundle|osax|qlgenerator|mdimporter|saver|prefpane|webloc|inetloc|fileloc|lnk|url|desktop|exe|dll|scr|com|bat|cmd|ps1|psm1|py|pyw|pl|pm|rb|php|pht|vbs|vbe|jse|wsf|hta|msi|iso|docm|dotm|xlsm|xltm|xlam|pptm|potm|ppam|sldm)(/|$)|(^|/)(LaunchAgents|LaunchDaemons|StartupItems|Login ?Items|ScriptingAdditions|Extensions)/|(^|/)\.(zshrc|zprofile|zshenv|zlogin|bash_profile|bashrc|profile|login)$|(^|/)(authorized_keys|crontab)$)'
64+
# Bundle types are directories, so they match anywhere in the path (every
65+
# file inside Foo.app/ is app content); every other extension must end the
66+
# path, or a folder such as "name@icloud.com/" would flag everything below it.
67+
SUSPECT_NAMES='(\.(app|pkg|mpkg|scptd|workflow|action|bundle|plugin|kext|osax|qlgenerator|mdimporter|saver|prefpane)(/|$)|\.(dmg|command|tool|scpt|applescript|terminal|jar|dylib|so|webloc|inetloc|fileloc|lnk|url|desktop|exe|dll|scr|com|bat|cmd|ps1|psm1|py|pyw|pl|pm|rb|php|pht|vbs|vbe|jse|wsf|hta|msi|iso|docm|dotm|xlsm|xltm|xlam|pptm|potm|ppam|sldm)$|(^|/)(LaunchAgents|LaunchDaemons|StartupItems|Login ?Items|ScriptingAdditions|Extensions)/|(^|/)\.(zshrc|zprofile|zshenv|zlogin|bash_profile|bashrc|profile|login)$|(^|/)(authorized_keys|crontab)$)'
6568

6669
PKGS_FEDORA=(apfs-fuse clamav clamav-update curl ddrescue file jq kernel-modules-extra unzip yara)
6770
PKGS_ARCH=(clamav curl ddrescue file jq unzip yara)
@@ -769,7 +772,8 @@ acquire_device() {
769772
die "${dev} has mounted filesystems. Unmount them first (udisksctl unmount -b <partition>), then rerun."
770773
fi
771774
swapon --show=NAME --noheadings 2>/dev/null | grep -qxF "${dev}" && die "${dev} is in use as swap"
772-
RO_DEVS=("${dev}")
775+
# lsblk lists the disk itself first, then its partitions.
776+
RO_DEVS=()
773777
while read -r node; do
774778
sudo blockdev --setro "${node}" || die "blockdev --setro ${node} failed"
775779
RO_DEVS+=("${node}")

‎tests/test-scanner-helpers.sh‎

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -200,10 +200,11 @@ test_suspect_regexes() (
200200
done
201201
for value in 'Foo.app/' 'note.docm' 'Library/LaunchAgents/com.example.plist' \
202202
'/home/u/Downloads/notes.txt.py' 'home/u/.bashrc' 'ssh/authorized_keys' \
203-
'EVIL.APP/install'; do
203+
'EVIL.APP/install' 'x/setup.com' 'Kit.kext/Contents/Info.plist'; do
204204
[[ ${value} =~ ${SUSPECT_NAMES} ]] || fail "SUSPECT_NAMES does not match ${value}"
205205
done
206-
for value in photo.jpg report.pdf notes.txt Resume.docx fake.appendix; do
206+
for value in photo.jpg report.pdf notes.txt Resume.docx fake.appendix \
207+
'someone@icloud.com/Old Downloads/notes.txt' 'backup.exe/readme.txt'; do
207208
! [[ ${value} =~ ${SUSPECT_NAMES} ]] || fail "SUSPECT_NAMES unexpectedly matches ${value}"
208209
done
209210
)

0 commit comments

Comments
 (0)