⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 sp_pattern_match.c

📁 著名的入侵检测系统snort的最新版本的源码
💻 C
📖 第 1 页 / 共 5 页
字号:
static void make_precomp(PatternMatchData * idx){    if(idx->skip_stride)       free(idx->skip_stride);    if(idx->shift_stride)       free(idx->shift_stride);    idx->skip_stride = make_skip(idx->pattern_buf, idx->pattern_size);    idx->shift_stride = make_shift(idx->pattern_buf, idx->pattern_size);}#if 0void PayloadSearchListInit(char *data, OptTreeNode * otn, int protocol){    char *sptr;    char *eptr;    lastType = PLUGIN_PATTERN_MATCH_OR;    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "In PayloadSearchListInit()\n"););    /* get the path/file name from the data */    while(isspace((int) *data))        data++;    /* grab everything between the starting " and the end one */    sptr = index(data, '"');    eptr = strrchr(data, '"');    if(sptr != NULL && eptr != NULL)    {        /* increment past the first quote */        sptr++;        /* zero out the second one */        *eptr = 0;    }    else    {        sptr = data;    }    /* read the content keywords from the list file */    ParseContentListFile(sptr, otn, protocol);    /* link the plugin function in to the current OTN */    AddOptFuncToList(CheckORPatternMatch, otn);    return;}#endifvoid PayloadSearchInit(char *data, OptTreeNode * otn, int protocol){    OptFpList *fpl;    PatternMatchData *pmd;    lastType = PLUGIN_PATTERN_MATCH;    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "In PayloadSearchInit()\n"););    /* whack a new node onto the list */    pmd = NewNode(otn, PLUGIN_PATTERN_MATCH);        /* set up the pattern buffer */    ParsePattern(data, otn, PLUGIN_PATTERN_MATCH);    /* link the plugin function in to the current OTN */    fpl = AddOptFuncToList(CheckANDPatternMatch, otn);    fpl->context = pmd;    pmd->fpl = fpl;    if(pmd->use_doe == 1)        fpl->isRelative = 1;    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,                 "OTN function PatternMatch Added to rule!\n"););}void PayloadSearchUri(char *data, OptTreeNode * otn, int protocol){    PatternMatchData * pmd;    OptFpList *fpl;    lastType = PLUGIN_PATTERN_MATCH_URI;    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "In PayloadSearchUri()\n"););    /* whack a new node onto the list */    pmd = NewNode(otn, PLUGIN_PATTERN_MATCH_URI);    /* set up the pattern buffer */    ParsePattern(data, otn, PLUGIN_PATTERN_MATCH_URI);    pmd->uri_buffer = HTTP_BUFFER_URI;#ifdef PATTERN_FAST    pmd->search = uniSearch;    make_precomp(pmd);#endif    /* link the plugin function in to the current OTN */    fpl = AddOptFuncToList(CheckUriPatternMatch, otn);    fpl->context = pmd;    pmd->fpl = fpl;    if(pmd->use_doe == 1)        fpl->isRelative = 1;    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH,                 "OTN function PatternMatch Added to rule!\n"););}void PayloadSearchHttpBody(char *data, OptTreeNode * otn, int protocol){    PatternMatchData *idx = NULL;    PatternMatchData *uriidx = NULL, *previdx = NULL;    idx = (PatternMatchData *) otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("(%s)%d => Please place \"content\" rules before"           " http_client_body modifier.\n", file_name, file_line);    }    while(idx->next != NULL)    {        previdx = idx;        idx = idx->next;    }    if (lastType != PLUGIN_PATTERN_MATCH_URI)    {        /* Need to move this PatternMatchData structure to the         * PLUGIN_PATTERN_MATCH_URI */                /* Remove it from the tail of the old list */        if (previdx)        {            previdx->next = idx->next;        }        if (idx)        {            idx->next = NULL;        }        uriidx = (PatternMatchData *) otn->ds_list[PLUGIN_PATTERN_MATCH_URI];        if (uriidx)        {            /* There are some uri/post patterns in this rule already */            while (uriidx->next != NULL)            {                uriidx = uriidx->next;            }            uriidx->next = idx;        }        else        {            /* This is the first uri/post patterns in this rule */            otn->ds_list[PLUGIN_PATTERN_MATCH_URI] = idx;        }        lastType = PLUGIN_PATTERN_MATCH_URI;        idx->fpl->OptTestFunc = CheckUriPatternMatch;    }    idx->uri_buffer = HTTP_BUFFER_CLIENT_BODY;    if (idx->rawbytes == 1)    {        FatalError("(%s)%d => Cannot use 'rawbytes' and 'http_client_body'"            " as modifiers for the same \"content\".\n", file_name, file_line);    }    return;}void PayloadSearchHttpUri(char *data, OptTreeNode * otn, int protocol){    PatternMatchData *idx = NULL;    PatternMatchData *uriidx = NULL, *previdx = NULL;    idx = (PatternMatchData *) otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("(%s)%d => Please place \"content\" rules before"           " http_uri offset modifiers.\n", file_name, file_line);    }    while(idx->next != NULL)    {        previdx = idx;        idx = idx->next;    }    if (lastType != PLUGIN_PATTERN_MATCH_URI)    {        /* Need to move this PatternMatchData structure to the         * PLUGIN_PATTERN_MATCH_URI */                /* Remove it from the tail of the old list */        if (previdx)        {            previdx->next = idx->next;        }        if (idx)        {            idx->next = NULL;        }        uriidx = (PatternMatchData *) otn->ds_list[PLUGIN_PATTERN_MATCH_URI];        if (uriidx)        {            /* There are some uri/post patterns in this rule already */            while (uriidx->next != NULL)            {                uriidx = uriidx->next;            }            uriidx->next = idx;        }        else        {            /* This is the first uri/post patterns in this rule */            otn->ds_list[PLUGIN_PATTERN_MATCH_URI] = idx;        }        lastType = PLUGIN_PATTERN_MATCH_URI;        idx->fpl->OptTestFunc = CheckUriPatternMatch;    }    idx->uri_buffer = HTTP_BUFFER_URI;    if (idx->rawbytes == 1)    {        FatalError("(%s)%d => Cannot use 'rawbytes' and 'http_uri'"            " as modifiers for the same \"content\".\n", file_name, file_line);    }    return;}void PayloadSearchOffset(char *data, OptTreeNode * otn, int protocol){    PatternMatchData *idx;    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "In PayloadSearch()\n"););    idx = otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("%s(%d) => Please place \"content\" rules before "                "depth, nocase or offset modifiers.\n", file_name, file_line);    }    while(idx->next != NULL)        idx = idx->next;    while(isspace((int) *data))        data++;    errno = 0;        idx->offset = strtol(data, NULL, 10);    if(errno == ERANGE)    {        FatalError("ERROR %s Line %d => Range problem on offset value\n",                 file_name, file_line);    }    if(idx->offset > 65535 || idx->offset < -65535)    {        FatalError("ERROR %s Line %d => Offset greater than max Ipv4 "                "packet size\n", file_name, file_line);    }    DEBUG_WRAP(DebugMessage(DEBUG_PARSER, "Pattern offset = %d\n",                 idx->offset););    return;}void PayloadSearchDepth(char *data, OptTreeNode * otn, int protocol){    PatternMatchData *idx;    idx = (PatternMatchData *) otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("ERROR %s Line %d => Please place \"content\" rules "                "before depth, nocase or offset modifiers.\n",                 file_name, file_line);    }    while(idx->next != NULL)        idx = idx->next;    while(isspace((int) *data))        data++;    errno = 0;        idx->depth = strtol(data, NULL, 10);    if(errno == ERANGE)    {        FatalError("ERROR %s Line %d => Range problem on depth value\n",                 file_name, file_line);    }    if(idx->depth > 65535 || idx->depth < -65535)    {        FatalError("ERROR %s Line %d => Depth greater than max Ipv4 "                "packet size\n", file_name, file_line);    }    /* check to make sure that this the depth allows this rule to fire */    if(idx->depth != 0 && idx->depth < (int)idx->pattern_size)    {        FatalError("%s(%d) => The depth(%d) is less than the size of the content(%u)!\n",                   file_name, file_line, idx->depth, idx->pattern_size);    }    DEBUG_WRAP(DebugMessage(DEBUG_PATTERN_MATCH, "Pattern depth = %d\n",                 idx->depth););    return;}void PayloadSearchNocase(char *data, OptTreeNode * otn, int protocol){    PatternMatchData *idx;    int i;    idx = (PatternMatchData *) otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("(%s)%d => Please place \"content\" rules before"           " depth, nocase or offset modifiers.\n", file_name, file_line);    }    while(idx->next != NULL)        idx = idx->next;    i = idx->pattern_size;    while(--i >= 0)        idx->pattern_buf[i] = toupper((unsigned char) idx->pattern_buf[i]);    idx->nocase = 1;#ifdef PATTERN_FAST    idx->search = setSearch;#else    idx->search = uniSearchCI;    make_precomp(idx);#endif    return;}void PayloadSearchRawbytes(char *data, OptTreeNode * otn, int protocol){    PatternMatchData *idx;    idx = (PatternMatchData *) otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("ERROR Line %d => Please place \"content\" rules before"                " rawbytes, depth, nocase or offset modifiers.\n", file_line);    }    while(idx->next != NULL)        idx = idx->next;    /* mark this as inspecting a raw pattern match rather than a       decoded application buffer */    idx->rawbytes = 1;        if (lastType == PLUGIN_PATTERN_MATCH_URI)    {        FatalError("(%s)%d => Cannot use 'rawbytes' and '%s' as modifiers for "            "the same \"content\" nor use 'rawbytes' with \"uricontent\".\n",            file_name, file_line,            idx->uri_buffer == HTTP_BUFFER_CLIENT_BODY ?                "http_client_body" : "http_uri" );    }    return;}void PayloadSearchDistance(char *data, OptTreeNode *otn, int protocol){    PatternMatchData *idx;    idx = (PatternMatchData *) otn->ds_list[lastType];    if(idx == NULL)    {        FatalError("Error %s(%d) => Distance without context, please place "                "\"content\" keywords before distance modifiers\n", file_name,                file_line);    }    while(idx->next != NULL)        idx = idx->next;    while(isspace((int) *data))        data++;    errno = 0;        idx->distance = strtol(data, NULL, 10);    if(errno == ERANGE)    {        FatalError("ERROR %s Line %d => Range problem on distance value\n",                 file_name, file_line);    }    if(idx->distance > 65535 || idx->distance < -65535)

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -