@@ -34,19 +34,18 @@ func (c *Checker) Check(target string, pocItem poc.Poc) (err error) {
34
34
c .FastClient .DialTimeout = c .Options .Config .ConfigHttp .DialTimeout
35
35
c .FastClient .UserAgent = c .Options .Config .ConfigHttp .UserAgent
36
36
37
- pocHandler := ""
37
+ matchCondition := ""
38
38
if strings .Contains (pocItem .Expression , "&&" ) && ! strings .Contains (pocItem .Expression , "||" ) {
39
- pocHandler = poc .ALLAND
39
+ matchCondition = poc .STOP_IF_FIRST_MISMATCH
40
40
}
41
41
if strings .Contains (pocItem .Expression , "||" ) && ! strings .Contains (pocItem .Expression , "&&" ) {
42
- pocHandler = poc .ALLOR
42
+ matchCondition = poc .STOP_IF_FIRST_MATCH
43
43
}
44
44
45
45
if ! strings .HasPrefix (target , "http://" ) && ! strings .HasPrefix (target , "https://" ) {
46
46
target = "http://" + target
47
47
}
48
48
49
- // original request
50
49
c .OriginalRequest , err = http .NewRequest ("GET" , target , nil )
51
50
if err != nil {
52
51
log .Log ().Error (fmt .Sprintf ("rule map originalRequest err, %s" , err .Error ()))
@@ -76,67 +75,56 @@ func (c *Checker) Check(target string, pocItem poc.Poc) (err error) {
76
75
k := ruleMap .Key
77
76
rule := ruleMap .Value
78
77
79
- utils .RandSleep (500 ) // firewall just test.
78
+ utils .RandSleep (500 )
80
79
81
- err = c .FastClient .HTTPRequest (c .OriginalRequest , rule , c .VariableMap )
82
- if err != nil {
83
- log .Log ().Error (fmt .Sprintf ("rule map fasthttp.HTTPRequest err, %s" , err .Error ()))
84
- c .CustomLib .WriteRuleFunctionsROptions (k , false )
85
- continue
86
- }
87
-
88
- // run cel expression
89
- isVul , err := c .CustomLib .RunEval (rule .Expression , c .VariableMap )
90
- if err != nil {
91
- log .Log ().Error (fmt .Sprintf ("rule map RunEval err, %s" , err .Error ()))
92
- c .CustomLib .WriteRuleFunctionsROptions (k , false )
93
- continue // not return, because may be need test next pocItem. ???
80
+ isMatch := false
81
+ if err = c .FastClient .HTTPRequest (c .OriginalRequest , rule , c .VariableMap ); err == nil {
82
+ evalResult , _ := c .CustomLib .RunEval (rule .Expression , c .VariableMap )
83
+ isMatch = evalResult .Value ().(bool )
94
84
}
95
85
96
- // set result function eg: r1() r2()
97
- c .CustomLib .WriteRuleFunctionsROptions (k , isVul .Value ().(bool ))
86
+ c .CustomLib .WriteRuleFunctionsROptions (k , isMatch )
98
87
99
- // update output cel and variableMap
100
88
if len (rule .Output ) > 0 {
101
89
c .UpdateVariableMap (rule .Output )
102
90
}
103
91
104
- c .Result .AllPocResult = append (c .Result .AllPocResult , & PocResult {IsVul : isVul .Value ().(bool ), ResultRequest : c .VariableMap ["request" ].(* proto.Request ), ResultResponse : c .VariableMap ["response" ].(* proto.Response )})
92
+ c .Result .AllPocResult = append (c .Result .AllPocResult ,
93
+ & PocResult {IsVul : isMatch , ResultRequest : c .VariableMap ["request" ].(* proto.Request ), ResultResponse : c .VariableMap ["response" ].(* proto.Response )})
105
94
106
- if rule .Request . Todo == poc . TODO_FAILURE_NOT_CONTINUE && ! isVul . Value ().( bool ) {
95
+ if rule .StopIfMismatch && ! isMatch {
107
96
c .Result .IsVul = false
108
97
c .Options .ApiCallBack (c .Result )
109
98
return err
110
99
}
111
100
112
- if rule .Request . Todo == poc . TODO_SUCCESS_NOT_CONTINUE && isVul . Value ().( bool ) {
101
+ if rule .StopIfMatch && isMatch {
113
102
c .Result .IsVul = true
114
103
c .Options .ApiCallBack (c .Result )
115
104
return err
116
105
}
117
106
118
- if pocHandler == poc .ALLOR && isVul . Value ().( bool ) {
119
- c .Result .IsVul = true
107
+ if matchCondition == poc .STOP_IF_FIRST_MISMATCH && ! isMatch {
108
+ c .Result .IsVul = false
120
109
c .Options .ApiCallBack (c .Result )
121
110
return err
122
111
}
123
- if pocHandler == poc .ALLAND && ! isVul .Value ().(bool ) {
124
- c .Result .IsVul = false
112
+
113
+ if matchCondition == poc .STOP_IF_FIRST_MATCH && isMatch {
114
+ c .Result .IsVul = true
125
115
c .Options .ApiCallBack (c .Result )
126
116
return err
127
117
}
128
118
}
129
119
130
- // run final cel expression
131
120
isVul , err := c .CustomLib .RunEval (pocItem .Expression , c .VariableMap )
132
121
if err != nil {
133
- log .Log ().Error (fmt .Sprintf ("final RunEval err, %s" , err .Error ()))
122
+ log .Log ().Error (fmt .Sprintf ("Final RunEval Error: %s" , err .Error ()))
134
123
c .Result .IsVul = false
135
124
c .Options .ApiCallBack (c .Result )
136
125
return err
137
126
}
138
127
139
- // save final result
140
128
c .Result .IsVul = isVul .Value ().(bool )
141
129
c .Options .ApiCallBack (c .Result )
142
130
0 commit comments