suricata
output-json-smb.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 /**
19  * \file
20  *
21  * \author Victor Julien <victor@inliniac.net>
22  *
23  * Implement JSON/eve logging app-layer SMB.
24  */
25 
26 #include "suricata-common.h"
27 #include "util-buffer.h"
28 #include "output.h"
29 #include "output-json.h"
30 #include "app-layer-parser.h"
31 #include "output-json-smb.h"
32 #include "rust.h"
33 
34 bool EveSMBAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
35 {
36  SMBState *state = FlowGetAppState(f);
37  if (state) {
38  SMBTransaction *tx = AppLayerParserGetTx(f->proto, ALPROTO_SMB, state, tx_id);
39  if (tx) {
40  return rs_smb_log_json_response(jb, state, tx);
41  }
42  }
43  return false;
44 }
45 
46 static int JsonSMBLogger(ThreadVars *tv, void *thread_data,
47  const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
48 {
49  OutputJsonThreadCtx *thread = thread_data;
50 
51  JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "smb", NULL, thread->ctx);
52  if (unlikely(jb == NULL)) {
53  return TM_ECODE_FAILED;
54  }
55 
56  jb_open_object(jb, "smb");
57  if (!rs_smb_log_json_response(jb, state, tx)) {
58  goto error;
59  }
60  jb_close(jb);
61 
62  OutputJsonBuilderBuffer(tv, p, p->flow, jb, thread);
63 
64  jb_free(jb);
65  return TM_ECODE_OK;
66 
67 error:
68  jb_free(jb);
69  return TM_ECODE_FAILED;
70 }
71 
72 static OutputInitResult SMBLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
73 {
76  return OutputJsonLogInitSub(conf, parent_ctx);
77 }
78 
80 {
81  /* Register as an eve sub-module. */
82  OutputRegisterTxSubModule(LOGGER_JSON_TX, "eve-log", "JsonSMBLog", "eve-log.smb", SMBLogInitSub,
84 
85  SCLogDebug("SMB JSON logger registered.");
86 }
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
JsonSMBLogRegister
void JsonSMBLogRegister(void)
Definition: output-json-smb.c:79
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
Flow_::proto
uint8_t proto
Definition: flow.h:378
JsonLogThreadInit
TmEcode JsonLogThreadInit(ThreadVars *t, const void *initdata, void **data)
Definition: output-json-common.c:90
Flow_
Flow data structure.
Definition: flow.h:356
OutputJsonBuilderBuffer
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:958
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)
Definition: output.c:377
rust.h
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
OutputCtx_
Definition: tm-modules.h:84
OutputJsonThreadCtx_
Definition: output-json.h:89
output-json.h
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:457
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:806
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
app-layer-parser.h
Packet_
Definition: decode.h:476
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1094
OutputInitResult_
Definition: output.h:46
Packet_::flow
struct Flow_ * flow
Definition: decode.h:515
suricata-common.h
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-json.h:38
LOGGER_JSON_TX
@ LOGGER_JSON_TX
Definition: suricata-common.h:468
ConfNode_
Definition: conf.h:32
util-buffer.h
output-json-smb.h
ALPROTO_SMB
@ ALPROTO_SMB
Definition: app-layer-protos.h:37
JsonLogThreadDeinit
TmEcode JsonLogThreadDeinit(ThreadVars *t, void *data)
Definition: output-json-common.c:123
EveSMBAddMetadata
bool EveSMBAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
Definition: output-json-smb.c:34
output.h