suricata
output-json-rdp.c
Go to the documentation of this file.
1 /* Copyright (C) 2019-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 /**
19  * \file
20  *
21  * \author Zach Kelly <zach.kelly@lmco.com>
22  *
23  * Application layer logger for RDP
24  */
25 
26 #include "suricata-common.h"
27 #include "detect.h"
28 #include "pkt-var.h"
29 #include "conf.h"
30 #include "threads.h"
31 #include "threadvars.h"
32 #include "tm-threads.h"
33 #include "util-unittest.h"
34 #include "util-buffer.h"
35 #include "util-debug.h"
36 #include "util-byte.h"
37 #include "output.h"
38 #include "output-json.h"
39 #include "app-layer.h"
40 #include "app-layer-parser.h"
41 #include "app-layer-rdp.h"
42 #include "output-json-rdp.h"
43 #include "rust.h"
44 
45 static int JsonRdpLogger(ThreadVars *tv, void *thread_data,
46  const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
47 {
48  OutputJsonThreadCtx *thread = thread_data;
49 
50  JsonBuilder *js = CreateEveHeader(p, LOG_DIR_PACKET, "rdp", NULL, thread->ctx);
51  if (unlikely(js == NULL)) {
52  return TM_ECODE_OK;
53  }
54  if (!rs_rdp_to_json(tx, js)) {
55  jb_free(js);
56  return TM_ECODE_FAILED;
57  }
58  OutputJsonBuilderBuffer(js, thread);
59 
60  jb_free(js);
61  return TM_ECODE_OK;
62 }
63 
64 static OutputInitResult OutputRdpLogInitSub(ConfNode *conf,
65  OutputCtx *parent_ctx)
66 {
68  return OutputJsonLogInitSub(conf, parent_ctx);
69 }
70 
72 {
73  /* Register as an eve sub-module. */
74  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonRdpLog", "eve-log.rdp",
75  OutputRdpLogInitSub, ALPROTO_RDP, JsonRdpLogger, JsonLogThreadInit, JsonLogThreadDeinit,
76  NULL);
77 
78  SCLogDebug("rdp json logger registered.");
79 }
util-byte.h
tm-threads.h
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:73
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
threads.h
Flow_
Flow data structure.
Definition: flow.h:357
JsonRdpLogRegister
void JsonRdpLogRegister(void)
Definition: output-json-rdp.c:71
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:934
rust.h
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
util-unittest.h
output-json-rdp.h
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
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:477
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:796
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
pkt-var.h
app-layer-parser.h
Packet_
Definition: decode.h:428
ALPROTO_RDP
@ ALPROTO_RDP
Definition: app-layer-protos.h:60
conf.h
OutputInitResult_
Definition: output.h:46
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-json.h:39
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:410
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
threadvars.h
LOGGER_JSON_TX
@ LOGGER_JSON_TX
Definition: suricata-common.h:456
ConfNode_
Definition: conf.h:32
util-buffer.h
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:123
output.h
app-layer-rdp.h
app-layer.h