@@ -85,6 +85,42 @@ static void logCb(void *data, const void *ruleMessagev) {
85
85
}
86
86
}
87
87
88
+ int process_intervention (modsecurity::Transaction *transaction)
89
+ {
90
+ modsecurity::ModSecurityIntervention intervention;
91
+ intervention.status = 200 ;
92
+ intervention.url = NULL ;
93
+ intervention.log = NULL ;
94
+ intervention.disruptive = 0 ;
95
+
96
+ if (msc_intervention (transaction, &intervention) == 0 ) {
97
+ return 0 ;
98
+ }
99
+
100
+ if (intervention.log == NULL ) {
101
+ intervention.log = strdup (" (no log message was specified)" );
102
+ }
103
+
104
+ std::cout << " Log: " << intervention.log << std::endl;
105
+ free (intervention.log );
106
+
107
+ if (intervention.url != NULL )
108
+ {
109
+ std::cout << " Intervention, redirect to: " << intervention.url ;
110
+ std::cout << " with status code: " << intervention.status << std::endl;
111
+ free (intervention.url );
112
+ return intervention.status ;
113
+ }
114
+
115
+ if (intervention.status != 200 )
116
+ {
117
+ std::cout << " Intervention, returning code: " << intervention.status ;
118
+ std::cout << std::endl;
119
+ return intervention.status ;
120
+ }
121
+
122
+ return 0 ;
123
+ }
88
124
89
125
int main (int argc, char **argv) {
90
126
modsecurity::ModSecurity *modsec;
@@ -129,36 +165,36 @@ int main(int argc, char **argv) {
129
165
*/
130
166
modsecurity::Transaction *modsecTransaction = \
131
167
new modsecurity::Transaction (modsec, rules, NULL );
132
- // TODO: verify if there is any disruptive action.
168
+ process_intervention (modsecTransaction);
133
169
134
170
/* *
135
171
* Initial connection setup
136
172
*
137
173
*/
138
174
modsecTransaction->processConnection (ip, 12345 , " 127.0.0.1" , 80 );
139
- // TODO: verify if there is any disruptive action.
175
+ process_intervention (modsecTransaction);
140
176
141
177
/* *
142
178
* Finally we've got the URI
143
179
*
144
180
*/
145
181
modsecTransaction->processURI (request_uri, " GET" , " 1.1" );
146
- // TODO: verify if there is any disruptive action.
182
+ process_intervention (modsecTransaction);
147
183
148
184
/* *
149
185
* Lets add our request headers.
150
186
*
151
187
*/
152
188
modsecTransaction->addRequestHeader (" Host" ,
153
189
" net.tutsplus.com" );
154
- // TODO: verify if there is any disruptive action.
190
+ process_intervention (modsecTransaction);
155
191
156
192
/* *
157
193
* No other reuqest header to add, let process it.
158
194
*
159
195
*/
160
196
modsecTransaction->processRequestHeaders ();
161
- // TODO: verify if there is any disruptive action.
197
+ process_intervention (modsecTransaction);
162
198
163
199
/* *
164
200
* There is a request body to be informed...
@@ -167,38 +203,38 @@ int main(int argc, char **argv) {
167
203
modsecTransaction->appendRequestBody (
168
204
(const unsigned char *)request_body_first,
169
205
strlen ((const char *)request_body_first));
170
- // TODO: verify if there is any disruptive action.
206
+ process_intervention (modsecTransaction);
171
207
172
208
modsecTransaction->appendRequestBody (
173
209
(const unsigned char *)request_body_second,
174
210
strlen ((const char *)request_body_second));
175
- // TODO: verify if there is any disruptive action.
211
+ process_intervention (modsecTransaction);
176
212
177
213
modsecTransaction->appendRequestBody (
178
214
(const unsigned char *)request_body_third,
179
215
strlen ((const char *)request_body_third));
180
- // TODO: verify if there is any disruptive action.
216
+ process_intervention (modsecTransaction);
181
217
182
218
/* *
183
219
* Request body is there ;) lets process it.
184
220
*
185
221
*/
186
222
modsecTransaction->processRequestBody ();
187
- // TODO: verify if there is any disruptive action.
223
+ process_intervention (modsecTransaction);
188
224
189
225
/* *
190
226
* The webserver is giving back the response headers.
191
227
*/
192
228
modsecTransaction->addResponseHeader (" HTTP/1.1" ,
193
229
" 200 OK" );
194
- // TODO: verify if there is any disruptive action.
230
+ process_intervention (modsecTransaction);
195
231
196
232
/* *
197
233
* The response headers are filled in, lets process.
198
234
*
199
235
*/
200
236
modsecTransaction->processResponseHeaders (200 , " HTTP 1.2" );
201
- // TODO: verify if there is any disruptive action.
237
+ process_intervention (modsecTransaction);
202
238
203
239
/* *
204
240
* It is time to let modsec aware of the response body
@@ -207,31 +243,31 @@ int main(int argc, char **argv) {
207
243
modsecTransaction->appendResponseBody (
208
244
(const unsigned char *)response_body_first,
209
245
strlen ((const char *)response_body_first));
210
- // TODO: verify if there is any disruptive action.
246
+ process_intervention (modsecTransaction);
211
247
212
248
modsecTransaction->appendResponseBody (
213
249
(const unsigned char *)response_body_second,
214
250
strlen ((const char *)response_body_second));
215
- // TODO: verify if there is any disruptive action.
251
+ process_intervention (modsecTransaction);
216
252
217
253
modsecTransaction->appendResponseBody (
218
254
(const unsigned char *)response_body_third,
219
255
strlen ((const char *)response_body_third));
220
- // TODO: verify if there is any disruptive action.
256
+ process_intervention (modsecTransaction);
221
257
222
258
/* *
223
259
* Finally, lets have the response body processed.
224
260
*
225
261
*/
226
262
modsecTransaction->processResponseBody ();
227
- // TODO: verify if there is any disruptive action.
263
+ process_intervention (modsecTransaction);
228
264
229
265
/* *
230
266
* Keeping track of everything: saving the logs.
231
267
*
232
268
*/
233
269
modsecTransaction->processLogging ();
234
- // TODO: verify if there is any disruptive action.
270
+ process_intervention (modsecTransaction);
235
271
236
272
237
273
/* *
0 commit comments