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 JA3S fingerprint support #3850

Closed
wants to merge 13 commits into from
Closed

Add JA3S fingerprint support #3850

wants to merge 13 commits into from

Conversation

thus
Copy link
Contributor

@thus thus commented May 13, 2019

This pull request implements JA3S fingerprints as implemented in the bro script in the JA3 github repo:
https://github.com/salesforce/ja3/blob/master/bro/ja3s.bro

Updates:

Redmine:
https://redmine.openinfosecfoundation.org/issues/2684

thus added 13 commits May 13, 2019 11:49
Generate JA3S fingerprints based on fields in the ServerHello record.
Add JA3S object to TLS JSON logger (extended log).
Add Ja3SGetHash() to return the content of the JA3S hash buffer from
the TLS session.

Example:

  function init (args)
      local needs = {}
      needs["protocol"] = "tls"
      return needs
  end

  function setup (args)
      filename = SCLogPath() .. "/ja3s_hash.log"
      file = assert(io.open(filename, "a"))
  end

  function log (args)
      ja3s_hash = Ja3SGetHash()
      if ja3s_hash == nil then
          return
      end

      file:write(ja3s_hash .. "\n")
      file:flush()
  end

  function deinit (args)
      file:close()
  end

In the example above, each JA3S hash is logged to a log file.
Add Ja3SGetString() to return the content of the JA3S string buffer from
the TLS session.

Example:

  function init (args)
      local needs = {}
      needs["protocol"] = "tls"
      return needs
  end

  function setup (args)
      filename = SCLogPath() .. "/ja3s_string.log"
      file = assert(io.open(filename, "a"))
  end

  function log (args)
      ja3s_string = Ja3SGetString()
      if ja3s_string == nil then
          return
      end

      file:write(ja3s_string .. "\n")
      file:flush()
  end

  function deinit (args)
      file:close()
  end
Match on JA3S hash using ja3s.hash keyword, e.g:

  alert tls any any -> any any (msg:"ja3s.hash test";
      ja3s.hash; content:"b26c652e0a402a24b5ca2a660e84f9d5"; sid:1;)
Match on JA3S string using ja3s.string keyword, e.g:

  alert tls any any -> any any (msg:"ja3s.string test";
      ja3s.string; content:"10-11-12"; sid:1;)
@thus thus requested review from norg and a team as code owners May 13, 2019 12:22
{
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].name = "ja3s.hash";
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].desc = "content modifier to match the JA3S sticky buffer";
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].url = DOC_URL DOC_VERSION "/rules/ja3-keywords.html#ja3s.hash";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably be "#ja3s-hash" instead of "#ja3s.hash".

{
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].name = "ja3s.string";
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].desc = "content modifier to match the JA3S sticky buffer";
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].url = DOC_URL DOC_VERSION "/rules/ja3-keywords.html#ja3s.string";
Copy link
Contributor Author

Choose a reason for hiding this comment

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

This should probably be "#ja3s-string" instead of "#ja3s.string".

void DetectTlsJa3SHashRegister(void)
{
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].name = "ja3s.hash";
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].desc = "content modifier to match the JA3S sticky 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.

"match the JA3S hash sticky buffer" instead :)

void DetectTlsJa3SStringRegister(void)
{
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].name = "ja3s.string";
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].desc = "content modifier to match the JA3S sticky 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.

Should be "match the JA3S string sticky buffer".

#endif
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms,
Flow *_f, const uint8_t _flow_flags,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Should remove the underscores from the variables here as well.

#endif
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms,
Flow *_f, const uint8_t _flow_flags,
Copy link
Contributor Author

Choose a reason for hiding this comment

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

And here!

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.

I guess I forgot to 'submit review'. Not a full review but some quick feedback.

Can you also add suricata-verify tests?

#ifdef UNITTESTS
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].RegisterTests = DetectTlsJa3SHashRegisterTests;
#endif
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].flags |= SIGMATCH_NOOPT;
Copy link
Member

Choose a reason for hiding this comment

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

add SIGMATCH_INFO_STICKY_BUFFER

#ifdef UNITTESTS
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].RegisterTests = DetectTlsJa3SStringRegisterTests;
#endif
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].flags |= SIGMATCH_NOOPT;
Copy link
Member

Choose a reason for hiding this comment

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

info sticky buffer flag

@thus
Copy link
Contributor Author

thus commented May 16, 2019

Replaced by #3858

@thus thus closed this May 16, 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.

2 participants