@ -43,6 +43,7 @@
# include "detect-engine.h"
# include "detect-engine.h"
# include "detect-engine-mpm.h"
# include "detect-engine-mpm.h"
# include "detect-reference.h"
# include "detect-reference.h"
# include "detect-metadata.h"
# include "app-layer-parser.h"
# include "app-layer-parser.h"
# include "app-layer-dnp3.h"
# include "app-layer-dnp3.h"
# include "app-layer-htp.h"
# include "app-layer-htp.h"
@ -85,6 +86,7 @@
# define LOG_JSON_FLOW BIT_U16(5)
# define LOG_JSON_FLOW BIT_U16(5)
# define LOG_JSON_HTTP_BODY BIT_U16(6)
# define LOG_JSON_HTTP_BODY BIT_U16(6)
# define LOG_JSON_HTTP_BODY_BASE64 BIT_U16(7)
# define LOG_JSON_HTTP_BODY_BASE64 BIT_U16(7)
# define LOG_JSON_RULE_METADATA BIT_U16(8)
# define LOG_JSON_METADATA (LOG_JSON_APP_LAYER | LOG_JSON_FLOW)
# define LOG_JSON_METADATA (LOG_JSON_APP_LAYER | LOG_JSON_FLOW)
@ -226,9 +228,42 @@ static void AlertJsonSourceTarget(const Packet *p, const PacketAlert *pa,
json_object_set_new ( ajs , " target " , tjs ) ;
json_object_set_new ( ajs , " target " , tjs ) ;
}
}
static void AlertJsonMetadata ( AlertJsonOutputCtx * json_output_ctx , const PacketAlert * pa , json_t * ajs )
{
if ( pa - > s - > metadata ) {
const DetectMetadata * kv = pa - > s - > metadata ;
json_t * mjs = json_object ( ) ;
if ( unlikely ( mjs = = NULL ) ) {
return ;
}
while ( kv ) {
json_t * jkey = json_object_get ( mjs , kv - > key ) ;
if ( jkey = = NULL ) {
jkey = json_array ( ) ;
if ( unlikely ( jkey = = NULL ) )
break ;
json_array_append_new ( jkey , json_string ( kv - > value ) ) ;
json_object_set_new ( mjs , kv - > key , jkey ) ;
} else {
json_array_append_new ( jkey , json_string ( kv - > value ) ) ;
}
void AlertJsonHeader ( const Packet * p , const PacketAlert * pa , json_t * js )
kv = kv - > next ;
}
if ( json_object_size ( mjs ) = = 0 ) {
json_decref ( mjs ) ;
} else {
json_object_set_new ( ajs , " metadata " , mjs ) ;
}
}
}
void AlertJsonHeader ( void * ctx , const Packet * p , const PacketAlert * pa , json_t * js ,
uint16_t flags )
{
{
AlertJsonOutputCtx * json_output_ctx = ( AlertJsonOutputCtx * ) ctx ;
const char * action = " allowed " ;
const char * action = " allowed " ;
/* use packet action if rate_filter modified the action */
/* use packet action if rate_filter modified the action */
if ( unlikely ( pa - > flags & PACKET_ALERT_RATE_FILTER_MODIFIED ) ) {
if ( unlikely ( pa - > flags & PACKET_ALERT_RATE_FILTER_MODIFIED ) ) {
@ -271,6 +306,10 @@ void AlertJsonHeader(const Packet *p, const PacketAlert *pa, json_t *js)
AlertJsonSourceTarget ( p , pa , js , ajs ) ;
AlertJsonSourceTarget ( p , pa , js , ajs ) ;
}
}
if ( ( json_output_ctx ! = NULL ) & & ( flags & LOG_JSON_RULE_METADATA ) ) {
AlertJsonMetadata ( json_output_ctx , pa , ajs ) ;
}
/* alert */
/* alert */
json_object_set_new ( js , " alert " , ajs ) ;
json_object_set_new ( js , " alert " , ajs ) ;
}
}
@ -364,7 +403,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
MemBufferReset ( aft - > json_buffer ) ;
MemBufferReset ( aft - > json_buffer ) ;
/* alert */
/* alert */
AlertJsonHeader ( p, pa , j s) ;
AlertJsonHeader ( json_output_ctx, p, pa , j s, json_output_ctx - > flag s) ;
if ( IS_TUNNEL_PKT ( p ) ) {
if ( IS_TUNNEL_PKT ( p ) ) {
AlertJsonTunnel ( p , js ) ;
AlertJsonTunnel ( p , js ) ;
@ -721,7 +760,6 @@ static void JsonAlertLogDeInitCtxSub(OutputCtx *output_ctx)
if ( xff_cfg ! = NULL ) {
if ( xff_cfg ! = NULL ) {
SCFree ( xff_cfg ) ;
SCFree ( xff_cfg ) ;
}
}
SCFree ( json_output_ctx ) ;
SCFree ( json_output_ctx ) ;
}
}
SCFree ( output_ctx ) ;
SCFree ( output_ctx ) ;
@ -777,6 +815,19 @@ static void XffSetup(AlertJsonOutputCtx *json_output_ctx, ConfNode *conf)
SetFlag ( conf , " http-body-printable " , LOG_JSON_HTTP_BODY , & flags ) ;
SetFlag ( conf , " http-body-printable " , LOG_JSON_HTTP_BODY , & flags ) ;
SetFlag ( conf , " http-body " , LOG_JSON_HTTP_BODY_BASE64 , & flags ) ;
SetFlag ( conf , " http-body " , LOG_JSON_HTTP_BODY_BASE64 , & flags ) ;
ConfNode * rmetadata = ConfNodeLookupChild ( conf , " rule-metadata " ) ;
if ( rmetadata ! = NULL ) {
int enabled = 0 , ret ;
ret = ConfGetChildValueBool ( rmetadata , " enabled " , & enabled ) ;
if ( ret & & enabled ) {
json_output_ctx - > flags | = LOG_JSON_RULE_METADATA ;
}
}
if ( json_output_ctx - > flags & LOG_JSON_RULE_METADATA ) {
DetectEngineSetParseMetadata ( ) ;
}
const char * payload_buffer_value = ConfNodeLookupChildValue ( conf , " payload-buffer-size " ) ;
const char * payload_buffer_value = ConfNodeLookupChildValue ( conf , " payload-buffer-size " ) ;
if ( payload_buffer_value ! = NULL ) {
if ( payload_buffer_value ! = NULL ) {