简体   繁体   English

审计实时事件处理C / C ++

[英]auditd real-time events processing C/C++

I'm trying to write a process in C/C++ that will analyze auditd events in real time. 我正在尝试用C / C ++编写一个过程来实时分析审计事件。

Currently, I'm using the af_unix plugin to read the audit events from Unix socket ( /var/run/audisp_events by default). 目前,我正在使用af_unix插件从Unix套接字读取审计事件(默认情况下为/var/run/audisp_events )。

I tried using select() , recv() to consume the events from the socket like this: 我尝试使用select()recv()来使用套接字中的事件,如下所示:

select(FD_SETSIZE, &set, NULL, NULL, NULL);
recv(sockfd, message, size, MSG_DONTWAIT);

And then sending to auparse callback to parse the buffer similer to this example : 然后发送到auparse回调来解析缓冲区similer到这个例子

auparse_feed(au, buf, (size_t)len);
auparse_flush_feed(au);

The issue here is that auditd events can be multi-records events (like SYSCALL) and use the recv() only consume some of the records and not all of them, so in the parsing callback, I don't have all the information. 这里的问题是审计事件可以是多记录事件(如SYSCALL),并且使用recv()只消耗一些记录而不是所有记录,因此在解析回调中,我没有所有信息。

Then I tried using getline() to consume one record at a time but I still cannot tell if the record is one record event or muli-records events. 然后我尝试使用getline()使用一条记录,但我仍然无法判断记录是一个记录事件还是多个记录事件。

After reading the auditd documentation here , I found this: EOE Triggered to record the end of a multi-record event. 这里阅读审计文档后,我发现: EOE Triggered to record the end of a multi-record event. I can use this to know when to stop consuming (because getline() is a blocking operation) but the EOE event only exists in multi-records events. 我可以用它来知道何时停止消费(因为getline()是一个阻塞操作)但EOE事件只存在于多记录事件中。

My questions are: 我的问题是:

  • Is using af_unix plugin is the best way to consume auditd events in real-time? 使用af_unix插件是实时消费审计事件的最佳方式吗?
  • Is there any way to know from the record information if this is a multi-records event? 有没有办法从记录信息中知道这是多记录事件? if no, is there any documentation on what events are multi-records events? 如果没有,是否有关于哪些事件是多记录事件的文档?

You should use an Audit Dispatcher (audisp) plugin for this. 您应该使用Audit Dispatcher(audisp)插件。

Here are some resources: 以下是一些资源:

For the number of records in an event, call auparse_get_num_records . 对于事件中的记录数,请调用auparse_get_num_records

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM