如何从 linux 内核中提取特征?

How to extract features from linux kernel?

我正在从事一个基于机器学习技术检测恶意软件的项目。我的主要目标是 linux 台设备。我的第一个问题是;

  1. 如何使用内核驱动程序从 linux 内核中提取有关进程的数据? 我想第一次自己提取有关 运行 进程的数据,只是为了概念验证。稍后我想编写一个内核驱动程序来自动实时地执行此操作。
  2. 是否有任何其他方法可以提取 运行 进程的数据,例如 ProcessName、PID、UID、IS_ROOT 等?

用户 space 执行此操作:

ps -U <username/UID> | tr -s ' '| tr ' ' ','| cut -d ',' -f2,5 > out.csv

来自内核 space,作为模块:

#include <linux/init.h>
#include <linux/kernel.h>
#include <linux/module.h>
#include <linux/sched.h>

static int uid=0;

static int procx_init(void){
    struct task_struct *task;
    for_each_process(task)
            printk ("uid=%d, pid=%d, command=%s\n", task->cred->uid, task->pid, task->comm);
    return 0;
}
static void procx_exit(void)
{
    printk("procx destructor\n");
}
module_init(procx_init);
module_exit(procx_exit);
module_param(uid, int, 0);

MODULE_AUTHOR ("sundeep471@gmail.com");
MODULE_DESCRIPTION ("Print process Info");
MODULE_LICENSE("GPL");

我没有检查 UID,但您可以将其作为模块参数或运行时传递程序传递以触发 kthread