|
|
|
@ -33,18 +33,13 @@
|
|
|
|
|
|
|
|
|
|
#include "util-unittest.h"
|
|
|
|
|
#include "util-print.h"
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
|
#include <sechash.h>
|
|
|
|
|
#endif
|
|
|
|
|
#include "rust.h"
|
|
|
|
|
|
|
|
|
|
static int DetectTransformToMd5Setup (DetectEngineCtx *, Signature *, const char *);
|
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
|
static void DetectTransformToMd5RegisterTests(void);
|
|
|
|
|
#endif
|
|
|
|
|
static void TransformToMd5(InspectionBuffer *buffer, void *options);
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
void DetectTransformMd5Register(void)
|
|
|
|
|
{
|
|
|
|
@ -55,25 +50,15 @@ void DetectTransformMd5Register(void)
|
|
|
|
|
"/rules/transforms.html#to-md5";
|
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_MD5].Setup =
|
|
|
|
|
DetectTransformToMd5Setup;
|
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_MD5].Transform =
|
|
|
|
|
TransformToMd5;
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_MD5].RegisterTests =
|
|
|
|
|
DetectTransformToMd5RegisterTests;
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_MD5].flags |= SIGMATCH_NOOPT;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_NSS
|
|
|
|
|
static int DetectTransformToMd5Setup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
|
|
|
|
|
{
|
|
|
|
|
SCLogError(SC_ERR_NO_MD5_SUPPORT, "no MD5 calculation support built in, "
|
|
|
|
|
"needed for to_md5 keyword");
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
#else
|
|
|
|
|
/**
|
|
|
|
|
* \internal
|
|
|
|
|
* \brief Apply the nocase keyword to the last pattern match, either content or uricontent
|
|
|
|
@ -86,6 +71,11 @@ static int DetectTransformToMd5Setup (DetectEngineCtx *de_ctx, Signature *s, con
|
|
|
|
|
static int DetectTransformToMd5Setup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
|
|
|
|
|
{
|
|
|
|
|
SCEnter();
|
|
|
|
|
if (g_disable_hashing) {
|
|
|
|
|
SCLogError(SC_ERR_HASHING_DISABLED, "MD5 hashing has been disabled, "
|
|
|
|
|
"needed for to_md5 keyword");
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
}
|
|
|
|
|
int r = DetectSignatureAddTransform(s, DETECT_TRANSFORM_MD5, NULL);
|
|
|
|
|
SCReturnInt(r);
|
|
|
|
|
}
|
|
|
|
@ -94,20 +84,11 @@ static void TransformToMd5(InspectionBuffer *buffer, void *options)
|
|
|
|
|
{
|
|
|
|
|
const uint8_t *input = buffer->inspect;
|
|
|
|
|
const uint32_t input_len = buffer->inspect_len;
|
|
|
|
|
uint8_t output[MD5_LENGTH];
|
|
|
|
|
uint8_t output[SC_MD5_LEN];
|
|
|
|
|
|
|
|
|
|
//PrintRawDataFp(stdout, input, input_len);
|
|
|
|
|
|
|
|
|
|
HASHContext *ctx = HASH_Create(HASH_AlgMD5);
|
|
|
|
|
if (ctx) {
|
|
|
|
|
HASH_Begin(ctx);
|
|
|
|
|
HASH_Update(ctx, input, input_len);
|
|
|
|
|
unsigned int len = 0;
|
|
|
|
|
HASH_End(ctx, output, &len, sizeof(output));
|
|
|
|
|
HASH_Destroy(ctx);
|
|
|
|
|
|
|
|
|
|
InspectionBufferCopy(buffer, output, sizeof(output));
|
|
|
|
|
}
|
|
|
|
|
SCMd5HashBuffer(input, input_len, output, sizeof(output));
|
|
|
|
|
InspectionBufferCopy(buffer, output, sizeof(output));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
@ -131,5 +112,4 @@ static void DetectTransformToMd5RegisterTests(void)
|
|
|
|
|
UtRegisterTest("DetectTransformToMd5Test01",
|
|
|
|
|
DetectTransformToMd5Test01);
|
|
|
|
|
}
|
|
|
|
|
#endif
|
|
|
|
|
#endif
|