Go to the documentation of this file.
46 static uint16_t g_file_flow_mask = 0;
51 static int g_file_force_filestore = 0;
56 static int g_file_force_magic = 0;
61 static int g_file_force_md5 = 0;
66 static int g_file_force_sha1 = 0;
71 static int g_file_force_sha256 = 0;
76 static int g_file_force_tracking = 0;
81 static int g_file_store_enable = 0;
86 static uint32_t g_file_store_reassembly_depth = 0;
90 static void FileEndSha256(
File *ff);
94 g_file_force_filestore = 1;
100 g_file_force_magic = 1;
106 g_file_force_md5 = 1;
112 g_file_force_sha1 = 1;
118 g_file_force_sha256 = 1;
124 return g_file_force_filestore;
129 g_file_store_enable = 1;
130 g_file_store_reassembly_depth = size;
135 if (g_file_store_enable == 1)
136 return g_file_store_reassembly_depth;
143 return g_file_force_magic;
148 return g_file_force_md5;
153 return g_file_force_sha1;
158 return g_file_force_sha256;
163 g_file_force_tracking = 1;
178 if (force_md5 != NULL) {
180 "found. Please use 'force-hash: [md5]' instead");
185 "not forcing md5 calculation for logged files: hashing globally disabled");
188 SCLogInfo(
"forcing md5 calculation for logged files");
196 if (forcehash_node != NULL) {
200 if (strcasecmp(
"md5", field->
val) == 0) {
202 SCLogInfo(
"not forcing md5 calculation for logged files: hashing globally "
206 SCLogConfig(
"forcing md5 calculation for logged or stored files");
210 if (strcasecmp(
"sha1", field->
val) == 0) {
212 SCLogInfo(
"not forcing sha1 calculation for logged files: hashing globally "
216 SCLogConfig(
"forcing sha1 calculation for logged or stored files");
220 if (strcasecmp(
"sha256", field->
val) == 0) {
222 SCLogInfo(
"not forcing sha256 calculation for logged files: hashing globally "
226 SCLogConfig(
"forcing sha256 calculation for logged or stored files");
237 if (direction == STREAM_TOSERVER) {
306 file->
flags |= update_flags;
314 static int FileMagicSize(
void)
328 if (file != NULL && file->
sb != NULL) {
329 const uint64_t size = StreamingBufferGetConsecutiveDataRightEdge(file->
sb);
371 SCLogDebug(
"file->state %d. Is >= FILE_STATE_CLOSED: %s",
380 if (file->magic == NULL)
385 SCLogDebug(
"file->flags & FILE_NOMAGIC == true");
398 const uint64_t file_offset = StreamingBufferGetOffset(file->
sb);
400 if (file_offset == 0)
404 uint64_t data_size = file_size - file_offset;
406 SCLogDebug(
"window %"PRIu32
", file_size %"PRIu64
", data_size %"PRIu64,
407 window, file_size, data_size);
409 if (data_size > (window * 3)) {
414 if (left_edge > window)
430 #define P(file, flag) ((file)->flags & (flag)) ? "true" : "false"
467 if (FilePruneFile(file, cfg) == 0) {
478 prev->
next = file_next;
480 if (file == ffc->
head)
481 ffc->
head = file_next;
482 if (file == ffc->
tail)
504 new->head =
new->tail = NULL;
521 for (;cur != NULL; cur =
next) {
541 for (;ptr != NULL; ptr =
next) {
557 static File *FileAlloc(
const uint8_t *name, uint16_t name_len)
566 if (new->name == NULL) {
571 new->name_len = name_len;
572 memcpy(new->name, name, name_len);
577 new->sid =
SCMalloc(
sizeof(uint32_t) * new->sid_max);
578 if (new->sid == NULL)
590 if (ff->
name != NULL)
596 if (ff->magic != NULL)
599 if (ff->
sb != NULL) {
615 if (ffc->
head == NULL || ffc->
tail == NULL) {
643 static int FileStoreNoStoreCheck(
File *ff)
662 static int AppendData(
668 SCLogDebug(
"file %p data_len %u", file, data_len);
670 SCLogDebug(
"file %p StreamingBufferAppendNoTrack failed", file);
675 SCMd5Update(file->
md5_ctx, data, data_len);
678 SCSha1Update(file->
sha1_ctx, data, data_len);
681 SCLogDebug(
"SHA256 file %p data %p data_len %u", file, data, data_len);
682 SCSha256Update(file->
sha256_ctx, data, data_len);
684 SCLogDebug(
"NO SHA256 file %p data %p data_len %u", file, data, data_len);
694 static void FileFlagGap(
File *ff) {
711 static int FileAppendDataDo(
715 #ifdef DEBUG_VALIDATION
719 ff->
size += data_len;
736 SCMd5Update(ff->
md5_ctx, data, data_len);
740 SCSha1Update(ff->
sha1_ctx, data, data_len);
744 SCLogDebug(
"file %p data %p data_len %u", ff, data, data_len);
745 SCSha256Update(ff->
sha256_ctx, data, data_len);
756 SCLogDebug(
"flowfile state transitioned to FILE_STATE_TRUNCATED");
760 SCLogDebug(
"appending %"PRIu32
" bytes", data_len);
762 int r = AppendData(sbcfg, ff, data, data_len);
788 if (ffc == NULL || ffc->
tail == NULL || data_len == 0 || sbcfg == NULL) {
791 int r = FileAppendDataDo(sbcfg, ffc->
tail, data, data_len);
809 const uint8_t *data, uint32_t data_len)
813 if (ffc == NULL || ffc->
tail == NULL || data == NULL || data_len == 0) {
817 for ( ; ff != NULL; ff = ff->
next) {
819 int r = FileAppendDataDo(sbcfg, ff, data, data_len);
840 const uint8_t *data, uint32_t data_len)
844 if (ffc == NULL || ffc->
tail == NULL || data == NULL || data_len == 0) {
848 for ( ; ff != NULL; ff = ff->
next) {
853 int r = FileAppendDataDo(sbcfg, ff, data, data_len);
880 if (ffc == NULL || ffc->
tail == NULL) {
904 const uint8_t *name, uint16_t name_len,
905 const uint8_t *data, uint32_t data_len, uint16_t
flags)
911 File *ff = FileAlloc(name, name_len);
917 if (ff->
sb == NULL) {
958 SCLogDebug(
"flowfile state transitioned to FILE_STATE_OPENED");
967 ff->
size += data_len;
969 if (AppendData(sbcfg, ff, data, data_len) != 0) {
974 }
else if (data_len > 0) {
985 uint32_t track_id,
const uint8_t *name, uint16_t name_len,
986 const uint8_t *data, uint32_t data_len, uint16_t
flags)
988 SCLogDebug(
"ffc %p track_id %u", ffc, track_id);
989 File *ff = FileOpenFile(ffc, sbcfg, name, name_len, data, data_len,
flags);
998 uint32_t data_len, uint16_t
flags)
1010 ff->
size += data_len;
1015 SCMd5Update(ff->
md5_ctx, data, data_len);
1017 SCSha1Update(ff->
sha1_ctx, data, data_len);
1019 SCLogDebug(
"file %p data %p data_len %u", ff, data, data_len);
1020 SCSha256Update(ff->
sha256_ctx, data, data_len);
1023 if (AppendData(sbcfg, ff, data, data_len) != 0) {
1035 SCLogDebug(
"flowfile state transitioned to FILE_STATE_TRUNCATED");
1042 SCLogDebug(
"file %p data %p data_len %u", ff, data, data_len);
1048 SCLogDebug(
"flowfile state transitioned to FILE_STATE_CLOSED");
1061 SCLogDebug(
"file %p data %p data_len %u", ff, data, data_len);
1081 uint32_t data_len, uint16_t
flags)
1085 if (ffc == NULL || ffc->
tail == NULL) {
1097 const uint8_t *data, uint32_t data_len, uint16_t
flags)
1101 if (ffc == NULL || ffc->
tail == NULL) {
1106 for ( ; ff != NULL; ff = ff->
next) {
1128 if (direction == STREAM_TOSERVER) {
1135 SCLogDebug(
"f->file_flags %04x set_file_flags %04x g_file_flow_mask %04x",
1136 f->
file_flags, set_file_flags, g_file_flow_mask);
1142 SCLogDebug(
"state data: updating file_flags %04x with flow file_flags %04x",
1159 if (g_file_force_filestore == 0) {
1162 if (direction & STREAM_TOSERVER) {
1184 for (ptr = fc->
head; ptr != NULL; ptr = ptr->
next) {
1199 for (ptr = fc->
head; ptr != NULL; ptr = ptr->
next) {
1210 FileTruncateAllOpenFiles(fc, sbcfg);
1212 FilePrune(fc, sbcfg);
1218 static void FileEndSha256(
File *ff)
#define FLOWFILE_NO_MD5_TS
#define FLOWFILE_NO_MD5_TC
int FileForceFilestore(void)
void StreamingBufferSlideToOffset(StreamingBuffer *sb, const StreamingBufferConfig *cfg, uint64_t offset)
slide to absolute offset
#define FLOWFILE_NO_SIZE_TS
#define FLOWFILE_NO_SIZE_TC
void FileContainerAdd(FileContainer *ffc, File *ff)
FileContainer * FileContainerAlloc(void)
allocate a FileContainer
void FileReassemblyDepthEnable(uint32_t size)
void FileForceTrackingEnable(void)
uint32_t inspect_min_size
void StreamingBufferFree(StreamingBuffer *sb, const StreamingBufferConfig *cfg)
struct HtpBodyChunk_ * next
#define FLOWFILE_NO_MAGIC_TS
void FileContainerFree(FileContainer *ffc, const StreamingBufferConfig *cfg)
Free a FileContainer.
uint32_t reassembly_depth
#define TAILQ_FOREACH(var, head, field)
void FileForceMagicEnable(void)
int FileAppendGAPById(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id, const uint8_t *data, uint32_t data_len)
Store/handle a chunk of file data in the File structure The file with 'track_id' in the FileContainer...
AppLayerStateData * AppLayerParserGetStateData(uint8_t ipproto, AppProto alproto, void *state)
#define FLOWFILE_STORE_TS
uint8_t sha1[SC_SHA1_LEN]
TcpStreamCnf stream_config
void FileForceMd5Enable(void)
int ConfValIsTrue(const char *val)
Check if a value is true.
void FileForceSha1Enable(void)
#define FLOWFILE_NO_SHA1_TC
StreamingBuffer * StreamingBufferInit(const StreamingBufferConfig *cfg)
uint16_t FileFlowToFlags(const Flow *flow, uint8_t direction)
#define FLOWFILE_STORE_TC
#define FLOWFILE_NO_STORE_TS
void FileStoreFileById(FileContainer *fc, uint32_t file_id)
flag a file with id "file_id" to be stored.
#define FLOWFILE_NO_SHA256_TS
uint64_t FileTrackedSize(const File *file)
get the size of the file
#define FILEDATA_CONTENT_INSPECT_MIN_SIZE
#define SCLogWarning(...)
Macro used to log WARNING messages.
void FileUpdateFlowFileFlags(Flow *f, uint16_t set_file_flags, uint8_t direction)
set a flow's file flags
uint32_t FileReassemblyDepth(void)
#define DEBUG_ASSERT_FLOW_LOCKED(f)
int FileOpenFileWithId(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id, const uint8_t *name, uint16_t name_len, const uint8_t *data, uint32_t data_len, uint16_t flags)
Open a new File.
#define SCReturnPtr(x, type)
int FileCloseFilePtr(File *ff, const StreamingBufferConfig *sbcfg, const uint8_t *data, uint32_t data_len, uint16_t flags)
int FileAppendData(FileContainer *ffc, const StreamingBufferConfig *sbcfg, const uint8_t *data, uint32_t data_len)
Store/handle a chunk of file data in the File structure The last file in the FileContainer will be us...
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
uint64_t FileDataSize(const File *file)
get the size of the file data
int FileCloseFileById(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id, const uint8_t *data, uint32_t data_len, uint16_t flags)
int FileStore(File *ff)
Tag a file for storing.
#define FLOWFILE_NO_SHA256_TC
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
void FileDisableStoringForTransaction(Flow *f, const uint8_t direction, void *tx, uint64_t tx_id)
disable file storing for files in a transaction
uint64_t content_inspected
struct AppLayerTxData AppLayerTxData
#define FLOWFILE_NO_MAGIC_TC
int StreamingBufferAppendNoTrack(StreamingBuffer *sb, const StreamingBufferConfig *cfg, const uint8_t *data, uint32_t data_len)
add data w/o tracking a segment
void FileForceFilestoreEnable(void)
int FileForceSha256(void)
void FileForceHashParseCfg(ConfNode *conf)
Function to parse forced file hashing configuration.
void FileSetInspectSizes(File *file, const uint32_t win, const uint32_t min)
void FilesPrune(FileContainer *fc, const StreamingBufferConfig *sbcfg, const bool trunc)
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
int FileSetRange(FileContainer *ffc, uint64_t start, uint64_t end)
Sets the offset range for a file.
#define FLOWFILE_NO_STORE_TC
uint8_t sha256[SC_SHA256_LEN]
#define FilePrintFlags(file)
void FileContainerRecycle(FileContainer *ffc, const StreamingBufferConfig *cfg)
Recycle a FileContainer.
struct SCLogConfig_ SCLogConfig
Holds the config state used by the logging api.
#define FLOWFILE_NO_SHA1_TS
#define SCLogError(...)
Macro used to log ERROR messages.
int FileCloseFile(FileContainer *ffc, const StreamingBufferConfig *sbcfg, const uint8_t *data, uint32_t data_len, uint16_t flags)
Close a File.
int FileAppendDataById(FileContainer *ffc, const StreamingBufferConfig *sbcfg, uint32_t track_id, const uint8_t *data, uint32_t data_len)
Store/handle a chunk of file data in the File structure The file with 'track_id' in the FileContainer...
#define FILEDATA_CONTENT_INSPECT_WINDOW
void FileForceSha256Enable(void)
uint16_t FileFlowFlagsToFlags(const uint16_t flow_file_flags, uint8_t direction)
AppProto alproto
application level protocol
void FileApplyTxFlags(const AppLayerTxData *txd, const uint8_t direction, File *file)
#define DEBUG_VALIDATE_BUG_ON(exp)
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.