suricata
output-json-dcerpc.c
Go to the documentation of this file.
1 /* Copyright (C) 2017-2020 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 "debug.h"
20 #include "pkt-var.h"
21 #include "conf.h"
22 
23 #include "threads.h"
24 #include "threadvars.h"
25 #include "tm-threads.h"
26 
27 #include "util-unittest.h"
28 #include "util-buffer.h"
29 #include "util-debug.h"
30 #include "util-byte.h"
31 
32 #include "output.h"
33 #include "output-json.h"
34 
35 #include "app-layer.h"
36 #include "app-layer-parser.h"
37 #include "app-layer-dcerpc-udp.h"
39 #include "output-json-dcerpc.h"
40 
41 #include "rust.h"
42 
43 
44 static int JsonDCERPCLogger(ThreadVars *tv, void *thread_data,
45  const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
46 {
47  OutputJsonThreadCtx *thread = thread_data;
48 
49  JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "dcerpc", NULL);
50  if (unlikely(jb == NULL)) {
51  return TM_ECODE_FAILED;
52  }
53 
54  jb_open_object(jb, "dcerpc");
55  if (!rs_dcerpc_log_json_record(state, tx, jb)) {
56  goto error;
57  }
58  jb_close(jb);
59 
60  MemBufferReset(thread->buffer);
61  OutputJsonBuilderBuffer(jb, thread->file_ctx, &thread->buffer);
62 
63  jb_free(jb);
64  return TM_ECODE_OK;
65 
66 error:
67  jb_free(jb);
68  return TM_ECODE_FAILED;
69 }
70 
71 static OutputInitResult DCERPCLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
72 {
75  return OutputJsonLogInitSub(conf, parent_ctx);
76 }
77 
79 {
80  /* Register as an eve sub-module. */
81  OutputRegisterTxSubModule(LOGGER_JSON_DCERPC, "eve-log", "JsonDCERPCLog",
82  "eve-log.dcerpc", DCERPCLogInitSub, ALPROTO_DCERPC,
83  JsonDCERPCLogger, JsonLogThreadInit,
84  JsonLogThreadDeinit, NULL);
85 
86  SCLogDebug("DCERPC JSON logger registered.");
87 }
util-byte.h
tm-threads.h
app-layer-dcerpc-udp.h
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:50
JsonDCERPCLogRegister
void JsonDCERPCLogRegister(void)
Definition: output-json-dcerpc.c:78
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
JsonLogThreadInit
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
Definition: output-json-common.c:75
threads.h
Flow_
Flow data structure.
Definition: flow.h:347
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(JsonBuilder *js, LogFileCtx *file_ctx, MemBuffer **buffer)
Definition: output-json.c:978
rust.h
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
util-unittest.h
output-json-dcerpc.h
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
OutputCtx_
Definition: tm-modules.h:78
OutputJsonThreadCtx_
Definition: output-json.h:109
util-debug.h
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr)
Definition: output-json.c:846
output-json.h
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:456
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
pkt-var.h
LOGGER_JSON_DCERPC
@ LOGGER_JSON_DCERPC
Definition: suricata-common.h:470
app-layer-parser.h
Packet_
Definition: decode.h:414
app-layer-dcerpc-common.h
conf.h
OutputJsonThreadCtx_::file_ctx
LogFileCtx * file_ctx
Definition: output-json.h:111
MemBufferReset
#define MemBufferReset(mem_buffer)
Reset the mem buffer.
Definition: util-buffer.h:42
OutputInitResult_
Definition: output.h:43
OutputJsonThreadCtx_::buffer
MemBuffer * buffer
Definition: output-json.h:112
suricata-common.h
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, ThreadExitPrintStatsFunc ThreadExitPrintStats)
Definition: output.c:409
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
threadvars.h
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-json.h:40
ConfNode_
Definition: conf.h:32
util-buffer.h
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:109
debug.h
output.h
app-layer.h