suricata
detect-http-client-body.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 Open Information Security Foundation
2  *
3  * You can copy, redistribute or modify this Program under the terms of
4  * the GNU General Public License version 2 as published by the Free
5  * Software Foundation.
6  *
7  * This program is distributed in the hope that it will be useful,
8  * but WITHOUT ANY WARRANTY; without even the implied warranty of
9  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
10  * GNU General Public License for more details.
11  *
12  * You should have received a copy of the GNU General Public License
13  * version 2 along with this program; if not, write to the Free Software
14  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
15  * 02110-1301, USA.
16  */
17 
18 /**
19  * \ingroup httplayer
20  *
21  * @{
22  */
23 
24 
25 /** \file
26  *
27  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
28  * \author Victor Julien <victor@inliniac.net>
29  *
30  * \brief Handle HTTP request body match corresponding to http_client_body
31  * keyword.
32  *
33  */
34 
35 #include "../suricata-common.h"
36 #include "../suricata.h"
37 #include "../decode.h"
38 
39 #include "detect.h"
40 #include "detect-engine.h"
41 #include "detect-engine-mpm.h"
42 #include "detect-parse.h"
43 #include "detect-engine-state.h"
46 #include "detect-isdataat.h"
47 #include "stream-tcp-reassemble.h"
48 #include "detect-engine-build.h"
49 
50 #include "flow-util.h"
51 #include "util-debug.h"
52 #include "util-print.h"
53 #include "flow.h"
54 
55 #include "app-layer-parser.h"
56 
57 #include "stream-tcp.h"
58 
59 #include "util-unittest.h"
60 #include "util-unittest-helper.h"
61 #include "app-layer.h"
62 #include "app-layer-htp.h"
63 #include "app-layer-protos.h"
64 
65 #include "conf.h"
66 #include "conf-yaml-loader.h"
67 
68 #include "util-validate.h"
69 
70 #ifdef UNITTESTS
71 
72 /**
73  * \test Test parser accepting valid rules and rejecting invalid rules
74  */
75 static int DetectHttpClientBodyParserTest01(void)
76 {
77  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; content:\"abc\"; http_client_body; sid:1;)", true));
78  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; content:\"abc\"; nocase; http_client_body; sid:1;)", true));
79  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; content:\"abc\"; endswith; http_client_body; sid:1;)", true));
80  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; content:\"abc\"; startswith; http_client_body; sid:1;)", true));
81  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; content:\"abc\"; startswith; endswith; http_client_body; sid:1;)", true));
82 
83  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; content:\"abc\"; rawbytes; http_client_body; sid:1;)", false));
84  FAIL_IF_NOT(UTHParseSignature("alert tcp any any -> any any (flow:to_server; http_client_body; sid:1;)", false));
85  FAIL_IF_NOT(UTHParseSignature("alert tls any any -> any any (flow:to_server; content:\"abc\"; http_client_body; sid:1;)", false));
86  PASS;
87 }
88 
89 /**
90  * \test Test parser accepting valid rules and rejecting invalid rules
91  */
92 static int DetectHttpClientBodyParserTest02(void)
93 {
94  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; content:\"abc\"; sid:1;)", true));
95  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; content:\"abc\"; nocase; sid:1;)", true));
96  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; content:\"abc\"; endswith; sid:1;)", true));
97  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; content:\"abc\"; startswith; sid:1;)", true));
98  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; content:\"abc\"; startswith; endswith; sid:1;)", true));
99  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; bsize:10; sid:1;)", true));
100 
101  FAIL_IF_NOT(UTHParseSignature("alert http any any -> any any (flow:to_server; http.request_body; content:\"abc\"; rawbytes; sid:1;)", false));
102  FAIL_IF_NOT(UTHParseSignature("alert tcp any any -> any any (flow:to_server; http.request_body; sid:1;)", false));
103  FAIL_IF_NOT(UTHParseSignature("alert tls any any -> any any (flow:to_server; http.request_body; content:\"abc\"; sid:1;)", false));
104  PASS;
105 }
106 
107 struct TestSteps {
108  const uint8_t *input;
109  size_t input_size; /**< if 0 strlen will be used */
110  int direction; /**< STREAM_TOSERVER, STREAM_TOCLIENT */
111  int expect;
112 };
113 
114 static int RunTest (struct TestSteps *steps, const char *sig, const char *yaml)
115 {
116  TcpSession ssn;
117  Flow f;
118  ThreadVars th_v;
119  DetectEngineThreadCtx *det_ctx = NULL;
122 
123  memset(&th_v, 0, sizeof(th_v));
124  StatsThreadInit(&th_v.stats);
125  memset(&f, 0, sizeof(f));
126  memset(&ssn, 0, sizeof(ssn));
127 
128  if (yaml) {
130  SCConfInit();
132 
133  SCConfYamlLoadString(yaml, strlen(yaml));
134  HTPConfigure();
135  }
136 
137  StreamTcpInitConfig(true);
138 
141  de_ctx->flags |= DE_QUIET;
142 
143  FLOW_INITIALIZE(&f);
144  f.protoctx = (void *)&ssn;
145  f.proto = IPPROTO_TCP;
146  f.flags |= FLOW_IPV4;
148 
149  SCLogDebug("sig %s", sig);
150  Signature *s = DetectEngineAppendSig(de_ctx, (char *)sig);
151  FAIL_IF_NULL(s);
152 
154  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
155  FAIL_IF_NULL(det_ctx);
156 
157  struct TestSteps *b = steps;
158  int i = 0;
159  while (b->input != NULL) {
160  SCLogDebug("chunk %p %d", b, i);
161  (void)i;
162  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
163  FAIL_IF_NULL(p);
164  p->flow = &f;
165  p->flowflags = (b->direction == STREAM_TOSERVER) ? FLOW_PKT_TOSERVER : FLOW_PKT_TOCLIENT;
168 
169  int r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, b->direction,
170  (uint8_t *)b->input,
171  b->input_size ? b->input_size : strlen((const char *)b->input));
172  FAIL_IF_NOT(r == 0);
173 
174  /* do detect */
175  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
176 
177  int match = PacketAlertCheck(p, 1);
178  FAIL_IF_NOT (b->expect == match);
179 
180  UTHFreePackets(&p, 1);
181  b++;
182  i++;
183  }
184 
185  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
188 
189  StreamTcpFreeConfig(true);
190  FLOW_DESTROY(&f);
191 
192  if (yaml) {
193  HTPFreeConfig();
194  SCConfDeInit();
197  }
198  StatsThreadCleanup(&th_v.stats);
199  PASS;
200 }
201 
202 static int DetectEngineHttpClientBodyTest01(void)
203 {
204  struct TestSteps steps[] = {
205  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
206  "Host: www.openinfosecfoundation.org\r\n"
207  "Content-Type: text/html\r\n"
208  "Content-Length: 46\r\n"
209  "\r\n"
210  "This is dummy body1",
211  0, STREAM_TOSERVER, 0 },
212  { (const uint8_t *)"This is dummy message body2",
213  0, STREAM_TOSERVER, 1 },
214  { NULL, 0, 0, 0 },
215  };
216 
217  const char *sig = "alert http any any -> any any (content:\"body1This\"; http_client_body; sid:1;)";
218  return RunTest(steps, sig, NULL);
219 }
220 
221 static int DetectEngineHttpClientBodyTest02(void)
222 {
223  struct TestSteps steps[] = {
224  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
225  "Host: www.openinfosecfoundation.org\r\n"
226  "Content-Type: text/html\r\n"
227  "Content-Length: 19\r\n"
228  "\r\n"
229  "This is dummy body1",
230  0, STREAM_TOSERVER, 1 },
231  { NULL, 0, 0, 0 },
232  };
233 
234  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; offset:5; sid:1;)";
235  return RunTest(steps, sig, NULL);
236 }
237 
238 static int DetectEngineHttpClientBodyTest03(void)
239 {
240  struct TestSteps steps[] = {
241  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
242  "Host: www.openinfosecfoundation.org\r\n"
243  "Content-Type: text/html\r\n"
244  "Content-Length: 46\r\n"
245  "\r\n"
246  "This is dummy body1",
247  0, STREAM_TOSERVER, 0 },
248  { (const uint8_t *)"This is dummy message body2",
249  0, STREAM_TOSERVER, 0 },
250  { NULL, 0, 0, 0 },
251  };
252 
253  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; offset:16; sid:1;)";
254  return RunTest(steps, sig, NULL);
255 }
256 
257 static int DetectEngineHttpClientBodyTest04(void)
258 {
259  struct TestSteps steps[] = {
260  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
261  "Host: www.openinfosecfoundation.org\r\n"
262  "Content-Type: text/html\r\n"
263  "Content-Length: 46\r\n"
264  "\r\n"
265  "This is dummy body1",
266  0, STREAM_TOSERVER, 0 },
267  { (const uint8_t *)"This is dummy message body2",
268  0, STREAM_TOSERVER, 1 },
269  { NULL, 0, 0, 0 },
270  };
271 
272  const char *sig = "alert http any any -> any any (content:!\"body1\"; http_client_body; offset:16; sid:1;)";
273  return RunTest(steps, sig, NULL);
274 }
275 
276 static int DetectEngineHttpClientBodyTest05(void)
277 {
278  struct TestSteps steps[] = {
279  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
280  "Host: www.openinfosecfoundation.org\r\n"
281  "Content-Type: text/html\r\n"
282  "Content-Length: 46\r\n"
283  "\r\n"
284  "This is dummy body1",
285  0, STREAM_TOSERVER, 0 },
286  { (const uint8_t *)"This is dummy message body2",
287  0, STREAM_TOSERVER, 1 },
288  { NULL, 0, 0, 0 },
289  };
290 
291  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; depth:25; sid:1;)";
292  return RunTest(steps, sig, NULL);
293 }
294 
295 static int DetectEngineHttpClientBodyTest06(void)
296 {
297  struct TestSteps steps[] = {
298  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
299  "Host: www.openinfosecfoundation.org\r\n"
300  "Content-Type: text/html\r\n"
301  "Content-Length: 46\r\n"
302  "\r\n"
303  "This is dummy body1",
304  0, STREAM_TOSERVER, 0 },
305  { (const uint8_t *)"This is dummy message body2",
306  0, STREAM_TOSERVER, 0 },
307  { NULL, 0, 0, 0 },
308  };
309 
310  const char *sig = "alert http any any -> any any (content:!\"body1\"; http_client_body; depth:25; sid:1;)";
311  return RunTest(steps, sig, NULL);
312 }
313 
314 static int DetectEngineHttpClientBodyTest07(void)
315 {
316  struct TestSteps steps[] = {
317  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
318  "Host: www.openinfosecfoundation.org\r\n"
319  "Content-Type: text/html\r\n"
320  "Content-Length: 46\r\n"
321  "\r\n"
322  "This is dummy body1",
323  0, STREAM_TOSERVER, 0 },
324  { (const uint8_t *)"This is dummy message body2",
325  0, STREAM_TOSERVER, 1 },
326  { NULL, 0, 0, 0 },
327  };
328 
329  const char *sig = "alert http any any -> any any (content:!\"body1\"; http_client_body; depth:15; sid:1;)";
330  return RunTest(steps, sig, NULL);
331 }
332 
333 static int DetectEngineHttpClientBodyTest08(void)
334 {
335  struct TestSteps steps[] = {
336  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
337  "Host: www.openinfosecfoundation.org\r\n"
338  "Content-Type: text/html\r\n"
339  "Content-Length: 46\r\n"
340  "\r\n"
341  "This is dummy body1",
342  0, STREAM_TOSERVER, 0 },
343  { (const uint8_t *)"This is dummy message body2",
344  0, STREAM_TOSERVER, 1 },
345  { NULL, 0, 0, 0 },
346  };
347 
348  const char *sig = "alert http any any -> any any (content:\"This is dummy body1This is dummy message body2\"; http_client_body; sid:1;)";
349  return RunTest(steps, sig, NULL);
350 }
351 
352 static int DetectEngineHttpClientBodyTest09(void)
353 {
354  struct TestSteps steps[] = {
355  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
356  "Host: www.openinfosecfoundation.org\r\n"
357  "Content-Type: text/html\r\n"
358  "Content-Length: 46\r\n"
359  "\r\n"
360  "This is dummy body1",
361  0, STREAM_TOSERVER, 0 },
362  { (const uint8_t *)"This is dummy message body2",
363  0, STREAM_TOSERVER, 1 },
364  { NULL, 0, 0, 0 },
365  };
366 
367  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"This\"; http_client_body; within:5; sid:1;)";
368  return RunTest(steps, sig, NULL);
369 }
370 
371 static int DetectEngineHttpClientBodyTest10(void)
372 {
373  struct TestSteps steps[] = {
374  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
375  "Host: www.openinfosecfoundation.org\r\n"
376  "Content-Type: text/html\r\n"
377  "Content-Length: 46\r\n"
378  "\r\n"
379  "This is dummy body1",
380  0, STREAM_TOSERVER, 0 },
381  { (const uint8_t *)"This is dummy message body2",
382  0, STREAM_TOSERVER, 1 },
383  { NULL, 0, 0, 0 },
384  };
385 
386  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"boom\"; http_client_body; within:5; sid:1;)";
387  return RunTest(steps, sig, NULL);
388 }
389 
390 static int DetectEngineHttpClientBodyTest11(void)
391 {
392  struct TestSteps steps[] = {
393  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
394  "Host: www.openinfosecfoundation.org\r\n"
395  "Content-Type: text/html\r\n"
396  "Content-Length: 46\r\n"
397  "\r\n"
398  "This is dummy body1",
399  0, STREAM_TOSERVER, 0 },
400  { (const uint8_t *)"This is dummy message body2",
401  0, STREAM_TOSERVER, 0 },
402  { NULL, 0, 0, 0 },
403  };
404 
405  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"boom\"; http_client_body; within:5; sid:1;)";
406  return RunTest(steps, sig, NULL);
407 }
408 
409 static int DetectEngineHttpClientBodyTest12(void)
410 {
411  struct TestSteps steps[] = {
412  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
413  "Host: www.openinfosecfoundation.org\r\n"
414  "Content-Type: text/html\r\n"
415  "Content-Length: 46\r\n"
416  "\r\n"
417  "This is dummy body1",
418  0, STREAM_TOSERVER, 0 },
419  { (const uint8_t *)"This is dummy message body2",
420  0, STREAM_TOSERVER, 0 },
421  { NULL, 0, 0, 0 },
422  };
423 
424  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"This\"; http_client_body; within:5; sid:1;)";
425  return RunTest(steps, sig, NULL);
426 }
427 
428 static int DetectEngineHttpClientBodyTest13(void)
429 {
430  struct TestSteps steps[] = {
431  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
432  "Host: www.openinfosecfoundation.org\r\n"
433  "Content-Type: text/html\r\n"
434  "Content-Length: 46\r\n"
435  "\r\n"
436  "This is dummy body1",
437  0, STREAM_TOSERVER, 0 },
438  { (const uint8_t *)"This is dummy message body2",
439  0, STREAM_TOSERVER, 1 },
440  { NULL, 0, 0, 0 },
441  };
442 
443  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"dummy\"; http_client_body; distance:5; sid:1;)";
444  return RunTest(steps, sig, NULL);
445 }
446 
447 static int DetectEngineHttpClientBodyTest14(void)
448 {
449  struct TestSteps steps[] = {
450  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
451  "Host: www.openinfosecfoundation.org\r\n"
452  "Content-Type: text/html\r\n"
453  "Content-Length: 46\r\n"
454  "\r\n"
455  "This is dummy body1",
456  0, STREAM_TOSERVER, 0 },
457  { (const uint8_t *)"This is dummy message body2",
458  0, STREAM_TOSERVER, 1 },
459  { NULL, 0, 0, 0 },
460  };
461 
462  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"dummy\"; http_client_body; distance:10; sid:1;)";
463  return RunTest(steps, sig, NULL);
464 }
465 
466 static int DetectEngineHttpClientBodyTest15(void)
467 {
468  struct TestSteps steps[] = {
469  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
470  "Host: www.openinfosecfoundation.org\r\n"
471  "Content-Type: text/html\r\n"
472  "Content-Length: 46\r\n"
473  "\r\n"
474  "This is dummy body1",
475  0, STREAM_TOSERVER, 0 },
476  { (const uint8_t *)"This is dummy message body2",
477  0, STREAM_TOSERVER, 0 },
478  { NULL, 0, 0, 0 },
479  };
480 
481  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"dummy\"; http_client_body; distance:10; sid:1;)";
482  return RunTest(steps, sig, NULL);
483 }
484 
485 static int DetectEngineHttpClientBodyTest16(void)
486 {
487  struct TestSteps steps[] = {
488  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
489  "Host: www.openinfosecfoundation.org\r\n"
490  "Content-Type: text/html\r\n"
491  "Content-Length: 46\r\n"
492  "\r\n"
493  "This is dummy body1",
494  0, STREAM_TOSERVER, 0 },
495  { (const uint8_t *)"This is dummy message body2",
496  0, STREAM_TOSERVER, 0 },
497  { NULL, 0, 0, 0 },
498  };
499 
500  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"dummy\"; http_client_body; distance:5; sid:1;)";
501  return RunTest(steps, sig, NULL);
502 }
503 
504 static int DetectEngineHttpClientBodyTest17(void)
505 {
506  struct TestSteps steps[] = {
507  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
508  "Host: www.openinfosecfoundation.org\r\n"
509  "Content-Type: text/html\r\n"
510  "Content-Length: 19\r\n"
511  "\r\n"
512  "This is dummy body1",
513  0, STREAM_TOSERVER, 0 },
514  { NULL, 0, 0, 0 },
515  };
516 
517  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"bambu\"; http_client_body; sid:1;)";
518  return RunTest(steps, sig, NULL);
519 }
520 
521 static int DetectEngineHttpClientBodyTest18(void)
522 {
523  struct TestSteps steps[] = {
524  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
525  "Host: www.openinfosecfoundation.org\r\n"
526  "Content-Type: text/html\r\n"
527  "Content-Length: 19\r\n"
528  "\r\n"
529  "This is dummy body1",
530  0, STREAM_TOSERVER, 0 },
531  { NULL, 0, 0, 0 },
532  };
533 
534  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"bambu\"; http_client_body; fast_pattern; sid:1;)";
535  return RunTest(steps, sig, NULL);
536 }
537 
538 static int DetectEngineHttpClientBodyTest19(void)
539 {
540  struct TestSteps steps[] = {
541  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
542  "Host: www.openinfosecfoundation.org\r\n"
543  "Content-Type: text/html\r\n"
544  "Content-Length: 19\r\n"
545  "\r\n"
546  "This is dummy body1",
547  0, STREAM_TOSERVER, 0 },
548  { NULL, 0, 0, 0 },
549  };
550 
551  const char *sig = "alert http any any -> any any (content:\"bambu\"; http_client_body; content:\"is\"; http_client_body; sid:1;)";
552  return RunTest(steps, sig, NULL);
553 }
554 
555 static int DetectEngineHttpClientBodyTest20(void)
556 {
557  struct TestSteps steps[] = {
558  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
559  "Host: www.openinfosecfoundation.org\r\n"
560  "Content-Type: text/html\r\n"
561  "Content-Length: 19\r\n"
562  "\r\n"
563  "This is dummy body1",
564  0, STREAM_TOSERVER, 1 },
565  { NULL, 0, 0, 0 },
566  };
567 
568  const char *sig = "alert http any any -> any any (content:\"is\"; http_client_body; fast_pattern; sid:1;)";
569  return RunTest(steps, sig, NULL);
570 }
571 
572 static int DetectEngineHttpClientBodyTest21(void)
573 {
574  struct TestSteps steps[] = {
575  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
576  "Host: www.openinfosecfoundation.org\r\n"
577  "Content-Type: text/html\r\n"
578  "Content-Length: 46\r\n"
579  "\r\n"
580  "This is dummy body1",
581  0, STREAM_TOSERVER, 0 },
582  { (const uint8_t *)"This is dummy message body2",
583  0, STREAM_TOSERVER, 1 },
584  { NULL, 0, 0, 0 },
585  };
586 
587  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; http_client_body; within:7; sid:1;)";
588  return RunTest(steps, sig, NULL);
589 }
590 
591 static int DetectEngineHttpClientBodyTest22(void)
592 {
593  struct TestSteps steps[] = {
594  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
595  "Host: www.openinfosecfoundation.org\r\n"
596  "Content-Type: text/html\r\n"
597  "Content-Length: 46\r\n"
598  "\r\n"
599  "This is dummy body1",
600  0, STREAM_TOSERVER, 0 },
601  { (const uint8_t *)"This is dummy message body2",
602  0, STREAM_TOSERVER, 1 },
603  { NULL, 0, 0, 0 },
604  };
605 
606  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; within:7; http_client_body; sid:1;)";
607  return RunTest(steps, sig, NULL);
608 }
609 
610 static int DetectEngineHttpClientBodyTest23(void)
611 {
612  struct TestSteps steps[] = {
613  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
614  "Host: www.openinfosecfoundation.org\r\n"
615  "Content-Type: text/html\r\n"
616  "Content-Length: 46\r\n"
617  "\r\n"
618  "This is dummy body1",
619  0, STREAM_TOSERVER, 0 },
620  { (const uint8_t *)"This is dummy message body2",
621  0, STREAM_TOSERVER, 0 },
622  { NULL, 0, 0, 0 },
623  };
624 
625  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; distance:3; http_client_body; sid:1;)";
626  return RunTest(steps, sig, NULL);
627 }
628 
629 static int DetectEngineHttpClientBodyTest24(void)
630 {
631  struct TestSteps steps[] = {
632  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
633  "Host: www.openinfosecfoundation.org\r\n"
634  "Content-Type: text/html\r\n"
635  "Content-Length: 46\r\n"
636  "\r\n"
637  "This is dummy body1",
638  0, STREAM_TOSERVER, 0 },
639  { (const uint8_t *)"This is dummy message body2",
640  0, STREAM_TOSERVER, 1 },
641  { NULL, 0, 0, 0 },
642  };
643 
644  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; distance:13; http_client_body; sid:1;)";
645  return RunTest(steps, sig, NULL);
646 }
647 
648 static int DetectEngineHttpClientBodyTest25(void)
649 {
650  struct TestSteps steps[] = {
651  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
652  "Host: www.openinfosecfoundation.org\r\n"
653  "Content-Type: text/html\r\n"
654  "Content-Length: 46\r\n"
655  "\r\n"
656  "This is dummy body1",
657  0, STREAM_TOSERVER, 0 },
658  { (const uint8_t *)"This is dummy message body2",
659  0, STREAM_TOSERVER, 1 },
660  { NULL, 0, 0, 0 },
661  };
662 
663  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; within:15; http_client_body; sid:1;)";
664  return RunTest(steps, sig, NULL);
665 }
666 
667 static int DetectEngineHttpClientBodyTest26(void)
668 {
669  struct TestSteps steps[] = {
670  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
671  "Host: www.openinfosecfoundation.org\r\n"
672  "Content-Type: text/html\r\n"
673  "Content-Length: 46\r\n"
674  "\r\n"
675  "This is dummy body1",
676  0, STREAM_TOSERVER, 0 },
677  { (const uint8_t *)"This is dummy message body2",
678  0, STREAM_TOSERVER, 0 },
679  { NULL, 0, 0, 0 },
680  };
681 
682  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; within:10; http_client_body; sid:1;)";
683  return RunTest(steps, sig, NULL);
684 }
685 
686 static int DetectEngineHttpClientBodyTest27(void)
687 {
688  struct TestSteps steps[] = {
689  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
690  "Host: www.openinfosecfoundation.org\r\n"
691  "Content-Type: text/html\r\n"
692  "Content-Length: 46\r\n"
693  "\r\n"
694  "This is dummy body1",
695  0, STREAM_TOSERVER, 0 },
696  { (const uint8_t *)"This is dummy message body2",
697  0, STREAM_TOSERVER, 1 },
698  { NULL, 0, 0, 0 },
699  };
700 
701  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; distance:8; http_client_body; sid:1;)";
702  return RunTest(steps, sig, NULL);
703 }
704 
705 static int DetectEngineHttpClientBodyTest28(void)
706 {
707  struct TestSteps steps[] = {
708  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
709  "Host: www.openinfosecfoundation.org\r\n"
710  "Content-Type: text/html\r\n"
711  "Content-Length: 46\r\n"
712  "\r\n"
713  "This is dummy body1",
714  0, STREAM_TOSERVER, 0 },
715  { (const uint8_t *)"This is dummy message body2",
716  0, STREAM_TOSERVER, 0 },
717  { NULL, 0, 0, 0 },
718  };
719 
720  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; distance:14; http_client_body; sid:1;)";
721  return RunTest(steps, sig, NULL);
722 }
723 
724 static int DetectEngineHttpClientBodyTest29(void)
725 {
726  const char *request_buffer = "GET /one HTTP/1.0\r\n"
727  "Host: localhost\r\n\r\n";
728 #define TOTAL_REQUESTS 45
729  uint8_t *http_buf = SCMalloc(TOTAL_REQUESTS * strlen(request_buffer));
730  if (unlikely(http_buf == NULL))
731  return 0;
732  for (int i = 0; i < TOTAL_REQUESTS; i++) {
733  memcpy(http_buf + i * strlen(request_buffer), request_buffer,
734  strlen(request_buffer));
735  }
736  uint32_t http_buf_len = TOTAL_REQUESTS * strlen(request_buffer);
737 #undef TOTAL_REQUESTS
738 
739  struct TestSteps steps[] = {
740  { (const uint8_t *)http_buf,
741  (size_t)http_buf_len, STREAM_TOSERVER, 0 },
742 
743  { (const uint8_t *)"HTTP/1.0 200 ok\r\n"
744  "Content-Type: text/html\r\n"
745  "Content-Length: 5\r\n"
746  "\r\n"
747  "dummy",
748  0, STREAM_TOCLIENT, 0 },
749 
750  { NULL, 0, 0, 0 },
751  };
752 
753  const char *sig = "alert http any any -> any any (content:\"dummyone\"; fast_pattern:0,3; http_server_body; sid:1;)";
754  int result = RunTest(steps, sig, NULL);
755  SCFree(http_buf);
756  return result;
757 }
758 
759 static int DetectEngineHttpClientBodyTest30(void)
760 {
761  const char yaml[] = "\
762 %YAML 1.1\n\
763 ---\n\
764 libhtp:\n\
765 \n\
766  default-config:\n\
767  personality: IDS\n\
768  request-body-limit: 0\n\
769  response-body-limit: 0\n\
770 \n\
771  request-body-inspect-window: 0\n\
772  response-body-inspect-window: 0\n\
773  request-body-minimal-inspect-size: 0\n\
774  response-body-minimal-inspect-size: 0\n\
775 ";
776  struct TestSteps steps[] = {
777  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
778  "Host: www.openinfosecfoundation.org\r\n"
779  "Content-Type: text/html\r\n"
780  "Content-Length: 46\r\n"
781  "\r\n"
782  "This is dummy body1",
783  0, STREAM_TOSERVER, 0 },
784  { (const uint8_t *)"This is dummy message body2",
785  0, STREAM_TOSERVER, 0 },
786  { NULL, 0, 0, 0 },
787  };
788 
789  const char *sig = "alert http any any -> any any (content:\"bags\"; within:4; http_client_body; sid:1;)";
790  return RunTest(steps, sig, yaml);
791 }
792 
793 static int DetectEngineHttpClientBodyTest31(void)
794 {
795  const char yaml[] = "\
796 %YAML 1.1\n\
797 ---\n\
798 libhtp:\n\
799 \n\
800  default-config:\n\
801  personality: IDS\n\
802  request-body-limit: 0\n\
803  response-body-limit: 0\n\
804 \n\
805  request-body-inspect-window: 0\n\
806  response-body-inspect-window: 0\n\
807  request-body-minimal-inspect-size: 0\n\
808  response-body-minimal-inspect-size: 0\n\
809 ";
810 
811  struct TestSteps steps[] = {
812  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
813  "Host: www.openinfosecfoundation.org\r\n"
814  "Content-Type: text/html\r\n"
815  "Content-Length: 46\r\n"
816  "\r\n"
817  "This is dummy body1",
818  0, STREAM_TOSERVER, 0 },
819  { (const uint8_t *)"This is dummy message body2",
820  0, STREAM_TOSERVER, 0 },
821  { NULL, 0, 0, 0 },
822  };
823 
824  const char *sig = "alert http any any -> any any (content:\"bags\"; depth:4; http_client_body; sid:1;)";
825  return RunTest(steps, sig, yaml);
826 }
827 
828 /**
829  * \test Test that a signature containing a http_client_body is correctly parsed
830  * and the keyword is registered.
831  */
832 static int DetectHttpClientBodyTest01(void)
833 {
836  de_ctx->flags |= DE_QUIET;
837 
838  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
839  "(msg:\"Testing http_client_body\"; "
840  "content:\"one\"; http_client_body; sid:1;)");
841  FAIL_IF_NULL(s);
842 
844  FAIL_IF_NOT_NULL(sm);
845 
847  PASS;
848 }
849 
850 /**
851  * \test Test that a signature containing an valid http_client_body entry is
852  * parsed.
853  * \todo error in sig 'http_client_body:;'
854  */
855 static int DetectHttpClientBodyTest02(void)
856 {
859  de_ctx->flags |= DE_QUIET;
860 
861  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
862  "(msg:\"Testing http_client_body\"; "
863  "content:\"one\"; http_client_body:; sid:1;)");
864  FAIL_IF_NULL(s);
865 
867  PASS;
868 }
869 
870 /**
871  * \test Test invalid signatures
872  */
873 static int DetectHttpClientBodyTest03(void)
874 {
877  de_ctx->flags |= DE_QUIET;
878 
879  const char *sigs[] = {
880  "alert tcp any any -> any any (http_client_body; sid:1;)",
881  "alert tcp any any -> any any "
882  "(msg:\"Testing http_client_body\"; "
883  "content:\"one\"; rawbytes; http_client_body; sid:2;)",
884  NULL,
885  };
886 
887  for (uint32_t i = 0; sigs[i] != NULL; i++) {
888  Signature *s = DetectEngineAppendSig(de_ctx, sigs[i]);
889  FAIL_IF_NOT_NULL(s);
890  }
892  PASS;
893 }
894 
895 /**
896  * \test Test that an invalid signature containing a rawbytes along with a
897  * http_client_body is invalidated.
898  */
899 static int DetectHttpClientBodyTest05(void)
900 {
903  de_ctx->flags |= DE_QUIET;
904 
905  const char *sigs[] = {
906  "alert tcp any any -> any any (content:\"one\"; http_client_body; nocase; sid:1;)",
907  NULL,
908  };
909 
910  for (uint32_t i = 0; sigs[i] != NULL; i++) {
911  Signature *s = DetectEngineAppendSig(de_ctx, sigs[i]);
912  FAIL_IF_NULL(s);
913  }
915  PASS;
916 }
917 
918 /**
919  *\test Test that the http_client_body content matches against a http request
920  * which holds the content.
921  */
922 static int DetectHttpClientBodyTest06(void)
923 {
924  TcpSession ssn;
925  Packet *p = NULL;
926  ThreadVars th_v;
927  DetectEngineCtx *de_ctx = NULL;
928  DetectEngineThreadCtx *det_ctx = NULL;
929  HtpState *http_state = NULL;
930  Flow f;
931  uint8_t http_buf[] =
932  "GET /index.html HTTP/1.0\r\n"
933  "Host: www.openinfosecfoundation.org\r\n"
934  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
935  "Content-Type: text/html\r\n"
936  "Content-Length: 26\r\n"
937  "\r\n"
938  "This is dummy message body";
939  uint32_t http_len = sizeof(http_buf) - 1;
940  int result = 0;
942 
943  memset(&th_v, 0, sizeof(th_v));
944  StatsThreadInit(&th_v.stats);
945  memset(&f, 0, sizeof(f));
946  memset(&ssn, 0, sizeof(ssn));
947 
948  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
949 
950  FLOW_INITIALIZE(&f);
951  f.protoctx = (void *)&ssn;
952  f.proto = IPPROTO_TCP;
953  f.flags |= FLOW_IPV4;
954 
955  p->flow = &f;
960 
961  StreamTcpInitConfig(true);
962 
964  if (de_ctx == NULL)
965  goto end;
966 
967  de_ctx->flags |= DE_QUIET;
968 
969  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
970  "(msg:\"http client body test\"; "
971  "content:\"message\"; http_client_body; "
972  "sid:1;)");
973  FAIL_IF_NULL(s);
974 
976  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
977 
978  int r = AppLayerParserParse(
979  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
980  if (r != 0) {
981  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
982  result = 0;
983  goto end;
984  }
985 
986  http_state = f.alstate;
987  if (http_state == NULL) {
988  printf("no http state: \n");
989  result = 0;
990  goto end;
991  }
992 
993  /* do detect */
994  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
995 
996  if (!(PacketAlertCheck(p, 1))) {
997  printf("sid 1 didn't match but should have\n");
998  goto end;
999  }
1000 
1001  result = 1;
1002 end:
1003  if (alp_tctx != NULL)
1005  if (det_ctx != NULL) {
1006  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1007  }
1008  if (de_ctx != NULL)
1010 
1011  StreamTcpFreeConfig(true);
1012  FLOW_DESTROY(&f);
1013  UTHFreePackets(&p, 1);
1014  StatsThreadCleanup(&th_v.stats);
1015  return result;
1016 }
1017 
1018 /**
1019  *\test Test that the http_client_body content matches against a http request
1020  * which holds the content.
1021  */
1022 static int DetectHttpClientBodyTest07(void)
1023 {
1024  TcpSession ssn;
1025  Packet *p1 = NULL;
1026  Packet *p2 = NULL;
1027  ThreadVars th_v;
1028  DetectEngineCtx *de_ctx = NULL;
1029  DetectEngineThreadCtx *det_ctx = NULL;
1030  HtpState *http_state = NULL;
1031  Flow f;
1032  uint8_t http1_buf[] =
1033  "GET /index.html HTTP/1.0\r\n"
1034  "Host: www.openinfosecfoundation.org\r\n"
1035  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1036  "Content-Type: text/html\r\n"
1037  "Content-Length: 54\r\n"
1038  "\r\n"
1039  "This is dummy message body1";
1040  uint8_t http2_buf[] =
1041  "This is dummy message body2";
1042  uint32_t http1_len = sizeof(http1_buf) - 1;
1043  uint32_t http2_len = sizeof(http2_buf) - 1;
1044  int result = 0;
1046 
1047  memset(&th_v, 0, sizeof(th_v));
1048  StatsThreadInit(&th_v.stats);
1049  memset(&f, 0, sizeof(f));
1050  memset(&ssn, 0, sizeof(ssn));
1051 
1052  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1053  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1054 
1055  FLOW_INITIALIZE(&f);
1056  f.protoctx = (void *)&ssn;
1057  f.proto = IPPROTO_TCP;
1058  f.flags |= FLOW_IPV4;
1059 
1060  p1->flow = &f;
1064  p2->flow = &f;
1068  f.alproto = ALPROTO_HTTP1;
1069 
1070  StreamTcpInitConfig(true);
1071 
1073  if (de_ctx == NULL)
1074  goto end;
1075 
1076  de_ctx->flags |= DE_QUIET;
1077 
1078  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1079  "(msg:\"http client body test\"; "
1080  "content:\"message\"; http_client_body; "
1081  "sid:1;)");
1082  FAIL_IF_NULL(s);
1083 
1085  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1086 
1087  int r = AppLayerParserParse(
1088  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1089  if (r != 0) {
1090  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1091  result = 0;
1092  goto end;
1093  }
1094 
1095  http_state = f.alstate;
1096  if (http_state == NULL) {
1097  printf("no http state: ");
1098  goto end;
1099  }
1100 
1101  /* do detect */
1102  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1103 
1104  if (PacketAlertCheck(p1, 1)) {
1105  printf("sid 1 matched on p1 but shouldn't have: ");
1106  goto end;
1107  }
1108 
1109  r = AppLayerParserParse(
1110  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1111  if (r != 0) {
1112  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1113  goto end;
1114  }
1115 
1116  /* do detect */
1117  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1118  if (!(PacketAlertCheck(p2, 1))) {
1119  printf("sid 1 didn't match on p2 but should have: ");
1120  goto end;
1121  }
1122 
1123  result = 1;
1124 end:
1125  if (alp_tctx != NULL)
1127  if (det_ctx != NULL) {
1128  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1129  }
1130  if (de_ctx != NULL)
1132 
1133  StreamTcpFreeConfig(true);
1134  FLOW_DESTROY(&f);
1135  UTHFreePackets(&p1, 1);
1136  UTHFreePackets(&p2, 1);
1137  StatsThreadCleanup(&th_v.stats);
1138  return result;
1139 }
1140 
1141 /**
1142  *\test Test that the http_client_body content matches against a http request
1143  * which holds the content.
1144  */
1145 static int DetectHttpClientBodyTest08(void)
1146 {
1147  TcpSession ssn;
1148  Packet *p1 = NULL;
1149  Packet *p2 = NULL;
1150  ThreadVars th_v;
1151  DetectEngineCtx *de_ctx = NULL;
1152  DetectEngineThreadCtx *det_ctx = NULL;
1153  HtpState *http_state = NULL;
1154  Flow f;
1155  uint8_t http1_buf[] =
1156  "GET /index.html HTTP/1.0\r\n"
1157  "Host: www.openinfosecfoundation.org\r\n"
1158  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1159  "Content-Type: text/html\r\n"
1160  "Content-Length: 46\r\n"
1161  "\r\n"
1162  "This is dummy body1";
1163  uint8_t http2_buf[] =
1164  "This is dummy message body2";
1165  uint32_t http1_len = sizeof(http1_buf) - 1;
1166  uint32_t http2_len = sizeof(http2_buf) - 1;
1167  int result = 0;
1169 
1170  memset(&th_v, 0, sizeof(th_v));
1171  StatsThreadInit(&th_v.stats);
1172  memset(&f, 0, sizeof(f));
1173  memset(&ssn, 0, sizeof(ssn));
1174 
1175  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1176  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1177 
1178  FLOW_INITIALIZE(&f);
1179  f.protoctx = (void *)&ssn;
1180  f.proto = IPPROTO_TCP;
1181  f.flags |= FLOW_IPV4;
1182 
1183  p1->flow = &f;
1187  p2->flow = &f;
1191  f.alproto = ALPROTO_HTTP1;
1192 
1193  StreamTcpInitConfig(true);
1194 
1196  if (de_ctx == NULL)
1197  goto end;
1198 
1199  de_ctx->flags |= DE_QUIET;
1200 
1201  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1202  "(msg:\"http client body test\"; "
1203  "content:\"message\"; http_client_body; "
1204  "sid:1;)");
1205  FAIL_IF_NULL(s);
1206 
1208  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1209 
1210  int r = AppLayerParserParse(
1211  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1212  if (r != 0) {
1213  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1214  result = 0;
1215  goto end;
1216  }
1217 
1218  http_state = f.alstate;
1219  if (http_state == NULL) {
1220  printf("no http state: ");
1221  result = 0;
1222  goto end;
1223  }
1224 
1225  /* do detect */
1226  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1227 
1228  if ((PacketAlertCheck(p1, 1))) {
1229  printf("sid 1 didn't match but should have");
1230  goto end;
1231  }
1232 
1233  r = AppLayerParserParse(
1234  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1235  if (r != 0) {
1236  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1237  result = 0;
1238  goto end;
1239  }
1240 
1241  /* do detect */
1242  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1243 
1244  if (!(PacketAlertCheck(p2, 1))) {
1245  printf("sid 1 didn't match but should have");
1246  goto end;
1247  }
1248 
1249  result = 1;
1250 end:
1251  if (alp_tctx != NULL)
1253  if (det_ctx != NULL) {
1254  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1255  }
1256  if (de_ctx != NULL)
1258 
1259  StreamTcpFreeConfig(true);
1260  FLOW_DESTROY(&f);
1261  UTHFreePackets(&p1, 1);
1262  UTHFreePackets(&p2, 1);
1263  StatsThreadCleanup(&th_v.stats);
1264  return result;
1265 }
1266 
1267 /**
1268  *\test Test that the http_client_body content matches against a http request
1269  * which holds the content, against a cross boundary present pattern.
1270  */
1271 static int DetectHttpClientBodyTest09(void)
1272 {
1273  TcpSession ssn;
1274  Packet *p1 = NULL;
1275  Packet *p2 = NULL;
1276  ThreadVars th_v;
1277  DetectEngineCtx *de_ctx = NULL;
1278  DetectEngineThreadCtx *det_ctx = NULL;
1279  HtpState *http_state = NULL;
1280  Flow f;
1281  uint8_t http1_buf[] =
1282  "GET /index.html HTTP/1.0\r\n"
1283  "Host: www.openinfosecfoundation.org\r\n"
1284  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1285  "Content-Type: text/html\r\n"
1286  "Content-Length: 46\r\n"
1287  "\r\n"
1288  "This is dummy body1";
1289  uint8_t http2_buf[] =
1290  "This is dummy message body2";
1291  uint32_t http1_len = sizeof(http1_buf) - 1;
1292  uint32_t http2_len = sizeof(http2_buf) - 1;
1293  int result = 0;
1295 
1296  memset(&th_v, 0, sizeof(th_v));
1297  StatsThreadInit(&th_v.stats);
1298  memset(&f, 0, sizeof(f));
1299  memset(&ssn, 0, sizeof(ssn));
1300 
1301  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1302  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1303 
1304  FLOW_INITIALIZE(&f);
1305  f.protoctx = (void *)&ssn;
1306  f.proto = IPPROTO_TCP;
1307  f.flags |= FLOW_IPV4;
1308 
1309  p1->flow = &f;
1313  p2->flow = &f;
1317  f.alproto = ALPROTO_HTTP1;
1318 
1319  StreamTcpInitConfig(true);
1320 
1322  if (de_ctx == NULL)
1323  goto end;
1324 
1325  de_ctx->flags |= DE_QUIET;
1326 
1327  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1328  "(msg:\"http client body test\"; "
1329  "content:\"body1This\"; http_client_body; "
1330  "sid:1;)");
1331  FAIL_IF_NULL(s);
1332 
1334  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1335 
1336  int r = AppLayerParserParse(
1337  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1338  if (r != 0) {
1339  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1340  result = 0;
1341  goto end;
1342  }
1343 
1344  http_state = f.alstate;
1345  if (http_state == NULL) {
1346  printf("no http state: ");
1347  result = 0;
1348  goto end;
1349  }
1350 
1351  /* do detect */
1352  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1353 
1354  if ((PacketAlertCheck(p1, 1))) {
1355  printf("sid 1 didn't match but should have");
1356  goto end;
1357  }
1358 
1359  r = AppLayerParserParse(
1360  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1361  if (r != 0) {
1362  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1363  result = 0;
1364  goto end;
1365  }
1366 
1367  /* do detect */
1368  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1369 
1370  if (!(PacketAlertCheck(p2, 1))) {
1371  printf("sid 1 didn't match but should have");
1372  goto end;
1373  }
1374 
1375  result = 1;
1376 end:
1377  if (alp_tctx != NULL)
1379  if (det_ctx != NULL) {
1380  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1381  }
1382  if (de_ctx != NULL)
1384 
1385  StreamTcpFreeConfig(true);
1386  FLOW_DESTROY(&f);
1387  UTHFreePackets(&p1, 1);
1388  UTHFreePackets(&p2, 1);
1389  StatsThreadCleanup(&th_v.stats);
1390  return result;
1391 }
1392 
1393 /**
1394  *\test Test that the http_client_body content matches against a http request
1395  * against a case insensitive pattern.
1396  */
1397 static int DetectHttpClientBodyTest10(void)
1398 {
1399  TcpSession ssn;
1400  Packet *p1 = NULL;
1401  Packet *p2 = NULL;
1402  ThreadVars th_v;
1403  DetectEngineCtx *de_ctx = NULL;
1404  DetectEngineThreadCtx *det_ctx = NULL;
1405  HtpState *http_state = NULL;
1406  Flow f;
1407  uint8_t http1_buf[] =
1408  "GET /index.html HTTP/1.0\r\n"
1409  "Host: www.openinfosecfoundation.org\r\n"
1410  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1411  "Content-Type: text/html\r\n"
1412  "Content-Length: 46\r\n"
1413  "\r\n"
1414  "This is dummy bodY1";
1415  uint8_t http2_buf[] =
1416  "This is dummy message body2";
1417  uint32_t http1_len = sizeof(http1_buf) - 1;
1418  uint32_t http2_len = sizeof(http2_buf) - 1;
1419  int result = 0;
1421 
1422  memset(&th_v, 0, sizeof(th_v));
1423  StatsThreadInit(&th_v.stats);
1424  memset(&f, 0, sizeof(f));
1425  memset(&ssn, 0, sizeof(ssn));
1426 
1427  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1428  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1429 
1430  FLOW_INITIALIZE(&f);
1431  f.protoctx = (void *)&ssn;
1432  f.proto = IPPROTO_TCP;
1433  f.flags |= FLOW_IPV4;
1434 
1435  p1->flow = &f;
1439  p2->flow = &f;
1443  f.alproto = ALPROTO_HTTP1;
1444 
1445  StreamTcpInitConfig(true);
1446 
1448  if (de_ctx == NULL)
1449  goto end;
1450 
1451  de_ctx->flags |= DE_QUIET;
1452 
1453  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1454  "(msg:\"http client body test\"; "
1455  "content:\"body1This\"; http_client_body; nocase;"
1456  "sid:1;)");
1457  FAIL_IF_NULL(s);
1458 
1460  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1461 
1462  int r = AppLayerParserParse(
1463  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1464  if (r != 0) {
1465  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1466  result = 0;
1467  goto end;
1468  }
1469 
1470  http_state = f.alstate;
1471  if (http_state == NULL) {
1472  printf("no http state: \n");
1473  result = 0;
1474  goto end;
1475  }
1476 
1477  /* do detect */
1478  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1479 
1480  if ((PacketAlertCheck(p1, 1))) {
1481  printf("sid 1 didn't match but should have\n");
1482  goto end;
1483  }
1484 
1485  r = AppLayerParserParse(
1486  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1487  if (r != 0) {
1488  printf("toserver chunk 1 returned %" PRId32 ", expected 0: \n", r);
1489  result = 0;
1490  goto end;
1491  }
1492 
1493  /* do detect */
1494  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1495 
1496  if (!(PacketAlertCheck(p2, 1))) {
1497  printf("sid 1 didn't match but should have");
1498  goto end;
1499  }
1500 
1501  result = 1;
1502 end:
1503  if (alp_tctx != NULL)
1505  if (det_ctx != NULL) {
1506  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1507  }
1508  if (de_ctx != NULL)
1510 
1511  StreamTcpFreeConfig(true);
1512  FLOW_DESTROY(&f);
1513  UTHFreePackets(&p1, 1);
1514  UTHFreePackets(&p2, 1);
1515  StatsThreadCleanup(&th_v.stats);
1516  return result;
1517 }
1518 
1519 /**
1520  *\test Test that the negated http_client_body content matches against a
1521  * http request which doesn't hold the content.
1522  */
1523 static int DetectHttpClientBodyTest11(void)
1524 {
1525  TcpSession ssn;
1526  Packet *p = NULL;
1527  ThreadVars th_v;
1528  DetectEngineCtx *de_ctx = NULL;
1529  DetectEngineThreadCtx *det_ctx = NULL;
1530  HtpState *http_state = NULL;
1531  Flow f;
1532  uint8_t http_buf[] =
1533  "GET /index.html HTTP/1.0\r\n"
1534  "Host: www.openinfosecfoundation.org\r\n"
1535  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1536  "Content-Type: text/html\r\n"
1537  "Content-Length: 26\r\n"
1538  "\r\n"
1539  "This is dummy message body";
1540  uint32_t http_len = sizeof(http_buf) - 1;
1541  int result = 0;
1543 
1544  memset(&th_v, 0, sizeof(th_v));
1545  StatsThreadInit(&th_v.stats);
1546  memset(&f, 0, sizeof(f));
1547  memset(&ssn, 0, sizeof(ssn));
1548 
1549  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1550 
1551  FLOW_INITIALIZE(&f);
1552  f.protoctx = (void *)&ssn;
1553  f.proto = IPPROTO_TCP;
1554  f.flags |= FLOW_IPV4;
1555 
1556  p->flow = &f;
1560  f.alproto = ALPROTO_HTTP1;
1561 
1562  StreamTcpInitConfig(true);
1563 
1565  if (de_ctx == NULL)
1566  goto end;
1567 
1568  de_ctx->flags |= DE_QUIET;
1569 
1570  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1571  "(msg:\"http client body test\"; "
1572  "content:!\"message1\"; http_client_body; "
1573  "sid:1;)");
1574  FAIL_IF_NULL(s);
1575 
1577  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1578 
1579  int r = AppLayerParserParse(
1580  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
1581  if (r != 0) {
1582  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1583  result = 0;
1584  goto end;
1585  }
1586 
1587  http_state = f.alstate;
1588  if (http_state == NULL) {
1589  printf("no http state: ");
1590  result = 0;
1591  goto end;
1592  }
1593 
1594  /* do detect */
1595  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1596 
1597  if (!(PacketAlertCheck(p, 1))) {
1598  printf("sid 1 didn't match but should have");
1599  goto end;
1600  }
1601 
1602  result = 1;
1603 end:
1604  if (alp_tctx != NULL)
1606  if (det_ctx != NULL) {
1607  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1608  }
1609  if (de_ctx != NULL)
1611 
1612  StreamTcpFreeConfig(true);
1613  FLOW_DESTROY(&f);
1614  UTHFreePackets(&p, 1);
1615  StatsThreadCleanup(&th_v.stats);
1616  return result;
1617 }
1618 
1619 /**
1620  *\test Negative test that the negated http_client_body content matches against a
1621  * http request which holds hold the content.
1622  */
1623 static int DetectHttpClientBodyTest12(void)
1624 {
1625  TcpSession ssn;
1626  Packet *p = NULL;
1627  ThreadVars th_v;
1628  DetectEngineCtx *de_ctx = NULL;
1629  DetectEngineThreadCtx *det_ctx = NULL;
1630  HtpState *http_state = NULL;
1631  Flow f;
1632  uint8_t http_buf[] =
1633  "GET /index.html HTTP/1.0\r\n"
1634  "Host: www.openinfosecfoundation.org\r\n"
1635  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1636  "Content-Type: text/html\r\n"
1637  "Content-Length: 26\r\n"
1638  "\r\n"
1639  "This is dummy message body";
1640  uint32_t http_len = sizeof(http_buf) - 1;
1641  int result = 0;
1643 
1644  memset(&th_v, 0, sizeof(th_v));
1645  StatsThreadInit(&th_v.stats);
1646  memset(&f, 0, sizeof(f));
1647  memset(&ssn, 0, sizeof(ssn));
1648 
1649  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1650 
1651  FLOW_INITIALIZE(&f);
1652  f.protoctx = (void *)&ssn;
1653  f.proto = IPPROTO_TCP;
1654  f.flags |= FLOW_IPV4;
1655 
1656  p->flow = &f;
1660  f.alproto = ALPROTO_HTTP1;
1661 
1662  StreamTcpInitConfig(true);
1663 
1665  if (de_ctx == NULL)
1666  goto end;
1667 
1668  de_ctx->flags |= DE_QUIET;
1669 
1670  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1671  "(msg:\"http client body test\"; "
1672  "content:!\"message\"; http_client_body; "
1673  "sid:1;)");
1674  FAIL_IF_NULL(s);
1675 
1677  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1678 
1679  int r = AppLayerParserParse(
1680  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
1681  if (r != 0) {
1682  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1683  result = 0;
1684  goto end;
1685  }
1686 
1687  http_state = f.alstate;
1688  if (http_state == NULL) {
1689  printf("no http state: ");
1690  result = 0;
1691  goto end;
1692  }
1693 
1694  /* do detect */
1695  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1696 
1697  if ((PacketAlertCheck(p, 1))) {
1698  printf("sid 1 didn't match but should have");
1699  goto end;
1700  }
1701 
1702  result = 1;
1703 end:
1704  if (alp_tctx != NULL)
1706  if (det_ctx != NULL) {
1707  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1708  }
1709  if (de_ctx != NULL)
1711 
1712  StreamTcpFreeConfig(true);
1713  FLOW_DESTROY(&f);
1714  UTHFreePackets(&p, 1);
1715  StatsThreadCleanup(&th_v.stats);
1716  return result;
1717 }
1718 
1719 /**
1720  *\test Test that the http_client_body content matches against a http request
1721  * which holds the content.
1722  */
1723 static int DetectHttpClientBodyTest13(void)
1724 {
1725  TcpSession ssn;
1726  Packet *p = NULL;
1727  ThreadVars th_v;
1728  DetectEngineCtx *de_ctx = NULL;
1729  DetectEngineThreadCtx *det_ctx = NULL;
1730  HtpState *http_state = NULL;
1731  Flow f;
1732  uint8_t http_buf[] =
1733  "GET /index.html HTTP/1.0\r\n"
1734  "Host: www.openinfosecfoundation.org\r\n"
1735  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1736  "Content-Type: text/html\r\n"
1737  "Content-Length: 55\r\n"
1738  "\r\n"
1739  "longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend";
1740  uint32_t http_len = sizeof(http_buf) - 1;
1741  int result = 0;
1743 
1744  memset(&th_v, 0, sizeof(th_v));
1745  StatsThreadInit(&th_v.stats);
1746  memset(&f, 0, sizeof(f));
1747  memset(&ssn, 0, sizeof(ssn));
1748 
1749  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1750 
1751  FLOW_INITIALIZE(&f);
1752  f.protoctx = (void *)&ssn;
1753  f.proto = IPPROTO_TCP;
1754  f.flags |= FLOW_IPV4;
1755 
1756  p->flow = &f;
1760  f.alproto = ALPROTO_HTTP1;
1761 
1762  StreamTcpInitConfig(true);
1763 
1765  if (de_ctx == NULL)
1766  goto end;
1767 
1768  de_ctx->flags |= DE_QUIET;
1769 
1771  "alert http any any -> any any "
1772  "(msg:\"http client body test\"; "
1773  "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_client_body; "
1774  "sid:1;)");
1775  FAIL_IF_NULL(s);
1776 
1778  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1779 
1780  int r = AppLayerParserParse(
1781  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
1782  if (r != 0) {
1783  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1784  result = 0;
1785  goto end;
1786  }
1787 
1788  http_state = f.alstate;
1789  if (http_state == NULL) {
1790  printf("no http state: ");
1791  result = 0;
1792  goto end;
1793  }
1794 
1795  /* do detect */
1796  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1797 
1798  if (!(PacketAlertCheck(p, 1))) {
1799  printf("sid 1 didn't match but should have");
1800  goto end;
1801  }
1802 
1803  result = 1;
1804 end:
1805  if (alp_tctx != NULL)
1807  if (det_ctx != NULL) {
1808  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1809  }
1810  if (de_ctx != NULL)
1812 
1813  StreamTcpFreeConfig(true);
1814  FLOW_DESTROY(&f);
1815  UTHFreePackets(&p, 1);
1816  StatsThreadCleanup(&th_v.stats);
1817  return result;
1818 }
1819 
1820 /** \test multiple http transactions and body chunks of request handling */
1821 static int DetectHttpClientBodyTest14(void)
1822 {
1823  int result = 0;
1824  Signature *s = NULL;
1825  DetectEngineThreadCtx *det_ctx = NULL;
1826  ThreadVars th_v;
1827  Flow f;
1828  TcpSession ssn;
1829  Packet *p = NULL;
1830  uint8_t httpbuf1[] = "POST / HTTP/1.1\r\n";
1831  uint8_t httpbuf2[] = "User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1832  uint8_t httpbuf3[] = "Cookie: dummy\r\n\r\n";
1833  uint8_t httpbuf4[] = "Body one!!";
1834  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
1835  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
1836  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
1837  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
1838  uint8_t httpbuf5[] = "GET /?var=val HTTP/1.1\r\n";
1839  uint8_t httpbuf6[] = "User-Agent: Firefox/1.0\r\n";
1840  uint8_t httpbuf7[] = "Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1841  uint32_t httplen5 = sizeof(httpbuf5) - 1; /* minus the \0 */
1842  uint32_t httplen6 = sizeof(httpbuf6) - 1; /* minus the \0 */
1843  uint32_t httplen7 = sizeof(httpbuf7) - 1; /* minus the \0 */
1845 
1846  memset(&th_v, 0, sizeof(th_v));
1847  StatsThreadInit(&th_v.stats);
1848  memset(&f, 0, sizeof(f));
1849  memset(&ssn, 0, sizeof(ssn));
1850 
1851  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1852 
1853  FLOW_INITIALIZE(&f);
1854  f.protoctx = (void *)&ssn;
1855  f.proto = IPPROTO_TCP;
1856  f.flags |= FLOW_IPV4;
1857 
1858  p->flow = &f;
1862  f.alproto = ALPROTO_HTTP1;
1863 
1864  StreamTcpInitConfig(true);
1865 
1867  if (de_ctx == NULL) {
1868  goto end;
1869  }
1870 
1871  de_ctx->flags |= DE_QUIET;
1872 
1873  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (content:\"POST\"; http_method; content:\"Mozilla\"; http_header; content:\"dummy\"; http_cookie; content:\"one\"; http_client_body; sid:1; rev:1;)");
1874  if (s == NULL) {
1875  printf("sig parse failed: ");
1876  goto end;
1877  }
1878  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (content:\"GET\"; http_method; content:\"Firefox\"; http_header; content:\"dummy2\"; http_cookie; content:\"two\"; http_client_body; sid:2; rev:1;)");
1879  if (s == NULL) {
1880  printf("sig2 parse failed: ");
1881  goto end;
1882  }
1883 
1885  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1886 
1887  int r = AppLayerParserParse(
1888  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf1, httplen1);
1889  if (r != 0) {
1890  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1891  goto end;
1892  }
1893 
1894  /* do detect */
1895  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1896  if (PacketAlertCheck(p, 1)) {
1897  printf("sig 1 alerted: ");
1898  goto end;
1899  }
1900  p->alerts.cnt = 0;
1901 
1902  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
1903  if (r != 0) {
1904  printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
1905  goto end;
1906  }
1907 
1908  /* do detect */
1909  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1910  if (PacketAlertCheck(p, 1)) {
1911  printf("sig 1 alerted (2): ");
1912  goto end;
1913  }
1914  p->alerts.cnt = 0;
1915 
1916  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
1917  if (r != 0) {
1918  printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
1919  goto end;
1920  }
1921 
1922  /* do detect */
1923  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1924  if (PacketAlertCheck(p, 1)) {
1925  printf("signature matched, but shouldn't have: ");
1926  goto end;
1927  }
1928  p->alerts.cnt = 0;
1929 
1930  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf4, httplen4);
1931  if (r != 0) {
1932  printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
1933  result = 0;
1934  goto end;
1935  }
1936 
1937  /* do detect */
1938  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1939  if (!(PacketAlertCheck(p, 1))) {
1940  printf("sig 1 didn't alert: ");
1941  goto end;
1942  }
1943  p->alerts.cnt = 0;
1944 
1945  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf5, httplen5);
1946  if (r != 0) {
1947  printf("toserver chunk 5 returned %" PRId32 ", expected 0: ", r);
1948  goto end;
1949  }
1950 
1951  /* do detect */
1952  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1953  if (PacketAlertCheck(p, 1)) {
1954  printf("sig 1 alerted (5): ");
1955  goto end;
1956  }
1957  p->alerts.cnt = 0;
1958 
1959  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf6, httplen6);
1960  if (r != 0) {
1961  printf("toserver chunk 6 returned %" PRId32 ", expected 0: ", r);
1962  goto end;
1963  }
1964 
1965  /* do detect */
1966  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1967  if ((PacketAlertCheck(p, 1)) || (PacketAlertCheck(p, 2))) {
1968  printf("sig 1 alerted (request 2, chunk 6): ");
1969  goto end;
1970  }
1971  p->alerts.cnt = 0;
1972 
1973  SCLogDebug("sending data chunk 7");
1974 
1975  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf7, httplen7);
1976  if (r != 0) {
1977  printf("toserver chunk 7 returned %" PRId32 ", expected 0: ", r);
1978  goto end;
1979  }
1980 
1981  /* do detect */
1982  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1983  if (!(PacketAlertCheck(p, 2))) {
1984  printf("signature 2 didn't match, but should have: ");
1985  goto end;
1986  }
1987  p->alerts.cnt = 0;
1988 
1989  HtpState *htp_state = f.alstate;
1990  if (htp_state == NULL) {
1991  printf("no http state: ");
1992  result = 0;
1993  goto end;
1994  }
1995 
1996  if (AppLayerParserGetTxCnt(&f, htp_state) != 2) {
1997  printf("The http app layer doesn't have 2 transactions, but it should: ");
1998  goto end;
1999  }
2000 
2001  result = 1;
2002 end:
2003  if (alp_tctx != NULL)
2005  if (det_ctx != NULL) {
2006  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
2007  }
2008  if (de_ctx != NULL) {
2010  }
2011 
2012  StreamTcpFreeConfig(true);
2013  FLOW_DESTROY(&f);
2014  UTHFreePacket(p);
2015  StatsThreadCleanup(&th_v.stats);
2016  return result;
2017 }
2018 
2019 /** \test multiple http transactions and body chunks of request handling */
2020 static int DetectHttpClientBodyTest15(void)
2021 {
2022  int result = 0;
2023  Signature *s = NULL;
2024  DetectEngineThreadCtx *det_ctx = NULL;
2025  ThreadVars th_v;
2026  Flow f;
2027  TcpSession ssn;
2028  Packet *p = NULL;
2029  uint8_t httpbuf1[] = "POST / HTTP/1.1\r\n";
2030  uint8_t httpbuf2[] = "User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
2031  uint8_t httpbuf3[] = "Cookie: dummy\r\n\r\n";
2032  uint8_t httpbuf4[] = "Body one!!";
2033  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
2034  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
2035  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
2036  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
2037  uint8_t httpbuf5[] = "GET /?var=val HTTP/1.1\r\n";
2038  uint8_t httpbuf6[] = "User-Agent: Firefox/1.0\r\n";
2039  uint8_t httpbuf7[] = "Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
2040  uint32_t httplen5 = sizeof(httpbuf5) - 1; /* minus the \0 */
2041  uint32_t httplen6 = sizeof(httpbuf6) - 1; /* minus the \0 */
2042  uint32_t httplen7 = sizeof(httpbuf7) - 1; /* minus the \0 */
2044 
2045  memset(&th_v, 0, sizeof(th_v));
2046  StatsThreadInit(&th_v.stats);
2047  memset(&f, 0, sizeof(f));
2048  memset(&ssn, 0, sizeof(ssn));
2049 
2050  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
2051 
2052  FLOW_INITIALIZE(&f);
2053  f.protoctx = (void *)&ssn;
2054  f.proto = IPPROTO_TCP;
2055  f.flags |= FLOW_IPV4;
2056 
2057  p->flow = &f;
2061  f.alproto = ALPROTO_HTTP1;
2062 
2063  StreamTcpInitConfig(true);
2064 
2066  if (de_ctx == NULL) {
2067  goto end;
2068  }
2069 
2070  de_ctx->flags |= DE_QUIET;
2071 
2072  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (content:\"POST\"; http_method; content:\"Mozilla\"; http_header; content:\"dummy\"; http_cookie; content:\"one\"; http_client_body; sid:1; rev:1;)");
2073  if (s == NULL) {
2074  printf("sig parse failed: ");
2075  goto end;
2076  }
2077  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (content:\"GET\"; http_method; content:\"Firefox\"; http_header; content:\"dummy2\"; http_cookie; content:\"two\"; http_client_body; sid:2; rev:1;)");
2078  if (s == NULL) {
2079  printf("sig2 parse failed: ");
2080  goto end;
2081  }
2082 
2084  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
2085 
2086  int r = AppLayerParserParse(
2087  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf1, httplen1);
2088  if (r != 0) {
2089  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
2090  goto end;
2091  }
2092 
2093  /* do detect */
2094  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2095  if (PacketAlertCheck(p, 1)) {
2096  printf("sig 1 alerted: ");
2097  goto end;
2098  }
2099  p->alerts.cnt = 0;
2100 
2101  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
2102  if (r != 0) {
2103  printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
2104  goto end;
2105  }
2106 
2107  /* do detect */
2108  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2109  if (PacketAlertCheck(p, 1)) {
2110  printf("sig 1 alerted (2): ");
2111  goto end;
2112  }
2113  p->alerts.cnt = 0;
2114 
2115  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
2116  if (r != 0) {
2117  printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
2118  goto end;
2119  }
2120 
2121  /* do detect */
2122  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2123  if (PacketAlertCheck(p, 1)) {
2124  printf("signature matched, but shouldn't have: ");
2125  goto end;
2126  }
2127  p->alerts.cnt = 0;
2128 
2129  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf4, httplen4);
2130  if (r != 0) {
2131  printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
2132  result = 0;
2133  goto end;
2134  }
2135 
2136  /* do detect */
2137  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2138  if (!(PacketAlertCheck(p, 1))) {
2139  printf("sig 1 didn't alert: ");
2140  goto end;
2141  }
2142  p->alerts.cnt = 0;
2143 
2144  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf5, httplen5);
2145  if (r != 0) {
2146  printf("toserver chunk 5 returned %" PRId32 ", expected 0: ", r);
2147  goto end;
2148  }
2149 
2150  /* do detect */
2151  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2152  if (PacketAlertCheck(p, 1)) {
2153  printf("sig 1 alerted (5): ");
2154  goto end;
2155  }
2156  p->alerts.cnt = 0;
2157 
2158  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf6, httplen6);
2159  if (r != 0) {
2160  printf("toserver chunk 6 returned %" PRId32 ", expected 0: ", r);
2161  goto end;
2162  }
2163 
2164  /* do detect */
2165  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2166  if ((PacketAlertCheck(p, 1)) || (PacketAlertCheck(p, 2))) {
2167  printf("sig 1 alerted (request 2, chunk 6): ");
2168  goto end;
2169  }
2170  p->alerts.cnt = 0;
2171 
2172  SCLogDebug("sending data chunk 7");
2173 
2174  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf7, httplen7);
2175  if (r != 0) {
2176  printf("toserver chunk 7 returned %" PRId32 ", expected 0: ", r);
2177  goto end;
2178  }
2179 
2180  /* do detect */
2181  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2182  if (!(PacketAlertCheck(p, 2))) {
2183  printf("signature 2 didn't match, but should have: ");
2184  goto end;
2185  }
2186  p->alerts.cnt = 0;
2187 
2188  HtpState *htp_state = f.alstate;
2189  if (htp_state == NULL) {
2190  printf("no http state: ");
2191  result = 0;
2192  goto end;
2193  }
2194 
2195  /* hardcoded check of the transactions and it's client body chunks */
2196  if (AppLayerParserGetTxCnt(&f, htp_state) != 2) {
2197  printf("The http app layer doesn't have 2 transactions, but it should: ");
2198  goto end;
2199  }
2200 
2201  htp_tx_t *t1 = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, 0);
2202  htp_tx_t *t2 = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, 1);
2203 
2204  HtpTxUserData *htud = (HtpTxUserData *) htp_tx_get_user_data(t1);
2205 
2206  HtpBodyChunk *cur = htud->request_body.first;
2207  if (htud->request_body.first == NULL) {
2208  SCLogDebug("No body data in t1 (it should be removed only when the tx is destroyed): ");
2209  goto end;
2210  }
2211 
2213  (uint8_t *)"Body one!!", 10) != 1)
2214  {
2215  SCLogDebug("Body data in t1 is not correctly set: ");
2216  goto end;
2217  }
2218 
2219  htud = (HtpTxUserData *) htp_tx_get_user_data(t2);
2220 
2221  cur = htud->request_body.first;
2222  if (htud->request_body.first == NULL) {
2223  SCLogDebug("No body data in t1 (it should be removed only when the tx is destroyed): ");
2224  goto end;
2225  }
2226 
2228  (uint8_t *)"Body two!!", 10) != 1)
2229  {
2230  SCLogDebug("Body data in t1 is not correctly set: ");
2231  goto end;
2232  }
2233 
2234  result = 1;
2235 end:
2236  if (alp_tctx != NULL)
2238  if (det_ctx != NULL) {
2239  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
2240  }
2241  if (de_ctx != NULL) {
2243  }
2244 
2245  StreamTcpFreeConfig(true);
2246  FLOW_DESTROY(&f);
2247  UTHFreePacket(p);
2248  StatsThreadCleanup(&th_v.stats);
2249  return result;
2250 }
2251 
2252 static int DetectHttpClientBodyTest22(void)
2253 {
2256  de_ctx->flags |= DE_QUIET;
2258  "alert icmp any any -> any any "
2259  "(content:\"one\"; content:\"two\"; http_client_body; "
2260  "content:\"three\"; distance:10; http_client_body; content:\"four\"; sid:1;)");
2261  FAIL_IF_NULL(s);
2263  FAIL_IF(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL);
2264  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id);
2265  FAIL_IF_NULL(sm);
2266 
2267  DetectContentData *cd1 =
2269  DetectContentData *cd2 =
2271  DetectContentData *hcbd1 =
2272  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2273  ->prev->ctx;
2274  DetectContentData *hcbd2 =
2275  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2276  FAIL_IF(cd1->flags != 0);
2277  FAIL_IF(memcmp(cd1->content, "one", cd1->content_len) != 0);
2278  FAIL_IF(cd2->flags != 0);
2279  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2281  FAIL_IF(memcmp(hcbd1->content, "two", hcbd1->content_len) != 0);
2283  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2284 
2289 
2291  PASS;
2292 }
2293 
2294 static int DetectHttpClientBodyTest23(void)
2295 {
2298  de_ctx->flags |= DE_QUIET;
2299 
2301  "alert icmp any any -> any any "
2302  "(content:\"one\"; http_client_body; pcre:/two/; "
2303  "content:\"three\"; distance:10; http_client_body; content:\"four\"; sid:1;)");
2304  FAIL_IF_NULL(s);
2306  FAIL_IF_NULL(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id));
2307 
2308  DetectPcreData *pd1 =
2310  ->prev->ctx;
2311  DetectContentData *cd2 =
2313  ->ctx;
2314  DetectContentData *hcbd1 =
2315  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2316  ->prev->ctx;
2317  DetectContentData *hcbd2 =
2318  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2319  FAIL_IF(pd1->flags != 0);
2320  FAIL_IF(cd2->flags != 0);
2321  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2323  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2325  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2329 
2331  PASS;
2332 }
2333 
2334 static int DetectHttpClientBodyTest24(void)
2335 {
2338  de_ctx->flags |= DE_QUIET;
2339  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2340  "(content:\"one\"; http_client_body; pcre:/two/; "
2341  "content:\"three\"; distance:10; within:15; "
2342  "http_client_body; content:\"four\"; sid:1;)");
2343  FAIL_IF_NULL(s);
2344 
2346  FAIL_IF_NULL(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id));
2347 
2348  DetectPcreData *pd1 =
2350  ->prev->ctx;
2351  DetectContentData *cd2 =
2353  ->ctx;
2354  DetectContentData *hcbd1 =
2355  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2356  ->prev->ctx;
2357  DetectContentData *hcbd2 =
2358  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2359  FAIL_IF(pd1->flags != 0);
2360  FAIL_IF(cd2->flags != 0);
2361  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2363  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2365  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2366 
2370 
2372  PASS;
2373 }
2374 
2375 static int DetectHttpClientBodyTest25(void)
2376 {
2379  de_ctx->flags |= DE_QUIET;
2380  Signature *s =
2381  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2382  "(content:\"one\"; http_client_body; pcre:/two/; "
2383  "content:\"three\"; distance:10; http_client_body; "
2384  "content:\"four\"; distance:10; sid:1;)");
2385  FAIL_IF_NULL(s);
2387  FAIL_IF_NULL(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id));
2388 
2389  DetectPcreData *pd1 =
2391  ->prev->ctx;
2392  DetectContentData *cd2 =
2394  ->ctx;
2395  DetectContentData *hcbd1 =
2396  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2397  ->prev->ctx;
2398  DetectContentData *hcbd2 =
2399  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2401  FAIL_IF(cd2->flags != DETECT_CONTENT_DISTANCE);
2402  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2404  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2406  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2407 
2411 
2413  PASS;
2414 }
2415 
2416 static int DetectHttpClientBodyTest26(void)
2417 {
2418  DetectEngineCtx *de_ctx = NULL;
2419  int result = 0;
2420 
2421  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2422  goto end;
2423 
2424  de_ctx->flags |= DE_QUIET;
2426  "alert icmp any any -> any any "
2427  "(content:\"one\"; offset:10; http_client_body; pcre:/two/; "
2428  "content:\"three\"; distance:10; http_client_body; within:10; "
2429  "content:\"four\"; distance:10; sid:1;)");
2430  if (de_ctx->sig_list == NULL) {
2431  printf("de_ctx->sig_list == NULL\n");
2432  goto end;
2433  }
2434 
2436  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] == NULL\n");
2437  goto end;
2438  }
2439 
2440  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2441  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2442  goto end;
2443  }
2444 
2445  DetectPcreData *pd1 =
2447  ->prev->ctx;
2448  DetectContentData *cd2 =
2450  ->ctx;
2451  DetectContentData *hcbd1 =
2452  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2453  ->prev->ctx;
2454  DetectContentData *hcbd2 =
2455  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2456  if (pd1->flags != (DETECT_PCRE_RELATIVE_NEXT) || cd2->flags != DETECT_CONTENT_DISTANCE ||
2457  memcmp(cd2->content, "four", cd2->content_len) != 0 ||
2459  memcmp(hcbd1->content, "one", hcbd1->content_len) != 0 ||
2460  hcbd2->flags !=
2462  memcmp(hcbd2->content, "three", hcbd1->content_len) != 0) {
2463  printf ("failed: http_client_body incorrect flags");
2464  goto end;
2465  }
2466 
2467  if (DETECT_CONTENT_IS_SINGLE(cd2) ||
2468  DETECT_CONTENT_IS_SINGLE(hcbd1) ||
2469  DETECT_CONTENT_IS_SINGLE(hcbd2)) {
2470  goto end;
2471  }
2472 
2473  result = 1;
2474 
2475  end:
2477  return result;
2478 }
2479 
2480 static int DetectHttpClientBodyTest27(void)
2481 {
2482  DetectEngineCtx *de_ctx = NULL;
2483  int result = 0;
2484 
2485  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2486  goto end;
2487 
2488  de_ctx->flags |= DE_QUIET;
2490  "alert icmp any any -> any any "
2491  "(content:\"one\"; offset:10; http_client_body; pcre:/two/; "
2492  "content:\"three\"; distance:10; http_client_body; within:10; "
2493  "content:\"four\"; distance:10; sid:1;)");
2494  FAIL_IF_NULL(s);
2495 
2496  result = 1;
2497 
2498  end:
2500  return result;
2501 }
2502 
2503 static int DetectHttpClientBodyTest28(void)
2504 {
2505  DetectEngineCtx *de_ctx = NULL;
2506  int result = 0;
2507 
2508  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2509  goto end;
2510 
2511  de_ctx->flags |= DE_QUIET;
2512  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2513  "(content:\"one\"; http_client_body; pcre:/two/; "
2514  "content:\"three\"; http_client_body; depth:10; "
2515  "content:\"four\"; distance:10; sid:1;)");
2516  if (de_ctx->sig_list == NULL) {
2517  printf("de_ctx->sig_list == NULL\n");
2518  goto end;
2519  }
2520 
2522  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] == NULL\n");
2523  goto end;
2524  }
2525 
2526  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2527  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2528  goto end;
2529  }
2530 
2531  DetectPcreData *pd1 =
2533  ->prev->ctx;
2534  DetectContentData *cd2 =
2536  ->ctx;
2537  DetectContentData *hcbd1 =
2538  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2539  ->prev->ctx;
2540  DetectContentData *hcbd2 =
2541  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2542  if (pd1->flags != (DETECT_PCRE_RELATIVE_NEXT) || cd2->flags != DETECT_CONTENT_DISTANCE ||
2543  memcmp(cd2->content, "four", cd2->content_len) != 0 || hcbd1->flags != 0 ||
2544  memcmp(hcbd1->content, "one", hcbd1->content_len) != 0 ||
2546  memcmp(hcbd2->content, "three", hcbd1->content_len) != 0) {
2547  goto end;
2548  }
2549 
2550  if (DETECT_CONTENT_IS_SINGLE(cd2) ||
2551  !DETECT_CONTENT_IS_SINGLE(hcbd1) ||
2552  DETECT_CONTENT_IS_SINGLE(hcbd2)) {
2553  goto end;
2554  }
2555 
2556  result = 1;
2557 
2558  end:
2560  return result;
2561 }
2562 
2563 static int DetectHttpClientBodyTest29(void)
2564 {
2565  DetectEngineCtx *de_ctx = NULL;
2566  int result = 0;
2567 
2568  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2569  goto end;
2570 
2571  de_ctx->flags |= DE_QUIET;
2572  Signature *s =
2573  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2574  "(content:\"one\"; http_client_body; "
2575  "content:\"two\"; distance:0; http_client_body; sid:1;)");
2576  if (de_ctx->sig_list == NULL) {
2577  printf("de_ctx->sig_list == NULL\n");
2578  goto end;
2579  }
2580 
2582  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2583  goto end;
2584  }
2585 
2586  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2587  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2588  goto end;
2589  }
2590 
2591  DetectContentData *hcbd1 =
2592  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2593  ->prev->ctx;
2594  DetectContentData *hcbd2 =
2595  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2597  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2599  FAIL_IF(memcmp(hcbd2->content, "two", hcbd1->content_len) != 0);
2600 
2601  result = 1;
2602 
2603  end:
2605  return result;
2606 }
2607 
2608 static int DetectHttpClientBodyTest30(void)
2609 {
2610  DetectEngineCtx *de_ctx = NULL;
2611  int result = 0;
2612 
2613  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2614  goto end;
2615 
2616  de_ctx->flags |= DE_QUIET;
2617  Signature *s =
2618  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2619  "(content:\"one\"; http_client_body; "
2620  "content:\"two\"; within:5; http_client_body; sid:1;)");
2621  if (de_ctx->sig_list == NULL) {
2622  printf("de_ctx->sig_list == NULL\n");
2623  goto end;
2624  }
2625 
2627  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2628  goto end;
2629  }
2630 
2631  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2632  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2633  goto end;
2634  }
2635 
2636  DetectContentData *hcbd1 =
2637  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2638  ->prev->ctx;
2639  DetectContentData *hcbd2 =
2640  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2642  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2643  FAIL_IF(hcbd2->flags != DETECT_CONTENT_WITHIN);
2644  FAIL_IF(memcmp(hcbd2->content, "two", hcbd1->content_len) != 0);
2645 
2646  result = 1;
2647 
2648  end:
2650  return result;
2651 }
2652 
2653 static int DetectHttpClientBodyTest31(void)
2654 {
2655  DetectEngineCtx *de_ctx = NULL;
2656  int result = 0;
2657 
2658  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2659  goto end;
2660 
2661  de_ctx->flags |= DE_QUIET;
2662  Signature *s =
2663  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2664  "(content:\"one\"; within:5; http_client_body; sid:1;)");
2665  FAIL_IF_NULL(s);
2666 
2667  result = 1;
2668 
2669  end:
2671  return result;
2672 }
2673 
2674 static int DetectHttpClientBodyTest32(void)
2675 {
2676  DetectEngineCtx *de_ctx = NULL;
2677  int result = 0;
2678 
2679  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2680  goto end;
2681 
2682  de_ctx->flags |= DE_QUIET;
2683  Signature *s =
2684  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2685  "(content:\"one\"; http_client_body; within:5; sid:1;)");
2686  FAIL_IF_NULL(s);
2687 
2688  result = 1;
2689 
2690  end:
2692  return result;
2693 }
2694 
2695 static int DetectHttpClientBodyTest33(void)
2696 {
2697  DetectEngineCtx *de_ctx = NULL;
2698  int result = 0;
2699 
2700  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2701  goto end;
2702 
2703  de_ctx->flags |= DE_QUIET;
2704  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2705  "(content:\"one\"; within:5; sid:1;)");
2706  FAIL_IF_NULL(s);
2707 
2708  result = 1;
2709 
2710  end:
2712  return result;
2713 }
2714 
2715 static int DetectHttpClientBodyTest34(void)
2716 {
2717  DetectEngineCtx *de_ctx = NULL;
2718  int result = 0;
2719 
2720  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2721  goto end;
2722 
2723  de_ctx->flags |= DE_QUIET;
2724  Signature *s =
2725  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2726  "(pcre:/one/P; "
2727  "content:\"two\"; within:5; http_client_body; sid:1;)");
2728  if (de_ctx->sig_list == NULL) {
2729  printf("de_ctx->sig_list == NULL\n");
2730  goto end;
2731  }
2732 
2734  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2735  goto end;
2736  }
2737 
2738  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2739  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2740  goto end;
2741  }
2742 
2743  if (DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id) == NULL ||
2744  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->type != DETECT_CONTENT ||
2745  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev == NULL ||
2746  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev->type !=
2747  DETECT_PCRE) {
2748 
2749  goto end;
2750  }
2751 
2752  DetectPcreData *pd1 =
2753  (DetectPcreData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2754  ->prev->ctx;
2755  DetectContentData *hcbd2 =
2756  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2759  FAIL_IF(memcmp(hcbd2->content, "two", hcbd2->content_len) != 0);
2760 
2761  result = 1;
2762 
2763  end:
2765  return result;
2766 }
2767 
2768 static int DetectHttpClientBodyTest35(void)
2769 {
2770  DetectEngineCtx *de_ctx = NULL;
2771  int result = 0;
2772 
2773  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2774  goto end;
2775 
2776  de_ctx->flags |= DE_QUIET;
2777  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2778  "(content:\"two\"; http_client_body; "
2779  "pcre:/one/PR; sid:1;)");
2780  if (de_ctx->sig_list == NULL) {
2781  printf("de_ctx->sig_list == NULL\n");
2782  goto end;
2783  }
2784 
2786  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2787  goto end;
2788  }
2789 
2790  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2791  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2792  goto end;
2793  }
2794 
2795  if (DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id) == NULL ||
2796  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->type != DETECT_PCRE ||
2797  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev == NULL ||
2798  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev->type !=
2799  DETECT_CONTENT) {
2800 
2801  goto end;
2802  }
2803 
2804  DetectContentData *hcbd1 =
2805  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2806  ->prev->ctx;
2807  DetectPcreData *pd2 =
2808  (DetectPcreData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2809  FAIL_IF(pd2->flags != (DETECT_PCRE_RELATIVE));
2811  FAIL_IF(memcmp(hcbd1->content, "two", hcbd1->content_len) != 0);
2812 
2813  result = 1;
2814 
2815  end:
2817  return result;
2818 }
2819 
2820 static int DetectHttpClientBodyTest36(void)
2821 {
2822  DetectEngineCtx *de_ctx = NULL;
2823  int result = 0;
2824 
2825  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2826  goto end;
2827 
2828  de_ctx->flags |= DE_QUIET;
2829  Signature *s =
2830  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2831  "(pcre:/one/P; "
2832  "content:\"two\"; distance:5; http_client_body; sid:1;)");
2833  if (de_ctx->sig_list == NULL) {
2834  printf("de_ctx->sig_list == NULL\n");
2835  goto end;
2836  }
2837 
2839  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2840  goto end;
2841  }
2842 
2843  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2844  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2845  goto end;
2846  }
2847 
2848  if (DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id) == NULL ||
2849  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->type != DETECT_CONTENT ||
2850  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev == NULL ||
2851  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev->type !=
2852  DETECT_PCRE) {
2853 
2854  goto end;
2855  }
2856 
2857  DetectPcreData *pd1 =
2858  (DetectPcreData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2859  ->prev->ctx;
2860  DetectContentData *hcbd2 =
2861  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2864  FAIL_IF(memcmp(hcbd2->content, "two", hcbd2->content_len) != 0);
2865 
2866  result = 1;
2867 
2868  end:
2870  return result;
2871 }
2872 
2873 static int DetectHttpClientBodyIsdataatParseTest(void)
2874 {
2877  de_ctx->flags |= DE_QUIET;
2878 
2880  "alert tcp any any -> any any ("
2881  "content:\"one\"; http_client_body; "
2882  "isdataat:!4,relative; sid:1;)");
2883  FAIL_IF_NULL(s);
2884 
2885  SigMatch *sm = DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id);
2886  FAIL_IF_NULL(sm);
2888 
2889  DetectIsdataatData *data = (DetectIsdataatData *)sm->ctx;
2892  FAIL_IF(data->flags & ISDATAAT_RAWBYTES);
2893 
2895  PASS;
2896 }
2897 
2899 {
2900  UtRegisterTest("DetectHttpClientBodyParserTest01", DetectHttpClientBodyParserTest01);
2901  UtRegisterTest("DetectHttpClientBodyParserTest02", DetectHttpClientBodyParserTest02);
2902  UtRegisterTest("DetectHttpClientBodyTest01", DetectHttpClientBodyTest01);
2903  UtRegisterTest("DetectHttpClientBodyTest02", DetectHttpClientBodyTest02);
2904  UtRegisterTest("DetectHttpClientBodyTest03", DetectHttpClientBodyTest03);
2905  UtRegisterTest("DetectHttpClientBodyTest05", DetectHttpClientBodyTest05);
2906  UtRegisterTest("DetectHttpClientBodyTest06", DetectHttpClientBodyTest06);
2907  UtRegisterTest("DetectHttpClientBodyTest07", DetectHttpClientBodyTest07);
2908  UtRegisterTest("DetectHttpClientBodyTest08", DetectHttpClientBodyTest08);
2909  UtRegisterTest("DetectHttpClientBodyTest09", DetectHttpClientBodyTest09);
2910  UtRegisterTest("DetectHttpClientBodyTest10", DetectHttpClientBodyTest10);
2911  UtRegisterTest("DetectHttpClientBodyTest11", DetectHttpClientBodyTest11);
2912  UtRegisterTest("DetectHttpClientBodyTest12", DetectHttpClientBodyTest12);
2913  UtRegisterTest("DetectHttpClientBodyTest13", DetectHttpClientBodyTest13);
2914  UtRegisterTest("DetectHttpClientBodyTest14", DetectHttpClientBodyTest14);
2915  UtRegisterTest("DetectHttpClientBodyTest15", DetectHttpClientBodyTest15);
2916 
2917  UtRegisterTest("DetectHttpClientBodyTest22", DetectHttpClientBodyTest22);
2918  UtRegisterTest("DetectHttpClientBodyTest23", DetectHttpClientBodyTest23);
2919  UtRegisterTest("DetectHttpClientBodyTest24", DetectHttpClientBodyTest24);
2920  UtRegisterTest("DetectHttpClientBodyTest25", DetectHttpClientBodyTest25);
2921  UtRegisterTest("DetectHttpClientBodyTest26", DetectHttpClientBodyTest26);
2922  UtRegisterTest("DetectHttpClientBodyTest27", DetectHttpClientBodyTest27);
2923  UtRegisterTest("DetectHttpClientBodyTest28", DetectHttpClientBodyTest28);
2924  UtRegisterTest("DetectHttpClientBodyTest29", DetectHttpClientBodyTest29);
2925  UtRegisterTest("DetectHttpClientBodyTest30", DetectHttpClientBodyTest30);
2926  UtRegisterTest("DetectHttpClientBodyTest31", DetectHttpClientBodyTest31);
2927  UtRegisterTest("DetectHttpClientBodyTest32", DetectHttpClientBodyTest32);
2928  UtRegisterTest("DetectHttpClientBodyTest33", DetectHttpClientBodyTest33);
2929  UtRegisterTest("DetectHttpClientBodyTest34", DetectHttpClientBodyTest34);
2930  UtRegisterTest("DetectHttpClientBodyTest35", DetectHttpClientBodyTest35);
2931  UtRegisterTest("DetectHttpClientBodyTest36", DetectHttpClientBodyTest36);
2932 
2933  UtRegisterTest("DetectHttpClientBodyIsdataatParseTest",
2934  DetectHttpClientBodyIsdataatParseTest);
2935 
2936  UtRegisterTest("DetectEngineHttpClientBodyTest01",
2937  DetectEngineHttpClientBodyTest01);
2938  UtRegisterTest("DetectEngineHttpClientBodyTest02",
2939  DetectEngineHttpClientBodyTest02);
2940  UtRegisterTest("DetectEngineHttpClientBodyTest03",
2941  DetectEngineHttpClientBodyTest03);
2942  UtRegisterTest("DetectEngineHttpClientBodyTest04",
2943  DetectEngineHttpClientBodyTest04);
2944  UtRegisterTest("DetectEngineHttpClientBodyTest05",
2945  DetectEngineHttpClientBodyTest05);
2946  UtRegisterTest("DetectEngineHttpClientBodyTest06",
2947  DetectEngineHttpClientBodyTest06);
2948  UtRegisterTest("DetectEngineHttpClientBodyTest07",
2949  DetectEngineHttpClientBodyTest07);
2950  UtRegisterTest("DetectEngineHttpClientBodyTest08",
2951  DetectEngineHttpClientBodyTest08);
2952  UtRegisterTest("DetectEngineHttpClientBodyTest09",
2953  DetectEngineHttpClientBodyTest09);
2954  UtRegisterTest("DetectEngineHttpClientBodyTest10",
2955  DetectEngineHttpClientBodyTest10);
2956  UtRegisterTest("DetectEngineHttpClientBodyTest11",
2957  DetectEngineHttpClientBodyTest11);
2958  UtRegisterTest("DetectEngineHttpClientBodyTest12",
2959  DetectEngineHttpClientBodyTest12);
2960  UtRegisterTest("DetectEngineHttpClientBodyTest13",
2961  DetectEngineHttpClientBodyTest13);
2962  UtRegisterTest("DetectEngineHttpClientBodyTest14",
2963  DetectEngineHttpClientBodyTest14);
2964  UtRegisterTest("DetectEngineHttpClientBodyTest15",
2965  DetectEngineHttpClientBodyTest15);
2966  UtRegisterTest("DetectEngineHttpClientBodyTest16",
2967  DetectEngineHttpClientBodyTest16);
2968  UtRegisterTest("DetectEngineHttpClientBodyTest17",
2969  DetectEngineHttpClientBodyTest17);
2970  UtRegisterTest("DetectEngineHttpClientBodyTest18",
2971  DetectEngineHttpClientBodyTest18);
2972  UtRegisterTest("DetectEngineHttpClientBodyTest19",
2973  DetectEngineHttpClientBodyTest19);
2974  UtRegisterTest("DetectEngineHttpClientBodyTest20",
2975  DetectEngineHttpClientBodyTest20);
2976  UtRegisterTest("DetectEngineHttpClientBodyTest21",
2977  DetectEngineHttpClientBodyTest21);
2978  UtRegisterTest("DetectEngineHttpClientBodyTest22",
2979  DetectEngineHttpClientBodyTest22);
2980  UtRegisterTest("DetectEngineHttpClientBodyTest23",
2981  DetectEngineHttpClientBodyTest23);
2982  UtRegisterTest("DetectEngineHttpClientBodyTest24",
2983  DetectEngineHttpClientBodyTest24);
2984  UtRegisterTest("DetectEngineHttpClientBodyTest25",
2985  DetectEngineHttpClientBodyTest25);
2986  UtRegisterTest("DetectEngineHttpClientBodyTest26",
2987  DetectEngineHttpClientBodyTest26);
2988  UtRegisterTest("DetectEngineHttpClientBodyTest27",
2989  DetectEngineHttpClientBodyTest27);
2990  UtRegisterTest("DetectEngineHttpClientBodyTest28",
2991  DetectEngineHttpClientBodyTest28);
2992  UtRegisterTest("DetectEngineHttpClientBodyTest29",
2993  DetectEngineHttpClientBodyTest29);
2994 
2995  UtRegisterTest("DetectEngineHttpClientBodyTest30",
2996  DetectEngineHttpClientBodyTest30);
2997  UtRegisterTest("DetectEngineHttpClientBodyTest31",
2998  DetectEngineHttpClientBodyTest31);
2999 }
3000 
3001 #endif
3002 
3003 /**
3004  * @}
3005  */
TestSteps
Definition: detect-http-client-body.c:107
SCConfYamlLoadString
int SCConfYamlLoadString(const char *string, size_t len)
Load configuration from a YAML string.
Definition: conf-yaml-loader.c:535
DETECT_CONTENT_RELATIVE_NEXT
#define DETECT_CONTENT_RELATIVE_NEXT
Definition: detect-content.h:66
SigMatch_::prev
struct SigMatch_ * prev
Definition: detect.h:361
UTHParseSignature
int UTHParseSignature(const char *str, bool expect)
parser a sig and see if the expected result is correct
Definition: util-unittest-helper.c:917
detect-engine.h
DETECT_SM_LIST_PMATCH
@ DETECT_SM_LIST_PMATCH
Definition: detect.h:119
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
SignatureInitData_::smlists
struct SigMatch_ * smlists[DETECT_SM_LIST_MAX]
Definition: detect.h:642
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1268
flow-util.h
DetectBufferGetFirstSigMatch
SigMatch * DetectBufferGetFirstSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine-buffer.c:157
SignatureInitData_::smlists_tail
struct SigMatch_ * smlists_tail[DETECT_SM_LIST_MAX]
Definition: detect.h:644
stream-tcp.h
DetectHttpClientBodyRegisterTests
void DetectHttpClientBodyRegisterTests(void)
Definition: detect-http-client-body.c:2898
HtpBody_::sb
StreamingBuffer * sb
Definition: app-layer-htp.h:134
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
UtRegisterTest
void UtRegisterTest(const char *name, int(*TestFn)(void))
Register unit test.
Definition: util-unittest.c:103
DetectIsdataatData_::flags
uint8_t flags
Definition: detect-isdataat.h:34
DETECT_CONTENT
@ DETECT_CONTENT
Definition: detect-engine-register.h:69
TestSteps::direction
int direction
Definition: detect-http-client-body.c:110
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:279
detect-isdataat.h
TestSteps::input
const uint8_t * input
Definition: detect-http-client-body.c:108
Flow_::proto
uint8_t proto
Definition: flow.h:370
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:287
PacketAlertCheck
int PacketAlertCheck(Packet *p, uint32_t sid)
Check if a certain sid alerted, this is used in the test functions.
Definition: detect-engine-alert.c:142
Packet_::flags
uint32_t flags
Definition: decode.h:544
Flow_
Flow data structure.
Definition: flow.h:348
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:933
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2634
HtpTxUserData_::request_body
HtpBody request_body
Definition: app-layer-htp.h:164
AppLayerParserThreadCtxFree
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
Definition: app-layer-parser.c:324
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:225
DE_QUIET
#define DE_QUIET
Definition: detect.h:330
stream-tcp-reassemble.h
UTHBuildPacket
Packet * UTHBuildPacket(uint8_t *payload, uint16_t payload_len, uint8_t ipproto)
UTHBuildPacket is a wrapper that build packets with default ip and port fields.
Definition: util-unittest-helper.c:365
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:2418
DetectIsdataatData_
Definition: detect-isdataat.h:32
DetectContentData_
Definition: detect-content.h:93
DetectPcreData_::flags
uint16_t flags
Definition: detect-pcre.h:51
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3447
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:532
StreamingBufferSegmentCompareRawData
int StreamingBufferSegmentCompareRawData(const StreamingBuffer *sb, const StreamingBufferSegment *seg, const uint8_t *rawdata, uint32_t rawdata_len)
Definition: util-streaming-buffer.c:1797
Flow_::protoctx
void * protoctx
Definition: flow.h:433
FLOW_IPV4
#define FLOW_IPV4
Definition: flow.h:100
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:620
detect-engine-prefilter.h
util-unittest.h
HTPConfigure
void HTPConfigure(void)
Definition: app-layer-htp.c:2351
HtpBody_::first
HtpBodyChunk * first
Definition: app-layer-htp.h:131
HtpState_
Definition: app-layer-htp.h:181
util-unittest-helper.h
FAIL_IF_NOT
#define FAIL_IF_NOT(expr)
Fail a test if expression evaluates to false.
Definition: util-unittest.h:82
SCConfInit
void SCConfInit(void)
Initialize the configuration system.
Definition: conf.c:120
StreamTcpInitConfig
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
Definition: stream-tcp.c:496
FLOW_INITIALIZE
#define FLOW_INITIALIZE(f)
Definition: flow-util.h:38
app-layer-htp.h
TestSteps::expect
int expect
Definition: detect-http-client-body.c:111
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
util-debug.h
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
TOTAL_REQUESTS
#define TOTAL_REQUESTS
DETECT_CONTENT_DISTANCE
#define DETECT_CONTENT_DISTANCE
Definition: detect-content.h:30
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:18
HtpConfigCreateBackup
void HtpConfigCreateBackup(void)
Definition: app-layer-htp.c:2687
DetectBufferGetLastSigMatch
SigMatch * DetectBufferGetLastSigMatch(const Signature *s, const uint32_t buf_id)
Definition: detect-engine-buffer.c:167
DetectEngineThreadCtx_
Definition: detect.h:1245
alp_tctx
AppLayerParserThreadCtx * alp_tctx
Definition: fuzz_applayerparserparse.c:23
DETECT_CONTENT_DEPTH
#define DETECT_CONTENT_DEPTH
Definition: detect-content.h:33
util-print.h
detect-engine-mpm.h
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3364
DETECT_CONTENT_IS_SINGLE
#define DETECT_CONTENT_IS_SINGLE(c)
Definition: detect-content.h:68
DETECT_SM_LIST_MATCH
@ DETECT_SM_LIST_MATCH
Definition: detect.h:117
app-layer-parser.h
SigMatch_::ctx
SigMatchCtx * ctx
Definition: detect.h:359
Packet_
Definition: decode.h:501
detect-engine-build.h
type
uint16_t type
Definition: decode-vlan.c:106
conf-yaml-loader.h
ISDATAAT_RELATIVE
#define ISDATAAT_RELATIVE
Definition: detect-isdataat.h:27
conf.h
DetectContentData_::flags
uint32_t flags
Definition: detect-content.h:104
Signature_::init_data
SignatureInitData * init_data
Definition: detect.h:747
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
ISDATAAT_RAWBYTES
#define ISDATAAT_RAWBYTES
Definition: detect-isdataat.h:28
SCConfCreateContextBackup
void SCConfCreateContextBackup(void)
Creates a backup of the conf_hash hash_table used by the conf API.
Definition: conf.c:684
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:226
DETECT_PCRE
@ DETECT_PCRE
Definition: detect-engine-register.h:71
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1095
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2194
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1258
AppLayerParserThreadCtxAlloc
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
Definition: app-layer-parser.c:297
detect-engine-content-inspection.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:546
FAIL_IF
#define FAIL_IF(expr)
Fail a test if expression evaluates to true.
Definition: util-unittest.h:71
StreamTcpFreeConfig
void StreamTcpFreeConfig(bool quiet)
Definition: stream-tcp.c:867
AppLayerParserParse
int AppLayerParserParse(ThreadVars *tv, AppLayerParserThreadCtx *alp_tctx, Flow *f, AppProto alproto, uint8_t flags, const uint8_t *input, uint32_t input_len)
Definition: app-layer-parser.c:1277
SigMatch_::type
uint16_t type
Definition: detect.h:357
HtpBodyChunk_
Definition: app-layer-htp.h:122
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3601
DetectContentData_::content
uint8_t * content
Definition: detect-content.h:94
SCConfDeInit
void SCConfDeInit(void)
De-initializes the configuration system.
Definition: conf.c:703
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:942
HtpTxUserData_
Definition: app-layer-htp.h:151
util-validate.h
HtpConfigRestoreBackup
void HtpConfigRestoreBackup(void)
Definition: app-layer-htp.c:2692
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
ISDATAAT_NEGATED
#define ISDATAAT_NEGATED
Definition: detect-isdataat.h:29
SCFree
#define SCFree(p)
Definition: util-mem.h:61
UTHFreePacket
void UTHFreePacket(Packet *p)
UTHFreePacket: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:473
Flow_::alstate
void * alstate
Definition: flow.h:471
DETECT_CONTENT_OFFSET
#define DETECT_CONTENT_OFFSET
Definition: detect-content.h:32
DETECT_CONTENT_MPM
#define DETECT_CONTENT_MPM
Definition: detect-content.h:61
Flow_::flags
uint32_t flags
Definition: flow.h:413
SCConfRestoreContextBackup
void SCConfRestoreContextBackup(void)
Restores the backup of the hash_table present in backup_conf_hash back to conf_hash.
Definition: conf.c:694
detect-parse.h
Signature_
Signature container.
Definition: detect.h:668
SigMatch_
a single match condition for a signature
Definition: detect.h:356
DETECT_ISDATAAT
@ DETECT_ISDATAAT
Definition: detect-engine-register.h:93
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:227
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2595
DETECT_PCRE_RELATIVE_NEXT
#define DETECT_PCRE_RELATIVE_NEXT
Definition: detect-pcre.h:34
app-layer-protos.h
DetectPcreData_
Definition: detect-pcre.h:47
DetectContentData_::content_len
uint16_t content_len
Definition: detect-content.h:95
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:935
AppLayerParserThreadCtx_
Definition: app-layer-parser.c:60
DETECT_PCRE_RELATIVE
#define DETECT_PCRE_RELATIVE
Definition: detect-pcre.h:29
TcpSession_
Definition: stream-tcp-private.h:283
HTPFreeConfig
void HTPFreeConfig(void)
Clears the HTTP server configuration memory used by HTP library.
Definition: app-layer-htp.c:1591
flow.h
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:442
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:121
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1354
AppLayerParserGetTxCnt
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
Definition: app-layer-parser.c:1088
HtpBodyChunk_::sbseg
StreamingBufferSegment sbseg
Definition: app-layer-htp.h:125
TestSteps::input_size
size_t input_size
Definition: detect-http-client-body.c:109
FLOW_DESTROY
#define FLOW_DESTROY(f)
Definition: flow-util.h:119
DETECT_CONTENT_WITHIN
#define DETECT_CONTENT_WITHIN
Definition: detect-content.h:31
PKT_STREAM_EST
#define PKT_STREAM_EST
Definition: decode.h:1264
app-layer.h
UTHFreePackets
void UTHFreePackets(Packet **p, int numpkts)
UTHFreePackets: function to release the allocated data from UTHBuildPacket and the packet itself.
Definition: util-unittest-helper.c:456