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

Add keyword to match on 'raw' TLS certificates #3545

Closed
wants to merge 3 commits into from

Conversation

thus
Copy link
Contributor

@thus thus commented Nov 15, 2018

Add new keyword tls_cert to match on the 'raw' TLS certificate. This keyword matches on the first certificate in the certificate chain.

Example:
alert tls any any -> any any (msg:"test tls_cert"; tls_cert; content:"|01 02 03 04|"; sid:1;)

https://redmine.openinfosecfoundation.org/issues/2670

Prscript:

Add keyword to do "raw" matching on the TLS certificate buffer.

Example:
  alert tls any any -> any any (msg:"tls_cert test"; tls_cert; \
          content:"|01 02 03 04|"; sid:1;)
Rename buffer type for the old TLS keywords to avoid a name conflict
with the 'tls_cert' keyword.
alert tls any any -> any any (msg:"match bytes in TLS cert"; tls_cert; \
content:"|06 09 2a 86|"; sid:200070;)

``tls_cert`` is a 'Sticky buffer'.
Copy link
Member

Choose a reason for hiding this comment

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

sticky instead of Sticky? :) but in general doc looks good

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 is written as 'Sticky' on all the other keywords in the same file. Do you want me to lowercase the existing keywords as well? :)

Copy link
Member

Choose a reason for hiding this comment

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

I like the lowercase one better as well. If you want to update it elsewhere, please do.

@victorjulien victorjulien added this to the 5.0 milestone Nov 21, 2018
}

static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms, Flow *_f,
Copy link
Member

Choose a reason for hiding this comment

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

_f is a rust-ism, indicating that the variable isn't used. So seeing it being used as _f is kind of weird :)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree! I just copied that from some other code in the repo ;)
It's like that for the other mpm TLS keywords. Do you want me to change this for the other keywords as well?

Copy link
Member

Choose a reason for hiding this comment

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

Yes please.

SigGroupBuild(de_ctx);
DetectEngineThreadCtxInit(&tv, (void *)de_ctx, (void *)&det_ctx);

FLOWLOCK_WRLOCK(&f);
Copy link
Member

Choose a reason for hiding this comment

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

you can remove the locks from these tests

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure. Do you want me to remove them from the other mpm TLS keywords too? :)

Copy link
Member

Choose a reason for hiding this comment

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

Yeah I think that would be good.

de_ctx->mpm_matcher = mpm_default_matcher;
de_ctx->flags |= DE_QUIET;

s = DetectEngineAppendSig(de_ctx, "alert tls any any -> any any "
Copy link
Member

Choose a reason for hiding this comment

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

declare s 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.

Will do!

FAIL_IF_NOT(PacketAlertCheck(p3, 1));
AppLayerParserThreadCtxFree(alp_tctx);
DetectEngineThreadCtxDeinit(&tv, det_ctx);
SigGroupCleanup(de_ctx);
Copy link
Member

Choose a reason for hiding this comment

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

this is called as well by DetectEngineCtxFree

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll remove it then.

@@ -159,9 +159,9 @@ void DetectTlsRegister (void)
DetectSetupParseRegexes(PARSE_REGEX_FINGERPRINT,
&fingerprint_parse_regex, &fingerprint_parse_regex_study);

g_tls_cert_list_id = DetectBufferTypeRegister("tls_cert");
g_tls_cert_list_id = DetectBufferTypeRegister("tls_keywords_old");
Copy link
Member

Choose a reason for hiding this comment

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

I would suggest tls_legacy_keywords

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I agree, that's a better name!

return buffer;
}

#ifdef UNITTESTS
Copy link
Member

Choose a reason for hiding this comment

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

can you move the tests into their own file in tests/ ?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure :)

InspectionBuffer *buffer = &det_ctx->inspect_buffers[list_id];

if (buffer->inspect == NULL) {
SSLState *ssl_state = (SSLState *)_f->alstate;
Copy link
Member

Choose a reason for hiding this comment

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

can this be const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it.

return NULL;
}

SSLCertsChain *cert = TAILQ_FIRST(&ssl_state->server_connp.certs);
Copy link
Member

Choose a reason for hiding this comment

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

const?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I'll change it.

static int DetectTlsCertSetup(DetectEngineCtx *de_ctx, Signature *s,
const char *str)
{
DetectBufferSetActiveList(s, g_tls_cert_buffer_id);
Copy link
Member

Choose a reason for hiding this comment

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

check the return code here as well

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Will do!

Copy link
Member

Choose a reason for hiding this comment

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

This is probably something that is missing from a lot of other places too. So maybe you can check at least all the TLS ones for this?

sigmatch_table[DETECT_AL_TLS_CERT].name = "tls_cert";
sigmatch_table[DETECT_AL_TLS_CERT].desc = "content modifier to match the TLS certificate buffer";
sigmatch_table[DETECT_AL_TLS_CERT].url = DOC_URL DOC_VERSION "/rules/tls-keywords.html#tls-cert";
sigmatch_table[DETECT_AL_TLS_CERT].Match = NULL;
Copy link
Member

Choose a reason for hiding this comment

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

remove the NULL settings please, they are redundant

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Okay :)

@thus
Copy link
Contributor Author

thus commented May 13, 2019

Replaced by #3851

@thus thus mentioned this pull request May 14, 2019
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.

3 participants