From 3efeef969ebc344c993ce0fc46f557c7d8560525 Mon Sep 17 00:00:00 2001 From: We-unite <3205135446@qq.com> Date: Wed, 31 Jul 2024 11:46:01 +0800 Subject: Use netlink connector to recv pid info, fix exec For some reasons, kernel-connector can catch exec event, but it doesn't tell me about what the process exec and what're its args. So we should use audit to collect these infomations, and complete in the database. However, there's different delays between connector and audit, although they both use netlink socket, as a result of which, exec may comes before fork. we deal with it the same way. But, there's also exec event lost, may because of the check for ppid in exec event, but it's necessary, and if is deleted, too much irrelavent infomation would flood into database, i've tried. So make it there, just go forward. Besides, what's newly discovered is that pthread_create also use clone syscall, but if pid 1 has a thread 2, the exec info will say that pid 2 execs. So i shouldn't ignore connector msg that childPid ne childTgid. This is my first attempt to use git-submodule function in my own pro- ject, also golang local package. Congratulations! Now, fight to fix about file operations. Hope that there wouldn't be too many fucking bugs. --- src/deal.go | 30 +++++++++++++++++------------- 1 file changed, 17 insertions(+), 13 deletions(-) (limited to 'src/deal.go') diff --git a/src/deal.go b/src/deal.go index 717344c..3119fff 100644 --- a/src/deal.go +++ b/src/deal.go @@ -98,12 +98,15 @@ func deletePid(cooked Event) { "$set": bson.M{ "exit_timestamp": cooked.timestamp, "exit_code": cooked.exit_code, + "exit_signal": cooked.exit_signal, }, }) mongoMutex.Unlock() + fmt.Printf("Exit: %v\t%6d\t%6d\n", cooked.timestamp, cooked.pid, cooked.exit_code) } func dealNewPid(cooked Event) { + fmt.Printf("Fork: %v\t%6d\t%6d\n", cooked.timestamp, cooked.ppid, cooked.pid) // 有无父进程在观察中 docRes, err = pidCol.Finddoc(bson.M{"pid": cooked.ppid}) if err != nil || len(docRes) != 1 { @@ -153,6 +156,7 @@ func dealNewPid(cooked Event) { } func dealExecve(cooked Event) { + fmt.Printf("EXEC: %6d\t%6d\n", cooked.ppid, cooked.pid) // 父进程在不在?不在扔 docRes, err = pidCol.Finddoc(bson.M{"pid": cooked.ppid}) if err != nil || len(docRes) != 1 { @@ -175,19 +179,19 @@ func dealExecve(cooked Event) { }, }, }) - // } else { - // // 先fork抵达,插入 - // pidCol.InsertOne(bson.M{ - // "ppid": cooked.ppid, - // "pid": cooked.pid, - // "children": []bson.M{}, - // "execve": []bson.M{ - // { - // "timestamp": cooked.timestamp, - // "execArgs": cooked.argv, - // }, - // }, - // }) + } else { + // 先fork抵达,插入 + pidCol.InsertOne(bson.M{ + "ppid": cooked.ppid, + "pid": cooked.pid, + "children": []bson.M{}, + "execve": []bson.M{ + { + "timestamp": cooked.timestamp, + "execArgs": cooked.argv, + }, + }, + }) } mongoMutex.Unlock() } -- cgit v1.2.3-70-g09d2