rust/sip: add SIP logger

pull/4210/head
Giuseppe Longo 6 years ago committed by Victor Julien
parent 2e975a0481
commit edc2a583a9

@ -0,0 +1,58 @@
/* Copyright (C) 2019 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.
*/
// written by Giuseppe Longo <giuseppe@glongo.it>
use json::*;
use sip::sip::{SIPState, SIPTransaction};
#[no_mangle]
pub extern "C" fn rs_sip_log_json(_state: &mut SIPState, tx: &mut SIPTransaction) -> *mut JsonT
{
let js = Json::object();
match tx.request {
Some(ref req) => {
js.set_string("method", &req.method);
js.set_string("uri", &req.path);
js.set_string("version", &req.version);
},
None => {}
}
match tx.request_line {
Some (ref req_line) => {
js.set_string("request_line", &req_line);
},
None => {}
}
match tx.response {
Some(ref resp) => {
js.set_string("version", &resp.version);
js.set_string("code", &resp.code);
js.set_string("reason", &resp.reason);
},
None => {}
}
match tx.response_line {
Some (ref resp_line) => {
js.set_string("response_line", &resp_line);
},
None => {}
}
return js.unwrap();
}

@ -19,3 +19,4 @@
pub mod sip;
pub mod parser;
pub mod log;

@ -333,6 +333,7 @@ output-json-flow.c output-json-flow.h \
output-json-ftp.c output-json-ftp.h \
output-json-netflow.c output-json-netflow.h \
output-json-http.c output-json-http.h \
output-json-sip.c output-json-sip.h \
output-json-smtp.c output-json-smtp.h \
output-json-ssh.c output-json-ssh.h \
output-json-stats.c output-json-stats.h \

@ -0,0 +1,190 @@
/* Copyright (C) 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.
*/
/**
* \file
*
* \author Giuseppe Longo <giuseppe@glongo.it>
*
* Implement JSON/eve logging app-layer SIP.
*/
#include "suricata-common.h"
#include "debug.h"
#include "detect.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-sip.h"
#include "output-json-sip.h"
#include "rust.h"
#include "rust-sip-log-gen.h"
#ifdef HAVE_LIBJANSSON
typedef struct LogSIPFileCtx_ {
LogFileCtx *file_ctx;
OutputJsonCommonSettings cfg;
} LogSIPFileCtx;
typedef struct LogSIPLogThread_ {
LogSIPFileCtx *siplog_ctx;
MemBuffer *buffer;
} LogSIPLogThread;
static int JsonSIPLogger(ThreadVars *tv, void *thread_data,
const Packet *p, Flow *f, void *state, void *tx, uint64_t tx_id)
{
SIPTransaction *siptx = tx;
LogSIPLogThread *thread = thread_data;
json_t *js, *sipjs;
js = CreateJSONHeader(p, LOG_DIR_PACKET, "sip");
if (unlikely(js == NULL)) {
return TM_ECODE_FAILED;
}
JsonAddCommonOptions(&thread->siplog_ctx->cfg, p, f, js);
sipjs = rs_sip_log_json(state, siptx);
if (unlikely(sipjs == NULL)) {
goto error;
}
json_object_set_new(js, "sip", sipjs);
MemBufferReset(thread->buffer);
OutputJSONBuffer(js, thread->siplog_ctx->file_ctx, &thread->buffer);
json_decref(js);
return TM_ECODE_OK;
error:
json_decref(js);
return TM_ECODE_FAILED;
}
static void OutputSIPLogDeInitCtxSub(OutputCtx *output_ctx)
{
LogSIPFileCtx *siplog_ctx = (LogSIPFileCtx *)output_ctx->data;
SCFree(siplog_ctx);
SCFree(output_ctx);
}
static OutputInitResult OutputSIPLogInitSub(ConfNode *conf,
OutputCtx *parent_ctx)
{
OutputInitResult result = { NULL, false };
OutputJsonCtx *ajt = parent_ctx->data;
LogSIPFileCtx *siplog_ctx = SCCalloc(1, sizeof(*siplog_ctx));
if (unlikely(siplog_ctx == NULL)) {
return result;
}
siplog_ctx->file_ctx = ajt->file_ctx;
siplog_ctx->cfg = ajt->cfg;
OutputCtx *output_ctx = SCCalloc(1, sizeof(*output_ctx));
if (unlikely(output_ctx == NULL)) {
SCFree(siplog_ctx);
return result;
}
output_ctx->data = siplog_ctx;
output_ctx->DeInit = OutputSIPLogDeInitCtxSub;
SCLogDebug("SIP log sub-module initialized.");
AppLayerParserRegisterLogger(IPPROTO_UDP, ALPROTO_SIP);
result.ctx = output_ctx;
result.ok = true;
return result;
}
#define OUTPUT_BUFFER_SIZE 65535
static TmEcode JsonSIPLogThreadInit(ThreadVars *t, const void *initdata, void **data)
{
LogSIPLogThread *thread = SCCalloc(1, sizeof(*thread));
if (unlikely(thread == NULL)) {
return TM_ECODE_FAILED;
}
if (initdata == NULL) {
SCLogDebug("Error getting context for EveLogSIP. \"initdata\" is NULL.");
SCFree(thread);
return TM_ECODE_FAILED;
}
thread->buffer = MemBufferCreateNew(OUTPUT_BUFFER_SIZE);
if (unlikely(thread->buffer == NULL)) {
SCFree(thread);
return TM_ECODE_FAILED;
}
thread->siplog_ctx = ((OutputCtx *)initdata)->data;
*data = (void *)thread;
return TM_ECODE_OK;
}
static TmEcode JsonSIPLogThreadDeinit(ThreadVars *t, void *data)
{
LogSIPLogThread *thread = (LogSIPLogThread *)data;
if (thread == NULL) {
return TM_ECODE_OK;
}
if (thread->buffer != NULL) {
MemBufferFree(thread->buffer);
}
SCFree(thread);
return TM_ECODE_OK;
}
void JsonSIPLogRegister(void)
{
/* Register as an eve sub-module. */
OutputRegisterTxSubModule(LOGGER_JSON_SIP, "eve-log", "JsonSIPLog",
"eve-log.sip", OutputSIPLogInitSub, ALPROTO_SIP,
JsonSIPLogger, JsonSIPLogThreadInit,
JsonSIPLogThreadDeinit, NULL);
SCLogDebug("SIP JSON logger registered.");
}
#else /* No JSON support. */
void JsonSIPLogRegister(void)
{
}
#endif /* HAVE_LIBJANSSON */

@ -0,0 +1,29 @@
/* Copyright (C) 2015 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.
*/
/**
* \file
*
* \author Giuseppe Longo <giuseppe@glongo.it>
*/
#ifndef __OUTPUT_JSON_SIP_H__
#define __OUTPUT_JSON_SIP_H__
void JsonSIPLogRegister(void);
#endif /* __OUTPUT_JSON_SIP_H__ */

@ -75,6 +75,7 @@
#include "output-json-krb5.h"
#include "output-json-dhcp.h"
#include "output-json-snmp.h"
#include "output-json-sip.h"
#include "output-json-template.h"
#include "output-json-template-rust.h"
#include "output-json-rdp.h"
@ -1110,6 +1111,8 @@ void OutputRegisterLoggers(void)
JsonDHCPLogRegister();
/* SNMP JSON logger. */
JsonSNMPLogRegister();
/* SIP JSON logger. */
JsonSIPLogRegister();
/* Template JSON logger. */
JsonTemplateLogRegister();
/* Template Rust JSON logger. */

@ -440,6 +440,7 @@ typedef enum {
LOGGER_JSON_KRB5,
LOGGER_JSON_DHCP,
LOGGER_JSON_SNMP,
LOGGER_JSON_SIP,
LOGGER_JSON_TEMPLATE_RUST,
LOGGER_JSON_TEMPLATE,
LOGGER_JSON_RDP,

@ -1318,6 +1318,7 @@ const char * PacketProfileLoggertIdToString(LoggerId id)
CASE_CODE (LOGGER_JSON_SMTP);
CASE_CODE (LOGGER_JSON_SNMP);
CASE_CODE (LOGGER_JSON_TLS);
CASE_CODE (LOGGER_JSON_SIP);
CASE_CODE (LOGGER_JSON_TEMPLATE_RUST);
CASE_CODE (LOGGER_JSON_TEMPLATE);
CASE_CODE (LOGGER_JSON_RDP);

@ -267,6 +267,7 @@ outputs:
- ikev2
- krb5
- snmp
- sip
- dhcp:
enabled: yes
# When extended mode is on, all DHCP messages are logged

Loading…
Cancel
Save