Files
felhom.eu/documentation/audits/profile-refresh-spike-2026-11-14/tools/02-make-stale.sh
T

20 lines
2.0 KiB
Bash

# 02-make-stale.sh — demo-hp (Tier 0). Make ONE stale profile by the real mechanism: an old compiled copy in the
# running kernel's cache folder whose time is newer than its source. No package is changed.
set -u
C=/var/cache/apparmor; CUR=$C/f6da0254.0; OLD=$C/ae1a4050.0; F=usr.sbin.chronyd
LOADED=/sys/kernel/security/apparmor/policy/profiles
echo "#### $(hostname) $(date -u +%FT%TZ) kernel $(uname -r)"
echo "## before: chrony $(systemctl is-active chrony); loaded $(cat $LOADED/usr.sbin.chronyd*/raw_sha256 | cut -c1-12); cache(cur) $(sha256sum < $CUR/$F | cut -c1-12); cache(old folder) $(sha256sum < $OLD/$F | cut -c1-12); fresh $(apparmor_parser -S -K /etc/apparmor.d/$F | sha256sum | cut -c1-12)"
echo "## source mtime $(stat -c %y /etc/apparmor.d/$F | cut -c1-19); old copy mtime $(stat -c %y $OLD/$F | cut -c1-19)"
cp -a $CUR/$F /root/spike-profile-$F.good && echo "saved the good cache file to /root/spike-profile-$F.good ($(sha256sum < /root/spike-profile-$F.good | cut -c1-12))"
cp -a $OLD/$F $CUR/$F && echo "PLANTED: the old compiled copy is now in the running kernel's folder; its time $(stat -c %y $CUR/$F | cut -c1-19) is newer than the source"
echo "## reload the way the system does at a start (systemctl reload apparmor = apparmor_parser --write-cache --replace)"
systemctl reload apparmor; echo "reload rc=$?"
echo "## after the reload: loaded $(cat $LOADED/usr.sbin.chronyd*/raw_sha256 | cut -c1-12) (dbf67f16 = the profile of chrony 4.6.1; 83417e83 = of 4.8)"
echo "## chrony still runs under the replaced profile? $(systemctl is-active chrony); its confinement: $(cat /proc/$(pidof -s chronyd)/attr/current 2>/dev/null)"
T=$(date +"%Y-%m-%d %H:%M:%S")
systemctl restart chrony; echo "restart rc=$?"; sleep 6
echo "## after a restart: chrony $(systemctl is-active chrony); result=$(systemctl show chrony -p Result --value)"
journalctl -u chrony --since "$T" --no-pager -o short-iso | tail -6
journalctl -k --since "$T" --no-pager -o short-iso | grep -i 'apparmor="DENIED"' | tail -3