|
|
@ -34,17 +34,13 @@
|
|
|
|
#include "util-unittest.h"
|
|
|
|
#include "util-unittest.h"
|
|
|
|
#include "util-print.h"
|
|
|
|
#include "util-print.h"
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
#include "rust.h"
|
|
|
|
#include <sechash.h>
|
|
|
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
static int DetectTransformToSha256Setup (DetectEngineCtx *, Signature *, const char *);
|
|
|
|
static int DetectTransformToSha256Setup (DetectEngineCtx *, Signature *, const char *);
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
static void DetectTransformToSha256RegisterTests(void);
|
|
|
|
static void DetectTransformToSha256RegisterTests(void);
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
static void TransformToSha256(InspectionBuffer *buffer, void *options);
|
|
|
|
static void TransformToSha256(InspectionBuffer *buffer, void *options);
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
void DetectTransformSha256Register(void)
|
|
|
|
void DetectTransformSha256Register(void)
|
|
|
|
{
|
|
|
|
{
|
|
|
@ -55,25 +51,15 @@ void DetectTransformSha256Register(void)
|
|
|
|
"/rules/transforms.html#to-sha256";
|
|
|
|
"/rules/transforms.html#to-sha256";
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].Setup =
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].Setup =
|
|
|
|
DetectTransformToSha256Setup;
|
|
|
|
DetectTransformToSha256Setup;
|
|
|
|
#ifdef HAVE_NSS
|
|
|
|
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].Transform =
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].Transform =
|
|
|
|
TransformToSha256;
|
|
|
|
TransformToSha256;
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].RegisterTests =
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].RegisterTests =
|
|
|
|
DetectTransformToSha256RegisterTests;
|
|
|
|
DetectTransformToSha256RegisterTests;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].flags |= SIGMATCH_NOOPT;
|
|
|
|
sigmatch_table[DETECT_TRANSFORM_SHA256].flags |= SIGMATCH_NOOPT;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifndef HAVE_NSS
|
|
|
|
|
|
|
|
static int DetectTransformToSha256Setup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
|
|
|
|
|
|
|
|
{
|
|
|
|
|
|
|
|
SCLogError(SC_ERR_NO_SHA256_SUPPORT, "no SHA-256 calculation support built in, "
|
|
|
|
|
|
|
|
"needed for to_sha256 keyword");
|
|
|
|
|
|
|
|
return -1;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
#else
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* \internal
|
|
|
|
* \internal
|
|
|
|
* \brief Apply the nocase keyword to the last pattern match, either content or uricontent
|
|
|
|
* \brief Apply the nocase keyword to the last pattern match, either content or uricontent
|
|
|
@ -86,6 +72,11 @@ static int DetectTransformToSha256Setup (DetectEngineCtx *de_ctx, Signature *s,
|
|
|
|
static int DetectTransformToSha256Setup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
|
|
|
|
static int DetectTransformToSha256Setup (DetectEngineCtx *de_ctx, Signature *s, const char *nullstr)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
SCEnter();
|
|
|
|
SCEnter();
|
|
|
|
|
|
|
|
if (g_disable_hashing) {
|
|
|
|
|
|
|
|
SCLogError(SC_ERR_HASHING_DISABLED, "SHA256 hashing has been disabled, "
|
|
|
|
|
|
|
|
"needed for to_sha256 keyword");
|
|
|
|
|
|
|
|
SCReturnInt(-1);
|
|
|
|
|
|
|
|
}
|
|
|
|
int r = DetectSignatureAddTransform(s, DETECT_TRANSFORM_SHA256, NULL);
|
|
|
|
int r = DetectSignatureAddTransform(s, DETECT_TRANSFORM_SHA256, NULL);
|
|
|
|
SCReturnInt(r);
|
|
|
|
SCReturnInt(r);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -94,20 +85,11 @@ static void TransformToSha256(InspectionBuffer *buffer, void *options)
|
|
|
|
{
|
|
|
|
{
|
|
|
|
const uint8_t *input = buffer->inspect;
|
|
|
|
const uint8_t *input = buffer->inspect;
|
|
|
|
const uint32_t input_len = buffer->inspect_len;
|
|
|
|
const uint32_t input_len = buffer->inspect_len;
|
|
|
|
uint8_t output[SHA256_LENGTH];
|
|
|
|
uint8_t output[SC_SHA256_LEN];
|
|
|
|
|
|
|
|
|
|
|
|
//PrintRawDataFp(stdout, input, input_len);
|
|
|
|
//PrintRawDataFp(stdout, input, input_len);
|
|
|
|
|
|
|
|
SCSha256HashBuffer(input, input_len, output, sizeof(output));
|
|
|
|
HASHContext *sha256_ctx = HASH_Create(HASH_AlgSHA256);
|
|
|
|
InspectionBufferCopy(buffer, output, sizeof(output));
|
|
|
|
if (sha256_ctx) {
|
|
|
|
|
|
|
|
HASH_Begin(sha256_ctx);
|
|
|
|
|
|
|
|
HASH_Update(sha256_ctx, input, input_len);
|
|
|
|
|
|
|
|
unsigned int len = 0;
|
|
|
|
|
|
|
|
HASH_End(sha256_ctx, output, &len, sizeof(output));
|
|
|
|
|
|
|
|
HASH_Destroy(sha256_ctx);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
InspectionBufferCopy(buffer, output, sizeof(output));
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
#ifdef UNITTESTS
|
|
|
|
#ifdef UNITTESTS
|
|
|
@ -131,5 +113,4 @@ static void DetectTransformToSha256RegisterTests(void)
|
|
|
|
UtRegisterTest("DetectTransformToSha256Test01",
|
|
|
|
UtRegisterTest("DetectTransformToSha256Test01",
|
|
|
|
DetectTransformToSha256Test01);
|
|
|
|
DetectTransformToSha256Test01);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
|
|
|
#endif
|
|
|
|
#endif
|