suricata
output-json-dcerpc.c
Go to the documentation of this file.
1/* Copyright (C) 2017-2021 Open Information Security Foundation
2 *
3 * You can copy, redistribute or modify this Program under the terms of
4 * the GNU General Public License version 2 as published by the Free
5 * Software Foundation.
6 *
7 * This program is distributed in the hope that it will be useful,
8 * but WITHOUT ANY WARRANTY; without even the implied warranty of
9 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10 * GNU General Public License for more details.
11 *
12 * You should have received a copy of the GNU General Public License
13 * version 2 along with this program; if not, write to the Free Software
14 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15 * 02110-1301, USA.
16 */
17
18#include "suricata-common.h"
19#include "util-buffer.h"
20#include "output.h"
21#include "output-json.h"
22#include "app-layer-parser.h"
23#include "output-json-dcerpc.h"
24#include "rust.h"
25
26
27static int JsonDCERPCLogger(ThreadVars *tv, void *thread_data,
28 const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
29{
30 OutputJsonThreadCtx *thread = thread_data;
31
32 SCJsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "dcerpc", NULL, thread->ctx);
33 if (unlikely(jb == NULL)) {
34 return TM_ECODE_FAILED;
35 }
36
37 SCJbOpenObject(jb, "dcerpc");
38 if (p->proto == IPPROTO_TCP) {
39 if (!SCDcerpcLogJsonRecordTcp(state, tx, jb)) {
40 goto error;
41 }
42 } else {
43 if (!SCDcerpcLogJsonRecordUdp(state, tx, jb)) {
44 goto error;
45 }
46 }
47 SCJbClose(jb);
48
49 MemBufferReset(thread->buffer);
50 OutputJsonBuilderBuffer(tv, p, p->flow, jb, thread);
51
52 SCJbFree(jb);
53 return TM_ECODE_OK;
54
55error:
56 SCJbFree(jb);
57 return TM_ECODE_FAILED;
58}
59
60static OutputInitResult DCERPCLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
61{
64 return OutputJsonLogInitSub(conf, parent_ctx);
65}
66
68{
69 /* Register as an eve sub-module. */
70 OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonDCERPCLog", "eve-log.dcerpc",
71 DCERPCLogInitSub, ALPROTO_DCERPC, JsonDCERPCLogger, JsonLogThreadInit,
73
74 SCLogDebug("DCERPC JSON logger registered.");
75}
void SCAppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
@ ALPROTO_DCERPC
ThreadVars * tv
@ LOG_DIR_FLOW
OutputInitResult OutputJsonLogInitSub(SCConfNode *conf, OutputCtx *parent_ctx)
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
void JsonDCERPCLogRegister(void)
SCJsonBuilder * CreateEveHeader(const Packet *p, enum SCOutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, SCJsonBuilder *js, OutputJsonThreadCtx *ctx)
void OutputRegisterTxSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Definition output.c:406
Flow data structure.
Definition flow.h:356
OutputJsonCtx * ctx
Definition output-json.h:84
struct Flow_ * flow
Definition decode.h:546
uint8_t proto
Definition decode.h:523
Per thread variable structure.
Definition threadvars.h:58
@ LOGGER_JSON_TX
@ TM_ECODE_FAILED
@ TM_ECODE_OK
#define SCLogDebug(...)
Definition util-debug.h:275
#define unlikely(expr)