Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce generic analyzer_confirmation_info and analyzer_violation_info #2390

Merged
merged 5 commits into from
Sep 28, 2022

Conversation

awelzel
Copy link
Contributor

@awelzel awelzel commented Aug 31, 2022

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, they are invoked from script-land using the new
analyzer_confirmation_info and analyzer_violation_info events.

The last point yields to a subtle change of behavior visible in some of
the disable-analyzer tests: As the old events are now scheduled from
script-land now, they may be raised after protocol specific events have
been processed already. I presume if that matters to someone we can ask
them to use the new event.

@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch 2 times, most recently from a987c84 to 691c2d8 Compare August 31, 2022 15:10
@awelzel
Copy link
Contributor Author

awelzel commented Aug 31, 2022

Related to #2031

@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch 2 times, most recently from 9eef898 to daf9b9f Compare September 1, 2022 11:20
@awelzel
Copy link
Contributor Author

awelzel commented Sep 1, 2022

Adding this here for thoughts: @ckreibich mentioned that an analyzer_not_implemented or analyzer_todo event came up in discussions with @vpax (?) to raise information from an analyzers to script land for parts of a protocol that just hasn't been done (rather than using weird or debug logging).

I'm wondering a bit if that would be worth considering a very generic analyzer_event_info and funneling confirm/violation/todo through that. But I don't think it is - having discrete events seems more sensible and common.

@vpax
Copy link
Contributor

vpax commented Sep 1, 2022

Adding this here for thoughts: @ckreibich mentioned that an analyzer_not_implemented or analyzer_todo event came up in discussions with @vpax (?) to raise information from an analyzers to script land for parts of a protocol that just hasn't been done (rather than using weird or debug logging).

I don't recall that. That said, it makes sense to me, and as you then comment, I think it also makes sense to keep the events discrete, rather than bundled.

@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch 2 times, most recently from 0961cdc to 174b4ed Compare September 2, 2022 15:23
@rsmmr rsmmr self-assigned this Sep 6, 2022
@rsmmr
Copy link
Member

rsmmr commented Sep 7, 2022

I looked over this high-level: I like the approach with the two new events and passing them records with fields set as a available. I'll go over in more detail but one question: What's the plan for the existing events? This code keeps triggering them, but doesn't deprecate. I think I'd do deprecate and then phase them out over time.

Also wondering if we should keep triggering the old ones from C++ so that we don't change timing for them. While for most events this wouldn't be an issue, I can see it for analyzer_violation that the order may impact something.

@awelzel
Copy link
Contributor Author

awelzel commented Sep 7, 2022

I looked over this high-level: I like the approach with the two new events and passing them records with fields set as a available. I'll go over in more detail but one question: What's the plan for the existing events? This code keeps triggering them, but doesn't deprecate. I think I'd do deprecate and then phase them out over time.

Okay. I had intended to keep them and even thought of introducing a file_analyzer_violation(...) based off the generic events, but seems you're leaning in the other direction. One other motivating factor for not deprecating them was that we just deprecated protocol_violation and introduced analyzer_violation as replacement, and now we're deprecating them again. But, oh well I guess ;-)

Also wondering if we should keep triggering the old ones from C++ so that we don't change timing for them. While for most events this wouldn't be an issue, I can see it for analyzer_violation that the order may impact something.

Yep, okay. I actually ran into the timing issue for the "dpd segement logging" script which gets the current packet, but that already had a comment that it might not be doing the right thing. If we go for deprecation of those event, I wouldn't mind continuing to have the C++ layer raise the events. If we weren't deprecating, that would feel a bit duplicated..

I'll address both as follow-up commits, but will probably rebase once #2379 is in. Maybe better to wait before you look closer?

@rsmmr
Copy link
Member

rsmmr commented Sep 7, 2022

Okay. I had intended to keep them and even thought of introducing a file_analyzer_violation(...) based off the generic events, but seems you're leaning in the other direction.

Yeah, that would get confusing I think.

One other motivating factor for not deprecating them was that we just deprecated protocol_violation and introduced >analyzer_violation as replacement, and now we're deprecating them again.

Yeah, I know, but I'd rather work towards where we want to be eventually, even if that means changing again.

I'd actually prefer to call the new events analyzer_confirmation/violation as well, just with different arguments. But I don't see how we'd get there without breaking existing scripts.

I'll address both as follow-up commits, but will probably rebase once #2379 is in. Maybe better to wait before you look closer?

Ack.

@rsmmr rsmmr removed their assignment Sep 8, 2022
@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch from 174b4ed to d62c0f3 Compare September 8, 2022 16:47
scripts/base/frameworks/analyzer/dpd.zeek Show resolved Hide resolved
scripts/base/init-bare.zeek Outdated Show resolved Hide resolved
scripts/base/init-bare.zeek Show resolved Hide resolved
scripts/base/init-bare.zeek Show resolved Hide resolved
scripts/base/init-bare.zeek Outdated Show resolved Hide resolved
src/file_analysis/analyzer/pe/PE.cc Show resolved Hide resolved
src/packet_analysis/Analyzer.cc Outdated Show resolved Hide resolved
src/packet_analysis/Analyzer.cc Outdated Show resolved Hide resolved
scripts/base/frameworks/analyzer/dpd.zeek Show resolved Hide resolved
@awelzel
Copy link
Contributor Author

awelzel commented Sep 19, 2022

@rsmmr - I've pushed a few more fixups. I'd rebase on top of master and squash it down and we could possibly chat with this is Zeek 5.1 or 5.2 material. It might be nice to have it in 5.1 as a stepping-stone.

@rsmmr
Copy link
Member

rsmmr commented Sep 26, 2022

Sorry, too late now for 5.1, but yeah, go ahead and rebase on master and then I'll take another look and we can wrap it up.

@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch from a38d3a2 to 9bb99e6 Compare September 26, 2022 13:26
@awelzel
Copy link
Contributor Author

awelzel commented Sep 26, 2022

Sorry, too late now for 5.1, but yeah, go ahead and rebase on master and then I'll take another look and we can wrap it up.

@rsmmr - I have rebased, squashed and added the "violation only once for packet analyzers" change we talked about.

Let me know if something looks off to you.

@awelzel awelzel requested a review from rsmmr September 26, 2022 13:27
@awelzel
Copy link
Contributor Author

awelzel commented Sep 26, 2022

I had looked at analyzer_confirmation/violation a bit more.

  • Found packet_analysis: Do not raise analyzer_confirmation per-packet for tunnels #2437 while there. This will conflict with this branch so can also fold it in here if you'd prefer, but could also see it back-port worthy.

  • The analyzer/dpd.zeek script within master can currently be tricked into calling disable_analyzer() with a packet analyzers tag and tunnel connections that will have no effect.

  • In the same area one can also trigger a dpd.log for every other vxlan packet in a connection by interleaving good and corrupted packets. It's mostly unexpected.

The latter two should be fixed with this PR by raising confirmation/violations only once and also ignoring packet analyzers when attempting to disable analyzers.

Copy link
Member

@rsmmr rsmmr left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just one question.

src/packet_analysis/Analyzer.cc Outdated Show resolved Hide resolved
@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch from 9bb99e6 to a76e308 Compare September 27, 2022 13:18
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.
Add a test parsing a malformed PE file showing that analyzer_violation_info
is raised with the fa_file object set.

It could be interesting to pass through an optional connection if one
exists, but access is provided through f$conns, too.
I wonder if there's another one that covers errors during a basic zeek -r,
but didn't seem like.
… after violations)

This is mostly to avoid per-packet violations for packet analyzers that
have sessions attached to them.
Passing nullptr sessions to AnalyzerConfirmation and AnalyzerViolation
of protocol analyzers previously blew up - protect from that.

Related to zeek/spicy-plugin#133.
@awelzel awelzel force-pushed the topic/awelzel/analyzer-violation-info branch from a76e308 to fbf379b Compare September 27, 2022 15:59
@rsmmr rsmmr merged commit 5a5e16c into master Sep 28, 2022
@rsmmr rsmmr deleted the topic/awelzel/analyzer-violation-info branch September 28, 2022 08:37
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants