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

LDAP protocol parser v5 #11360

Closed
wants to merge 4 commits into from
Closed

Conversation

glongo
Copy link
Contributor

@glongo glongo commented Jun 24, 2024

Make sure these boxes are signed before submitting your Pull Request -- thank you.

Link to ticket: https://redmine.openinfosecfoundation.org/issues/1199

Describe changes:

  • Rebase

I still haven't made any changes regarding logging (#11163 (comment)).
The protocol itself seems to be very verbose, so I will leave this point open for discussion.

SV_BRANCH=OISF/suricata-verify#1860

This implementation adds types and filters specified in the LDAP RFC to
work with the ldap_parser.
Although using the parser directly would be
best, strange behavior has been observed during transaction logging.
It appears that C pointers are being overwritten, leading to incorrect
output when LDAP fields are logged.
@catenacyber catenacyber added the needs rebase Needs rebase to master label Jul 13, 2024
#[derive(Debug, PartialEq, Eq, Clone, Copy)]
pub struct Operation(pub u32);

impl Display for Operation {
Copy link
Contributor

Choose a reason for hiding this comment

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

There is the EnumStringU32 derive, would it be relevant here ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Don't think so

}

impl Display for ProtocolOp {
fn fmt(&self, f: &mut Formatter<'_>) -> fmt::Result {
Copy link
Contributor

Choose a reason for hiding this comment

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

Why do we need this impl ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

It's needed for this:

let protocol_op_str = req.protocol_op.to_string();

ldap_parser::ldap::ProtocolOp::IntermediateResponse(msg) => {
Self::from_intermediate_response(msg)
}
_ => ProtocolOp::Unknown,
Copy link
Contributor

Choose a reason for hiding this comment

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

Which ones are missing ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Only abandon request operation, see rusticata/ldap-parser#6

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe, I will make it explicit in a follow-up commit as a nit improvement

}
}

pub fn is_response(&self) -> bool {
Copy link
Contributor

Choose a reason for hiding this comment

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

Is this not the opposite of is_request ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes.

Copy link
Contributor

Choose a reason for hiding this comment

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

Maybe I will make it explicit in a follow-up commit as a nit improvement, by returning !self.is_request() instead of listing the types again

if let Filter::Present(val) = &msg.filter {
js.open_object("filter")?;
js.set_string("type", "present")?;
js.set_string("value", &val.0.to_string())?;
Copy link
Contributor

Choose a reason for hiding this comment

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

Does a ldap filter have a maximum size ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Nope


// written by Giuseppe Longo <[email protected]>

use crate::applayer::{self, *};
Copy link
Contributor

Choose a reason for hiding this comment

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

Would prefer to see a precise list instead of *


#[derive(AppLayerEvent)]
enum LdapEvent {
TooManyTransactions,
Copy link
Contributor

Choose a reason for hiding this comment

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

Should there be one for a failed parsing ?

Copy link
Contributor

@catenacyber catenacyber left a comment

Choose a reason for hiding this comment

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

Thanks for the big work, needs at least a rebase

let mut tx = LdapTransaction::new();
self.tx_id += 1;
tx.tx_id = self.tx_id;
if self.transactions.len() > unsafe { LDAP_MAX_TX } {
Copy link
Contributor

Choose a reason for hiding this comment

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

Another option would be to fail the allocation of the new transaction...

start = rem;

let response = LdapMessage::from(msg);
if let Some(tx) = self.find_request(response.message_id) {
Copy link
Contributor

Choose a reason for hiding this comment

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

Id we do not find the associated request, we should still mark the tx complete, right ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yes, and I think an event should be set.

get_state_data: SCLdapGetStateData,
apply_tx_config: None,
flags: APP_LAYER_PARSER_OPT_ACCEPT_GAPS,
truncate: None,
Copy link
Contributor

Choose a reason for hiding this comment

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

no longer needed on rebase

@glongo
Copy link
Contributor Author

glongo commented Jul 16, 2024

Replaced with #11513

@glongo glongo closed this Jul 16, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
needs rebase Needs rebase to master
Development

Successfully merging this pull request may close these issues.

2 participants