iT邦幫忙

1

Day 2 從 /proc 到 Process Tree:讓 BehaviorGuard 開始看懂誰啟動誰

  • 分享至 

  • xImage
  •  

昨天 Day 1,我先讓 BehaviorGuard 可以讀取單一 Process 的資訊,例如 PID、PPID、UID、Command 和 Executable。

今天 Day 2 的目標,是讓 BehaviorGuard 不只看自己,而是開始掃描整台 Linux 的 Process,並建立 Parent / Child 關係。

掃描 /proc

Linux 的 /proc 會保存目前正在執行的 Process 資訊。

例如:

ls /proc | head

其中純數字的資料夾就是 PID,例如:

/proc/1
/proc/2
/proc/573941

所以我用 Python 掃描 /proc:

for item in os.listdir("/proc"):
    if item.isdigit():
        pid = int(item)
        
這樣就能找到系統目前正在執行的 Process。
收集 Process Telemetry
目前 BehaviorGuard 會收集:

PID
PPID
Name
UID
Command
Executable

其中最重要的是 PPID。
PPID 是 Parent Process ID,也就是:
這個 Process 是誰啟動的?
例如:
qterminal(573933)
        ↓
zsh(573941)

如果 zsh 的 PPID 是 573933,就可以知道它是由 qterminal 啟動的。
測試 Process Chain
我另外建立一個簡單的測試腳本:

#!/bin/bash

echo "BehaviorGuard test chain"
sleep 300

執行之後,就能形成:
zsh
 ↓
test_chain.sh
 ↓
sleep

BehaviorGuard 透過 PID 和 PPID,就可以還原出:
qterminal -> zsh
zsh -> test_chain.sh
test_chain.sh -> sleep

為什麼 Process Tree 很重要?
單獨看到一個 curl 不一定有問題。

例如:
qterminal
└── zsh
    └── curl
可能只是使用者正常操作。
但如果看到:
apache2
└── sh
    └── curl
就會比較值得進一步調查。
因為資安分析不能只看「什麼程式出現」,還要看:
誰啟動誰
前面的 Parent 是誰
後面又執行了什麼


Day 2 小結
今天完成的流程:
/proc
  ↓
掃描所有 Process
  ↓
收集 PID / PPID
  ↓
建立 Parent / Child
  ↓
建立 Process Tree
到這裡,BehaviorGuard 已經有一個簡單的 Endpoint Process Collector。
下一步 Day 3,就可以開始做第一個 Behavior Detection Rule,判斷哪些 Process Chain 值得被標記成可疑。

圖片
  熱門推薦
圖片
{{ item.channelVendor }} | {{ item.webinarstarted }} |
{{ formatDate(item.duration) }}
直播中

尚未有邦友留言

立即登入留言