]>
git.ipfire.org Git - people/ms/suricata.git/blob - src/output-json-smb.c
1 /* Copyright (C) 2017-2021 Open Information Security Foundation
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
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.
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
21 * \author Victor Julien <victor@inliniac.net>
23 * Implement JSON/eve logging app-layer SMB.
26 #include "suricata-common.h"
32 #include "threadvars.h"
33 #include "tm-threads.h"
35 #include "util-unittest.h"
36 #include "util-buffer.h"
37 #include "util-debug.h"
38 #include "util-byte.h"
41 #include "output-json.h"
43 #include "app-layer.h"
44 #include "app-layer-parser.h"
46 #include "output-json-smb.h"
50 bool EveSMBAddMetadata(const Flow
*f
, uint64_t tx_id
, JsonBuilder
*jb
)
52 SMBState
*state
= FlowGetAppState(f
);
54 SMBTransaction
*tx
= AppLayerParserGetTx(f
->proto
, ALPROTO_SMB
, state
, tx_id
);
56 return rs_smb_log_json_response(jb
, state
, tx
);
62 static int JsonSMBLogger(ThreadVars
*tv
, void *thread_data
,
63 const Packet
*p
, Flow
*f
, void *state
, void *tx
, uint64_t tx_id
)
65 OutputJsonThreadCtx
*thread
= thread_data
;
67 JsonBuilder
*jb
= CreateEveHeader(p
, LOG_DIR_FLOW
, "smb", NULL
, thread
->ctx
);
68 if (unlikely(jb
== NULL
)) {
69 return TM_ECODE_FAILED
;
72 jb_open_object(jb
, "smb");
73 if (!rs_smb_log_json_response(jb
, state
, tx
)) {
78 OutputJsonBuilderBuffer(jb
, thread
);
85 return TM_ECODE_FAILED
;
88 static OutputInitResult
SMBLogInitSub(ConfNode
*conf
, OutputCtx
*parent_ctx
)
90 AppLayerParserRegisterLogger(IPPROTO_TCP
, ALPROTO_SMB
);
91 AppLayerParserRegisterLogger(IPPROTO_UDP
, ALPROTO_SMB
);
92 return OutputJsonLogInitSub(conf
, parent_ctx
);
95 void JsonSMBLogRegister(void)
97 /* Register as an eve sub-module. */
98 OutputRegisterTxSubModule(LOGGER_JSON_SMB
, "eve-log", "JsonSMBLog",
99 "eve-log.smb", SMBLogInitSub
, ALPROTO_SMB
,
100 JsonSMBLogger
, JsonLogThreadInit
,
101 JsonLogThreadDeinit
, NULL
);
103 SCLogDebug("SMB JSON logger registered.");