Skip to content

Output alert applayer v5#8922

Closed
catenacyber wants to merge 28 commits intoOISF:masterfrom
catenacyber:output-alert-applayer-v5
Closed

Output alert applayer v5#8922
catenacyber wants to merge 28 commits intoOISF:masterfrom
catenacyber:output-alert-applayer-v5

Conversation

@catenacyber
Copy link
Contributor

Link to redmine ticket:
None, preliminary work for https://redmine.openinfosecfoundation.org/issues/5053 and app-layer plugins
Continuation of #8772
https://redmine.openinfosecfoundation.org/issues/5977

Describe changes:

  • Fix setup-app-layer script so that it adds app-layer metadata to alerts
  • Adds ftp metadata to alerts
  • Adds tftp metadata to alerts
  • Adds krb5 metadata to alerts
  • Removes tx_id from ssh and http2 logging

Continues #8893 with rebase and adding ticket number to krb5 commit

SV_BRANCH=pr/1196

OISF/suricata-verify#1196

Still to do :

  • Create tickets for missing protocols : pgsql, dcerpc, dhcp,
  • Any ideas about the commit segmentation ?

Especially fix setup-app-layer script to not forget this part
and used by bittorrent
And fix setup app layer script up for it
@catenacyber catenacyber requested a review from a team as a code owner May 25, 2023 11:32
@catenacyber
Copy link
Contributor Author

@codecov
Copy link

codecov bot commented May 25, 2023

Codecov Report

Merging #8922 (9ccda72) into master (ebe0a7b) will increase coverage by 0.04%.
The diff coverage is 96.96%.

Additional details and impacted files
@@            Coverage Diff             @@
##           master    #8922      +/-   ##
==========================================
+ Coverage   82.30%   82.34%   +0.04%     
==========================================
  Files         969      957      -12     
  Lines      273335   272773     -562     
==========================================
- Hits       224961   224627     -334     
+ Misses      48374    48146     -228     
Flag Coverage Δ
fuzzcorpus 64.84% <84.24%> (+0.19%) ⬆️
suricata-verify 60.38% <96.96%> (-0.08%) ⬇️
unittests 63.07% <24.84%> (+0.12%) ⬆️

Flags with carried forward coverage won't be shown. Click here to find out more.

Copy link
Member

@victorjulien victorjulien left a comment

Choose a reason for hiding this comment

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

Main issue is the central table, see inline.

if (!rs_mqtt_logger_log(state, tx, thread->mqttlog_ctx->flags, js))
jb_open_object(js, "mqtt");
if (!rs_mqtt_logger_log(tx, thread->mqttlog_ctx->flags, js))
goto error;
Copy link
Member

Choose a reason for hiding this comment

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

no close on error?

Copy link
Member

Choose a reason for hiding this comment

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

No, the error handler just free's it. Its not used anymore.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed as Jason said.

To be more complete :

  • When we log a MQTT event, if we fail to log the MQTT data, we do not log anything at all
  • When we log an alert, if we fail to log the MQTT data, we still log the alert

}
}

static AppLayerLogger alert_applayer_loggers[ALPROTO_MAX] = {
Copy link
Member

Choose a reason for hiding this comment

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

I don't really like this idea of handling these per protocol things be in a central table. Seems an anti-pattern wrt trying to make it as much a plugin as possible.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

The use of this central table is indeed the central point, and it is meant to allow the use of app-layer plugins

What do we want ?
I think we want

  • to avoid duplicating boilerplate code (and remove C file, to get better rust stats)
  • that every app-layer protocols log their metadata for alerts, and for their own events

The solution currently used is to have

  1. For alerts, output-json-alert.c has a big switch with boilerplate wrapper code calling hardcoded app-layer logging functions, and this is missing for several protocols

So, the use of a central table, for alerts,

  • makes it easy to sport the missing protocols (and to add them, as is done in this PR for krb5 for instance)
  • removes the boilerplate code (taking the mark, trying to log, closing or restoring the mark...)
  • makes it easy to extend by plugins (that "just" need to extend the array)
  1. For app-layer events, we have registration of boilerplate-wrapper functions that are registered in a central table
    static OutputTxLogger *list[ALPROTO_MAX] in output-tx.c

Here, this PR

  • removes boilerplate code for simple logger (not ones using state, or flags...), like JsonLogThreadInit already exists but is not used by every protocol and JsonGenericLogger is introduced making use of the new table for simple loggers

So @victorjulien what do you think ?
It looks like a design flaw to have different wrapper functions for logging alert and app-layer metadata (causing not to have app-layer metadata for every protocol/alert)
Most of the protocols/cases are simple, but some require more complexity

Should I make a first part of this PR with the uncontroversial changes ? (first commits, use of JsonLogThreadInit)

Copy link
Member

Choose a reason for hiding this comment

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

I think a centralized store doesn't have to use a table of hardcoded entries, but could also be more dynamic, like with many other parts of the engine. The parsers could then all a registration function that adds their entry into the store.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Well, not sure to see the point but this is quite easy to add :-)

}
}

bool AlertJsonDns(void *txptr, JsonBuilder *js)
Copy link
Member

Choose a reason for hiding this comment

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

should this return false if both calls return NULL?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Likely so, this is a behavioral change

Copy link
Member

Choose a reason for hiding this comment

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

Likely so, this is a behavioral change

Not a big one right? It would allow the caller to reset to mark to prevent an empty dns object from being logger in alert.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Does not look a big one

#9005 is the part without behavior changes

Then I intend to do the behavioral changes about alerts : addition of protocols missing alert metadata (like krb5) + behavioral change for dns alert metadata

@@ -27,7 +27,6 @@ pub extern "C" fn rs_modbus_to_json(tx: &mut ModbusTransaction, js: &mut JsonBui

Copy link
Member

Choose a reason for hiding this comment

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

this commit does a lot more than the commit message indicates

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Indeed, so, any ideas about the commit segmentation ?
One big commit ? One commit per protocol ? (but if so, the first commit introducing the generic changes should also be applied on some protocol, otherwise, commit-check will fail because of unused functions)

Should I split this PR ?

@suricata-qa
Copy link

Information: QA ran without warnings.

Pipeline 14069

@catenacyber
Copy link
Contributor Author

Main issue is the central table, see inline.

Thanks for the review, sorry for taking long to respond.
I answer inline

@catenacyber
Copy link
Contributor Author

Continues in #8961

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

4 participants

Comments