osquery-defense-kit/detection/evasion/unexpected-etc-executables.sql

156 lines
3.7 KiB
MySQL
Raw Normal View History

2022-10-14 18:19:32 +00:00
-- Find unexpected executables in /etc
--
-- references:
-- * https://blog.lumen.com/chaos-is-a-go-based-swiss-army-knife-of-malware/
--
-- tags: persistent
-- platform: posix
2022-10-17 23:06:17 +00:00
SELECT
file.path,
2022-10-14 18:19:32 +00:00
file.directory,
uid,
gid,
mode,
file.mtime,
file.size,
hash.sha256,
magic.data
2022-10-17 23:06:17 +00:00
FROM
file
2022-10-14 18:19:32 +00:00
LEFT JOIN hash on file.path = hash.path
LEFT JOIN magic ON file.path = magic.path
2022-10-17 23:06:17 +00:00
WHERE
(file.path LIKE '/etc/%%')
2022-10-14 18:19:32 +00:00
AND file.type = 'regular'
AND (
file.mode LIKE '%7%'
or file.mode LIKE '%5%'
or file.mode LIKE '%1%'
)
AND file.directory NOT IN (
'/etc/acpi',
'/etc/alternatives',
'/etc/apcupsd',
2022-10-14 18:19:32 +00:00
'/etc/apm/resume.d',
'/etc/apm/scripts.d',
'/etc/apm/suspend.d',
'/etc/avahi',
'/etc/bash_completion.d',
2022-10-14 18:19:32 +00:00
'/etc/brltty/Contraction',
'/etc/ca-certificates/update.d',
'/etc/chromium/native-messaging-hosts',
'/etc/cifs-utils',
2022-10-14 18:19:32 +00:00
'/etc/console-setup',
'/etc/cron.daily',
'/etc/cron.hourly',
2022-10-14 18:19:32 +00:00
'/etc/cron.monthly',
'/etc/cron.weekly',
'/etc/dhcp/dhclient.d',
2022-10-14 18:19:32 +00:00
'/etc/dhcp/dhclient-enter-hooks.d',
'/etc/dhcp/dhclient-exit-hooks.d',
'/etc/dkms',
'/etc/flatpak/remotes.d',
'/etc/gdm',
'/etc/gdm3',
2022-10-14 18:19:32 +00:00
'/etc/gdm3/Init',
'/etc/gdm3/PostLogin',
'/etc/gdm3/PostSession',
'/etc/gdm3/PreSession',
'/etc/gdm3/Prime',
'/etc/gdm3/PrimeOff',
'/etc/gdm/Init',
'/etc/gdm/PostLogin',
'/etc/gdm/PostSession',
'/etc/gdm/PreSession',
'/etc/grub.d',
'/etc/httpd/modules',
'/etc/ifplugd',
2022-10-14 18:19:32 +00:00
'/etc/ifplugd/action.d',
'/etc/init.d',
'/etc/initramfs/post-update.d',
2022-11-10 17:14:18 +00:00
'/etc/kde/shutdown',
2022-10-14 18:19:32 +00:00
'/etc/kernel/header_postinst.d',
'/etc/kernel/install.d',
'/etc/kernel/postinst.d',
'/etc/kernel/postrm.d',
'/etc/kernel/preinst.d',
'/etc/kernel/prerm.d',
'/etc/lightdm',
'/etc/localtime',
'/etc/mcelog/triggers',
'/etc/menu-methods',
2022-10-14 18:19:32 +00:00
'/etc/network/if-down.d',
'/etc/smartmontools',
2022-10-14 18:19:32 +00:00
'/etc/network/if-post-down.d',
'/etc/network/if-pre-up.d',
'/etc/network/if-up.d',
'/etc/NetworkManager/dispatcher.d',
2022-11-10 17:14:18 +00:00
'/etc/nix/result',
'/etc/nix/result/sw/bin',
2022-10-14 18:19:32 +00:00
'/etc/openvpn',
'/etc/periodic/daily',
'/etc/periodic/monthly',
'/etc/periodic/weekly',
'/etc/pinentry',
2022-10-14 18:19:32 +00:00
'/etc/pm/sleep.d',
'/etc/pop-os/update-motd.d',
'/etc/ppp',
'/etc/ppp/ip-down.d',
'/etc/ppp/ip-up.d',
'/etc/ppp/ipv6-up.d',
'/etc/profile.d',
'/etc/qemu-ga',
2022-10-14 18:19:32 +00:00
'/etc/rc0.d',
'/etc/rc1.d',
'/etc/rc2.d',
'/etc/rc3.d',
'/etc/rc4.d',
'/etc/rc5.d',
'/etc/rc6.d',
'/etc/rc.d/init.d',
'/etc/rc.d/rc0.d',
'/etc/rc.d/rc1.d',
'/etc/rc.d/rc2.d',
'/etc/rc.d/rc3.d',
'/etc/rc.d/rc4.d',
'/etc/rc.d/rc5.d',
'/etc/rc.d/rc6.d',
'/etc/rcS.d',
'/etc/rdnssd',
2022-11-10 17:14:18 +00:00
'/etc/redhat-lsb',
'/etc/resolvconf/update.d',
'/etc/security',
'/etc/skel',
2022-10-14 18:19:32 +00:00
'/etc/ssl/certs',
'/etc/ssl/misc',
2022-10-14 18:19:32 +00:00
'/etc/ssl/trust-source',
'/etc/systemd/system',
'/etc/systemd/system/graphical.target.wants',
'/etc/systemd/system-shutdown',
'/etc/udev/rules.d',
'/etc/update-motd.d',
'/etc/vmware-tools',
'/etc/vpnc',
'/etc/wpa_supplicant',
'/etc/X11',
'/etc/X11/xinit',
'/etc/X11/xinit/xinitrc.d',
'/etc/xdg/Xwayland-session.d',
'/etc/zfs-fuse',
'/etc/zfs/zed.d',
'/etc/zfs/zpool.d'
2022-10-14 18:19:32 +00:00
)
AND file.path NOT IN (
'/etc/nftables.conf',
'/etc/rmt',
'/etc/grub2.cfg',
'/etc/grub2-efi.cfg',
'/etc/paths.d/100-rvictl',
'/etc/profile',
2022-10-14 18:19:32 +00:00
'/etc/qemu-ifdown',
'/etc/qemu-ifup',
'/etc/opt/chrome/native-messaging-hosts/com.google.endpoint_verification.api_helper.json'
2022-10-17 23:06:17 +00:00
)
-- Nix (on macOS) -- actually a symbolic link
AND file.path NOT LIKE '/etc/profiles/per-user/%/bin/%'