suricata
output-json-ssh.c
Go to the documentation of this file.
1 /* Copyright (C) 2014-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 Victor Julien <victor@inliniac.net>
22  *
23  * Implements SSH JSON logging portion of the engine.
24  */
25 
26 #include "suricata-common.h"
27 #include "debug.h"
28 #include "detect.h"
29 #include "pkt-var.h"
30 #include "conf.h"
31 
32 #include "threads.h"
33 #include "threadvars.h"
34 #include "tm-threads.h"
35 
36 #include "util-print.h"
37 #include "util-unittest.h"
38 
39 #include "util-debug.h"
40 #include "app-layer-parser.h"
41 #include "output.h"
42 #include "app-layer-ssh.h"
43 #include "app-layer.h"
44 #include "util-privs.h"
45 #include "util-buffer.h"
46 
47 #include "util-logopenfile.h"
48 
49 #include "output-json.h"
50 #include "output-json-ssh.h"
51 #include "rust.h"
52 
53 #define MODULE_NAME "LogSshLog"
54 
55 static int JsonSshLogger(ThreadVars *tv, void *thread_data, const Packet *p,
56  Flow *f, void *state, void *txptr, uint64_t tx_id)
57 {
58  OutputJsonThreadCtx *thread = thread_data;
59 
60  if (unlikely(state == NULL)) {
61  return 0;
62  }
63 
64  JsonBuilder *js = CreateEveHeaderWithTxId(p, LOG_DIR_FLOW, "ssh", NULL, tx_id, thread->ctx);
65  if (unlikely(js == NULL))
66  return 0;
67 
68  jb_open_object(js, "ssh");
69  if (!rs_ssh_log_json(txptr, js)) {
70  goto end;
71  }
72  jb_close(js);
73  OutputJsonBuilderBuffer(js, thread);
74 
75 end:
76  jb_free(js);
77  return 0;
78 }
79 
80 static OutputInitResult OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
81 {
83  return OutputJsonLogInitSub(conf, parent_ctx);
84 }
85 
86 void JsonSshLogRegister (void)
87 {
88  /* register as child of eve-log */
89  OutputRegisterTxSubModuleWithCondition(LOGGER_JSON_SSH, "eve-log", "JsonSshLog", "eve-log.ssh",
90  OutputSshLogInitSub, ALPROTO_SSH, JsonSshLogger, SSHTxLogCondition, JsonLogThreadInit,
91  JsonLogThreadDeinit, NULL);
92 }
tm-threads.h
OutputJsonLogInitSub
OutputInitResult OutputJsonLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
Definition: output-json-common.c:88
app-layer-ssh.h
OutputJsonThreadCtx_::ctx
OutputJsonCtx * ctx
Definition: output-json.h:90
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
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
LOGGER_JSON_SSH
@ LOGGER_JSON_SSH
Definition: suricata-common.h:453
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:960
rust.h
util-privs.h
JsonSshLogRegister
void JsonSshLogRegister(void)
Definition: output-json-ssh.c:86
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:34
util-unittest.h
OutputCtx_
Definition: tm-modules.h:78
OutputJsonThreadCtx_
Definition: output-json.h:89
SSHTxLogCondition
int SSHTxLogCondition(ThreadVars *tv, const Packet *p, void *state, void *tx, uint64_t tx_id)
Definition: app-layer-ssh.c:75
util-debug.h
output-json.h
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:492
util-print.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:56
pkt-var.h
app-layer-parser.h
CreateEveHeaderWithTxId
JsonBuilder * CreateEveHeaderWithTxId(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx)
Definition: output-json.c:905
Packet_
Definition: decode.h:433
conf.h
OutputRegisterTxSubModuleWithCondition
void OutputRegisterTxSubModuleWithCondition(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, TxLoggerCondition TxLogCondition, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats)
Definition: output.c:350
OutputInitResult_
Definition: output.h:44
suricata-common.h
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:31
threadvars.h
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-json.h:40
ConfNode_
Definition: conf.h:32
util-logopenfile.h
util-buffer.h
output-json-ssh.h
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:138
debug.h
output.h
app-layer.h