]> git.ipfire.org Git - thirdparty/suricata.git/commitdiff
logging: Add DCERPC logger
authorShivani Bhardwaj <shivanib134@gmail.com>
Tue, 21 Apr 2020 09:08:09 +0000 (14:38 +0530)
committerShivani Bhardwaj <shivanib134@gmail.com>
Wed, 15 Jul 2020 16:52:34 +0000 (22:22 +0530)
rust/src/dcerpc/log.rs [new file with mode: 0644]
rust/src/dcerpc/mod.rs
src/Makefile.am
src/output-json-dcerpc.c [new file with mode: 0644]
src/output-json-dcerpc.h [new file with mode: 0644]
src/output.c
src/suricata-common.h
src/util-profiling.c
suricata.yaml.in

diff --git a/rust/src/dcerpc/log.rs b/rust/src/dcerpc/log.rs
new file mode 100644 (file)
index 0000000..fd13b82
--- /dev/null
@@ -0,0 +1,87 @@
+/* Copyright (C) 2020 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+use uuid::Uuid;
+
+use crate::dcerpc::dcerpc::*;
+use crate::jsonbuilder::{JsonBuilder, JsonError};
+
+fn log_dcerpc_header(
+    jsb: &mut JsonBuilder, state: &DCERPCState, tx: &DCERPCTransaction,
+) -> Result<(), JsonError> {
+    if tx.req_done == true {
+        jsb.set_string("request", &dcerpc_type_string(tx.req_cmd))?;
+        match tx.req_cmd {
+            DCERPC_TYPE_REQUEST => {
+                jsb.open_object("req")?;
+                jsb.set_uint("opnum", tx.opnum as u64)?;
+                jsb.set_uint("frag_cnt", tx.frag_cnt_ts as u64)?;
+                jsb.set_uint("stub_data_size", tx.stub_data_buffer_len_ts as u64)?;
+                jsb.close()?;
+            }
+            DCERPC_TYPE_BIND => match &state.bind {
+                Some(bind) => {
+                    jsb.open_array("interfaces")?;
+                    for uuid in &bind.uuid_list {
+                        jsb.start_object()?;
+                        let ifstr = Uuid::from_slice(uuid.uuid.as_slice());
+                        let ifstr = ifstr.map(|uuid| uuid.to_hyphenated().to_string()).unwrap();
+                        jsb.set_string("uuid", &ifstr)?;
+                        let vstr = format!("{}.{}", uuid.version, uuid.versionminor);
+                        jsb.set_string("version", &vstr)?;
+                        jsb.set_uint("ack_result", uuid.result as u64)?;
+                        jsb.close()?;
+                    }
+                    jsb.close()?;
+                }
+                None => {}
+            },
+            _ => {}
+        }
+    } else {
+        jsb.set_string("request", "REQUEST_LOST")?;
+    }
+
+    if tx.resp_done == true {
+        jsb.set_string("response", &dcerpc_type_string(tx.resp_cmd))?;
+        match tx.resp_cmd {
+            DCERPC_TYPE_RESPONSE => {
+                jsb.open_object("res")?;
+                jsb.set_uint("frag_cnt", tx.frag_cnt_tc as u64)?;
+                jsb.set_uint("stub_data_size", tx.stub_data_buffer_len_tc as u64)?;
+                jsb.close()?;
+            }
+            _ => {} // replicating behavior from smb
+        }
+    } else {
+        jsb.set_string("response", "UNREPLIED")?;
+    }
+
+    jsb.set_uint("call_id", tx.call_id as u64)?;
+    if let Some(ref hdr) = state.header {
+        let vstr = format!("{}.{}", hdr.rpc_vers, hdr.rpc_vers_minor);
+        jsb.set_string("rpc_version", &vstr)?;
+    }
+
+    return Ok(());
+}
+
+#[no_mangle]
+pub extern "C" fn rs_dcerpc_log_json_record(
+    state: &DCERPCState, tx: &DCERPCTransaction, mut jsb: &mut JsonBuilder,
+) -> bool {
+    log_dcerpc_header(&mut jsb, state, tx).is_ok()
+}
index 6b17244dda6a3c28ba5b30a02b04558cfcd0ba3a..7765e044ca81d19c3cc9cf7fb5a03e8e3505ab98 100644 (file)
@@ -19,3 +19,4 @@ pub mod dcerpc;
 pub mod dcerpc_udp;
 pub mod parser;
 pub mod detect;
+pub mod log;
index fffb07de3746e717fb6ab58f4dce43c33fe5669a..b3868b48549723b9664c1f56cebc554930509488 100755 (executable)
@@ -369,6 +369,7 @@ output-json-rfb.c output-json-rfb.h \
 output-json-template.c output-json-template.h \
 output-json-template-rust.c output-json-template-rust.h \
 output-json-rdp.c output-json-rdp.h \
+output-json-dcerpc.c output-json-dcerpc.h \
 output-json-metadata.c output-json-metadata.h \
 output-lua.c output-lua.h \
 output-packet.c output-packet.h \
diff --git a/src/output-json-dcerpc.c b/src/output-json-dcerpc.c
new file mode 100644 (file)
index 0000000..f27eef4
--- /dev/null
@@ -0,0 +1,87 @@
+/* Copyright (C) 2017-2018 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#include "suricata-common.h"
+#include "debug.h"
+#include "pkt-var.h"
+#include "conf.h"
+
+#include "threads.h"
+#include "threadvars.h"
+#include "tm-threads.h"
+
+#include "util-unittest.h"
+#include "util-buffer.h"
+#include "util-debug.h"
+#include "util-byte.h"
+
+#include "output.h"
+#include "output-json.h"
+
+#include "app-layer.h"
+#include "app-layer-parser.h"
+#include "app-layer-dcerpc-udp.h"
+#include "app-layer-dcerpc-common.h"
+#include "output-json-dcerpc.h"
+
+#include "rust.h"
+
+
+static int JsonDCERPCLogger(ThreadVars *tv, void *thread_data,
+    const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
+{
+    OutputJsonThreadCtx *thread = thread_data;
+
+    JsonBuilder *jb = CreateEveHeader(p, LOG_DIR_FLOW, "dcerpc", NULL);
+    if (unlikely(jb == NULL)) {
+        return TM_ECODE_FAILED;
+    }
+
+    jb_open_object(jb, "dcerpc");
+    if (!rs_dcerpc_log_json_record(state, tx, jb)) {
+        goto error;
+    }
+    jb_close(jb);
+
+    MemBufferReset(thread->buffer);
+    OutputJsonBuilderBuffer(jb, thread->ctx->file_ctx, &thread->buffer);
+
+    jb_free(jb);
+    return TM_ECODE_OK;
+
+error:
+    jb_free(jb);
+    return TM_ECODE_FAILED;
+}
+
+static OutputInitResult DCERPCLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
+{
+    AppLayerParserRegisterLogger(IPPROTO_TCP, ALPROTO_DCERPC);
+    AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_DCERPC);
+    return OutputJsonLogInitSub(conf, parent_ctx);
+}
+
+void JsonDCERPCLogRegister(void)
+{
+    /* Register as an eve sub-module. */
+    OutputRegisterTxSubModule(LOGGER_JSON_DCERPC, "eve-log", "JsonDCERPCLog",
+        "eve-log.dcerpc", DCERPCLogInitSub, ALPROTO_DCERPC,
+        JsonDCERPCLogger, JsonLogThreadInit,
+        JsonLogThreadDeinit, NULL);
+
+    SCLogDebug("DCERPC JSON logger registered.");
+}
diff --git a/src/output-json-dcerpc.h b/src/output-json-dcerpc.h
new file mode 100644 (file)
index 0000000..c139ed0
--- /dev/null
@@ -0,0 +1,23 @@
+/* Copyright (C) 2017 Open Information Security Foundation
+ *
+ * You can copy, redistribute or modify this Program under the terms of
+ * the GNU General Public License version 2 as published by the Free
+ * Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * version 2 along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
+ * 02110-1301, USA.
+ */
+
+#ifndef __OUTPUT_JSON_DCERPC_H__
+#define __OUTPUT_JSON_DCERPC_H__
+
+void JsonDCERPCLogRegister(void);
+
+#endif /* __OUTPUT_JSON_DCERPC_H__ */
index 62547d8fd94218ebbaa1e8d13d7e5665bdd50381..bddab2eb592ec585b8fe0049030496721b275fcf 100644 (file)
@@ -81,6 +81,7 @@
 #include "output-lua.h"
 #include "output-json-dnp3.h"
 #include "output-json-metadata.h"
+#include "output-json-dcerpc.h"
 #include "output-filestore.h"
 
 typedef struct RootLogger_ {
@@ -1148,4 +1149,6 @@ void OutputRegisterLoggers(void)
     JsonTemplateRustLogRegister();
     /* RDP JSON logger. */
     JsonRdpLogRegister();
+    /* DCERPC JSON logger. */
+    JsonDCERPCLogRegister();
 }
index b04f6da6e5107cb12c7499a9ad2f064312826ab6..9f3bfc1b48f5b09fa450f788c93af73736ef5735 100644 (file)
@@ -466,6 +466,7 @@ typedef enum {
     LOGGER_JSON_RFB,
     LOGGER_JSON_TEMPLATE,
     LOGGER_JSON_RDP,
+    LOGGER_JSON_DCERPC,
 
     LOGGER_ALERT_DEBUG,
     LOGGER_ALERT_FAST,
index af84a5469d71503d8bca8487a75a35b9fa42f16a..28b0dc239e43674b08fd69376d387b2c293fffdb 100644 (file)
@@ -1320,6 +1320,7 @@ const char * PacketProfileLoggertIdToString(LoggerId id)
         CASE_CODE (LOGGER_JSON_RFB);
         CASE_CODE (LOGGER_JSON_TEMPLATE);
         CASE_CODE (LOGGER_JSON_RDP);
+        CASE_CODE (LOGGER_JSON_DCERPC);
         CASE_CODE (LOGGER_TLS_STORE);
         CASE_CODE (LOGGER_TLS);
         CASE_CODE (LOGGER_FILE_STORE);
index 2cbbbcc86f3f338e0fc81e53dd95bb3fb6facf1f..80928e04cfb1c5ef42140067b257fbcd0ab53941 100644 (file)
@@ -262,6 +262,7 @@ outputs:
         - smb
         - tftp
         - ikev2
+        - dcerpc
         - krb5
         - snmp
         - rfb