mirror of https://github.com/OISF/suricata
You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
87 lines
2.9 KiB
C
87 lines
2.9 KiB
C
17 years ago
|
/* DISTANCE part of the detection engine. */
|
||
|
|
||
|
#include "decode.h"
|
||
|
#include "detect.h"
|
||
|
#include "flow-var.h"
|
||
|
|
||
|
#include <pcre.h>
|
||
|
#include "detect-content.h"
|
||
|
#include "detect-uricontent.h"
|
||
|
#include "detect-pcre.h"
|
||
|
|
||
|
int DetectDistanceSetup (Signature *s, SigMatch *m, char *distancestr);
|
||
|
|
||
|
void DetectDistanceRegister (void) {
|
||
|
sigmatch_table[DETECT_DISTANCE].name = "distance";
|
||
|
sigmatch_table[DETECT_DISTANCE].Match = NULL;
|
||
|
sigmatch_table[DETECT_DISTANCE].Setup = DetectDistanceSetup;
|
||
|
sigmatch_table[DETECT_DISTANCE].Free = NULL;
|
||
|
sigmatch_table[DETECT_DISTANCE].RegisterTests = NULL;
|
||
|
}
|
||
|
|
||
|
int DetectDistanceSetup (Signature *s, SigMatch *m, char *distancestr)
|
||
|
{
|
||
|
char *str = distancestr;
|
||
|
char dubbed = 0;
|
||
|
|
||
|
//printf("DetectDistanceSetup: s->match:%p,m:%p,distancestr:\'%s\'\n", s->match, m, distancestr);
|
||
|
|
||
|
/* strip "'s */
|
||
|
if (distancestr[0] == '\"' && distancestr[strlen(distancestr)-1] == '\"') {
|
||
|
str = strdup(distancestr+1);
|
||
|
str[strlen(distancestr)-2] = '\0';
|
||
|
dubbed = 1;
|
||
|
}
|
||
|
|
||
|
SigMatch *pm = m;
|
||
|
if (pm != NULL) {
|
||
|
if (pm->type == DETECT_PCRE) {
|
||
|
DetectPcreData *pe = (DetectPcreData *)pm->ctx;
|
||
|
|
||
|
pe->distance = strtol(str, NULL, 10);
|
||
|
pe->flags |= DETECT_PCRE_DISTANCE;
|
||
|
|
||
|
//printf("DetectDistanceSetup: set distance %d for previous pcre\n", pe->distance);
|
||
|
} else if (pm->type == DETECT_CONTENT) {
|
||
|
DetectContentData *cd = (DetectContentData *)pm->ctx;
|
||
|
|
||
|
cd->distance = strtol(str, NULL, 10);
|
||
|
cd->flags |= DETECT_CONTENT_DISTANCE;
|
||
|
|
||
|
//printf("DetectDistanceSetup: set distance %d for previous content\n", cd->distance);
|
||
|
} else if (pm->type == DETECT_URICONTENT) {
|
||
|
DetectUricontentData *cd = (DetectUricontentData *)pm->ctx;
|
||
|
|
||
|
cd->distance = strtol(str, NULL, 10);
|
||
|
cd->flags |= DETECT_URICONTENT_DISTANCE;
|
||
|
|
||
|
//printf("DetectDistanceSetup: set distance %d for previous content\n", cd->distance);
|
||
|
} else {
|
||
|
printf("DetectDistanceSetup: Unknown previous keyword!\n");
|
||
|
}
|
||
|
} else {
|
||
|
printf("DetectDistanceSetup: No previous match!\n");
|
||
|
}
|
||
|
pm = m->prev;
|
||
|
if (pm != NULL) {
|
||
|
if (pm->type == DETECT_PCRE) {
|
||
|
DetectPcreData *pe = (DetectPcreData *)pm->ctx;
|
||
|
pe->flags |= DETECT_PCRE_DISTANCE_NEXT;
|
||
|
} else if (pm->type == DETECT_CONTENT) {
|
||
|
DetectContentData *cd = (DetectContentData *)pm->ctx;
|
||
|
cd->flags |= DETECT_CONTENT_DISTANCE_NEXT;
|
||
|
} else if (pm->type == DETECT_URICONTENT) {
|
||
|
DetectUricontentData *cd = (DetectUricontentData *)pm->ctx;
|
||
|
cd->flags |= DETECT_URICONTENT_DISTANCE_NEXT;
|
||
|
} else {
|
||
|
printf("DetectDistanceSetup: Unknown previous-previous keyword!\n");
|
||
|
}
|
||
|
} else {
|
||
|
printf("DetectDistanceSetup: No previous-previous match!\n");
|
||
|
}
|
||
|
|
||
|
if (dubbed) free(str);
|
||
|
return 0;
|
||
|
}
|
||
|
|