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 "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"
38 #include "output-json-dcerpc.h"
39 
40 #include "rust.h"
41 
42 
43 static int JsonDCERPCLogger(ThreadVars *tv, void *thread_data,
44  const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
45 {
46  OutputJsonThreadCtx *thread = thread_data;
47 
48  JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "dcerpc", NULL, thread->ctx);
49  if (unlikely(jb == NULL)) {
50  return TM_ECODE_FAILED;
51  }
52 
53  jb_open_object(jb, "dcerpc");
54  if (p->proto == IPPROTO_TCP) {
55  if (!rs_dcerpc_log_json_record_tcp(state, tx, jb)) {
56  goto error;
57  }
58  } else {
59  if (!rs_dcerpc_log_json_record_udp(state, tx, jb)) {
60  goto error;
61  }
62  }
63  jb_close(jb);
64 
65  MemBufferReset(thread->buffer);
66  OutputJsonBuilderBuffer(jb, thread);
67 
68  jb_free(jb);
69  return TM_ECODE_OK;
70 
71 error:
72  jb_free(jb);
73  return TM_ECODE_FAILED;
74 }
75 
76 static OutputInitResult DCERPCLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
77 {
80  return OutputJsonLogInitSub(conf, parent_ctx);
81 }
82 
84 {
85  /* Register as an eve sub-module. */
86  OutputRegisterTxSubModule(LOGGER_JSON_DCERPC, "eve-log", "JsonDCERPCLog",
87  "eve-log.dcerpc", DCERPCLogInitSub, ALPROTO_DCERPC,
88  JsonDCERPCLogger, JsonLogThreadInit,
89  JsonLogThreadDeinit, NULL);
90 
91  SCLogDebug("DCERPC JSON logger registered.");
92 }
util-byte.h
tm-threads.h
Packet_::proto
uint8_t proto
Definition: decode.h:436
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:88
JsonDCERPCLogRegister
void JsonDCERPCLogRegister(void)
Definition: output-json-dcerpc.c:83
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:298
JsonLogThreadInit
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
Definition: output-json-common.c:105
threads.h
Flow_
Flow data structure.
Definition: flow.h:353
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:975
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:89
util-debug.h
output-json.h
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:455
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:839
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
pkt-var.h
LOGGER_JSON_DCERPC
@ LOGGER_JSON_DCERPC
Definition: suricata-common.h:465
app-layer-parser.h
Packet_
Definition: decode.h:414
app-layer-dcerpc-common.h
conf.h
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:92
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:138
debug.h
output.h
app-layer.h