-
Notifications
You must be signed in to change notification settings - Fork 1.4k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Integrate tlshc library, calculate telfhash and import hash in ELF mo…
…dule (#1624) * Add simple_str string implementation * Integrate tlshc library, calculate telfhash and import hash in the ELF module. * Hide usage of MD5 into #ifdef crypto
- Loading branch information
Showing
17 changed files
with
4,894 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,64 @@ | ||
#ifndef __TLSH_TLSH_H__ | ||
#define __TLSH_TLSH_H__ | ||
|
||
#include <stdbool.h> | ||
|
||
#define TLSH_OPTION_CONSERVATIVE 2 | ||
#define TLSH_OPTION_KEEP_BUCKET 4 | ||
#define TLSH_OPTION_PRIVATE 8 | ||
#define TLSH_OPTION_THREADED 16 | ||
|
||
// Define TLSH_STRING_LEN_REQ, which is the string length of "T1" + the hex | ||
// value of the Tlsh hash. BUCKETS_256 & CHECKSUM_3B are compiler switches | ||
// defined in CMakeLists.txt | ||
#if defined BUCKETS_256 | ||
#define TLSH_STRING_LEN_REQ 136 | ||
// changed the minimum data length to 256 for version 3.3 | ||
#define MIN_DATA_LENGTH 50 | ||
// added the -force option for version 3.5 | ||
// added the -conservatibe option for version 3.17 | ||
#define MIN_CONSERVATIVE_DATA_LENGTH 256 | ||
#endif | ||
|
||
#if defined BUCKETS_128 | ||
#define TLSH_STRING_LEN_REQ 72 | ||
// changed the minimum data length to 256 for version 3.3 | ||
#define MIN_DATA_LENGTH 50 | ||
// added the -force option for version 3.5 | ||
// added the -conservatibe option for version 3.17 | ||
#define MIN_CONSERVATIVE_DATA_LENGTH 256 | ||
#endif | ||
|
||
#if defined BUCKETS_48 | ||
// No 3 Byte checksum option for 48 Bucket min hash | ||
#define TLSH_STRING_LEN 30 | ||
// changed the minimum data length to 256 for version 3.3 | ||
#define MIN_DATA_LENGTH 10 | ||
// added the -force option for version 3.5 | ||
#define MIN_CONSERVATIVE_DATA_LENGTH 10 | ||
#endif | ||
|
||
#define TLSH_STRING_BUFFER_LEN (TLSH_STRING_LEN_REQ + 1) | ||
|
||
#ifdef __cplusplus | ||
extern "C" { | ||
#endif | ||
|
||
typedef struct TlshImpl TlshImpl; | ||
|
||
typedef struct { | ||
TlshImpl* impl; | ||
} Tlsh; | ||
|
||
Tlsh* tlsh_new(); | ||
void tlsh_free(Tlsh* tlsh); | ||
void tlsh_reset(Tlsh* tlsh); | ||
int tlsh_update(Tlsh* tlsh, const unsigned char* data, unsigned int len); | ||
int tlsh_final(Tlsh* tlsh, const unsigned char* data, unsigned int len, int tlsh_option); | ||
const char* tlsh_get_hash(Tlsh* tlsh, bool showvers); | ||
|
||
#ifdef __cplusplus | ||
} | ||
#endif | ||
|
||
#endif // __TLSH_TLSH_H__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
#ifndef YR_ELF_UTILS_H | ||
#define YR_ELF_UTILS_H | ||
|
||
#include <yara/elf.h> | ||
|
||
typedef struct _ELF_SYMBOL | ||
{ | ||
char *name; | ||
int value; | ||
int size; | ||
int type; | ||
int bind; | ||
int shndx; | ||
int visibility; | ||
|
||
struct _ELF_SYMBOL *next; // Next symbol in the list | ||
} ELF_SYMBOL; | ||
|
||
// Linked list of symbols | ||
typedef struct _ELF_SYMBOL_LIST | ||
{ | ||
int count; | ||
ELF_SYMBOL *symbols; | ||
} ELF_SYMBOL_LIST; | ||
|
||
typedef struct _ELF | ||
{ | ||
ELF_SYMBOL_LIST *symtab; | ||
ELF_SYMBOL_LIST *dynsym; | ||
char *telfhash; | ||
char *import_hash; | ||
} ELF; | ||
|
||
#endif //YR_ELF_UTILS_H |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
#ifndef _SIMPLESTR_H | ||
#define _SIMPLESTR_H | ||
|
||
#include <yara/types.h> | ||
|
||
/* Simple dynamic string implementation for more readable/maintainable code | ||
Can be further optimized */ | ||
typedef struct _SIMPLE_STR | ||
{ | ||
uint32_t len; | ||
uint32_t cap; | ||
char* str; | ||
} SIMPLE_STR, *PSIMPLE_STR; | ||
|
||
SIMPLE_STR* sstr_new(const char* s); | ||
SIMPLE_STR* sstr_newf(const char* fmt, ...); | ||
void sstr_free(SIMPLE_STR* ss); | ||
bool sstr_appendf(SIMPLE_STR* ss, const char* fmt, ...); | ||
char* sstr_move(SIMPLE_STR* ss); | ||
|
||
#endif |
Oops, something went wrong.