# Original Author: Justin Henderson
#         SANS Instructor and author of SANS SEC555: SIEM and Tactical Analytics
# Updated by: Doug Burks
# Last Update: 2/7/2018
#
# This conf file is based on accepting logs for ftp.log from Bro systems
filter {
  if [type] == "bro_ftp" {
	# If message looks like json, try to parse it as such. Otherwise, fall back to csv or grok.
	if [message] =~ /^{.*}$/ {
		json {
			source => "message"
		}

		mutate {
			rename => { "ts" => "timestamp" }
			#uid
			rename => { "id.orig_h" => "source_ip" }
			rename => { "id.orig_p" => "source_port" }
			rename => { "id.resp_h" => "destination_ip" }
			rename => { "id.resp_p" => "destination_port" }
			rename => { "user" => "username" }
			#password
			rename => { "command" => "ftp_command" }
			rename => { "arg" => "ftp_argument" }
			rename => { "mime_type" => "mimetype" }
			#file_size
			#reply_code
			rename => { "reply_msg" => "reply_message" }
			rename => { "data_channel.passive" => "data_channel_passive" }
			rename => { "data_channel.orig_h" => "data_channel_source_ip" }
			rename => { "data_channel.resp_h" => "data_channel_destination_ip" }
			rename => { "data_channel.resp_p" => "data_channel_destination_port" }
			#fuid
		}

		mutate {
			convert => { "reply" => "string" }
		}

        } else {

	    mutate {
	      gsub => [ "message", "[\"']", "" ]
	    }
	    csv {
	      columns => ["timestamp","uid","source_ip","source_port","destination_ip","destination_port","username","password","ftp_command","ftp_argument","mimetype","file_size","reply_code","reply_message","data_channel_passive","data_channel_source_ip","data_channel_destination_ip","data_channel_destination_port","fuid"]
	      separator => "	"
	    }
	}

	mutate {
		#add_tag => [ "conf_file_1105"]
	}
  }	
}
