Skip to content

Comments

detect/sip: add sticky buffers to match headers v3#11004

Closed
glongo wants to merge 11 commits intoOISF:masterfrom
glongo:dev-6374-sip-hdrs-sticky-buffers-v3
Closed

detect/sip: add sticky buffers to match headers v3#11004
glongo wants to merge 11 commits intoOISF:masterfrom
glongo:dev-6374-sip-hdrs-sticky-buffers-v3

Conversation

@glongo
Copy link
Contributor

@glongo glongo commented May 1, 2024

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

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

Describe changes:

  • Add new keywords in doc/userguide/rules/sip-keywords.rst
  • Rebase

SV_BRANCH=OISF/suricata-verify#1787

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 work :-)

Should these fields get logged in addition to have a keyword ?
Would you do a rebase for green CI ?

  • CI : 🟠 probably just need a rebase
  • Code : Checking now
  • Commits segmentation : note sure, feels weird to have a specific commit for registering for instance
  • Commit messages : ok for me
  • Git ID set : looks fine for me
  • CLA : you already contributed
  • Doc update : will leave some more comments in the code
  • Redmine ticket : ok
  • Rustfmt : looks good
  • Tests : looks good, left a few questions there
  • Dependencies added: none


sip.from; content:<from>

Where <from> is the value of the From header.
Copy link
Contributor

Choose a reason for hiding this comment

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

@jufajardini we should precise this is a sticky buffer, right ?

- sip.content_type
- sip.content_length

Note: Headers expressed in compact form will still be matched.
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the Note line is too much details for this file

use std::ptr;

fn header_compact_name(h: &str) -> Option<String> {
let compact = match h {
Copy link
Contributor

Choose a reason for hiding this comment

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

Would you add a comment to the RFC specifying these ?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, would not it be simpler the other way, to associate i to Call-Id?

sip.from
--------

This keyword matches on the From field that can be present in SIP headers.
Copy link
Contributor

Choose a reason for hiding this comment

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

What happens if there are multiple From headers ?

Should it be a multi buffer ?

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, it should.

"Via" => "v",
_ => return None,
};
Some(compact.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.

Why do we need the allocation ?

if let Some(headers) = headers {
let header_value = headers
.get(s)
.or_else(|| s2.as_ref().and_then(|s2| headers.get(s2)));
Copy link
Contributor

Choose a reason for hiding this comment

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

That means if I have the header in long and short form, I only get the long form, 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, right.

.or_else(|| s2.as_ref().and_then(|s2| headers.get(s2)));

if let Some(value) = header_value {
if !value.is_empty() {
Copy link
Contributor

Choose a reason for hiding this comment

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

* 02110-1301, USA.
*/

#ifndef __DETECT_SIP_CONTENT_LENGTH_H__
Copy link
Contributor

Choose a reason for hiding this comment

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

Old guard style

#define HEADER_NAME "User-Agent"
#define KEYWORD_ID DETECT_AL_SIP_HEADER_UA
#define KEYWORD_TOSERVER 1
#define KEYWORD_TOCLIENT 1
Copy link
Contributor

Choose a reason for hiding this comment

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

User Agent is to client as well ?

Or should we get rid of KEYWORD_TOSERVER as they are always true

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, UA is to client as well.

DetectAppLayerMpmRegister(BUFFER_NAME, SIG_FLAG_TOCLIENT, 2, PrefilterGenericMpmRegister,
GetResponseData, ALPROTO_SIP, 1);
#endif
#ifdef KEYWORD_TOSERVER
Copy link
Contributor

Choose a reason for hiding this comment

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

You can group the 2 lines instead of having 2 ifdef KEYWORD_TOSERVER groups

return 0;
}

static void DetectSipHeadersRegisterStub(void)
Copy link
Contributor

Choose a reason for hiding this comment

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

I still think it would be easier and more expressive to have a sip.headers buffer or frame

#include "detect-engine-mpm.h"
#include "detect-engine-prefilter.h"

#include "util-debug.h"
Copy link
Contributor

Choose a reason for hiding this comment

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

Why this include ?

@glongo
Copy link
Contributor Author

glongo commented Jun 20, 2024

Replaced with #11330

@glongo glongo closed this Jun 20, 2024
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.

2 participants