AgentSmith-HIDS:一套輕量級高性能的基於主機的入侵檢測系統

  • 2020 年 2 月 24 日
  • 筆記

AgentSmith-HIDS

從技術角度來說,AgentSmith-HIDS嚴格意義上來說並不是一個傳統的「基於主機的入侵檢測系統」(HIDS),因為就該項目目前開源的部分來說,它還缺少了規則引擎以及相關的檢測能力。但是它可以作為一個高性能的主機資訊收集工具來幫助安全研究人員構建屬於自己的HIDS。

而AgentSmit-HIDS的優秀特性(從內核態獲取儘可能完整的數據)在跟用戶態的HIDS相比,擁有巨大的優勢:

1、性能更優秀:通過內核態驅動來獲取相關資訊,無需進行類似「遍歷/proc」這樣的操作來提升性能或進行數據補全;數據的傳輸使用的是共享記憶體,相對來說也有更好的性能表現。 2、更加難以躲避和繞過:由於我們的資訊獲取來自於內核態驅動,因此面對很惡意行為都無法繞過AgentSmith-HIDS的檢測。 3、易於整合:AgentSmith-HIDS不僅可以作為安全工具使用,也可以作為監控工具使用,或者幫助從業人員整理組織內部資產。我們通過內核模組對進程/用戶/文件/網路連接進行整理,如果檢測到了CMDB相關資訊,那麼整合後你將會得到一張從網路到主機/容器/業務資訊的調用/依賴關係圖;如果組織還部署有資料庫審計工具的話,整合後你還可以得到資料庫的用戶/庫表欄位/應用/網路/主機容器的關係;除此之外,你還可以跟NIDS/威脅情報進行整合,達到溯源的目的。 4、用戶態+內核態:AgentSmith-HIDS同時擁有內核態和用戶態的模組,可以協同工作。

AgentSmith-HIDS實現了以下幾個主要功能:

1、內核棧模組通過Kprobe針對 execve、通訊連接、進程注入、文件創建、DNS查詢和LKM載入等行為設置了鉤子,並且通過兼容Linux命名空間來對容器環境進行監控。 2、用戶棧模組實用工具內置了檢測功能,其中包括系統用戶列表查詢、系統埠監聽列表查詢、系統RPM LIST查詢和系統定時任務查詢。 3、AntiRootKit,基於Tyton實現,目前已經移植了PROC_FILE_HOOK、SYSCALL_HOOK、LKM_HIDDEN和INTERRUPTS_HOOK,目前僅支援Kernel > 3.10。 4、cred 變化檢測 (sudo/su/sshd除外) 5、用戶登陸監控

內核版本兼容性

Kernel > 2.6.25

AntiRootKit > 3.10

容器兼容性

行為源

節點名稱

Host

主機名

Docker

容器名

k8s

POD名

AgentSmith-HIDS的組成部分

1、內核驅動模組(LKM),通過Kprobe掛鉤關鍵函數,完成數據捕獲; 2、用戶態代理,接收驅動捕獲的指令並進行處理,然後將數據發送給Kafka;並向伺服器端發送heartbeat包來進行確認,然後接收並執行伺服器發送的指令; 3、代理伺服器(可選組件),向代理髮送控制指令,查看當前代理的狀態和數量等資訊;

Execve鉤子

通過掛鉤sys_execve()/sys_execveat()/compat_sys_execve()/compat_sys_execveat() 實現,使用樣例如下:

{      "uid":"0",      "data_type":"59",      "run_path":"/opt/ltp/testcases/bin/growfiles",      "exe":"/opt/ltp/testcases/bin/growfiles",      "argv":"growfiles -W gf26 -D 0 -b -i 0 -L 60 -u -B 1000b -e 1 -r 128-32768:128 -R 512-64000 -T 4 -f gfsmallio-35861 -d /tmp/ltp-Ujxl8kKsKY ",      "pid":"35861",      "ppid":"35711",      "pgid":"35861",      "tgid":"35861",      "comm":"growfiles",      "nodename":"test",      "stdin":"/dev/pts/1",      "stdout":"/dev/pts/1",      "sessionid":"3",      "dip":"192.168.165.1",      "dport":"61726",      "sip":"192.168.165.128",      "sport":"22",      "sa_family":"1",      "pid_tree":"1(systemd)->1384(sshd)->2175(sshd)->2177(bash)->2193(fish)->35552(runltp)->35711(ltp-pan)->35861(growfiles)",      "tty_name":"pts1",      "socket_process_pid":"2175",      "socket_process_exe":"/usr/sbin/sshd",      "SSH_CONNECTION":"192.168.165.1 61726 192.168.165.128 22",      "LD_PRELOAD":"/root/ldpreload/test.so",      "user":"root",      "time":"1579575429143",      "local_ip":"192.168.165.128",      "hostname":"test",      "exe_md5":"01272152d4901fd3c2efacab5c0e38e5",      "socket_process_exe_md5":"686cd72b4339da33bfb6fe8fb94a301f"  }

鏈接鉤子

通過掛鉤sys_connect() 實現,使用樣例如下:

{      "uid":"0",      "data_type":"42",      "sa_family":"2",      "fd":"4",      "dport":"1025",      "dip":"180.101.49.11",      "exe":"/usr/bin/ping",      "pid":"6294",      "ppid":"1941",      "pgid":"6294",      "tgid":"6294",      "comm":"ping",      "nodename":"test",      "sip":"192.168.165.153",      "sport":"45524",      "res":"0",      "sessionid":"1",      "user":"root",      "time":"1575721921240",      "local_ip":"192.168.165.153",      "hostname":"test",      "exe_md5":"735ae70b4ceb8707acc40bc5a3d06e04"  }

DNS查詢鉤子

通過掛鉤sys_recvfrom() 實現,使用樣例如下:

{      "uid":"0",      "data_type":"601",      "sa_family":"2",      "fd":"4",      "dport":"53",      "dip":"192.168.165.2",      "exe":"/usr/bin/ping",      "pid":"6294",      "ppid":"1941",      "pgid":"6294",      "tgid":"6294",      "comm":"ping",      "nodename":"test",      "sip":"192.168.165.153",      "sport":"53178",      "qr":"1",      "opcode":"0",      "rcode":"0",      "query":"www.baidu.com",      "sessionid":"1",      "user":"root",      "time":"1575721921240",      "local_ip":"192.168.165.153",      "hostname":"test",      "exe_md5":"39c45487a85e26ce5755a893f7e88293"  }

文件創建鉤子

通過掛鉤security_inode_create() 實現,使用樣例如下:

{      "uid":"0",      "data_type":"602",      "exe":"/usr/lib/jvm/java-1.8.0-openjdk-1.8.0.232.b09-0.el7_7.x86_64/jre/bin/java",      "file_path":"/tmp/kafka-logs/replication-offset-checkpoint.tmp",      "pid":"3341",      "ppid":"1",      "pgid":"2657",      "tgid":"2659",      "comm":"kafka-scheduler",      "nodename":"test",      "sessionid":"3",      "user":"root",      "time":"1575721984257",      "local_ip":"192.168.165.153",      "hostname":"test",      "exe_md5":"215be70a38c3a2e14e09d637c85d5311",      "create_file_md5":"d41d8cd98f00b204e9800998ecf8427e"  }

進程注入鉤子

通過掛鉤sys_ptrace()實現,使用樣例如下:

{      "uid":"0",      "data_type":"101",      "ptrace_request":"4",      "target_pid":"7402",      "addr":"00007ffe13011ee6",      "data":"-a",      "exe":"/root/ptrace/ptrace",      "pid":"7401",      "ppid":"1941",      "pgid":"7401",      "tgid":"7401",      "comm":"ptrace",      "nodename":"test",      "sessionid":"1",      "user":"root",      "time":"1575722717065",      "local_ip":"192.168.165.153",      "hostname":"test",      "exe_md5":"863293f9fcf1af7afe5797a4b6b7aa0a"  }

LKM文件載入鉤子

通過掛鉤load_module()實現,使用樣例如下:

{      "uid":"0",      "data_type":"603",      "exe":"/usr/bin/kmod",      "lkm_file":"/root/ptrace/ptrace",      "pid":"29461",      "ppid":"9766",      "pgid":"29461",      "tgid":"29461",      "comm":"insmod",      "nodename":"test",      "sessionid":"13",      "user":"root",      "time":"1577212873791",      "local_ip":"192.168.165.152",      "hostname":"test",      "exe_md5":"0010433ab9105d666b044779f36d6d1e",      "load_file_md5":"863293f9fcf1af7afe5797a4b6b7aa0a"  }

Cred修改鉤子

通過掛鉤commit_creds()實現,使用樣例如下:

{      "uid":"0",      "data_type":"604",      "exe":"/tmp/tt",      "pid":"27737",      "ppid":"26865",      "pgid":"27737",      "tgid":"27737",      "comm":"tt",      "old_uid":"1000",      "nodename":"test",      "sessionid":"42",      "user":"root",      "time":"1578396197131",      "local_ip":"192.168.165.152",      "hostname":"test",      "exe_md5":"d99a695d2dc4b5099383f30964689c55"  }

用戶登錄警報

{      "data_type":"1001",      "status":"Failed",      "type":"password",      "user_exsit":"false",      "user":"sad",      "from_ip":"192.168.165.1",      "port":"63089",      "processor":"ssh2",      "time":"1578405483119",      "local_ip":"192.168.165.128",      "hostname":"localhost.localdomain"  }

PROC文件鉤子警報

{      "uid":"-1",      "data_type":"700",      "module_name":"autoipv6",      "hidden":"0",      "time":"1578384987766",      "local_ip":"192.168.165.152",      "hostname":"test"  }

系統調用鉤子警報

{      "uid":"-1",      "data_type":"701",      "module_name":"diamorphine",      "hidden":"1",      "syscall_number":"78",      "time":"1578384927606",      "local_ip":"192.168.165.152",      "hostname":"test"  }

LKM隱藏警告

{      "uid":"-1",      "data_type":"702",      "module_name":"diamorphine",      "hidden":"1",      "time":"1578384927606",      "local_ip":"192.168.165.152",      "hostname":"test"  }

攔截鉤子警報

{      "uid":"-1",      "data_type":"703",      "module_name":"syshook",      "hidden":"1",      "interrupt_number":"2",      "time":"1578384927606",      "local_ip":"192.168.165.152",      "hostname":"test"  }

性能測試

測試環境

CPU

Intel(R) Core(TM) i7-4870HQ CPU @ 2.50GHz 雙核

RAM

2GB

OS/Kernel

Centos7 / 3.10.0-1062.7.1.el7.x86_64

測試結果

鉤子處理器

平均延遲(us)

execve_entry_handler

10.4

connect_handler

7.5

connect_entry_handler

0.06

recvfrom_handler

9.2

recvfrom_entry_handler

0.17

fsnotify_post_handler

0.07

許可證協議

本項目的開發與發布遵循GNU GPLv2開源許可證協議。

項目地址

AgentSmith-HIDS:【點擊底部閱讀原文查看】

* 參考來源:EBWi11,FB小編Alpha_h4ck編譯,轉載請註明來自FreeBuf.COM