Go to the documentation of this file.
47 int ReadHashString(uint8_t *hash,
const char *
string,
const char *filename,
int line_no,
48 uint16_t expected_len)
50 if (strlen(
string) != expected_len) {
51 SCLogError(
"%s:%d hash string not %d characters", filename, line_no, expected_len);
56 for (x = 0, i = 0; i < expected_len; i+=2, x++) {
57 char buf[3] = { 0, 0, 0 };
61 long value = strtol(buf, NULL, 16);
62 if (value >= 0 && value <= 255)
63 hash[x] = (uint8_t)value;
65 SCLogError(
"%s:%d hash byte out of range %ld", filename, line_no, value);
86 int line_no, uint32_t
type)
101 uint16_t expected_len = (size * 2);
103 if (
ReadHashString(hash,
string, filename, line_no, expected_len) == 1) {
121 static int HashMatchHashTable(
ROHashTable *hash_table, uint8_t *hash,
124 void *ptr =
ROHashLookup(hash_table, hash, (uint16_t)hash_len);
158 match = HashMatchHashTable(filehash->
hash, file->
md5,
sizeof(file->
md5));
161 match = HashMatchHashTable(filehash->
hash, file->
sha1,
sizeof(file->
sha1));
164 match = HashMatchHashTable(filehash->
hash, file->
sha256,
sizeof(file->
sha256));
173 else if (match == 0) {
183 static const char *hexcodes =
"ABCDEFabcdef0123456789";
196 const char *
str, uint32_t
type)
200 char *filename = NULL;
201 char *rule_filename = NULL;
208 if (strlen(
str) &&
str[0] ==
'!') {
223 if (filehash->
hash == NULL) {
229 if (filename == NULL) {
234 if (rule_filename == NULL) {
238 char line[8192] =
"";
239 fp = fopen(filename,
"r");
243 char *dir = dirname(rule_filename);
246 snprintf(path,
sizeof(path),
"%s/%s", dir,
str);
247 fp = fopen(path,
"r");
249 SCLogError(
"opening hash file %s: %s", path, strerror(errno));
256 SCLogError(
"opening hash file %s: %s", filename, strerror(errno));
264 while(fgets(line, (
int)
sizeof(line), fp) != NULL) {
265 size_t valid = 0,
len = strlen(line);
268 while (strchr(hexcodes, line[valid]) != NULL && valid++ <
len);
294 if (filehash != NULL)
298 if (filename != NULL)
300 if (rule_filename != NULL) {
324 if (filehash == NULL)
349 if (filehash != NULL)
363 if (filehash->
hash != NULL)
#define FILE_SIG_NEED_SHA1
main detection engine ctx
uint8_t sha1[SC_SHA1_LEN]
#define FILE_SIG_NEED_MD5
int ROHashInitFinalize(ROHashTable *table)
create final hash data structure
void DetectFileHashFree(DetectEngineCtx *de_ctx, void *ptr)
this function will free memory associated with DetectFileHashData
int DetectFileHashSetup(DetectEngineCtx *de_ctx, Signature *s, const char *str, uint16_t type, int list)
this function is used to parse filemd5, filesha1 and filesha256 options
void * ROHashLookup(ROHashTable *table, void *data, uint16_t size)
int DetectFileHashMatch(DetectEngineThreadCtx *det_ctx, Flow *f, uint8_t flags, File *file, const Signature *s, const SigMatchCtx *m)
Match the specified file hash.
#define FILE_SIG_NEED_SHA256
uint32_t ROHashMemorySize(ROHashTable *table)
#define SCLogInfo(...)
Macro used to log INFORMATIONAL messages.
Used to start a pointer to SigMatch context Should never be dereferenced without casting to something...
ROHashTable * ROHashInit(uint8_t hash_bits, uint16_t item_size)
initialize a new rohash
int ROHashInitQueueValue(ROHashTable *table, void *value, uint16_t size)
Add a new value to the hash.
uint8_t sha256[SC_SHA256_LEN]
#define SCLogError(...)
Macro used to log ERROR messages.
void ROHashFree(ROHashTable *table)
int LoadHashTable(ROHashTable *hash_table, const char *string, const char *filename, int line_no, uint32_t type)
Store a hash into the hash table.
#define FILE_SIG_NEED_FILE
char * DetectLoadCompleteSigPath(const DetectEngineCtx *de_ctx, const char *sig_file)
Create the path if default-rule-path was specified.
SigMatch * SigMatchAppendSMToList(DetectEngineCtx *de_ctx, Signature *s, uint16_t type, SigMatchCtx *ctx, const int list)
Append a SigMatch to the list type.
int ReadHashString(uint8_t *hash, const char *string, const char *filename, int line_no, uint16_t expected_len)
Read the bytes of a hash from an hexadecimal string.