mirror of https://github.com/OISF/suricata
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
162 lines
4.5 KiB
C
162 lines
4.5 KiB
C
/* Copyright (C) 2026 Open Information Security Foundation
|
|
*
|
|
* You can copy, redistribute or modify this Program under the terms of
|
|
* the GNU General Public License version 2 as published by the Free
|
|
* Software Foundation.
|
|
*
|
|
* This program is distributed in the hope that it will be useful,
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
* GNU General Public License for more details.
|
|
*
|
|
* You should have received a copy of the GNU General Public License
|
|
* version 2 along with this program; if not, write to the Free Software
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
|
|
* 02110-1301, USA.
|
|
*/
|
|
|
|
// written by Giuseppe Longo <giuseppe@glongo.it>
|
|
|
|
#include "suricata-common.h"
|
|
#include "conf.h"
|
|
|
|
#include "threadvars.h"
|
|
|
|
#include "util-byte.h"
|
|
#include "util-debug.h"
|
|
#include "util-mem.h"
|
|
#include "app-layer-parser.h"
|
|
#include "output.h"
|
|
|
|
#include "output-json.h"
|
|
#include "output-json-llmnr.h"
|
|
#include "rust.h"
|
|
|
|
typedef struct SCLLMNRLogFileCtx_ {
|
|
uint64_t flags; /** Store mode */
|
|
OutputJsonCtx *eve_ctx;
|
|
} SCLLMNRLogFileCtx;
|
|
|
|
typedef struct LogLLMNRLogThread_ {
|
|
SCLLMNRLogFileCtx *llmnrlog_ctx;
|
|
OutputJsonThreadCtx *ctx;
|
|
} SCLLMNRLogThread;
|
|
|
|
bool AlertJsonLLMNR(void *txptr, SCJsonBuilder *js)
|
|
{
|
|
return SCLLMNRLogJson(txptr, js);
|
|
}
|
|
|
|
static int JsonLLMNRLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f,
|
|
void *alstate, void *txptr, uint64_t tx_id)
|
|
{
|
|
SCLLMNRLogThread *td = (SCLLMNRLogThread *)thread_data;
|
|
SCLLMNRLogFileCtx *llmnrlog_ctx = td->llmnrlog_ctx;
|
|
|
|
SCJsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "llmnr", NULL, llmnrlog_ctx->eve_ctx);
|
|
if (unlikely(jb == NULL)) {
|
|
return TM_ECODE_OK;
|
|
}
|
|
|
|
if (SCLLMNRLogJson(txptr, jb)) {
|
|
OutputJsonBuilderBuffer(tv, p, p->flow, jb, td->ctx);
|
|
}
|
|
SCJbFree(jb);
|
|
|
|
return TM_ECODE_OK;
|
|
}
|
|
|
|
static TmEcode SCLLMNRLogThreadInit(ThreadVars *t, const void *initdata, void **data)
|
|
{
|
|
SCLLMNRLogThread *aft = SCCalloc(1, sizeof(SCLLMNRLogThread));
|
|
if (unlikely(aft == NULL))
|
|
return TM_ECODE_FAILED;
|
|
|
|
if (initdata == NULL) {
|
|
SCLogDebug("Error getting context for EveLogLLMNR. \"initdata\" argument NULL");
|
|
goto error_exit;
|
|
}
|
|
|
|
/* Use the Output Context (file pointer and mutex) */
|
|
aft->llmnrlog_ctx = ((OutputCtx *)initdata)->data;
|
|
aft->ctx = CreateEveThreadCtx(t, aft->llmnrlog_ctx->eve_ctx);
|
|
if (!aft->ctx) {
|
|
goto error_exit;
|
|
}
|
|
|
|
*data = (void *)aft;
|
|
return TM_ECODE_OK;
|
|
|
|
error_exit:
|
|
SCFree(aft);
|
|
return TM_ECODE_FAILED;
|
|
}
|
|
|
|
static TmEcode SCLLMNRLogThreadDeinit(ThreadVars *t, void *data)
|
|
{
|
|
SCLLMNRLogThread *aft = (SCLLMNRLogThread *)data;
|
|
if (aft == NULL) {
|
|
return TM_ECODE_OK;
|
|
}
|
|
FreeEveThreadCtx(aft->ctx);
|
|
|
|
/* clear memory */
|
|
memset(aft, 0, sizeof(SCLLMNRLogThread));
|
|
|
|
SCFree(aft);
|
|
return TM_ECODE_OK;
|
|
}
|
|
|
|
static void SCLLMNRLogDeInitCtxSub(OutputCtx *output_ctx)
|
|
{
|
|
SCLogDebug("cleaning up sub output_ctx %p", output_ctx);
|
|
SCLLMNRLogFileCtx *llmnrlog_ctx = (SCLLMNRLogFileCtx *)output_ctx->data;
|
|
SCFree(llmnrlog_ctx);
|
|
SCFree(output_ctx);
|
|
}
|
|
|
|
static OutputInitResult JsonLLMNRLogInitCtxSub(SCConfNode *conf, OutputCtx *parent_ctx)
|
|
{
|
|
OutputInitResult result = { NULL, false };
|
|
const char *enabled = SCConfNodeLookupChildValue(conf, "enabled");
|
|
if (enabled != NULL && !SCConfValIsTrue(enabled)) {
|
|
result.ok = true;
|
|
return result;
|
|
}
|
|
|
|
OutputJsonCtx *ojc = parent_ctx->data;
|
|
|
|
SCLLMNRLogFileCtx *llmnrlog_ctx = SCCalloc(1, sizeof(SCLLMNRLogFileCtx));
|
|
if (unlikely(llmnrlog_ctx == NULL)) {
|
|
return result;
|
|
}
|
|
|
|
llmnrlog_ctx->eve_ctx = ojc;
|
|
llmnrlog_ctx->flags = ~0ULL;
|
|
|
|
OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
|
|
if (unlikely(output_ctx == NULL)) {
|
|
SCFree(llmnrlog_ctx);
|
|
return result;
|
|
}
|
|
|
|
output_ctx->data = llmnrlog_ctx;
|
|
output_ctx->DeInit = SCLLMNRLogDeInitCtxSub;
|
|
|
|
SCLogDebug("LLMNR log sub-module initialized");
|
|
|
|
SCAppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_LLMNR);
|
|
SCAppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_LLMNR);
|
|
|
|
result.ctx = output_ctx;
|
|
result.ok = true;
|
|
return result;
|
|
}
|
|
|
|
void JsonLLMNRLogRegister(void)
|
|
{
|
|
OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonLLMNRLog", "eve-log.llmnr",
|
|
JsonLLMNRLogInitCtxSub, ALPROTO_LLMNR, JsonLLMNRLogger, SCLLMNRLogThreadInit,
|
|
SCLLMNRLogThreadDeinit);
|
|
}
|