Go to the documentation of this file.
61 #define PARSE_REGEX "^\\s*([A-z_]+)\\s*(?:,\\s*([A-z_]+))?\\s*(?:,\\s*([A-z_]+))?\\s*$"
72 static void DetectFilestoreRegisterTests(
void);
74 static int g_file_match_list_id = 0;
107 if (filestore == NULL) {
115 int toserver_dir = 0;
116 int toclient_dir = 0;
134 switch (filestore->
scope) {
154 }
else if (this_tx) {
166 }
else if (this_flow) {
219 void *alstate = FlowGetAppState(p->
flow);
231 SCLogDebug(
"u %u txv %p ffc_tx %p file_id %u", u, txv, ffc_tx,
267 uint32_t file_id = 0;
274 SCLogDebug(
"not storing file match: no filedata logger enabled");
286 if (file->
sid != NULL && s->
id > 0) {
294 goto continue_after_realloc_fail;
305 continue_after_realloc_fail:
333 static bool warn_not_configured =
false;
334 static uint32_t de_version = 0;
337 if (!warn_not_configured || (
de_ctx->
version != de_version)) {
339 SCLogDebug(
"reload-detected; re-checking feature presence; DE version now %"PRIu32,
344 "file-store output log which is not enabled. "
345 "Enable the output \"file-store\".");
347 warn_not_configured =
true;
353 char *args[3] = {NULL,NULL,NULL};
356 pcre2_match_data *match = NULL;
360 SCLogError(
"filestore can't work with bypass keyword");
370 if (
str != NULL && strlen(
str) > 0) {
377 if (ret < 1 || ret > 4) {
378 SCLogError(
"parse error, ret %" PRId32
", string %s", ret,
str);
383 pcre2len =
sizeof(str_0);
384 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)str_0, &pcre2len);
386 SCLogError(
"pcre2_substring_copy_bynumber failed");
389 args[0] = (
char *)str_0;
392 pcre2len =
sizeof(str_1);
393 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)str_1, &pcre2len);
395 SCLogError(
"pcre2_substring_copy_bynumber failed");
398 args[1] = (
char *)str_1;
401 pcre2len =
sizeof(str_2);
402 res = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)str_2, &pcre2len);
404 SCLogError(
"pcre2_substring_copy_bynumber failed");
407 args[2] = (
char *)str_2;
416 if (args[0] != NULL) {
419 if (strcasecmp(args[0],
"request") == 0 ||
420 strcasecmp(args[0],
"to_server") == 0)
425 else if (strcasecmp(args[0],
"response") == 0 ||
426 strcasecmp(args[0],
"to_client") == 0)
431 else if (strcasecmp(args[0],
"both") == 0)
440 if (args[1] != NULL) {
443 if (strcasecmp(args[1],
"file") == 0)
446 }
else if (strcasecmp(args[1],
"tx") == 0)
449 }
else if (strcasecmp(args[1],
"ssn") == 0 ||
450 strcasecmp(args[1],
"flow") == 0)
481 pcre2_match_data_free(match);
487 pcre2_match_data_free(match);
507 static int DetectFilestoreTest01(
void)
518 "(bypass; filestore; "
519 "content:\"message\"; http_host; "
528 void DetectFilestoreRegisterTests(
void)
struct DetectEngineThreadCtx_::@98 filestore[DETECT_FILESTORE_MAX]
void AppLayerHtpNeedFileInspection(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request file...
void SigMatchAppendSMToList(Signature *s, SigMatch *new, const int list)
Append a SigMatch to the list type.
void(* Free)(DetectEngineCtx *, void *)
const struct DetectFilestoreData_ * filestore_ctx
void AppLayerParserSetStreamDepthFlag(uint8_t ipproto, AppProto alproto, void *state, uint64_t tx_id, uint8_t flags)
bool g_filedata_logger_enabled
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
#define FILESTORE_DIR_DEFAULT
int(* FileMatch)(DetectEngineThreadCtx *, Flow *, uint8_t flags, File *, const Signature *, const SigMatchCtx *)
main detection engine ctx
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
#define FLOW_PKT_TOSERVER
int DetectParsePcreExec(DetectParseRegex *parse_regex, pcre2_match_data **match, const char *str, int start_offset, int options)
AppLayerStateData * AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
#define FILESTORE_SCOPE_TX
@ DETECT_SM_LIST_POSTMATCH
bool RequiresFeature(const char *feature_name)
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
#define DETECT_FILESTORE_MAX
#define FILESTORE_SCOPE_SSN
void DetectSetupParseRegexes(const char *parse_str, DetectParseRegex *detect_parse)
#define STREAM_FLAGS_FOR_PACKET(p)
void FileStoreFileById(FileContainer *fc, uint32_t file_id)
flag a file with id "file_id" to be stored.
#define SCLogWarning(...)
Macro used to log WARNING messages.
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
uint32_t FileReassemblyDepth(void)
#define FILESTORE_DIR_TOCLIENT
Data structures and function prototypes for keeping state for the detection engine.
int(* Match)(DetectEngineThreadCtx *, Packet *, const Signature *, const SigMatchCtx *)
#define FLOW_PKT_TOCLIENT
int RunmodeIsUnittests(void)
SigMatch * SigMatchAlloc(void)
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
#define SCRealloc(ptr, sz)
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
#define FILESTORE_DIR_BOTH
#define FILESTORE_DIR_TOSERVER
void DetectFilestoreRegister(void)
Registration function for keyword: filestore.
struct AppLayerTxData AppLayerTxData
#define FEATURE_OUTPUT_FILESTORE
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
int DetectBufferTypeRegister(const char *name)
SigTableElmt sigmatch_table[DETECT_TBLSIZE]
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
#define SIGMATCH_OPTIONAL_OPT
#define SCLogError(...)
Macro used to log ERROR messages.
#define PARSE_REGEX
Regex for parsing our flow options.
void TcpSessionSetReassemblyDepth(TcpSession *ssn, uint32_t size)
a single match condition for a signature
DetectEngineCtx * DetectEngineCtxInit(void)
#define FILESTORE_SCOPE_DEFAULT
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *state, void *tx, const uint8_t direction)
AppProto alproto
application level protocol
#define DEBUG_VALIDATE_BUG_ON(exp)
#define SIG_FLAG_FILESTORE
void(* RegisterTests)(void)
@ DETECT_FILESTORE_POSTMATCH