該章主要是討論透過分析系統和使用者的「正常行為模式」,找出異常或可疑的活動,這邊主要都是透過 falco 進行偵測,
今天會先著重於Falco 安裝和基本設定、Falco 架構和運作原理、以及行為分析的概念和方法。
Falco 是一個雲原生的服務主要是由 sysdig 構成,主要提供在 host, containers, kubernetes 以及各式雲端環境中 runtime security 的偵測。主要提供 Linux kernel 事件,若要偵測其他行為可以透過plugins,透過取得這些 metadata 進行及時的分析 並透過制定好的規則即時提出告警。
Plugins 可以支援 Kubernetes Audit Events, AWS CloudTrail, 以及 Okta
可以監控的內容:
execve
建立的spawned processes (如 /usr/bin/python3 script.py
)cp malicious_ls /bin/ls # 替換成惡意版本
)規則及 Output 會在之後陸續介紹。
透過以下指令安裝
sudo docker run --rm -i -t --name falco --privileged \
-v /var/run/docker.sock:/host/var/run/docker.sock \
-v /dev:/host/dev -v /proc:/host/proc:ro -v /boot:/host/boot:ro \
-v /lib/modules:/host/lib/modules:ro -v /usr:/host/usr:ro -v /etc:/host/etc:ro \
falcosecurity/falco:0.41.3
安裝後 Falco 會有一些預設的 rule ,當安裝完後可以另外開啟一個 terminal 並嘗試開啟檔案sudo cat /etc/shadow
執行後回到 Falco 可以看到相關告警
2024-06-21T08:54:23.812791015+0000: Warning Sensitive file opened for reading by non-trusted program (file=/etc/shadow gparent=sudo ggparent=bash gggparent=tmux: evt_type=openat user=root user_uid=0 user_loginuid=1000 process=cat proc_exepath=/usr/bin/cat parent=sudo command=cat /etc/shadow terminal=34826 container_id=host container_name=host)
透過 helm 安裝
helm repo add falcosecurity https://falcosecurity.github.io/charts
helm repo update
helm install --replace falco --namespace falco --create-namespace --set tty=true falcosecurity/falco
kubectl get pods -n falco
kubectl logs -l app.kubernetes.io/name=falco -n falco -c falco | grep Warning
helm upgrade --namespace falco falco falcosecurity/falco -f falco_custom_rules_cm.yaml --set falcosidekick.enabled=true --set falcosidekick.webui.enabled=true
helm upgrade --namespace falco falco falcosecurity/falco \
--set falcosidekick.enabled=true \
--set falcosidekick.config.slack.webhookurl=YOUR_WEBHOOK_URL_HERE \
--set falcosidekick.config.slack.minimumpriority=notice
helm -n falco uninstall falco
curl -fsSL https://falco.org/repo/falcosecurity-packages.asc | \
sudo gpg --dearmor -o /usr/share/keyrings/falco-archive-keyring.gpg
sudo bash -c 'cat << EOF > /etc/apt/sources.list.d/falcosecurity.list
deb [signed-by=/usr/share/keyrings/falco-archive-keyring.gpg] https://download.falco.org/packages/deb stable main
EOF'
sudo apt-get update -y
sudo apt-get install -y dialog
Modern eBPF
sudo apt-get install -y falco
sudo systemctl status falco-modern-bpf.service
Event Source 方面可以透過 Configure 檔配置設定要使用 Engine (drivers, gVisor) 還是 Plugins
Falco 在偵測 syscall 的時候有以下三種模式
當透過 debian/rpm 安裝時會安裝 falcoctl driver 的工具,同時會需要 full privileges 的權限無法透過 Linux capabilities 限制。
當請求發生時會是以下途徑:
execve() → Falco 核心模組攔截(tracepoints) → ring buffer → 送到 userspace
eBPF 則是不需要額外安裝 driver,已內建在 Falco 執行檔中,可以直接載入 eBPF 程式來監控 syscall。
當請求發生時:
execve() → eBPF 程式攔截 → ring buffer → 送到 Falco userspace
參考資料
https://falco.org/
https://en.wikipedia.org/wiki/EBPF