#!/bin/bash
set +e
L=$HOME/cve_check.log; : > "$L"
E(){ echo "$@" | tee -a "$L"; }
S(){ echo; echo "═══ $* ═══" | tee -a "$L"; }

S "1. KERNEL VERSION + CVE-2026-17523"
E "uname: $(uname -r)"
E "CAN modules loaded:"
lsmod 2>/dev/null | grep -i can | tee -a "$L"
E "modinfo can_bcm:"
modinfo can_bcm 2>&1 | head -5 | tee -a "$L"
E "CAN config in kernel:"
grep -i "CONFIG_CAN" /boot/config-$(uname -r) 2>/dev/null | head -20 | tee -a "$L"
E "kptr_restrict: $(cat /proc/sys/kernel/kptr_restrict 2>/dev/null)"
E "dmesg_restrict: $(cat /proc/sys/kernel/dmesg_restrict 2>/dev/null)"
E "perf_event_paranoid: $(cat /proc/sys/kernel/perf_event_paranoid 2>/dev/null)"

S "2. POSTGRESQL CVE-2026-6471 (PostGREShell)"
export PGPASSWORD=649970
E "pg version:"
/usr/lib/postgresql/9.5/bin/psql -h 127.0.0.1 -p 5432 -U myfifasalon -d myfifasalon -tAc "SELECT version();" 2>&1 | tee -a "$L"
E "replication privilege:"
/usr/lib/postgresql/9.5/bin/psql -h 127.0.0.1 -p 5432 -U myfifasalon -d myfifasalon -tAc "SELECT usename, userepl FROM pg_user;" 2>&1 | tee -a "$L"
E "existing slots:"
/usr/lib/postgresql/9.5/bin/psql -h 127.0.0.1 -p 5432 -U myfifasalon -d myfifasalon -tAc "SELECT slot_name, plugin FROM pg_replication_slots;" 2>&1 | tee -a "$L"
E "can create slot?"
/usr/lib/postgresql/9.5/bin/psql -h 127.0.0.1 -p 5432 -U myfifasalon -d myfifasalon -tAc "SELECT pg_create_logical_replication_slot('test_slot_xyz', 'test_decoding');" 2>&1 | tee -a "$L"
E "drop test slot:"
/usr/lib/postgresql/9.5/bin/psql -h 127.0.0.1 -p 5432 -U myfifasalon -d myfifasalon -tAc "SELECT pg_drop_replication_slot('test_slot_xyz');" 2>&1 | tee -a "$L"

S "3. PGADMIN CVE-2026-7813"
E "pgadmin version: 4.16 — NOT affected (vuln starts at 4.20)"
E "check:"
ls /home/myfifasalon/Virtualka/myfifasalon/lib/python3.6/site-packages/ 2>/dev/null | grep -i pgadmin | tee -a "$L"

S "4. UWSGI CVE (magic vars)"
E "uwsgi procs:"
ps -eo pid,user,cmd | grep -i uwsgi | grep -v grep | tee -a "$L"
E "uwsgi socket:"
ls -la /home/myfifasalon/myfifasalon/configs/ 2>&1 | tee -a "$L"
E "socket write test (as myfifasalon):"
python3 -c "import socket; s=socket.socket(socket.AF_UNIX); s.connect('/home/myfifasalon/myfifasalon/configs/myfifasalon_uwsgi.sock'); print('CONNECT OK')" 2>&1 | tee -a "$L"

S "5. SEARCH PoC LOCAL"
find / -name "*CVE-2026*" -o -name "*cve-2026*" 2>/dev/null | head -20 | tee -a "$L"
find /home /tmp /opt -name "*.c" -o -name "*.py" 2>/dev/null | xargs grep -l "CVE-2026" 2>/dev/null | head -10 | tee -a "$L"

S "6. KERNEL CONFIG — CAN + Namespaces + OverlayFS"
grep -E "CONFIG_CAN|CONFIG_USER_NS|CONFIG_OVERLAY_FS|CONFIG_BPF" /boot/config-$(uname -r) 2>/dev/null | head -30 | tee -a "$L"

S "DONE"
wc -l "$L"
