assert(file);
FileVerdict verdict = policy->type_lookup(p, file);
-
- if ( file->get_file_sig_sha256() and
- ((verdict == FILE_VERDICT_UNKNOWN) or (verdict == FILE_VERDICT_STOP_CAPTURE)))
+ if (verdict == FILE_VERDICT_STOP_CAPTURE)
{
- verdict = policy->signature_lookup(p, file);
+ verdict = FILE_VERDICT_UNKNOWN;
}
- if ((verdict == FILE_VERDICT_UNKNOWN) or (verdict == FILE_VERDICT_STOP_CAPTURE))
+ if ( file->get_file_sig_sha256() and verdict == FILE_VERDICT_UNKNOWN )
{
- verdict = file->verdict;
+ verdict = policy->signature_lookup(p, file);
}
return verdict;
{ "enable_type", Parameter::PT_BOOL, nullptr, "true",
"enable type ID" },
- { "enable_signature", Parameter::PT_BOOL, nullptr, "true",
+ { "enable_signature", Parameter::PT_BOOL, nullptr, "false",
"enable signature calculation" },
{ "enable_capture", Parameter::PT_BOOL, nullptr, "false",
{ "verdict_delay", Parameter::PT_INT, "0:max53", "0",
"number of queries to return final verdict" },
+ { "b64_decode_depth", Parameter::PT_INT, "-1:65535", "-1",
+ "base64 decoding depth (-1 no limit)" },
+
+ { "bitenc_decode_depth", Parameter::PT_INT, "-1:65535", "-1",
+ "Non-Encoded MIME attachment extraction depth (-1 no limit)" },
+
+ { "decompress_pdf", Parameter::PT_BOOL, nullptr, "false",
+ "decompress pdf files in MIME attachments" },
+
+ { "decompress_swf", Parameter::PT_BOOL, nullptr, "false",
+ "decompress swf files in MIME attachments" },
+
+ { "decompress_zip", Parameter::PT_BOOL, nullptr, "false",
+ "decompress zip files in MIME attachments" },
+
+ { "qp_decode_depth", Parameter::PT_INT, "-1:65535", "-1",
+ "Quoted Printable decoding depth (-1 no limit)" },
+
+ { "uu_decode_depth", Parameter::PT_INT, "-1:65535", "-1",
+ "Unix-to-Unix decoding depth (-1 no limit)" },
+
{ nullptr, Parameter::PT_MAX, nullptr, nullptr, nullptr }
};
else if ( v.is("enable_type") )
{
- if ( v.get_bool() )
- {
- fp.set_file_type(true);
- }
+ fp.set_file_type(v.get_bool());
}
else if ( v.is("enable_signature") )
{
- if ( v.get_bool() )
- {
- fp.set_file_signature(true);
- }
+ fp.set_file_signature(v.get_bool());
}
else if ( v.is("enable_capture") )
{
- if ( v.get_bool() )
+ if (v.get_bool() and Snort::is_reloading() and !FileService::is_file_capture_enabled())
{
- if (Snort::is_reloading() && !FileService::is_file_capture_enabled())
- {
- ReloadError("Changing file_id.enable_capture requires a restart.\n");
- return false;
- }
- fp.set_file_capture(true);
+ ReloadError("Changing file_id.enable_capture requires a restart.\n");
+ return false;
}
+ fp.set_file_capture(v.get_bool());
}
else if ( v.is("show_data_depth") )
fc->show_data_depth = v.get_int64();
fc->verdict_delay = v.get_int64();
fp.set_verdict_delay(fc->verdict_delay);
}
+ else if ( v.is("decompress_pdf") )
+ FileService::decode_conf.set_decompress_pdf(v.get_bool());
+
+ else if ( v.is("decompress_swf") )
+ FileService::decode_conf.set_decompress_swf(v.get_bool());
+
+ else if ( v.is("decompress_zip") )
+ FileService::decode_conf.set_decompress_zip(v.get_bool());
+
+ else if (v.is("b64_decode_depth"))
+ {
+ int32_t value = v.get_int32();
+ int32_t mime = value > 0 ? value : -(value+1);
+ FileService::decode_conf.set_b64_depth(mime);
+ }
+ else if (v.is("bitenc_decode_depth"))
+ {
+ int32_t value = v.get_int32();
+ int32_t mime = value > 0 ? value : -(value+1);
+ FileService::decode_conf.set_bitenc_depth(mime);
+ }
+ else if (v.is("qp_decode_depth"))
+ {
+ int32_t value = v.get_int32();
+ int32_t mime = value > 0 ? value : -(value+1);
+ FileService::decode_conf.set_qp_depth(mime);
+ }
+ else if (v.is("uu_decode_depth"))
+ {
+ int32_t value = v.get_int32();
+ int32_t mime = value > 0 ? value : -(value+1);
+ FileService::decode_conf.set_uu_depth(mime);
+ }
else if ( v.is("file_rules") )
return true;
bool FileService::file_processing_initiated = false;
FileCache* FileService::file_cache = nullptr;
+DecodeConfig FileService::decode_conf;
// FIXIT-L make these params reloadable
static int64_t max_files_cached = 0;
}
}
+void FileService::reset_depths()
+{
+ FileConfig* file_config = get_file_config();
+
+ if (file_config)
+ file_config->file_depth = 0;
+
+ decode_conf.sync_all_depths();
+}
+
namespace snort
{
uint64_t get_file_processed_size(Flow* flow)
#include "file_api/file_policy.h"
#include "main/snort_config.h"
#include "main/snort_types.h"
+#include "mime/file_mime_config.h"
class FileEnforcer;
class FileCache;
static bool is_file_capture_enabled() { return file_capture_enabled; }
static bool is_file_service_enabled();
static int64_t get_max_file_depth();
+ static void reset_depths();
static FileCache* get_file_cache() { return file_cache; }
+ static DecodeConfig decode_conf;
private:
static bool file_type_id_enabled;
static FileContext* DCE2_get_main_file_context()
{
FileFlows* file_flows = FileFlows::get_file_flows(DetectionEngine::get_current_packet()->flow);
- assert(file_flows);
- return file_flows->get_current_file_context();
+ if (file_flows)
+ return file_flows->get_current_file_context();
+ else
+ return nullptr;
}
FileVerdict DCE2_get_file_verdict()
Packet* p = DetectionEngine::get_current_packet();
FileFlows* file_flows = FileFlows::get_file_flows(p->flow);
+
+ if (!file_flows)
+ return DCE2_RET__ERROR;
+
if (!file_flows->file_process(p, data_ptr, (int)data_len, position, upload,
DCE2_SmbIsVerdictSuspend(upload, position)))
{
if (params->js_norm_param.normalize_javascript)
params->js_norm_param.js_norm->configure();
- config_decode();
-
return true;
}
break;
case SEC_HEADER:
current_section = new HttpMsgHeader(
- data, dsize, session_data, source_id, buf_owner, flow, params,
- decode_conf);
+ data, dsize, session_data, source_id, buf_owner, flow, params);
break;
case SEC_BODY_CL:
current_section = new HttpMsgBodyCl(
static int get_xtra_uri(snort::Flow*, uint8_t**, uint32_t*, uint32_t*);
static int get_xtra_host(snort::Flow*, uint8_t** buf, uint32_t* len, uint32_t* type);
static int get_xtra_jsnorm(snort::Flow*, uint8_t**, uint32_t*, uint32_t*);
- void config_decode() { decode_conf.sync_all_depths(); }
private:
friend HttpApi;
const uint32_t xtra_uri_id;
const uint32_t xtra_host_id;
const uint32_t xtra_jsnorm_id;
- snort::DecodeConfig decode_conf;
};
#endif
if (!session_data->mime_state[source_id])
{
FileFlows* file_flows = FileFlows::get_file_flows(flow);
+ if (!file_flows)
+ return;
+
const FileDirection dir = source_id == SRC_SERVER ? FILE_DOWNLOAD : FILE_UPLOAD;
size_t file_index = 0;
HttpMsgHeader::HttpMsgHeader(const uint8_t* buffer, const uint16_t buf_size,
HttpFlowData* session_data_, SourceId source_id_, bool buf_owner, Flow* flow_,
- const HttpParaList* params_, DecodeConfig decode_conf_) :
- HttpMsgHeadShared(buffer, buf_size, session_data_, source_id_, buf_owner, flow_, params_),
- decode_conf(decode_conf_)
+ const HttpParaList* params_) :
+ HttpMsgHeadShared(buffer, buf_size, session_data_, source_id_, buf_owner, flow_, params_)
{
transaction->set_header(this, source_id);
get_related_sections();
{
if (boundary_present(content_type))
{
- session_data->mime_state[source_id] = new MimeSession(&decode_conf, &mime_conf,
+ session_data->mime_state[source_id] = new MimeSession(&FileService::decode_conf, &mime_conf,
transaction->get_file_processing_id(source_id));
// Show file processing the Content-Type header as if it were regular data.
// This will enable it to find the boundary string.
public:
HttpMsgHeader(const uint8_t* buffer, const uint16_t buf_size, HttpFlowData* session_data_,
HttpCommon::SourceId source_id_, bool buf_owner, snort::Flow* flow_,
- const HttpParaList* params_, snort::DecodeConfig decode_conf);
+ const HttpParaList* params_);
HttpEnums::InspectSection get_inspection_section() const override
{ return HttpEnums::IS_HEADER; }
bool detection_required() const override { return true; }
// Dummy configurations to support MIME processing
snort::MailLogConfig mime_conf;
- snort::DecodeConfig decode_conf;
Field true_ip;
Field true_ip_addr;
if (!session_data->mime_state[source_id])
{
FileFlows* file_flows = FileFlows::get_file_flows(flow);
+ if (!file_flows)
+ return false;
+
const FileDirection dir = source_id == SRC_SERVER ? FILE_DOWNLOAD : FILE_UPLOAD;
size_t file_index = 0;