-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.c
executable file
·150 lines (120 loc) · 4.32 KB
/
main.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
#include <detection/common/detection_com.h>
#include <detection/common/detection_mod.h>
#include <detection/common/detection_pub.h>
#include <detection/common/detection_mod.h>
#include <detection/common/detection_debug.h>
#include <detection/common/detection_common_mpse.h>
unsigned long g_ulDetectionParseDbg = 0;
unsigned long g_ulDetectionDbg = 0;
unsigned long g_PLAYLOAD_DEBUG = 0;
typedef struct stPmx{
VOID * pvRuleNode;
VOID * pvPatternMatchData;
} DETECTION_PMX_S;
typedef struct stAppPatternMatchData
{
ULONG ulExceptionFlag; /*是否使用了取反符号*/
LONG lOffset; /* 匹配的起点*/
LONG lDepth; /* 匹配的长度*/
LONG lDistance; /* 相对于上一个content选项匹配成功的串尾再加多少字节开始搜索*/
LONG lWithin; /* 与depth类似,只不过是相对于上一个content选项匹配成功的串尾加distance选项指定的字节数而不是相对于数据区净载的开头*/
ULONG ulRawbytes; /* 在原始报文中查找*/
ULONG ulNocase;
ULONG ulUseDoe; /* 查找时使用doe_ptr*/
ULONG ulUriBuffer; /* URI buffer索引*/
ULONG ulPatternSize; /*匹配字符串长度*/
ULONG ulReplaceSize;
CHAR *pcReplaceBuf;
CHAR *pcPatternBuf; /* 用于匹配的模式字符串*/
ULONG (*pulFunsearch)(const CHAR *, LONG, struct stAppPatternMatchData *,UCHAR **); /*指向模式匹配函数的指针,这里采用的时B-M字符串匹配算法*/
LONG *lSkipStride; /* B-M算法的跳转数组*/
LONG *lShiftStride; /*B-M算法的移位数组*/
ULONG ulPatternMaxJumpSize;
struct stAppPatternMatchData *pstNext; /* 指向下一个模式匹配结构*/
ULONG ulFlags; /* flags */
DETECTION_OPTFPLIST_S *pstFpl; /* 选项匹配链表指针*/
} DETECTION_PATTERNMATCHDATA_S;
VOID Detection_Detect_DeletePMX(VOID *pvData)
{
DETECTION_PMX_S *pstPmx = (DETECTION_PMX_S *)pvData;
DETECTION_RULENODE_S *pstRuleNode = NULL;
DETECTION_OTNX_S *pstOtnx = NULL;
pstRuleNode = (DETECTION_RULENODE_S *)pstPmx->pvRuleNode;
pstOtnx = (DETECTION_OTNX_S *)pstRuleNode->pvRuleData;
if ( pstRuleNode )
{
Detection_GlobalFree(pstRuleNode);
}
else
{
printf("%s %d NULL\n", __FUNCTION__, __LINE__);
}
if ( pstOtnx )
{
Detection_GlobalFree(pstOtnx);
}
else
{
printf("%s %d NULL\n", __FUNCTION__, __LINE__);
}
if ( pstPmx )
{
Detection_GlobalFree(pstPmx);
}
else
{
printf("%s %d NULL\n", __FUNCTION__, __LINE__);
}
}
int main(int argc, char **argv)
{
DETECTION_PORTGROUP_S * pstPg = NULL;
DETECTION_PATTERNMATCHDATA_S *pstPmd = NULL;
if(getenv("TAWL7_DEBUG")){
g_ulDetectionParseDbg = DETECTION_DEBUGTYPE_ERR | DETECTION_DEBUGTYPE_PROCESS;
g_ulDetectionDbg = DETECTION_DEBUGTYPE_ERR | DETECTION_DEBUGTYPE_PROCESS ;
}
else{
g_ulDetectionParseDbg = DETECTION_DEBUGTYPE_ERR ;
g_ulDetectionDbg = DETECTION_DEBUGTYPE_ERR ;
}
pstPg = (DETECTION_PORTGROUP_S*)Detection_GlobalMalloc (sizeof(DETECTION_PORTGROUP_S), DETECTION_MEM_TAG);
if(pstPg == NULL)
{
DETECTION_PARSER_DEBUG(DETECTION_DEBUGTYPE_ERR, " Fail to malloc for DETECTION_PORTGROUP_S\n");
return DETECTION_ERR;
}
pstPg->pvPgPatData = Detection_Common_MpseNew(DETECTION_COMMON_MPSE_AC_BNFA, DETECTION_COMMON_MPSE_INCREMENT_GLOBAL_CNT,
Detection_Detect_DeletePMX );
if( pstPg->pvPgPatData == NULL )
{
Detection_GlobalFree(pstPg);
DETECTION_PARSER_DEBUG(DETECTION_DEBUGTYPE_PROCESS, "%s:mpseNew failed\n", __FUNCTION__);
return DETECTION_ERR;
}
Detection_Common_MpseSetOpt(pstPg->pvPgPatData,1);
int i;
char * pcpattern_data[4] = {"test", "hello", "yes", "what"};
for(i = 0; i < 4; i++){
Detection_Common_MpseAddPattern( pstPg->pvPgPatData,
pcpattern_data[i],
strlen(pcpattern_data[i]),
0,
1,
0,
pcpattern_data[i],
i);
if(Detection_Common_MpsePrepPatterns( pstPg->pvPgPatData ))
{
/* 编译失败,释放模式匹配数据结构 */
Detection_Common_MpseFree( pstPg->pvPgPatData );
pstPg->pvPgPatData = NULL;
Detection_GlobalFree( pstPg );
DETECTION_PARSER_DEBUG(DETECTION_DEBUGTYPE_PROCESS, "%s: MpsePrepPatterns failed\n", __FUNCTION__);
return DETECTION_ERR;
}
}
Detection_Common_MpsePrintInfo( pstPg->pvPgPatData );
Detection_Common_MpseSearch(pstPg->pvPgPatData, argv[1], strlen(argv[1]), NULL, NULL, 0);
return DETECTION_OK;
}