Introduce generic analyzer_confirmation_info and analyzer_violation_info

Introduce two new events for analyzer confirmation and analyzer violation
reporting. The current analyzer_confirmation and analyzer_violation
events assume connection objects and analyzer ids are available which
is not always the case. We're already passing aid=0 for packet analyzers
and there's not currently a way to report violations from file analyzers
using analyzer_violation, for example.

These new events use an extensible Info record approach so that additional
(optional) information can be added later without changing the signature.
It would allow for per analyzer extensions to the info records to pass
analyzer specific info to script land. It's not clear that this would be
a good idea, however.

The previous analyzer_confirmation and analyzer_violation events
continue to exist, but are deprecated and will be removed with Zeek 6.1.
This commit is contained in:
Arne Welzel 2022-09-27 15:11:01 +02:00
parent 2e58d6a1a9
commit bc8fd5a4c6
24 changed files with 456 additions and 77 deletions

View file

@ -166,6 +166,22 @@ void Analyzer::Weird(const char* name, Packet* packet, const char* addl) const
session_mgr->Weird(name, packet, addl, GetAnalyzerName());
}
void Analyzer::EnqueueAnalyzerConfirmationInfo(session::Session* session, const zeek::Tag& arg_tag)
{
static auto info_type = zeek::id::find_type<RecordType>("AnalyzerConfirmationInfo");
static auto info_c_idx = info_type->FieldOffset("c");
auto info = make_intrusive<RecordVal>(info_type);
info->Assign(info_c_idx, session->GetVal());
event_mgr.Enqueue(analyzer_confirmation_info, arg_tag.AsVal(), info);
}
void Analyzer::EnqueueAnalyzerConfirmation(session::Session* session, const zeek::Tag& arg_tag)
{
event_mgr.Enqueue(analyzer_confirmation, session->GetVal(), arg_tag.AsVal(), val_mgr->Count(0));
}
void Analyzer::AnalyzerConfirmation(session::Session* session, zeek::Tag arg_tag)
{
const auto& effective_tag = arg_tag ? arg_tag : GetAnalyzerTag();
@ -175,25 +191,34 @@ void Analyzer::AnalyzerConfirmation(session::Session* session, zeek::Tag arg_tag
session->SetAnalyzerState(effective_tag, session::AnalyzerConfirmationState::CONFIRMED);
if ( ! analyzer_confirmation )
return;
if ( analyzer_confirmation_info )
EnqueueAnalyzerConfirmationInfo(session, effective_tag);
event_mgr.Enqueue(analyzer_confirmation, session->GetVal(), effective_tag.AsVal(),
val_mgr->Count(0));
if ( analyzer_confirmation )
EnqueueAnalyzerConfirmation(session, effective_tag);
}
void Analyzer::AnalyzerViolation(const char* reason, session::Session* session, const char* data,
int len, zeek::Tag arg_tag)
void Analyzer::EnqueueAnalyzerViolationInfo(session::Session* session, const char* reason,
const char* data, int len, const zeek::Tag& arg_tag)
{
const auto& effective_tag = arg_tag ? arg_tag : GetAnalyzerTag();
static auto info_type = zeek::id::find_type<RecordType>("AnalyzerViolationInfo");
static auto info_reason_idx = info_type->FieldOffset("reason");
static auto info_c_idx = info_type->FieldOffset("c");
static auto info_data_idx = info_type->FieldOffset("data");
session->SetAnalyzerState(effective_tag, session::AnalyzerConfirmationState::VIOLATED);
auto info = zeek::make_intrusive<RecordVal>(info_type);
info->Assign(info_reason_idx, make_intrusive<StringVal>(reason));
info->Assign(info_c_idx, session->GetVal());
if ( data && len )
info->Assign(info_data_idx, make_intrusive<StringVal>(len, data));
if ( ! analyzer_violation )
return;
event_mgr.Enqueue(analyzer_violation_info, arg_tag.AsVal(), info);
}
void Analyzer::EnqueueAnalyzerViolation(session::Session* session, const char* reason,
const char* data, int len, const zeek::Tag& arg_tag)
{
StringValPtr r;
if ( data && len )
{
const char* tmp = util::copy_string(reason);
@ -204,8 +229,22 @@ void Analyzer::AnalyzerViolation(const char* reason, session::Session* session,
else
r = make_intrusive<StringVal>(reason);
event_mgr.Enqueue(analyzer_violation, session->GetVal(), effective_tag.AsVal(),
val_mgr->Count(0), std::move(r));
event_mgr.Enqueue(analyzer_violation, session->GetVal(), arg_tag.AsVal(), val_mgr->Count(0),
std::move(r));
}
void Analyzer::AnalyzerViolation(const char* reason, session::Session* session, const char* data,
int len, zeek::Tag arg_tag)
{
const auto& effective_tag = arg_tag ? arg_tag : GetAnalyzerTag();
session->SetAnalyzerState(effective_tag, session::AnalyzerConfirmationState::VIOLATED);
if ( analyzer_violation_info )
EnqueueAnalyzerViolationInfo(session, reason, data, len, effective_tag);
if ( analyzer_violation )
EnqueueAnalyzerViolation(session, reason, data, len, effective_tag);
}
} // namespace zeek::packet_analysis