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;
135 switch (filestore->
scope) {
155 }
else if (this_tx) {
172 }
else if (this_flow) {
232 void *alstate = FlowGetAppState(p->
flow);
244 SCLogDebug(
"u %u txv %p ffc_tx %p file_id %u", u, txv, ffc_tx,
280 uint32_t file_id = 0;
287 SCLogDebug(
"not storing file match: no filedata logger enabled");
299 if (file->
sid != NULL && s->
id > 0) {
307 goto continue_after_realloc_fail;
318 continue_after_realloc_fail:
346 static bool warn_not_configured =
false;
347 static uint32_t de_version = 0;
350 SCLogError(
"Cannot have more than 65535 filestore signatures");
355 if (!warn_not_configured || (
de_ctx->
version != de_version)) {
357 SCLogDebug(
"reload-detected; re-checking feature presence; DE version now %"PRIu32,
362 "file-store output log which is not enabled. "
363 "Enable the output \"file-store\".");
365 warn_not_configured =
true;
370 char *args[3] = {NULL,NULL,NULL};
373 pcre2_match_data *match = NULL;
377 SCLogError(
"filestore can't work with bypass keyword");
381 if (
str != NULL && strlen(
str) > 0) {
388 if (ret < 1 || ret > 4) {
389 SCLogError(
"parse error, ret %" PRId32
", string %s", ret,
str);
394 pcre2len =
sizeof(str_0);
395 res = pcre2_substring_copy_bynumber(match, 1, (PCRE2_UCHAR8 *)str_0, &pcre2len);
397 SCLogError(
"pcre2_substring_copy_bynumber failed");
400 args[0] = (
char *)str_0;
403 pcre2len =
sizeof(str_1);
404 res = pcre2_substring_copy_bynumber(match, 2, (PCRE2_UCHAR8 *)str_1, &pcre2len);
406 SCLogError(
"pcre2_substring_copy_bynumber failed");
409 args[1] = (
char *)str_1;
412 pcre2len =
sizeof(str_2);
413 res = pcre2_substring_copy_bynumber(match, 3, (PCRE2_UCHAR8 *)str_2, &pcre2len);
415 SCLogError(
"pcre2_substring_copy_bynumber failed");
418 args[2] = (
char *)str_2;
426 if (args[0] != NULL) {
429 if (strcasecmp(args[0],
"request") == 0 ||
430 strcasecmp(args[0],
"to_server") == 0)
435 else if (strcasecmp(args[0],
"response") == 0 ||
436 strcasecmp(args[0],
"to_client") == 0)
441 else if (strcasecmp(args[0],
"both") == 0)
450 if (args[1] != NULL) {
453 if (strcasecmp(args[1],
"file") == 0)
456 }
else if (strcasecmp(args[1],
"tx") == 0)
459 }
else if (strcasecmp(args[1],
"ssn") == 0 ||
460 strcasecmp(args[1],
"flow") == 0)
476 DetectFilestoreFree(
de_ctx, fd);
490 pcre2_match_data_free(match);
496 pcre2_match_data_free(match);
514 static int DetectFilestoreTest01(
void)
525 "(bypass; filestore; "
526 "content:\"message\"; http_host; "
535 void DetectFilestoreRegisterTests(
void)
void AppLayerHtpNeedFileInspection(void)
Sets a flag that informs the HTP app layer that some module in the engine needs the http request file...
SigTableElmt * sigmatch_table
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)
struct DetectEngineThreadCtx_::@97 filestore[DETECT_FILESTORE_MAX]
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)
#define FLOWFILE_STORE_TS
int(* Setup)(DetectEngineCtx *, Signature *, const char *)
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
#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 FLOWFILE_STORE_TC
#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)
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)
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)
DetectEngineCtx * DetectEngineCtxInit(void)
#define FILESTORE_SCOPE_DEFAULT
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
AppProto alproto
application level protocol
#define DEBUG_VALIDATE_BUG_ON(exp)
#define SIG_FLAG_FILESTORE
void(* RegisterTests)(void)
@ DETECT_FILESTORE_POSTMATCH