/src/suricata7/src/output-json-ssh.c
Line | Count | Source (jump to first uncovered line) |
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 "detect.h" |
28 | | #include "pkt-var.h" |
29 | | #include "conf.h" |
30 | | |
31 | | #include "threads.h" |
32 | | #include "threadvars.h" |
33 | | #include "tm-threads.h" |
34 | | |
35 | | #include "util-print.h" |
36 | | #include "util-unittest.h" |
37 | | |
38 | | #include "util-debug.h" |
39 | | #include "app-layer-parser.h" |
40 | | #include "output.h" |
41 | | #include "app-layer-ssh.h" |
42 | | #include "app-layer.h" |
43 | | #include "util-privs.h" |
44 | | #include "util-buffer.h" |
45 | | |
46 | | #include "util-logopenfile.h" |
47 | | |
48 | | #include "output-json.h" |
49 | | #include "output-json-ssh.h" |
50 | | #include "rust.h" |
51 | | |
52 | | #define MODULE_NAME "LogSshLog" |
53 | | |
54 | | static int JsonSshLogger(ThreadVars *tv, void *thread_data, const Packet *p, |
55 | | Flow *f, void *state, void *txptr, uint64_t tx_id) |
56 | 312 | { |
57 | 312 | OutputJsonThreadCtx *thread = thread_data; |
58 | | |
59 | 312 | if (unlikely(state == NULL)) { |
60 | 0 | return 0; |
61 | 0 | } |
62 | | |
63 | 312 | JsonBuilder *js = CreateEveHeaderWithTxId(p, LOG_DIR_FLOW, "ssh", NULL, tx_id, thread->ctx); |
64 | 312 | if (unlikely(js == NULL)) |
65 | 0 | return 0; |
66 | | |
67 | 312 | jb_open_object(js, "ssh"); |
68 | 312 | if (!rs_ssh_log_json(txptr, js)) { |
69 | 60 | goto end; |
70 | 60 | } |
71 | 252 | jb_close(js); |
72 | 252 | OutputJsonBuilderBuffer(js, thread); |
73 | | |
74 | 312 | end: |
75 | 312 | jb_free(js); |
76 | 312 | return 0; |
77 | 252 | } |
78 | | |
79 | | static OutputInitResult OutputSshLogInitSub(ConfNode *conf, OutputCtx *parent_ctx) |
80 | 2 | { |
81 | 2 | AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_SSH); |
82 | 2 | return OutputJsonLogInitSub(conf, parent_ctx); |
83 | 2 | } |
84 | | |
85 | | void JsonSshLogRegister (void) |
86 | 33 | { |
87 | | /* register as child of eve-log */ |
88 | 33 | OutputRegisterTxSubModuleWithCondition(LOGGER_JSON_TX, "eve-log", "JsonSshLog", "eve-log.ssh", |
89 | 33 | OutputSshLogInitSub, ALPROTO_SSH, JsonSshLogger, SSHTxLogCondition, JsonLogThreadInit, |
90 | 33 | JsonLogThreadDeinit, NULL); |
91 | 33 | } |