Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
d4327cf
output/smtp: remove unused function parameters
catenacyber May 11, 2023
4cbbf38
output/dns: remove unused function parameters
catenacyber May 11, 2023
0f0cd12
output/ftp: remove unused function parameters
catenacyber May 11, 2023
1bdbe97
output/alert: rewrite code for app-layer properties
catenacyber May 11, 2023
bd3e47a
output/ftp: have ftp properties in alerts
catenacyber May 11, 2023
1fca44d
output/tftp: have tftp properties in alerts
catenacyber May 11, 2023
75e0969
output/mqtt: reuse standard code
catenacyber May 12, 2023
19aad9f
output/rfb: reuse standard code
catenacyber May 12, 2023
33d1c68
output/snmp: reuse standard code
catenacyber May 12, 2023
672f580
output/krb5: have krb5 properties in alerts
catenacyber May 12, 2023
7d2f312
output/ftp-data: reuse standard code
catenacyber May 14, 2023
2aa1e88
output/tls: reuse standard code
catenacyber May 14, 2023
171c7c5
output: comments for non-generic app-layers
catenacyber May 14, 2023
634568c
output: generic tx json logger
catenacyber May 14, 2023
dd9a17b
output/http2: generic tx json logger
catenacyber May 15, 2023
296793c
output/rdp: generic tx json logger
catenacyber May 15, 2023
ca27f88
output: code reuse for generic tx json logger
catenacyber May 15, 2023
c347f7f
output/rfb: generic tx json logger
catenacyber May 15, 2023
f16ad5f
output/sip: generic tx json logger
catenacyber May 15, 2023
c084c4e
output/snmp: generic tx json logger
catenacyber May 15, 2023
2264bf5
output/quic: generic tx json logger
catenacyber May 15, 2023
2ec8b53
output/krb5: generic tx json logger
catenacyber May 15, 2023
97668a9
output/tftp: generic tx json logger
catenacyber May 15, 2023
cb56ddd
output/dnp3: restrict function scope to one file
catenacyber May 15, 2023
bc65a1e
output/modbus: generic tx json logger
catenacyber May 15, 2023
481eb55
output/ssh: generic tx json logger
catenacyber May 15, 2023
9dbcbbd
output/http2: reuse code for file events
catenacyber May 15, 2023
d544917
output/template: reuse code for file events
catenacyber May 15, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions rust/src/krb/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// written by Pierre Chifflier <chifflier@wzdftpd.net>

use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::krb::krb5::{KRB5State,KRB5Transaction,test_weak_encryption};
use crate::krb::krb5::{KRB5Transaction,test_weak_encryption};

fn krb5_log_response(jsb: &mut JsonBuilder, tx: &mut KRB5Transaction) -> Result<(), JsonError>
{
Expand Down Expand Up @@ -68,7 +68,7 @@ fn krb5_log_response(jsb: &mut JsonBuilder, tx: &mut KRB5Transaction) -> Result<
}

#[no_mangle]
pub extern "C" fn rs_krb5_log_json_response(jsb: &mut JsonBuilder, _state: &mut KRB5State, tx: &mut KRB5Transaction) -> bool
pub extern "C" fn rs_krb5_log_json_response(tx: &mut KRB5Transaction, jsb: &mut JsonBuilder) -> bool
{
krb5_log_response(jsb, tx).is_ok()
}
2 changes: 0 additions & 2 deletions rust/src/modbus/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ pub extern "C" fn rs_modbus_to_json(tx: &mut ModbusTransaction, js: &mut JsonBui

/// populate a json object with transactional information, for logging
fn log(tx: &ModbusTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("modbus")?;
js.set_uint("id", tx.id)?;

if let Some(req) = &tx.request {
Expand All @@ -42,7 +41,6 @@ fn log(tx: &ModbusTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.close()?;
}

js.close()?;
Ok(())
}

Expand Down
6 changes: 2 additions & 4 deletions rust/src/mqtt/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@

// written by Sascha Steinbiss <sascha@steinbiss.name>

use super::mqtt::{MQTTState, MQTTTransaction};
use super::mqtt::MQTTTransaction;
use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::mqtt::mqtt_message::{MQTTOperation, MQTTSubscribeTopicData};
use crate::mqtt::parser::FixedHeader;
Expand All @@ -43,7 +43,6 @@ fn log_mqtt_header(js: &mut JsonBuilder, hdr: &FixedHeader) -> Result<(), JsonEr
}

fn log_mqtt(tx: &MQTTTransaction, flags: u32, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("mqtt")?;
for msg in tx.msg.iter() {
match msg.op {
MQTTOperation::CONNECT(ref conn) => {
Expand Down Expand Up @@ -291,14 +290,13 @@ fn log_mqtt(tx: &MQTTTransaction, flags: u32, js: &mut JsonBuilder) -> Result<()
MQTTOperation::UNASSIGNED => {}
}
}
js.close()?; // mqtt

return Ok(());
}

#[no_mangle]
pub unsafe extern "C" fn rs_mqtt_logger_log(
_state: &mut MQTTState, tx: *mut std::os::raw::c_void, flags: u32, js: &mut JsonBuilder,
tx: *mut std::os::raw::c_void, flags: u32, js: &mut JsonBuilder,
) -> bool {
let tx = cast_pointer!(tx, MQTTTransaction);
log_mqtt(tx, flags, js).is_ok()
Expand Down
2 changes: 0 additions & 2 deletions rust/src/quic/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,6 @@ fn quic_tls_extension_name(e: u16) -> Option<String> {
}

fn log_template(tx: &QuicTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("quic")?;
if tx.header.ty != QuicType::Short {
js.set_string("version", String::from(tx.header.version).as_str())?;

Expand Down Expand Up @@ -144,7 +143,6 @@ fn log_template(tx: &QuicTransaction, js: &mut JsonBuilder) -> Result<(), JsonEr
js.close()?;
}

js.close()?;
Ok(())
}

Expand Down
2 changes: 0 additions & 2 deletions rust/src/rdp/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,6 @@ pub extern "C" fn rs_rdp_to_json(tx: &mut RdpTransaction, js: &mut JsonBuilder)

/// populate a json object with transactional information, for logging
fn log(tx: &RdpTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("rdp")?;
js.set_uint("tx_id", tx.id)?;

match &tx.item {
Expand Down Expand Up @@ -58,7 +57,6 @@ fn log(tx: &RdpTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
}
}

js.close()?;
Ok(())
}

Expand Down
9 changes: 2 additions & 7 deletions rust/src/rfb/logger.rs
Original file line number Diff line number Diff line change
Expand Up @@ -19,12 +19,10 @@

use std;
use std::fmt::Write;
use super::rfb::{RFBState, RFBTransaction};
use super::rfb::RFBTransaction;
use crate::jsonbuilder::{JsonBuilder, JsonError};

fn log_rfb(tx: &RFBTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("rfb")?;

// Protocol version
if let Some(tx_spv) = &tx.tc_server_protocol_version {
js.open_object("server_protocol_version")?;
Expand Down Expand Up @@ -107,14 +105,11 @@ fn log_rfb(tx: &RFBTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.close()?;
}

js.close()?;

return Ok(());
}

#[no_mangle]
pub unsafe extern "C" fn rs_rfb_logger_log(_state: &mut RFBState,
tx: *mut std::os::raw::c_void,
pub unsafe extern "C" fn rs_rfb_logger_log(tx: *mut std::os::raw::c_void,
js: &mut JsonBuilder) -> bool {
let tx = cast_pointer!(tx, RFBTransaction);
log_rfb(tx, js).is_ok()
Expand Down
6 changes: 1 addition & 5 deletions rust/src/sip/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -21,8 +21,6 @@ use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::sip::sip::SIPTransaction;

fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.open_object("sip")?;

if let Some(req) = &tx.request {
js.set_string("method", &req.method)?
.set_string("uri", &req.path)?
Expand All @@ -43,12 +41,10 @@ fn log(tx: &SIPTransaction, js: &mut JsonBuilder) -> Result<(), JsonError> {
js.set_string("response_line", resp_line)?;
}

js.close()?;

Ok(())
}

#[no_mangle]
pub extern "C" fn rs_sip_log_json(tx: &mut SIPTransaction, js: &mut JsonBuilder) -> bool {
log(tx, js).is_ok()
}
}
10 changes: 5 additions & 5 deletions rust/src/snmp/log.rs
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,7 @@
// written by Pierre Chifflier <chifflier@wzdftpd.net>

use crate::jsonbuilder::{JsonBuilder, JsonError};
use crate::snmp::snmp::{SNMPState,SNMPTransaction};
use crate::snmp::snmp::SNMPTransaction;
use crate::snmp::snmp_parser::{NetworkAddress,PduType};
use std::borrow::Cow;

Expand All @@ -37,9 +37,9 @@ fn str_of_pdu_type(t:&PduType) -> Cow<str> {
}
}

fn snmp_log_response(jsb: &mut JsonBuilder, state: &mut SNMPState, tx: &mut SNMPTransaction) -> Result<(), JsonError>
fn snmp_log_response(jsb: &mut JsonBuilder, tx: &mut SNMPTransaction) -> Result<(), JsonError>
{
jsb.set_uint("version", state.version as u64)?;
jsb.set_uint("version", tx.version as u64)?;
if tx.encrypted {
jsb.set_string("pdu_type", "encrypted")?;
} else {
Expand Down Expand Up @@ -75,7 +75,7 @@ fn snmp_log_response(jsb: &mut JsonBuilder, state: &mut SNMPState, tx: &mut SNMP
}

#[no_mangle]
pub extern "C" fn rs_snmp_log_json_response(jsb: &mut JsonBuilder, state: &mut SNMPState, tx: &mut SNMPTransaction) -> bool
pub extern "C" fn rs_snmp_log_json_response(tx: &mut SNMPTransaction, jsb: &mut JsonBuilder) -> bool
{
snmp_log_response(jsb, state, tx).is_ok()
snmp_log_response(jsb, tx).is_ok()
}
30 changes: 12 additions & 18 deletions scripts/setup-app-layer.py
Original file line number Diff line number Diff line change
Expand Up @@ -200,39 +200,34 @@ def logger_patch_output_c(proto):
output = io.StringIO()
inlines = open(filename).readlines()
for i, line in enumerate(inlines):
if line.find("output-json-template.h") > -1:
output.write(line.replace("template", proto.lower()))
if line.find("/* Template JSON logger.") > -1:
output.write(inlines[i].replace("Template", proto))
output.write(inlines[i+1].replace("Template", proto))
output.write(inlines[i+2].replace("TEMPLATE", proto.upper()).replace(
"template", proto.lower()).replace("Template", proto))
output.write(inlines[i+3])
if line.find("rs_template_logger_log") > -1:
output.write(inlines[i].replace("TEMPLATE", proto.upper()).replace(
"template", proto.lower()))
if line.find("OutputTemplateLogInitSub(") > -1:
output.write(inlines[i].replace("Template", proto))
output.write(inlines[i+1])
output.write(inlines[i+2].replace("TEMPLATE", proto.upper()))
output.write(inlines[i+3])
output.write(inlines[i+4])
output.write(line)
open(filename, "w").write(output.getvalue())

def logger_copy_templates(proto):
lower = proto.lower()

pairs = (
("src/output-json-template.h",
"src/output-json-%s.h" % (lower)),
("src/output-json-template.c",
"src/output-json-%s.c" % (lower)),
("rust/src/applayertemplate/logger.rs",
"rust/src/applayer%s/logger.rs" % (lower)),
)

common_copy_templates(proto, pairs)

def logger_patch_makefile_am(protoname):
filename = "src/Makefile.am"
print("Patching %s." % (filename))
output = io.StringIO()
with open(filename) as infile:
for line in infile:
if line.lstrip().startswith("output-json-template."):
output.write(line.replace("template", protoname.lower()))
output.write(line)
open(filename, "w").write(output.getvalue())


def detect_copy_templates(proto, buffername):
lower = proto.lower()
Expand Down Expand Up @@ -394,7 +389,6 @@ def main():
raise SetupError("no app-layer parser exists for %s" % (proto))
logger_copy_templates(proto)
patch_rust_applayer_mod_rs(proto)
logger_patch_makefile_am(proto)
logger_patch_output_c(proto)
logger_patch_suricata_yaml_in(proto)

Expand Down
24 changes: 0 additions & 24 deletions src/Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -393,7 +393,6 @@ noinst_HEADERS = \
output.h \
output-json-alert.h \
output-json-anomaly.h \
output-json-bittorrent-dht.h \
output-json-dcerpc.h \
output-json-dhcp.h \
output-json-dnp3.h \
Expand All @@ -406,27 +405,16 @@ noinst_HEADERS = \
output-json-frame.h \
output-json-ftp.h \
output-json.h \
output-json-http2.h \
output-json-http.h \
output-json-ike.h \
output-json-krb5.h \
output-json-metadata.h \
output-json-modbus.h \
output-json-quic.h \
output-json-mqtt.h \
output-json-netflow.h \
output-json-nfs.h \
output-json-pgsql.h \
output-json-rdp.h \
output-json-rfb.h \
output-json-sip.h \
output-json-smb.h \
output-json-smtp.h \
output-json-snmp.h \
output-json-ssh.h \
output-json-stats.h \
output-json-template.h \
output-json-tftp.h \
output-json-tls.h \
output-eve-syslog.h \
output-lua.h \
Expand Down Expand Up @@ -1001,7 +989,6 @@ libsuricata_c_a_SOURCES = \
output-flow.c \
output-json-alert.c \
output-json-anomaly.c \
output-json-bittorrent-dht.c \
output-json.c \
output-json-common.c \
output-json-dcerpc.c \
Expand All @@ -1015,27 +1002,16 @@ libsuricata_c_a_SOURCES = \
output-json-flow.c \
output-json-frame.c \
output-json-ftp.c \
output-json-http2.c \
output-json-http.c \
output-json-ike.c \
output-json-krb5.c \
output-json-metadata.c \
output-json-modbus.c \
output-json-quic.c \
output-json-mqtt.c \
output-json-netflow.c \
output-json-nfs.c \
output-json-pgsql.c \
output-json-rdp.c \
output-json-rfb.c \
output-json-sip.c \
output-json-smb.c \
output-json-smtp.c \
output-json-snmp.c \
output-json-ssh.c \
output-json-stats.c \
output-json-template.c \
output-json-tftp.c \
output-json-tls.c \
output-eve-syslog.c \
output-lua.c \
Expand Down
9 changes: 3 additions & 6 deletions src/app-layer-ftp.c
Original file line number Diff line number Diff line change
Expand Up @@ -1408,13 +1408,9 @@ uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len)
return c == NULL ? len : (uint16_t)(c - buffer + 1);
}

void EveFTPDataAddMetadata(const Flow *f, JsonBuilder *jb)
bool EveFTPDataAddMetadata(void *vtx, JsonBuilder *jb)
{
const FtpDataState *ftp_state = NULL;
if (f->alstate == NULL)
return;

ftp_state = (FtpDataState *)f->alstate;
const FtpDataState *ftp_state = (FtpDataState *)vtx;

if (ftp_state->file_name) {
jb_set_string_from_bytes(jb, "filename", ftp_state->file_name, ftp_state->file_len);
Expand All @@ -1429,6 +1425,7 @@ void EveFTPDataAddMetadata(const Flow *f, JsonBuilder *jb)
default:
break;
}
return true;
}

/**
Expand Down
2 changes: 1 addition & 1 deletion src/app-layer-ftp.h
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ uint64_t FTPMemuseGlobalCounter(void);
uint64_t FTPMemcapGlobalCounter(void);

uint16_t JsonGetNextLineFromBuffer(const char *buffer, const uint16_t len);
void EveFTPDataAddMetadata(const Flow *f, JsonBuilder *jb);
bool EveFTPDataAddMetadata(void *vtx, JsonBuilder *jb);

#endif /* __APP_LAYER_FTP_H__ */

Loading