...
|
...
|
@@ -2998,7 +2998,7 @@ void ytable_delete(struct cli_ytable *ytable)
|
2998
|
2998
|
}
|
2999
|
2999
|
}
|
3000
|
3000
|
|
3001
|
|
-static unsigned int yara_total, yara_malform, yara_complex;
|
|
3001
|
+static unsigned int yara_total, yara_loaded, yara_malform, yara_complex;
|
3002
|
3002
|
#define YARATARGET0 "Target:0"
|
3003
|
3003
|
#define YARATARGET1 "Target:1"
|
3004
|
3004
|
#define EPSTR "EP+0:"
|
...
|
...
|
@@ -3016,11 +3016,12 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3016
|
3016
|
unsigned short target = 0;
|
3017
|
3017
|
size_t lsize;
|
3018
|
3018
|
char *logic = NULL, *target_str = NULL;
|
|
3019
|
+ uint8_t has_short_string;
|
3019
|
3020
|
char *exp_op = "|";
|
3020
|
3021
|
|
3021
|
3022
|
struct cli_ytable ytable = { 0 };
|
3022
|
3023
|
|
3023
|
|
- cli_yaramsg("called load_oneyara()\n");
|
|
3024
|
+ cli_yaramsg("load_oneyara: attempting to load %s\n", rule->id);
|
3024
|
3025
|
|
3025
|
3026
|
if (!rule) {
|
3026
|
3027
|
cli_errmsg("load_oneyara: empty rule passed as argument\n");
|
...
|
...
|
@@ -3067,7 +3068,7 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3067
|
3067
|
|
3068
|
3068
|
/* string type handler */
|
3069
|
3069
|
if (STRING_IS_NULL(string)) {
|
3070
|
|
- cli_warnmsg("load_oneyara: skipping NULL string %s\n", rule->id);
|
|
3070
|
+ cli_warnmsg("load_oneyara: skipping NULL string %s\n", string->id);
|
3071
|
3071
|
//str_error++; /* kill the insertion? */
|
3072
|
3072
|
continue;
|
3073
|
3073
|
} else if (STRING_IS_HEX(string)) {
|
...
|
...
|
@@ -3075,12 +3076,10 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3075
|
3075
|
cli_yaramsg("Yara hex string: \"%s\"\n", substr);
|
3076
|
3076
|
|
3077
|
3077
|
if (substr) {
|
3078
|
|
- /*
|
3079
|
|
- if (strlen(substr)/2 <= CLI_DEFAULT_AC_MINDEPTH) //FIXME: Yara has no length minimum
|
3080
|
|
- has_short_string = 1;
|
3081
|
|
- snprintf(rulestr+len, totsize-len, "%s", substr);
|
3082
|
|
- free(substr);
|
3083
|
|
- */
|
|
3078
|
+ if (strlen(substr)/2 <= CLI_DEFAULT_AC_MINDEPTH) {
|
|
3079
|
+ cli_warnmsg("load_oneyara: string is too short %s\n", string->id);
|
|
3080
|
+ str_error++;
|
|
3081
|
+ }
|
3084
|
3082
|
|
3085
|
3083
|
ytable_add_string(&ytable, substr);
|
3086
|
3084
|
free (substr);
|
...
|
...
|
@@ -3125,18 +3124,18 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3125
|
3125
|
cli_yaramsg("STRING_FITS_IN_ATOM %s\n", STRING_FITS_IN_ATOM(string) ? "yes" : "no");
|
3126
|
3126
|
|
3127
|
3127
|
str_error++;
|
3128
|
|
- free(substr);
|
3129
|
3128
|
continue;
|
3130
|
3129
|
}
|
3131
|
3130
|
}
|
3132
|
3131
|
|
3133
|
3132
|
if (str_error > 0) {
|
3134
|
|
- cli_warnmsg("load_oneyara: clamav does not support %d input strings\n", str_error);
|
|
3133
|
+ cli_warnmsg("load_oneyara: clamav does not support %d input strings for %s, skipping\n", str_error, rule->id);
|
3135
|
3134
|
ytable_delete(&ytable);
|
3136
|
3135
|
(*sigs)--;
|
3137
|
3136
|
return CL_SUCCESS; /* TODO - kill signature instead? */
|
3138
|
3137
|
} else if (ytable.tbl_cnt == 0) {
|
3139
|
|
- cli_warnmsg("load_oneyara: yara contains no supported strings\n");
|
|
3138
|
+ cli_warnmsg("load_oneyara: yara contains no supported strings, skipping\n");
|
|
3139
|
+ yara_malform++;
|
3140
|
3140
|
ytable_delete(&ytable);
|
3141
|
3141
|
(*sigs)--;
|
3142
|
3142
|
return CL_SUCCESS; /* TODO - kill signature instead? */
|
...
|
...
|
@@ -3170,7 +3169,11 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3170
|
3170
|
/*** END CONDITIONAL HANDLING ***/
|
3171
|
3171
|
|
3172
|
3172
|
/* TDB */
|
3173
|
|
- target_str = cli_strdup(YARATARGET0); /* adjust this for other targets */
|
|
3173
|
+ if (rule->g_flags & RULE_EP && ytable.tbl_cnt == 1)
|
|
3174
|
+ target_str = cli_strdup(YARATARGET1);
|
|
3175
|
+ else
|
|
3176
|
+ target_str = cli_strdup(YARATARGET0);
|
|
3177
|
+
|
3174
|
3178
|
if ((ret = init_tdb(&tdb, engine, target_str, rule->id)) != CL_SUCCESS) {
|
3175
|
3179
|
ytable_delete(&ytable);
|
3176
|
3180
|
free(logic);
|
...
|
...
|
@@ -3208,12 +3211,12 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3208
|
3208
|
return CL_EMEM;
|
3209
|
3209
|
}
|
3210
|
3210
|
} else {
|
3211
|
|
- cli_errmsg("load_oneyara: Unsupported logic type\n");
|
3212
|
|
- FREE_TDB(tdb);
|
3213
|
|
- ytable_delete(&ytable);
|
3214
|
|
- free(logic);
|
3215
|
|
- mpool_free(engine->mempool, lsig);
|
3216
|
|
- return CL_EMEM;
|
|
3211
|
+ cli_errmsg("load_oneyara: Unsupported logic type\n");
|
|
3212
|
+ FREE_TDB(tdb);
|
|
3213
|
+ ytable_delete(&ytable);
|
|
3214
|
+ free(logic);
|
|
3215
|
+ mpool_free(engine->mempool, lsig);
|
|
3216
|
+ return CL_EMEM;
|
3217
|
3217
|
}
|
3218
|
3218
|
free(logic);
|
3219
|
3219
|
|
...
|
...
|
@@ -3240,12 +3243,17 @@ static int load_oneyara(YR_RULE *rule, struct cl_engine *engine, unsigned int op
|
3240
|
3240
|
|
3241
|
3241
|
cli_yaramsg("%i: [%s] [%s] [%s]\n", i, ytable.table[i]->hexstr, ytable.table[i]->offset, ytable.table[i]->sigopts);
|
3242
|
3242
|
|
3243
|
|
- if((ret = cli_parse_add(root, rule->id, ytable.table[i]->hexstr, ytable.table[i]->sigopts, 0, 0, ytable.table[i]->offset, target, lsigid, options)))
|
|
3243
|
+ if((ret = cli_parse_add(root, rule->id, ytable.table[i]->hexstr, ytable.table[i]->sigopts, 0, 0, ytable.table[i]->offset, target, lsigid, options)) != CL_SUCCESS) {
|
|
3244
|
+ yara_malform++;
|
3244
|
3245
|
return ret;
|
|
3246
|
+ }
|
3245
|
3247
|
}
|
3246
|
3248
|
|
3247
|
3249
|
memcpy(&lsig->tdb, &tdb, sizeof(tdb));
|
3248
|
3250
|
ytable_delete(&ytable);
|
|
3251
|
+
|
|
3252
|
+ yara_loaded++;
|
|
3253
|
+ cli_yaramsg("load_oneyara: successfully loaded %s\n", rule->id);
|
3249
|
3254
|
return CL_SUCCESS;
|
3250
|
3255
|
}
|
3251
|
3256
|
|
...
|
...
|
@@ -3284,6 +3292,8 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo,
|
3284
|
3284
|
rc = load_oneyara(rule, engine, options, &sigs);
|
3285
|
3285
|
if (rc != CL_SUCCESS)
|
3286
|
3286
|
break;
|
|
3287
|
+
|
|
3288
|
+ /* do we free the rules? and where? */
|
3287
|
3289
|
}
|
3288
|
3290
|
|
3289
|
3291
|
if(rc) {
|
...
|
...
|
@@ -3296,6 +3306,9 @@ static int cli_loadyara(FILE *fs, struct cl_engine *engine, unsigned int *signo,
|
3296
|
3296
|
return CL_EMALFDB;
|
3297
|
3297
|
}
|
3298
|
3298
|
|
|
3299
|
+ /* globals */
|
|
3300
|
+ yara_total += rules;
|
|
3301
|
+
|
3299
|
3302
|
if(signo)
|
3300
|
3303
|
*signo += sigs;
|
3301
|
3304
|
|
...
|
...
|
@@ -3730,7 +3743,12 @@ int cl_load(const char *path, struct cl_engine *engine, unsigned int *signo, uns
|
3730
|
3730
|
return CL_EOPEN;
|
3731
|
3731
|
}
|
3732
|
3732
|
#ifdef YARA_PROTO
|
3733
|
|
- cli_errmsg("$$$$$$$$$$$$ YARA $$$$$$$$$$$$ \n Total Rules: %u \n Complex conditions: %u \n Malformed strings: %u \n $$$$$$$$$$$$ YARA $$$$$$$$$$$$ \n", yara_total, yara_complex, yara_malform);
|
|
3733
|
+ cli_yaramsg("$$$$$$$$$$$$ YARA $$$$$$$$$$$$\n");
|
|
3734
|
+ cli_yaramsg("\tTotal Rules: %u\n", yara_total);
|
|
3735
|
+ cli_yaramsg("\tRules Loaded: %u\n", yara_loaded);
|
|
3736
|
+ cli_yaramsg("\tComplex conditions: %u\n", yara_complex);
|
|
3737
|
+ cli_yaramsg("\tMalformed strings: %u\n", yara_malform);
|
|
3738
|
+ cli_yaramsg("$$$$$$$$$$$$ YARA $$$$$$$$$$$$\n");
|
3734
|
3739
|
#endif
|
3735
|
3740
|
return ret;
|
3736
|
3741
|
}
|