Skip to content

Commit

Permalink
ja3: make feature compile time configurable
Browse files Browse the repository at this point in the history
  • Loading branch information
satta committed Mar 4, 2024
1 parent c6a1c7f commit 0de66e7
Show file tree
Hide file tree
Showing 10 changed files with 168 additions and 16 deletions.
11 changes: 11 additions & 0 deletions configure.ac
Original file line number Diff line number Diff line change
Expand Up @@ -2228,6 +2228,16 @@
fi
fi

AC_ARG_ENABLE(ja3,
AS_HELP_STRING([--disable-ja3], [Disable JA3 support]),
[enable_ja3="$enableval"],
[enable_ja3=yes])
if test "$enable_ja3" = "yes"; then
AC_DEFINE([HAVE_JA3],[1],[JA3 enabled])
enable_ja3="yes"
fi
AM_CONDITIONAL([HAVE_JA3], [test "x$enable_ja3" != "xno"])

# Check for lz4
enable_liblz4="yes"
AC_CHECK_LIB(lz4, LZ4F_createCompressionContext, , enable_liblz4="no")
Expand Down Expand Up @@ -2672,6 +2682,7 @@ SURICATA_BUILD_CONF="Suricata Configuration:
LUA support: ${enable_lua}
libluajit: ${enable_luajit}
GeoIP2 support: ${enable_geoip}
JA3 support: ${enable_ja3}
Non-bundled htp: ${enable_non_bundled_htp}
Hyperscan support: ${enable_hyperscan}
Libnet support: ${enable_libnet}
Expand Down
45 changes: 31 additions & 14 deletions src/app-layer-ssl.c
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,8 @@
#include "decode-events.h"
#include "conf.h"

#include "feature.h"

#include "util-spm.h"
#include "util-unittest.h"
#include "util-debug.h"
Expand Down Expand Up @@ -2949,6 +2951,30 @@ static int SSLRegisterPatternsForProtocolDetection(void)
return 0;
}

#ifdef HAVE_JA3
static void CheckJA3Enabled(void) {
const char *strval = NULL;
/* Check if we should generate JA3 fingerprints */
int enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
if (ConfGet("app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
} else if (strcmp(strval, "auto") == 0) {
enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
} else if (ConfValIsFalse(strval)) {
enable_ja3 = 0;
ssl_config.disable_ja3 = true;
} else if (ConfValIsTrue(strval)) {
enable_ja3 = true;
}
SC_ATOMIC_SET(ssl_config.enable_ja3, enable_ja3);
if (!ssl_config.disable_ja3 && !g_disable_hashing) {
/* The feature is available, i.e. _could_ be activated by a rule or
even is enabled in the configuration. */
ProvidesFeature(FEATURE_JA3);
}
}
#endif /* HAVE_JA3 */

/**
* \brief Function to register the SSL protocol parser and other functions
*/
Expand Down Expand Up @@ -3048,20 +3074,9 @@ void RegisterSSLParsers(void)
}
SCLogDebug("ssl_config.encrypt_mode %u", ssl_config.encrypt_mode);

/* Check if we should generate JA3 fingerprints */
int enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
const char *strval = NULL;
if (ConfGet("app-layer.protocols.tls.ja3-fingerprints", &strval) != 1) {
enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
} else if (strcmp(strval, "auto") == 0) {
enable_ja3 = SSL_CONFIG_DEFAULT_JA3;
} else if (ConfValIsFalse(strval)) {
enable_ja3 = 0;
ssl_config.disable_ja3 = true;
} else if (ConfValIsTrue(strval)) {
enable_ja3 = true;
}
SC_ATOMIC_SET(ssl_config.enable_ja3, enable_ja3);
#ifdef HAVE_JA3
CheckJA3Enabled();
#endif /* HAVE_JA3 */

if (g_disable_hashing) {
if (SC_ATOMIC_GET(ssl_config.enable_ja3)) {
Expand All @@ -3070,7 +3085,9 @@ void RegisterSSLParsers(void)
}
} else {
if (RunmodeIsUnittests()) {
#ifdef HAVE_JA3
SC_ATOMIC_SET(ssl_config.enable_ja3, 1);
#endif /* HAVE_JA3 */
}
}
} else {
Expand Down
23 changes: 23 additions & 0 deletions src/detect-tls-ja3-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@
#include "util-unittest.h"
#include "util-unittest-helper.h"

#ifndef HAVE_JA3

static int DetectJA3SetupNoSupport(DetectEngineCtx *a, Signature *b, const char *c)
{
SCLogError("no JA3 support built in");
return -1;
}

void DetectTlsJa3HashRegister(void)
{
sigmatch_table[DETECT_AL_TLS_JA3_HASH].name = "ja3.hash";
sigmatch_table[DETECT_AL_TLS_JA3_HASH].alias = "ja3_hash";
sigmatch_table[DETECT_AL_TLS_JA3_HASH].desc = "sticky buffer to match the JA3 hash buffer";
sigmatch_table[DETECT_AL_TLS_JA3_HASH].url = "/rules/ja3-keywords.html#ja3-hash";
sigmatch_table[DETECT_AL_TLS_JA3_HASH].Setup = DetectJA3SetupNoSupport;
sigmatch_table[DETECT_AL_TLS_JA3_HASH].flags |= SIGMATCH_NOOPT;
sigmatch_table[DETECT_AL_TLS_JA3_HASH].flags |= SIGMATCH_INFO_STICKY_BUFFER;
}

#else /* HAVE_JA3 */

static int DetectTlsJa3HashSetup(DetectEngineCtx *, Signature *, const char *);
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms,
Expand Down Expand Up @@ -225,3 +246,5 @@ static void DetectTlsJa3HashSetupCallback(const DetectEngineCtx *de_ctx,
}
}
}

#endif /* HAVE_JA3 */
23 changes: 23 additions & 0 deletions src/detect-tls-ja3-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@
#include "util-unittest.h"
#include "util-unittest-helper.h"

#ifndef HAVE_JA3

static int DetectJA3SetupNoSupport(DetectEngineCtx *a, Signature *b, const char *c)
{
SCLogError("no JA3 support built in");
return -1;
}

void DetectTlsJa3StringRegister(void)
{
sigmatch_table[DETECT_AL_TLS_JA3_STRING].name = "ja3.string";
sigmatch_table[DETECT_AL_TLS_JA3_STRING].alias = "ja3_string";
sigmatch_table[DETECT_AL_TLS_JA3_STRING].desc = "sticky buffer to match the JA3 string buffer";
sigmatch_table[DETECT_AL_TLS_JA3_STRING].url = "/rules/ja3-keywords.html#ja3-string";
sigmatch_table[DETECT_AL_TLS_JA3_STRING].Setup = DetectJA3SetupNoSupport;
sigmatch_table[DETECT_AL_TLS_JA3_STRING].flags |= SIGMATCH_NOOPT;
sigmatch_table[DETECT_AL_TLS_JA3_STRING].flags |= SIGMATCH_INFO_STICKY_BUFFER;
}

#else /* HAVE_JA3 */

static int DetectTlsJa3StringSetup(DetectEngineCtx *, Signature *, const char *);
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms,
Expand Down Expand Up @@ -150,3 +171,5 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,

return buffer;
}

#endif /* HAVE_JA3 */
22 changes: 22 additions & 0 deletions src/detect-tls-ja3s-hash.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,26 @@
#include "util-unittest.h"
#include "util-unittest-helper.h"

#ifndef HAVE_JA3

static int DetectJA3SetupNoSupport(DetectEngineCtx *a, Signature *b, const char *c)
{
SCLogError("no JA3 support built in");
return -1;
}

void DetectTlsJa3SHashRegister(void)
{
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].name = "ja3s.hash";
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].desc = "sticky buffer to match the JA3S hash buffer";
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].url = "/rules/ja3-keywords.html#ja3s-hash";
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].Setup = DetectJA3SetupNoSupport;
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].flags |= SIGMATCH_NOOPT;
sigmatch_table[DETECT_AL_TLS_JA3S_HASH].flags |= SIGMATCH_INFO_STICKY_BUFFER;
}

#else /* HAVE_JA3 */

static int DetectTlsJa3SHashSetup(DetectEngineCtx *, Signature *, const char *);
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms,
Expand Down Expand Up @@ -223,3 +243,5 @@ static void DetectTlsJa3SHashSetupCallback(const DetectEngineCtx *de_ctx,
}
}
}

#endif /* HAVE_JA3 */
23 changes: 23 additions & 0 deletions src/detect-tls-ja3s-string.c
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,27 @@
#include "util-unittest.h"
#include "util-unittest-helper.h"

#ifndef HAVE_JA3

static int DetectJA3SetupNoSupport(DetectEngineCtx *a, Signature *b, const char *c)
{
SCLogError("no JA3 support built in");
return -1;
}

void DetectTlsJa3SStringRegister(void)
{
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].name = "ja3s.string";
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].desc =
"sticky buffer to match the JA3S string buffer";
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].url = "/rules/ja3-keywords.html#ja3s-string";
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].Setup = DetectJA3SetupNoSupport;
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].flags |= SIGMATCH_NOOPT;
sigmatch_table[DETECT_AL_TLS_JA3S_STRING].flags |= SIGMATCH_INFO_STICKY_BUFFER;
}

#else /* HAVE_JA3 */

static int DetectTlsJa3SStringSetup(DetectEngineCtx *, Signature *, const char *);
static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms,
Expand Down Expand Up @@ -150,3 +171,5 @@ static InspectionBuffer *GetData(DetectEngineThreadCtx *det_ctx,

return buffer;
}

#endif /* HAVE_JA3 */
2 changes: 2 additions & 0 deletions src/feature.h
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@

/* Provided feature names */
#define FEATURE_OUTPUT_FILESTORE "output::file-store"
#define FEATURE_JA3 "ja3"
#define FEATURE_JA4 "ja4"

void ProvidesFeature(const char *);
bool RequiresFeature(const char *);
Expand Down
3 changes: 3 additions & 0 deletions src/suricata.c
Original file line number Diff line number Diff line change
Expand Up @@ -741,6 +741,9 @@ static void PrintBuildInfo(void)
#ifdef HAVE_LUA
strlcat(features, "HAVE_LUA ", sizeof(features));
#endif
#ifdef HAVE_JA3
strlcat(features, "HAVE_JA3 ", sizeof(features));
#endif
#ifdef HAVE_LUAJIT
strlcat(features, "HAVE_LUAJIT ", sizeof(features));
#endif
Expand Down
28 changes: 28 additions & 0 deletions src/util-ja3.c
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,8 @@ void Ja3BufferFree(JA3Buffer **buffer)
*buffer = NULL;
}

#ifdef HAVE_JA3

/**
* \internal
* \brief Resize buffer if it is full.
Expand Down Expand Up @@ -300,3 +302,29 @@ InspectionBuffer *Ja3DetectGetString(DetectEngineThreadCtx *det_ctx,
}
return buffer;
}

#else /* HAVE_JA3 */

/* Stubs for when JA3 is disabled */

int Ja3BufferAppendBuffer(JA3Buffer **buffer1, JA3Buffer **buffer2)
{
return 0;
}

int Ja3BufferAddValue(JA3Buffer **buffer, uint32_t value)
{
return 0;
}

char *Ja3GenerateHash(JA3Buffer *buffer)
{
return NULL;
}

int Ja3IsDisabled(const char *type)
{
return true;
}

#endif /* HAVE_JA3 */
4 changes: 2 additions & 2 deletions src/util-ja3.h
Original file line number Diff line number Diff line change
Expand Up @@ -41,13 +41,13 @@ int Ja3BufferAddValue(JA3Buffer **, uint32_t);
char *Ja3GenerateHash(JA3Buffer *);
int Ja3IsDisabled(const char *);

#ifdef HAVE_JA3
InspectionBuffer *Ja3DetectGetHash(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv,
const int list_id);

InspectionBuffer *Ja3DetectGetString(DetectEngineThreadCtx *det_ctx,
const DetectEngineTransforms *transforms, Flow *_f, const uint8_t _flow_flags, void *txv,
const int list_id);

#endif /* HAVE_JA3 */
#endif /* __UTIL_JA3_H__ */

0 comments on commit 0de66e7

Please sign in to comment.