@ -65,6 +65,7 @@
# include "output-json-smb.h"
# include "app-layer-htp.h"
# include "app-layer-htp-xff.h"
# include "util-memcmp.h"
# include "stream-tcp-reassemble.h"
@ -73,6 +74,7 @@
typedef struct OutputFileCtx_ {
LogFileCtx * file_ctx ;
uint32_t file_cnt ;
HttpXFFCfg * xff_cfg ;
} OutputFileCtx ;
typedef struct JsonFileLogThread_ {
@ -81,7 +83,7 @@ typedef struct JsonFileLogThread_ {
} JsonFileLogThread ;
json_t * JsonBuildFileInfoRecord ( const Packet * p , const File * ff ,
const bool stored , uint8_t dir )
const bool stored , uint8_t dir , HttpXFFCfg * xff_cfg )
{
json_t * hjs = NULL ;
enum OutputJsonLogDirection fdir = LOG_DIR_FLOW ;
@ -205,6 +207,29 @@ json_t *JsonBuildFileInfoRecord(const Packet *p, const File *ff,
json_object_set_new ( fjs , " size " , json_integer ( FileTrackedSize ( ff ) ) ) ;
json_object_set_new ( fjs , " tx_id " , json_integer ( ff - > txid ) ) ;
/* xff header */
if ( ( xff_cfg ! = NULL ) & & ! ( xff_cfg - > flags & XFF_DISABLED ) & & p - > flow ! = NULL ) {
int have_xff_ip = 0 ;
char buffer [ XFF_MAXLEN ] ;
if ( FlowGetAppProtocol ( p - > flow ) = = ALPROTO_HTTP ) {
have_xff_ip = HttpXFFGetIPFromTx ( p - > flow , ff - > txid , xff_cfg , buffer , XFF_MAXLEN ) ;
}
if ( have_xff_ip ) {
if ( xff_cfg - > flags & XFF_EXTRADATA ) {
json_object_set_new ( js , " xff " , json_string ( buffer ) ) ;
}
else if ( xff_cfg - > flags & XFF_OVERWRITE ) {
if ( p - > flowflags & FLOW_PKT_TOCLIENT ) {
json_object_set ( js , " dest_ip " , json_string ( buffer ) ) ;
} else {
json_object_set ( js , " src_ip " , json_string ( buffer ) ) ;
}
}
}
}
/* originally just 'file', but due to bug 1127 naming it fileinfo */
json_object_set_new ( js , " fileinfo " , fjs ) ;
@ -218,8 +243,9 @@ json_t *JsonBuildFileInfoRecord(const Packet *p, const File *ff,
static void FileWriteJsonRecord ( JsonFileLogThread * aft , const Packet * p ,
const File * ff , uint32_t dir )
{
HttpXFFCfg * xff_cfg = aft - > filelog_ctx - > xff_cfg ;
json_t * js = JsonBuildFileInfoRecord ( p , ff ,
ff - > flags & FILE_STORED ? true : false , dir );
ff - > flags & FILE_STORED ? true : false , dir , xff_cfg );
if ( unlikely ( js = = NULL ) ) {
return ;
}
@ -290,6 +316,9 @@ static TmEcode JsonFileLogThreadDeinit(ThreadVars *t, void *data)
static void OutputFileLogDeinitSub ( OutputCtx * output_ctx )
{
OutputFileCtx * ff_ctx = output_ctx - > data ;
if ( ff_ctx - > xff_cfg ! = NULL ) {
SCFree ( ff_ctx - > xff_cfg ) ;
}
SCFree ( ff_ctx ) ;
SCFree ( output_ctx ) ;
}
@ -330,6 +359,10 @@ static OutputInitResult OutputFileLogInitSub(ConfNode *conf, OutputCtx *parent_c
FileForceHashParseCfg ( conf ) ;
}
output_file_ctx - > xff_cfg = SCCalloc ( 1 , sizeof ( HttpXFFCfg ) ) ;
if ( output_file_ctx - > xff_cfg ! = NULL ) {
HttpXFFGetCfg ( conf , output_file_ctx - > xff_cfg ) ;
}
output_ctx - > data = output_file_ctx ;
output_ctx - > DeInit = OutputFileLogDeinitSub ;