Giter Club home page Giter Club logo

agentsmith-hids's Introduction

AgentSmith-HIDS

                        --The name of this project was inspired by the movie - The Matrix

License Project Status: Active – The project has reached a stable, usable state and is being actively developed.

English | 简体中文

THIS REPO IS OLD

About AgentSmith-HIDS

Technically, AgentSmith-HIDS is not a Host-based Intrusion Detection System (HIDS) due to lack of rule engine and detection function. However, it can be used as a high performance 'Host Information Collect Agent' as part of your own HIDS solution. The comprehensiveness of information which can be collected by this agent was one of the most important metrics during developing this project, hence it was built to function in the kernel stack and achieve huge advantage comparing to those function in user stack, such as:

  • Better performance, Information needed are collected in kernel stack to avoid additional supplement actions such as traversal of '/proc'; and to enhance the performance of data transportation, data collected is transferred via shared ram instead of netlink.
  • Hard to be bypassed, Information collection was powered by specifically designed kernel drive, makes it almost impossible to bypass the detection for malicious software like rootkit, which can deliberately hide themselves.
  • Easy to be integrated,The AgentSmith-HIDS was built to integrate with other applications and can be used not only as security tool but also a good monitoring tool, or even a good detector of your assets. The agent is capable of collecting the users, files, processes and internet connections for you, so let's imagine when you integrate it with CMDB, you could get a comprehensive map consists of your network, host, container and business (even dependencies). What if you also have a Database audit tool at hand? The map can be extended to contain the relationship between your DB, DB User, tables, fields, applications, network, host and containers etc. Thinking of the possibility of integration with network intrusion detection system and/or threat intelligence etc., higher traceability could also be achieved. It just never gets old.
  • Kernel stack + User stack,AgentSmith-HIDS also provide user stack module, to further extend the functionality when working with kernel stack module.

Major abilities of AgentSmith-HIDS:

  • Kernel stack module hooks execve, connect, process inject, create file, DNS query, load LKM behaviors via Kprobe,and is also capable of monitoring containers by being compatible with Linux namespace.
  • User stack module utilize built in detection functions including queries of User ListListening ports listSystem RPM listSchedule jobs
  • AntiRootkit,From: Tyton ,for now add PROC_FILE_HOOKSYSCALL_HOOKLKM_HIDDENINTERRUPTS_HOOK feature,but only wark on Kernel > 3.10.
  • Cred Change monitoring (sudo/su/sshd except)
  • User Login monitoring

Usage scenarios/methods of AgentSmith-HIDS (to be added)

About the compatibility with Kernel version

  • Kernel > 2.6.25
  • AntiRootKit > 3.10

About the compatibility with Containers

Source Nodename
Host hostname
Docker container name
k8s pod name

Composition of AgentSmith-HIDS

  • Kernel stack module (LKM) Hook key functions via Kprobe to capture information needed.
  • User stack module Collect data capatured by kernel stack module, perform necessary process and send it to Kafka; Keep sending heartbeat packet to server so process integrity can be identitied; Execute commands received from server.
  • Agent Server(Optional) Send commands to user stack module and monitoring the status of user stack module.

Execve Hook

Achieved by hooking sys_execve()/sys_execveat()/compat_sys_execve()/compat_sys_execveat(), example:

{
    "uid":"0",
    "data_type":"59",
    "run_path":"/tmp",
    "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",
    "sip":"192.168.165.1",
    "sport":"61726",
    "dip":"192.168.165.128",
    "dport":"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"
}

Bind Hook

Achieved by hooking sys_bind(), example:

{
    "uid":"0",
    "data_type":"49",
    "sa_family":"2",
    "exe":"/usr/bin/python2.7",
    "pid":"109640",
    "ppid":"215496",
    "pgid":"109640",
    "tgid":"109640",
    "comm":"python",
    "nodename":"n225-117-018",
    "sip":"0.0.0.0",
    "sport":"8000",
    "res":"0",
    "sessionid":"30",
    "user":"root",
    "time":"1587540231936",
    "local_ip_str":"10.225.117.18",
    "hostname_str":"n225-117-018",
    "exe_md5":"4f458165a2129ba549f1b6605ee87e74"
}

Connect Hook

Achieved by hooking tcp_v4_connect()/tcp_v6_connect()/ip4_datagram_connect()/ip6_datagram_connect(), example:

{
    "uid":"0",
    "data_type":"42",
    "sa_family":"2",
    "connect_type":"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 Query Hook

Achieved by hooking udp_recvmsg()/udpv6_recvmsg(), example:

{
    "uid":"0",
    "data_type":"601",
    "sa_family":"2",
    "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"
}

Create File Hook

Achieved by hooking security_inode_create(), example:

{
    "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"
}

Process Inject Hook

Achieved by hooking sys_ptrace(), example:

{
    "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"
}

Load LKM File Hook

Achieved by hooking load_module(), example:

{
    "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 Change Hook

Achieved by Hook commit_creds(),example:

{
    "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"
}

User Login Alert

{
    "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 File Hook Alert

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

Syscall Hook Alert

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

LKM Hidden Alert

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

Interrupts Hook Alert

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

About Performance of AgentSmith-HIDS

Testing Environment(VM):

CPU Intel(R) Xeon(R) Platinum 8260 CPU @ 2.40GHz 4Core
RAM 8GB
OS/Kernel Debian9 / 4.14.81.bm.19-amd64

Testing Load:

ltp -f syscalls

Testing Result(1min):

Hook Handler Average Delay(us) TP99(us) TP95(us) TP90(us)
connect_entry_handler 0.2914 6.7627 0.355 0.3012
connect_handler 2.1406 18.3801 12.102 7.832
execve_entry_handler 5.9320 13.7034 9.908 8.334
execve_handler 6.8826 26.0584 15.9976 12.6260
security_inode_create_entry_handler 1.9963 9.3042 6.7730 4.6816
security_inode_create_handler 4.2114 13.2165 8.83775 6.534

Original Testing Data:

Benchmark Data

cyclictest testing

cyclictest -p 90 - m -c 0 -i 200 -n -h 100 -q -l 1000000

Uninstall Smith:

# Total: 000999485
# Min Latencies: 00002
# Avg Latencies: 00007
# Max Latencies: 13905
# Histogram Overflows: 00515

install Smith:

# Total: 000999519
# Min Latencies: 00002
# Avg Latencies: 00007
# Max Latencies: 15216
# Histogram Overflows: 00481

time -v /opt/ltp/testcases/bin/execve05 -n 30000

10 times

Install Smith:

Average User Time(s) Average System Time(s)
22.329 14.885

Uninstall Smith:

Average User Time(s) Average System Time(s)
22.271 14.395

Documents for deployment and testing purpose:

Quick Start

Special Thanks(Not in order)

yuzunzhi

hapood

HF-Daniel

smcdef

Wechat of developer

Wechat channel of '灾难控制局'

We would constantly provide information about the functionalities of AgentSmith-HIDS via this channel, a good place to receive the most updated news:)

License

AgentSmith-HIDS kernel module are distributed under the GNU GPLv2 license.

agentsmith-hids's People

Contributors

afei-d avatar alkenepan avatar ebwi11 avatar hf-daniel avatar qqlover avatar shelterz avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

agentsmith-hids's Issues

HeartBeat 不稳定

AgentSmith-HIDS的HeartBeat方案在未知情况下会出现HeartBeat线程退出的情况,难以稳定复现,正在全力排查

提个建议不定时更新

1、hook方式兼容性和稳定性太弱了,哪怕你换成ftrace方式也不错。

2、agent是需要考虑兼容性的,采用golang的话golang本身是需要epoll等接口支持的,所以你这样就得放弃一部分系统平台了。这块建议用C来做。

驱动在Ubuntu下编译出错

好像驱动不兼容Ubuntu,make编译出错
版本信息:
Linux version 4.4.0-116-generic (buildd@lgw01-amd64-021) (gcc version 5.4.0 20160609 (Ubuntu 5.4.0-6ubuntu1~16.04.9) ) #140-Ubuntu SMP Mon Feb 12 21:23:04 UTC 2018

关于AgentSmith-HIDS后续迭代的问题

(该issue是AgentSmith-HIDS作者所提,旨在能和大家保持一定的沟通,听取反馈,长期有效)

  1. 有一部分同学表示用户态Agent使用Rust导致一定难度,无法参与到新功能的研发中,调试也有一定困难,希望可以用GoLang替换。笔者也一部分认同该观点,且目前而言重构用户态Agent的工作还算简单,但是Rust作为一门无GC且内存安全的未来的系统级语言来说,还是有一定的优势的。不知道其他的小伙伴如何看待?
  2. 大家希望AgentSmith-HIDS什么在未来优先级较高的功能呢?可以留言交流。
  3. 有多少小伙伴使用AgentSmith-HIDS呢?是否在这个过程中遇到什么问题?无论是部署/测试/功能的问题,都欢迎提出来。

最后,个人以为,把README读完再进行提问应该是对他人时间的起码的尊重,你认为呢?

关于反弹shell及生产环境部署安全性问题

AgentSmith-HIDS 的定位就是一款轻量级,高性能的情报采集工具,首先可以检测如:反弹shell,执行可以命令,下载恶意程序,一些Rootkit等等NIDS的死角。其次可以和NIDS/CMDB完成联动,达到:PID+PPID+nodename+cmdline+cwd+user+exe+TCP/UDP五元组+部分协议的原始数据+业务相关信息+FW_RULE+NIDS/HIDS规则ID+威胁情报信息的联动效果。

初步看了下代码
https://github.com/DianrongSecurity/AgentSmith-HIDS/blob/master/agent/src/main.rs#L84

目前agent大致逻辑是解析syscall直接发送到kafka

这个目前elastic已经有一个类似的项目叫auditbeat,实现的也是类似效果
https://www.elastic.co/guide/en/beats/auditbeat/current/auditbeat-installation.html

相关建议

  • 不建议生产环境中 agent数据投递不经鉴权直接投递kakfa,如果黑客入侵一台机器,就可以伪造消息,而且可以攻击数据接收服务器
  • 反弹shell的逻辑建议在本地agent进行检测,直接关联进程及socket信息, 本地检测速度快,我们这边经实际攻防测试,能检测绝大多数的反弹shell, syscall 和nids关联听起来很美,但如果机器数量多的话,实际数据量极大,不具备可行性。

参考链接

关于性能测试及资源占用控制

https://github.com/DianrongSecurity/AgentSmith-HIDS/blob/master/doc/AgentSmith-HIDS%20Hook%20Design%20BencheMark(Netlink).md

由于 hook的是系统调用,wrk是web的benchmark工具,个人觉得不能很好的反映实际对系统影响

我们这边测试 audit由于会filter系统调用,相关影响和应用产生的系统调用次数有关,每秒20次系统调用的话,会有5%的延迟增加,

测试方法
从/dev/zero中读取500个字节数据并写入到/dev/null中,循环执行1亿次(也就是100M):

dd if=/dev/zero of=/dev/null bs=500 count=100M

该脚本会产生大约2亿次系统调用(read 1亿次,write 1亿次)。

测试目标 总耗时(s) 延迟影响 平均耗时(μs)
不加任何事件监听 42.3224   0.2116
auditd 47.6929 +12.68% 0.2385

另外你们是怎么做agent资源控制的?避免影响机器上的业务?

具体思路可以参考以下文章

insmod smith.ko 报错 Unknown symbol __check_object_size

  1. 系统 centos 7
  2. 内核版本 3.10.0-862.el7.x86_64

dmesg 结果:
[38272942.059519] smith: loading out-of-tree module taints kernel.
[38272942.065264] smith: module verification failed: signature and/or required key missing - tainting kernel
[38272942.066388] smith: Unknown symbol __check_object_size (err 0)
[38273001.870752] smith: Unknown symbol __check_object_size (err 0)
[38273178.720850] smith: Unknown symbol __check_object_size (err 0)
[38273997.969412] smith: Unknown symbol __check_object_size (err 0)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.