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 
27 static 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  JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "dcerpc", NULL, thread->ctx);
33  if (unlikely(jb == NULL)) {
34  return TM_ECODE_FAILED;
35  }
36 
37  jb_open_object(jb, "dcerpc");
38  if (p->proto == IPPROTO_TCP) {
39  if (!rs_dcerpc_log_json_record_tcp(state, tx, jb)) {
40  goto error;
41  }
42  } else {
43  if (!rs_dcerpc_log_json_record_udp(state, tx, jb)) {
44  goto error;
45  }
46  }
47  jb_close(jb);
48 
49  MemBufferReset(thread->buffer);
50  OutputJsonBuilderBuffer(tv, p, p->flow, jb, thread);
51 
52  jb_free(jb);
53  return TM_ECODE_OK;
54 
55 error:
56  jb_free(jb);
57  return TM_ECODE_FAILED;
58 }
59 
60 static OutputInitResult DCERPCLogInitSub(ConfNode *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 }
Packet_::proto
uint8_t proto
Definition: decode.h:495
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:73
JsonDCERPCLogRegister
void JsonDCERPCLogRegister(void)
Definition: output-json-dcerpc.c:67
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
OutputJsonThreadCtx_::ctx
OutputJsonCtx * ctx
Definition: output-json.h:90
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
JsonLogThreadInit
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
Definition: output-json-common.c:90
Flow_
Flow data structure.
Definition: flow.h:356
OutputRegisterTxSubModule
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:377
rust.h
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
output-json-dcerpc.h
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
OutputCtx_
Definition: tm-modules.h:84
OutputJsonThreadCtx_
Definition: output-json.h:89
output-json.h
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:457
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:806
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
app-layer-parser.h
Packet_
Definition: decode.h:473
OutputInitResult_
Definition: output.h:46
Packet_::flow
struct Flow_ * flow
Definition: decode.h:512
OutputJsonThreadCtx_::buffer
MemBuffer * buffer
Definition: output-json.h:92
suricata-common.h
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:958
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-json.h:38
LOGGER_JSON_TX
@ LOGGER_JSON_TX
Definition: suricata-common.h:468
ConfNode_
Definition: conf.h:32
util-buffer.h
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:123
output.h