-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscan-broken-libs.sh
More file actions
112 lines (102 loc) · 3.99 KB
/
scan-broken-libs.sh
File metadata and controls
112 lines (102 loc) · 3.99 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
#!/usr/bin/env bash
#
# scan-broken-libs.sh
#
# Scans system directories for broken or missing shared library dependencies.
#
# Copyright (c) 2025 Joost Ruis <joost.ruis@mocaccino.org>
# License: MIT
#
# Permission is hereby granted, free of charge, to any person obtaining a copy
# of this software and associated documentation files (the "Software"), to deal
# in the Software without restriction, including without limitation the rights
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
# copies of the Software, and to permit persons to whom the Software is
# furnished to do so, subject to the following conditions:
#
# The above copyright notice and this permission notice shall be included in all
# copies or substantial portions of the Software.
#
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
# SOFTWARE.
# Directories to scan (excluding /opt)
DIRS=(
/bin
/sbin
/usr/bin
/usr/sbin
/usr/local/bin
/usr/local/sbin
/lib
/lib64
/usr/lib
/usr/lib64
/usr/local/lib
)
# Patterns to ignore — these are known to trigger false positives with ldd
IGNORE_PATTERNS=(
"libsystemd-core" # systemd's internal modules, not meant to run standalone
"libsamba-modules" # samba plugin libs, dynamically loaded by smbd or similar
"tracker-miners" # tracker-miner extract modules, plugin-style
"/firefox/browser/" # Firefox plugin/component dirs — loaded via runtime paths
"/qt*/plugins/" # Qt plugin folders — not part of core runtime
"/gstreamer-*/libgst" # GStreamer plugin modules — optional codec loaders
"libvirt" # virtualization modules loaded by libvirtd/qemu
"libnss3" # NSS may appear missing when scanned directly
"libnssutil3" # same as above
"libsoftokn3" # crypto module, loaded dynamically
"/plugins" # Generic plugin folders — not directly executable
"linux-vdso" # special virtual DSO, not a real file
"ld-linux" # dynamic linker — may show up as missing in indirect scans
)
BROKEN_LIBS=$(mktemp)
SKIPPED_LIBS=$(mktemp)
echo "🔍 Scanning ELF executables for missing libraries..."
for dir in "${DIRS[@]}"; do
if [[ -d "$dir" ]]; then
find "$dir" -type f -executable -exec file {} + 2>/dev/null | \
grep -E 'ELF.*(executable|shared object)' | cut -d: -f1 | while read -r bin; do
[[ -L "$bin" || ! -r "$bin" ]] && continue
if ldd "$bin" 2>/dev/null | grep -q "not found"; then
skip=false
for pattern in "${IGNORE_PATTERNS[@]}"; do
if [[ "$bin" == *"$pattern"* ]]; then
skip=true
break
fi
done
if $skip; then
echo "⚠️ Possibly false positive: $bin"
ldd "$bin" 2>/dev/null | grep "not found" >> "$SKIPPED_LIBS"
else
echo "❌ Broken: $bin"
ldd "$bin" 2>/dev/null | grep "not found" >> "$BROKEN_LIBS"
fi
echo "---"
fi
done
fi
done
# Summary
echo ""
echo "✅ Scan complete."
echo ""
echo "❌ Definitely broken libraries:"
if [[ -s "$BROKEN_LIBS" ]]; then
sort "$BROKEN_LIBS" | uniq
else
echo "(none)"
fi
echo ""
echo "⚠️ Possibly false positives (ignored):"
if [[ -s "$SKIPPED_LIBS" ]]; then
sort "$SKIPPED_LIBS" | uniq
else
echo "(none)"
fi
rm -f "$BROKEN_LIBS" "$SKIPPED_LIBS"