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  memset(&f, 0, sizeof(f));
125  memset(&ssn, 0, sizeof(ssn));
126 
127  if (yaml) {
129  SCConfInit();
131 
132  SCConfYamlLoadString(yaml, strlen(yaml));
133  HTPConfigure();
134  }
135 
136  StreamTcpInitConfig(true);
137 
140  de_ctx->flags |= DE_QUIET;
141 
142  FLOW_INITIALIZE(&f);
143  f.protoctx = (void *)&ssn;
144  f.proto = IPPROTO_TCP;
145  f.flags |= FLOW_IPV4;
147 
148  SCLogDebug("sig %s", sig);
149  Signature *s = DetectEngineAppendSig(de_ctx, (char *)sig);
150  FAIL_IF_NULL(s);
151 
153  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
154  FAIL_IF_NULL(det_ctx);
155 
156  struct TestSteps *b = steps;
157  int i = 0;
158  while (b->input != NULL) {
159  SCLogDebug("chunk %p %d", b, i);
160  (void)i;
161  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
162  FAIL_IF_NULL(p);
163  p->flow = &f;
164  p->flowflags = (b->direction == STREAM_TOSERVER) ? FLOW_PKT_TOSERVER : FLOW_PKT_TOCLIENT;
167 
168  int r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, b->direction,
169  (uint8_t *)b->input,
170  b->input_size ? b->input_size : strlen((const char *)b->input));
171  FAIL_IF_NOT(r == 0);
172 
173  /* do detect */
174  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
175 
176  int match = PacketAlertCheck(p, 1);
177  FAIL_IF_NOT (b->expect == match);
178 
179  UTHFreePackets(&p, 1);
180  b++;
181  i++;
182  }
183 
184  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
187 
188  StreamTcpFreeConfig(true);
189  FLOW_DESTROY(&f);
190 
191  if (yaml) {
192  HTPFreeConfig();
193  SCConfDeInit();
196  }
197  StatsThreadCleanup(&th_v);
198  PASS;
199 }
200 
201 static int DetectEngineHttpClientBodyTest01(void)
202 {
203  struct TestSteps steps[] = {
204  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
205  "Host: www.openinfosecfoundation.org\r\n"
206  "Content-Type: text/html\r\n"
207  "Content-Length: 46\r\n"
208  "\r\n"
209  "This is dummy body1",
210  0, STREAM_TOSERVER, 0 },
211  { (const uint8_t *)"This is dummy message body2",
212  0, STREAM_TOSERVER, 1 },
213  { NULL, 0, 0, 0 },
214  };
215 
216  const char *sig = "alert http any any -> any any (content:\"body1This\"; http_client_body; sid:1;)";
217  return RunTest(steps, sig, NULL);
218 }
219 
220 static int DetectEngineHttpClientBodyTest02(void)
221 {
222  struct TestSteps steps[] = {
223  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
224  "Host: www.openinfosecfoundation.org\r\n"
225  "Content-Type: text/html\r\n"
226  "Content-Length: 19\r\n"
227  "\r\n"
228  "This is dummy body1",
229  0, STREAM_TOSERVER, 1 },
230  { NULL, 0, 0, 0 },
231  };
232 
233  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; offset:5; sid:1;)";
234  return RunTest(steps, sig, NULL);
235 }
236 
237 static int DetectEngineHttpClientBodyTest03(void)
238 {
239  struct TestSteps steps[] = {
240  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
241  "Host: www.openinfosecfoundation.org\r\n"
242  "Content-Type: text/html\r\n"
243  "Content-Length: 46\r\n"
244  "\r\n"
245  "This is dummy body1",
246  0, STREAM_TOSERVER, 0 },
247  { (const uint8_t *)"This is dummy message body2",
248  0, STREAM_TOSERVER, 0 },
249  { NULL, 0, 0, 0 },
250  };
251 
252  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; offset:16; sid:1;)";
253  return RunTest(steps, sig, NULL);
254 }
255 
256 static int DetectEngineHttpClientBodyTest04(void)
257 {
258  struct TestSteps steps[] = {
259  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
260  "Host: www.openinfosecfoundation.org\r\n"
261  "Content-Type: text/html\r\n"
262  "Content-Length: 46\r\n"
263  "\r\n"
264  "This is dummy body1",
265  0, STREAM_TOSERVER, 0 },
266  { (const uint8_t *)"This is dummy message body2",
267  0, STREAM_TOSERVER, 1 },
268  { NULL, 0, 0, 0 },
269  };
270 
271  const char *sig = "alert http any any -> any any (content:!\"body1\"; http_client_body; offset:16; sid:1;)";
272  return RunTest(steps, sig, NULL);
273 }
274 
275 static int DetectEngineHttpClientBodyTest05(void)
276 {
277  struct TestSteps steps[] = {
278  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
279  "Host: www.openinfosecfoundation.org\r\n"
280  "Content-Type: text/html\r\n"
281  "Content-Length: 46\r\n"
282  "\r\n"
283  "This is dummy body1",
284  0, STREAM_TOSERVER, 0 },
285  { (const uint8_t *)"This is dummy message body2",
286  0, STREAM_TOSERVER, 1 },
287  { NULL, 0, 0, 0 },
288  };
289 
290  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; depth:25; sid:1;)";
291  return RunTest(steps, sig, NULL);
292 }
293 
294 static int DetectEngineHttpClientBodyTest06(void)
295 {
296  struct TestSteps steps[] = {
297  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
298  "Host: www.openinfosecfoundation.org\r\n"
299  "Content-Type: text/html\r\n"
300  "Content-Length: 46\r\n"
301  "\r\n"
302  "This is dummy body1",
303  0, STREAM_TOSERVER, 0 },
304  { (const uint8_t *)"This is dummy message body2",
305  0, STREAM_TOSERVER, 0 },
306  { NULL, 0, 0, 0 },
307  };
308 
309  const char *sig = "alert http any any -> any any (content:!\"body1\"; http_client_body; depth:25; sid:1;)";
310  return RunTest(steps, sig, NULL);
311 }
312 
313 static int DetectEngineHttpClientBodyTest07(void)
314 {
315  struct TestSteps steps[] = {
316  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
317  "Host: www.openinfosecfoundation.org\r\n"
318  "Content-Type: text/html\r\n"
319  "Content-Length: 46\r\n"
320  "\r\n"
321  "This is dummy body1",
322  0, STREAM_TOSERVER, 0 },
323  { (const uint8_t *)"This is dummy message body2",
324  0, STREAM_TOSERVER, 1 },
325  { NULL, 0, 0, 0 },
326  };
327 
328  const char *sig = "alert http any any -> any any (content:!\"body1\"; http_client_body; depth:15; sid:1;)";
329  return RunTest(steps, sig, NULL);
330 }
331 
332 static int DetectEngineHttpClientBodyTest08(void)
333 {
334  struct TestSteps steps[] = {
335  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
336  "Host: www.openinfosecfoundation.org\r\n"
337  "Content-Type: text/html\r\n"
338  "Content-Length: 46\r\n"
339  "\r\n"
340  "This is dummy body1",
341  0, STREAM_TOSERVER, 0 },
342  { (const uint8_t *)"This is dummy message body2",
343  0, STREAM_TOSERVER, 1 },
344  { NULL, 0, 0, 0 },
345  };
346 
347  const char *sig = "alert http any any -> any any (content:\"This is dummy body1This is dummy message body2\"; http_client_body; sid:1;)";
348  return RunTest(steps, sig, NULL);
349 }
350 
351 static int DetectEngineHttpClientBodyTest09(void)
352 {
353  struct TestSteps steps[] = {
354  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
355  "Host: www.openinfosecfoundation.org\r\n"
356  "Content-Type: text/html\r\n"
357  "Content-Length: 46\r\n"
358  "\r\n"
359  "This is dummy body1",
360  0, STREAM_TOSERVER, 0 },
361  { (const uint8_t *)"This is dummy message body2",
362  0, STREAM_TOSERVER, 1 },
363  { NULL, 0, 0, 0 },
364  };
365 
366  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"This\"; http_client_body; within:5; sid:1;)";
367  return RunTest(steps, sig, NULL);
368 }
369 
370 static int DetectEngineHttpClientBodyTest10(void)
371 {
372  struct TestSteps steps[] = {
373  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
374  "Host: www.openinfosecfoundation.org\r\n"
375  "Content-Type: text/html\r\n"
376  "Content-Length: 46\r\n"
377  "\r\n"
378  "This is dummy body1",
379  0, STREAM_TOSERVER, 0 },
380  { (const uint8_t *)"This is dummy message body2",
381  0, STREAM_TOSERVER, 1 },
382  { NULL, 0, 0, 0 },
383  };
384 
385  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"boom\"; http_client_body; within:5; sid:1;)";
386  return RunTest(steps, sig, NULL);
387 }
388 
389 static int DetectEngineHttpClientBodyTest11(void)
390 {
391  struct TestSteps steps[] = {
392  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
393  "Host: www.openinfosecfoundation.org\r\n"
394  "Content-Type: text/html\r\n"
395  "Content-Length: 46\r\n"
396  "\r\n"
397  "This is dummy body1",
398  0, STREAM_TOSERVER, 0 },
399  { (const uint8_t *)"This is dummy message body2",
400  0, STREAM_TOSERVER, 0 },
401  { NULL, 0, 0, 0 },
402  };
403 
404  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"boom\"; http_client_body; within:5; sid:1;)";
405  return RunTest(steps, sig, NULL);
406 }
407 
408 static int DetectEngineHttpClientBodyTest12(void)
409 {
410  struct TestSteps steps[] = {
411  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
412  "Host: www.openinfosecfoundation.org\r\n"
413  "Content-Type: text/html\r\n"
414  "Content-Length: 46\r\n"
415  "\r\n"
416  "This is dummy body1",
417  0, STREAM_TOSERVER, 0 },
418  { (const uint8_t *)"This is dummy message body2",
419  0, STREAM_TOSERVER, 0 },
420  { NULL, 0, 0, 0 },
421  };
422 
423  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"This\"; http_client_body; within:5; sid:1;)";
424  return RunTest(steps, sig, NULL);
425 }
426 
427 static int DetectEngineHttpClientBodyTest13(void)
428 {
429  struct TestSteps steps[] = {
430  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
431  "Host: www.openinfosecfoundation.org\r\n"
432  "Content-Type: text/html\r\n"
433  "Content-Length: 46\r\n"
434  "\r\n"
435  "This is dummy body1",
436  0, STREAM_TOSERVER, 0 },
437  { (const uint8_t *)"This is dummy message body2",
438  0, STREAM_TOSERVER, 1 },
439  { NULL, 0, 0, 0 },
440  };
441 
442  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"dummy\"; http_client_body; distance:5; sid:1;)";
443  return RunTest(steps, sig, NULL);
444 }
445 
446 static int DetectEngineHttpClientBodyTest14(void)
447 {
448  struct TestSteps steps[] = {
449  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
450  "Host: www.openinfosecfoundation.org\r\n"
451  "Content-Type: text/html\r\n"
452  "Content-Length: 46\r\n"
453  "\r\n"
454  "This is dummy body1",
455  0, STREAM_TOSERVER, 0 },
456  { (const uint8_t *)"This is dummy message body2",
457  0, STREAM_TOSERVER, 1 },
458  { NULL, 0, 0, 0 },
459  };
460 
461  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"dummy\"; http_client_body; distance:10; sid:1;)";
462  return RunTest(steps, sig, NULL);
463 }
464 
465 static int DetectEngineHttpClientBodyTest15(void)
466 {
467  struct TestSteps steps[] = {
468  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
469  "Host: www.openinfosecfoundation.org\r\n"
470  "Content-Type: text/html\r\n"
471  "Content-Length: 46\r\n"
472  "\r\n"
473  "This is dummy body1",
474  0, STREAM_TOSERVER, 0 },
475  { (const uint8_t *)"This is dummy message body2",
476  0, STREAM_TOSERVER, 0 },
477  { NULL, 0, 0, 0 },
478  };
479 
480  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"dummy\"; http_client_body; distance:10; sid:1;)";
481  return RunTest(steps, sig, NULL);
482 }
483 
484 static int DetectEngineHttpClientBodyTest16(void)
485 {
486  struct TestSteps steps[] = {
487  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
488  "Host: www.openinfosecfoundation.org\r\n"
489  "Content-Type: text/html\r\n"
490  "Content-Length: 46\r\n"
491  "\r\n"
492  "This is dummy body1",
493  0, STREAM_TOSERVER, 0 },
494  { (const uint8_t *)"This is dummy message body2",
495  0, STREAM_TOSERVER, 0 },
496  { NULL, 0, 0, 0 },
497  };
498 
499  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:!\"dummy\"; http_client_body; distance:5; sid:1;)";
500  return RunTest(steps, sig, NULL);
501 }
502 
503 static int DetectEngineHttpClientBodyTest17(void)
504 {
505  struct TestSteps steps[] = {
506  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
507  "Host: www.openinfosecfoundation.org\r\n"
508  "Content-Type: text/html\r\n"
509  "Content-Length: 19\r\n"
510  "\r\n"
511  "This is dummy body1",
512  0, STREAM_TOSERVER, 0 },
513  { NULL, 0, 0, 0 },
514  };
515 
516  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"bambu\"; http_client_body; sid:1;)";
517  return RunTest(steps, sig, NULL);
518 }
519 
520 static int DetectEngineHttpClientBodyTest18(void)
521 {
522  struct TestSteps steps[] = {
523  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
524  "Host: www.openinfosecfoundation.org\r\n"
525  "Content-Type: text/html\r\n"
526  "Content-Length: 19\r\n"
527  "\r\n"
528  "This is dummy body1",
529  0, STREAM_TOSERVER, 0 },
530  { NULL, 0, 0, 0 },
531  };
532 
533  const char *sig = "alert http any any -> any any (content:\"body1\"; http_client_body; content:\"bambu\"; http_client_body; fast_pattern; sid:1;)";
534  return RunTest(steps, sig, NULL);
535 }
536 
537 static int DetectEngineHttpClientBodyTest19(void)
538 {
539  struct TestSteps steps[] = {
540  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
541  "Host: www.openinfosecfoundation.org\r\n"
542  "Content-Type: text/html\r\n"
543  "Content-Length: 19\r\n"
544  "\r\n"
545  "This is dummy body1",
546  0, STREAM_TOSERVER, 0 },
547  { NULL, 0, 0, 0 },
548  };
549 
550  const char *sig = "alert http any any -> any any (content:\"bambu\"; http_client_body; content:\"is\"; http_client_body; sid:1;)";
551  return RunTest(steps, sig, NULL);
552 }
553 
554 static int DetectEngineHttpClientBodyTest20(void)
555 {
556  struct TestSteps steps[] = {
557  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
558  "Host: www.openinfosecfoundation.org\r\n"
559  "Content-Type: text/html\r\n"
560  "Content-Length: 19\r\n"
561  "\r\n"
562  "This is dummy body1",
563  0, STREAM_TOSERVER, 1 },
564  { NULL, 0, 0, 0 },
565  };
566 
567  const char *sig = "alert http any any -> any any (content:\"is\"; http_client_body; fast_pattern; sid:1;)";
568  return RunTest(steps, sig, NULL);
569 }
570 
571 static int DetectEngineHttpClientBodyTest21(void)
572 {
573  struct TestSteps steps[] = {
574  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
575  "Host: www.openinfosecfoundation.org\r\n"
576  "Content-Type: text/html\r\n"
577  "Content-Length: 46\r\n"
578  "\r\n"
579  "This is dummy body1",
580  0, STREAM_TOSERVER, 0 },
581  { (const uint8_t *)"This is dummy message body2",
582  0, STREAM_TOSERVER, 1 },
583  { NULL, 0, 0, 0 },
584  };
585 
586  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; http_client_body; within:7; sid:1;)";
587  return RunTest(steps, sig, NULL);
588 }
589 
590 static int DetectEngineHttpClientBodyTest22(void)
591 {
592  struct TestSteps steps[] = {
593  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
594  "Host: www.openinfosecfoundation.org\r\n"
595  "Content-Type: text/html\r\n"
596  "Content-Length: 46\r\n"
597  "\r\n"
598  "This is dummy body1",
599  0, STREAM_TOSERVER, 0 },
600  { (const uint8_t *)"This is dummy message body2",
601  0, STREAM_TOSERVER, 1 },
602  { NULL, 0, 0, 0 },
603  };
604 
605  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; within:7; http_client_body; sid:1;)";
606  return RunTest(steps, sig, NULL);
607 }
608 
609 static int DetectEngineHttpClientBodyTest23(void)
610 {
611  struct TestSteps steps[] = {
612  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
613  "Host: www.openinfosecfoundation.org\r\n"
614  "Content-Type: text/html\r\n"
615  "Content-Length: 46\r\n"
616  "\r\n"
617  "This is dummy body1",
618  0, STREAM_TOSERVER, 0 },
619  { (const uint8_t *)"This is dummy message body2",
620  0, STREAM_TOSERVER, 0 },
621  { NULL, 0, 0, 0 },
622  };
623 
624  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; distance:3; http_client_body; sid:1;)";
625  return RunTest(steps, sig, NULL);
626 }
627 
628 static int DetectEngineHttpClientBodyTest24(void)
629 {
630  struct TestSteps steps[] = {
631  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
632  "Host: www.openinfosecfoundation.org\r\n"
633  "Content-Type: text/html\r\n"
634  "Content-Length: 46\r\n"
635  "\r\n"
636  "This is dummy body1",
637  0, STREAM_TOSERVER, 0 },
638  { (const uint8_t *)"This is dummy message body2",
639  0, STREAM_TOSERVER, 1 },
640  { NULL, 0, 0, 0 },
641  };
642 
643  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:!\"dummy\"; distance:13; http_client_body; sid:1;)";
644  return RunTest(steps, sig, NULL);
645 }
646 
647 static int DetectEngineHttpClientBodyTest25(void)
648 {
649  struct TestSteps steps[] = {
650  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
651  "Host: www.openinfosecfoundation.org\r\n"
652  "Content-Type: text/html\r\n"
653  "Content-Length: 46\r\n"
654  "\r\n"
655  "This is dummy body1",
656  0, STREAM_TOSERVER, 0 },
657  { (const uint8_t *)"This is dummy message body2",
658  0, STREAM_TOSERVER, 1 },
659  { NULL, 0, 0, 0 },
660  };
661 
662  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; within:15; http_client_body; sid:1;)";
663  return RunTest(steps, sig, NULL);
664 }
665 
666 static int DetectEngineHttpClientBodyTest26(void)
667 {
668  struct TestSteps steps[] = {
669  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
670  "Host: www.openinfosecfoundation.org\r\n"
671  "Content-Type: text/html\r\n"
672  "Content-Length: 46\r\n"
673  "\r\n"
674  "This is dummy body1",
675  0, STREAM_TOSERVER, 0 },
676  { (const uint8_t *)"This is dummy message body2",
677  0, STREAM_TOSERVER, 0 },
678  { NULL, 0, 0, 0 },
679  };
680 
681  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; within:10; http_client_body; sid:1;)";
682  return RunTest(steps, sig, NULL);
683 }
684 
685 static int DetectEngineHttpClientBodyTest27(void)
686 {
687  struct TestSteps steps[] = {
688  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
689  "Host: www.openinfosecfoundation.org\r\n"
690  "Content-Type: text/html\r\n"
691  "Content-Length: 46\r\n"
692  "\r\n"
693  "This is dummy body1",
694  0, STREAM_TOSERVER, 0 },
695  { (const uint8_t *)"This is dummy message body2",
696  0, STREAM_TOSERVER, 1 },
697  { NULL, 0, 0, 0 },
698  };
699 
700  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; distance:8; http_client_body; sid:1;)";
701  return RunTest(steps, sig, NULL);
702 }
703 
704 static int DetectEngineHttpClientBodyTest28(void)
705 {
706  struct TestSteps steps[] = {
707  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
708  "Host: www.openinfosecfoundation.org\r\n"
709  "Content-Type: text/html\r\n"
710  "Content-Length: 46\r\n"
711  "\r\n"
712  "This is dummy body1",
713  0, STREAM_TOSERVER, 0 },
714  { (const uint8_t *)"This is dummy message body2",
715  0, STREAM_TOSERVER, 0 },
716  { NULL, 0, 0, 0 },
717  };
718 
719  const char *sig = "alert http any any -> any any (pcre:/body1/P; content:\"dummy\"; distance:14; http_client_body; sid:1;)";
720  return RunTest(steps, sig, NULL);
721 }
722 
723 static int DetectEngineHttpClientBodyTest29(void)
724 {
725  const char *request_buffer = "GET /one HTTP/1.0\r\n"
726  "Host: localhost\r\n\r\n";
727 #define TOTAL_REQUESTS 45
728  uint8_t *http_buf = SCMalloc(TOTAL_REQUESTS * strlen(request_buffer));
729  if (unlikely(http_buf == NULL))
730  return 0;
731  for (int i = 0; i < TOTAL_REQUESTS; i++) {
732  memcpy(http_buf + i * strlen(request_buffer), request_buffer,
733  strlen(request_buffer));
734  }
735  uint32_t http_buf_len = TOTAL_REQUESTS * strlen(request_buffer);
736 #undef TOTAL_REQUESTS
737 
738  struct TestSteps steps[] = {
739  { (const uint8_t *)http_buf,
740  (size_t)http_buf_len, STREAM_TOSERVER, 0 },
741 
742  { (const uint8_t *)"HTTP/1.0 200 ok\r\n"
743  "Content-Type: text/html\r\n"
744  "Content-Length: 5\r\n"
745  "\r\n"
746  "dummy",
747  0, STREAM_TOCLIENT, 0 },
748 
749  { NULL, 0, 0, 0 },
750  };
751 
752  const char *sig = "alert http any any -> any any (content:\"dummyone\"; fast_pattern:0,3; http_server_body; sid:1;)";
753  int result = RunTest(steps, sig, NULL);
754  SCFree(http_buf);
755  return result;
756 }
757 
758 static int DetectEngineHttpClientBodyTest30(void)
759 {
760  const char yaml[] = "\
761 %YAML 1.1\n\
762 ---\n\
763 libhtp:\n\
764 \n\
765  default-config:\n\
766  personality: IDS\n\
767  request-body-limit: 0\n\
768  response-body-limit: 0\n\
769 \n\
770  request-body-inspect-window: 0\n\
771  response-body-inspect-window: 0\n\
772  request-body-minimal-inspect-size: 0\n\
773  response-body-minimal-inspect-size: 0\n\
774 ";
775  struct TestSteps steps[] = {
776  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
777  "Host: www.openinfosecfoundation.org\r\n"
778  "Content-Type: text/html\r\n"
779  "Content-Length: 46\r\n"
780  "\r\n"
781  "This is dummy body1",
782  0, STREAM_TOSERVER, 0 },
783  { (const uint8_t *)"This is dummy message body2",
784  0, STREAM_TOSERVER, 0 },
785  { NULL, 0, 0, 0 },
786  };
787 
788  const char *sig = "alert http any any -> any any (content:\"bags\"; within:4; http_client_body; sid:1;)";
789  return RunTest(steps, sig, yaml);
790 }
791 
792 static int DetectEngineHttpClientBodyTest31(void)
793 {
794  const char yaml[] = "\
795 %YAML 1.1\n\
796 ---\n\
797 libhtp:\n\
798 \n\
799  default-config:\n\
800  personality: IDS\n\
801  request-body-limit: 0\n\
802  response-body-limit: 0\n\
803 \n\
804  request-body-inspect-window: 0\n\
805  response-body-inspect-window: 0\n\
806  request-body-minimal-inspect-size: 0\n\
807  response-body-minimal-inspect-size: 0\n\
808 ";
809 
810  struct TestSteps steps[] = {
811  { (const uint8_t *)"GET /index.html HTTP/1.1\r\n"
812  "Host: www.openinfosecfoundation.org\r\n"
813  "Content-Type: text/html\r\n"
814  "Content-Length: 46\r\n"
815  "\r\n"
816  "This is dummy body1",
817  0, STREAM_TOSERVER, 0 },
818  { (const uint8_t *)"This is dummy message body2",
819  0, STREAM_TOSERVER, 0 },
820  { NULL, 0, 0, 0 },
821  };
822 
823  const char *sig = "alert http any any -> any any (content:\"bags\"; depth:4; http_client_body; sid:1;)";
824  return RunTest(steps, sig, yaml);
825 }
826 
827 /**
828  * \test Test that a signature containing a http_client_body is correctly parsed
829  * and the keyword is registered.
830  */
831 static int DetectHttpClientBodyTest01(void)
832 {
835  de_ctx->flags |= DE_QUIET;
836 
837  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
838  "(msg:\"Testing http_client_body\"; "
839  "content:\"one\"; http_client_body; sid:1;)");
840  FAIL_IF_NULL(s);
841 
843  FAIL_IF_NOT_NULL(sm);
844 
846  PASS;
847 }
848 
849 /**
850  * \test Test that a signature containing an valid http_client_body entry is
851  * parsed.
852  * \todo error in sig 'http_client_body:;'
853  */
854 static int DetectHttpClientBodyTest02(void)
855 {
858  de_ctx->flags |= DE_QUIET;
859 
860  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any "
861  "(msg:\"Testing http_client_body\"; "
862  "content:\"one\"; http_client_body:; sid:1;)");
863  FAIL_IF_NULL(s);
864 
866  PASS;
867 }
868 
869 /**
870  * \test Test invalid signatures
871  */
872 static int DetectHttpClientBodyTest03(void)
873 {
876  de_ctx->flags |= DE_QUIET;
877 
878  const char *sigs[] = {
879  "alert tcp any any -> any any (http_client_body; sid:1;)",
880  "alert tcp any any -> any any "
881  "(msg:\"Testing http_client_body\"; "
882  "content:\"one\"; rawbytes; http_client_body; sid:2;)",
883  NULL,
884  };
885 
886  for (uint32_t i = 0; sigs[i] != NULL; i++) {
887  Signature *s = DetectEngineAppendSig(de_ctx, sigs[i]);
888  FAIL_IF_NOT_NULL(s);
889  }
891  PASS;
892 }
893 
894 /**
895  * \test Test that an invalid signature containing a rawbytes along with a
896  * http_client_body is invalidated.
897  */
898 static int DetectHttpClientBodyTest05(void)
899 {
902  de_ctx->flags |= DE_QUIET;
903 
904  const char *sigs[] = {
905  "alert tcp any any -> any any (content:\"one\"; http_client_body; nocase; sid:1;)",
906  NULL,
907  };
908 
909  for (uint32_t i = 0; sigs[i] != NULL; i++) {
910  Signature *s = DetectEngineAppendSig(de_ctx, sigs[i]);
911  FAIL_IF_NULL(s);
912  }
914  PASS;
915 }
916 
917 /**
918  *\test Test that the http_client_body content matches against a http request
919  * which holds the content.
920  */
921 static int DetectHttpClientBodyTest06(void)
922 {
923  TcpSession ssn;
924  Packet *p = NULL;
925  ThreadVars th_v;
926  DetectEngineCtx *de_ctx = NULL;
927  DetectEngineThreadCtx *det_ctx = NULL;
928  HtpState *http_state = NULL;
929  Flow f;
930  uint8_t http_buf[] =
931  "GET /index.html HTTP/1.0\r\n"
932  "Host: www.openinfosecfoundation.org\r\n"
933  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
934  "Content-Type: text/html\r\n"
935  "Content-Length: 26\r\n"
936  "\r\n"
937  "This is dummy message body";
938  uint32_t http_len = sizeof(http_buf) - 1;
939  int result = 0;
941 
942  memset(&th_v, 0, sizeof(th_v));
943  memset(&f, 0, sizeof(f));
944  memset(&ssn, 0, sizeof(ssn));
945 
946  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
947 
948  FLOW_INITIALIZE(&f);
949  f.protoctx = (void *)&ssn;
950  f.proto = IPPROTO_TCP;
951  f.flags |= FLOW_IPV4;
952 
953  p->flow = &f;
958 
959  StreamTcpInitConfig(true);
960 
962  if (de_ctx == NULL)
963  goto end;
964 
965  de_ctx->flags |= DE_QUIET;
966 
967  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
968  "(msg:\"http client body test\"; "
969  "content:\"message\"; http_client_body; "
970  "sid:1;)");
971  FAIL_IF_NULL(s);
972 
974  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
975 
976  int r = AppLayerParserParse(
977  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
978  if (r != 0) {
979  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
980  result = 0;
981  goto end;
982  }
983 
984  http_state = f.alstate;
985  if (http_state == NULL) {
986  printf("no http state: \n");
987  result = 0;
988  goto end;
989  }
990 
991  /* do detect */
992  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
993 
994  if (!(PacketAlertCheck(p, 1))) {
995  printf("sid 1 didn't match but should have\n");
996  goto end;
997  }
998 
999  result = 1;
1000 end:
1001  if (alp_tctx != NULL)
1003  if (det_ctx != NULL) {
1004  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1005  }
1006  if (de_ctx != NULL)
1008 
1009  StreamTcpFreeConfig(true);
1010  FLOW_DESTROY(&f);
1011  UTHFreePackets(&p, 1);
1012  StatsThreadCleanup(&th_v);
1013  return result;
1014 }
1015 
1016 /**
1017  *\test Test that the http_client_body content matches against a http request
1018  * which holds the content.
1019  */
1020 static int DetectHttpClientBodyTest07(void)
1021 {
1022  TcpSession ssn;
1023  Packet *p1 = NULL;
1024  Packet *p2 = NULL;
1025  ThreadVars th_v;
1026  DetectEngineCtx *de_ctx = NULL;
1027  DetectEngineThreadCtx *det_ctx = NULL;
1028  HtpState *http_state = NULL;
1029  Flow f;
1030  uint8_t http1_buf[] =
1031  "GET /index.html HTTP/1.0\r\n"
1032  "Host: www.openinfosecfoundation.org\r\n"
1033  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1034  "Content-Type: text/html\r\n"
1035  "Content-Length: 54\r\n"
1036  "\r\n"
1037  "This is dummy message body1";
1038  uint8_t http2_buf[] =
1039  "This is dummy message body2";
1040  uint32_t http1_len = sizeof(http1_buf) - 1;
1041  uint32_t http2_len = sizeof(http2_buf) - 1;
1042  int result = 0;
1044 
1045  memset(&th_v, 0, sizeof(th_v));
1046  memset(&f, 0, sizeof(f));
1047  memset(&ssn, 0, sizeof(ssn));
1048 
1049  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1050  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1051 
1052  FLOW_INITIALIZE(&f);
1053  f.protoctx = (void *)&ssn;
1054  f.proto = IPPROTO_TCP;
1055  f.flags |= FLOW_IPV4;
1056 
1057  p1->flow = &f;
1061  p2->flow = &f;
1065  f.alproto = ALPROTO_HTTP1;
1066 
1067  StreamTcpInitConfig(true);
1068 
1070  if (de_ctx == NULL)
1071  goto end;
1072 
1073  de_ctx->flags |= DE_QUIET;
1074 
1075  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1076  "(msg:\"http client body test\"; "
1077  "content:\"message\"; http_client_body; "
1078  "sid:1;)");
1079  FAIL_IF_NULL(s);
1080 
1082  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1083 
1084  int r = AppLayerParserParse(
1085  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1086  if (r != 0) {
1087  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1088  result = 0;
1089  goto end;
1090  }
1091 
1092  http_state = f.alstate;
1093  if (http_state == NULL) {
1094  printf("no http state: ");
1095  goto end;
1096  }
1097 
1098  /* do detect */
1099  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1100 
1101  if (PacketAlertCheck(p1, 1)) {
1102  printf("sid 1 matched on p1 but shouldn't have: ");
1103  goto end;
1104  }
1105 
1106  r = AppLayerParserParse(
1107  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1108  if (r != 0) {
1109  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1110  goto end;
1111  }
1112 
1113  /* do detect */
1114  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1115  if (!(PacketAlertCheck(p2, 1))) {
1116  printf("sid 1 didn't match on p2 but should have: ");
1117  goto end;
1118  }
1119 
1120  result = 1;
1121 end:
1122  if (alp_tctx != NULL)
1124  if (det_ctx != NULL) {
1125  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1126  }
1127  if (de_ctx != NULL)
1129 
1130  StreamTcpFreeConfig(true);
1131  FLOW_DESTROY(&f);
1132  UTHFreePackets(&p1, 1);
1133  UTHFreePackets(&p2, 1);
1134  StatsThreadCleanup(&th_v);
1135  return result;
1136 }
1137 
1138 /**
1139  *\test Test that the http_client_body content matches against a http request
1140  * which holds the content.
1141  */
1142 static int DetectHttpClientBodyTest08(void)
1143 {
1144  TcpSession ssn;
1145  Packet *p1 = NULL;
1146  Packet *p2 = NULL;
1147  ThreadVars th_v;
1148  DetectEngineCtx *de_ctx = NULL;
1149  DetectEngineThreadCtx *det_ctx = NULL;
1150  HtpState *http_state = NULL;
1151  Flow f;
1152  uint8_t http1_buf[] =
1153  "GET /index.html HTTP/1.0\r\n"
1154  "Host: www.openinfosecfoundation.org\r\n"
1155  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1156  "Content-Type: text/html\r\n"
1157  "Content-Length: 46\r\n"
1158  "\r\n"
1159  "This is dummy body1";
1160  uint8_t http2_buf[] =
1161  "This is dummy message body2";
1162  uint32_t http1_len = sizeof(http1_buf) - 1;
1163  uint32_t http2_len = sizeof(http2_buf) - 1;
1164  int result = 0;
1166 
1167  memset(&th_v, 0, sizeof(th_v));
1168  memset(&f, 0, sizeof(f));
1169  memset(&ssn, 0, sizeof(ssn));
1170 
1171  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1172  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1173 
1174  FLOW_INITIALIZE(&f);
1175  f.protoctx = (void *)&ssn;
1176  f.proto = IPPROTO_TCP;
1177  f.flags |= FLOW_IPV4;
1178 
1179  p1->flow = &f;
1183  p2->flow = &f;
1187  f.alproto = ALPROTO_HTTP1;
1188 
1189  StreamTcpInitConfig(true);
1190 
1192  if (de_ctx == NULL)
1193  goto end;
1194 
1195  de_ctx->flags |= DE_QUIET;
1196 
1197  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1198  "(msg:\"http client body test\"; "
1199  "content:\"message\"; http_client_body; "
1200  "sid:1;)");
1201  FAIL_IF_NULL(s);
1202 
1204  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1205 
1206  int r = AppLayerParserParse(
1207  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1208  if (r != 0) {
1209  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1210  result = 0;
1211  goto end;
1212  }
1213 
1214  http_state = f.alstate;
1215  if (http_state == NULL) {
1216  printf("no http state: ");
1217  result = 0;
1218  goto end;
1219  }
1220 
1221  /* do detect */
1222  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1223 
1224  if ((PacketAlertCheck(p1, 1))) {
1225  printf("sid 1 didn't match but should have");
1226  goto end;
1227  }
1228 
1229  r = AppLayerParserParse(
1230  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1231  if (r != 0) {
1232  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1233  result = 0;
1234  goto end;
1235  }
1236 
1237  /* do detect */
1238  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1239 
1240  if (!(PacketAlertCheck(p2, 1))) {
1241  printf("sid 1 didn't match but should have");
1242  goto end;
1243  }
1244 
1245  result = 1;
1246 end:
1247  if (alp_tctx != NULL)
1249  if (det_ctx != NULL) {
1250  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1251  }
1252  if (de_ctx != NULL)
1254 
1255  StreamTcpFreeConfig(true);
1256  FLOW_DESTROY(&f);
1257  UTHFreePackets(&p1, 1);
1258  UTHFreePackets(&p2, 1);
1259  StatsThreadCleanup(&th_v);
1260  return result;
1261 }
1262 
1263 /**
1264  *\test Test that the http_client_body content matches against a http request
1265  * which holds the content, against a cross boundary present pattern.
1266  */
1267 static int DetectHttpClientBodyTest09(void)
1268 {
1269  TcpSession ssn;
1270  Packet *p1 = NULL;
1271  Packet *p2 = NULL;
1272  ThreadVars th_v;
1273  DetectEngineCtx *de_ctx = NULL;
1274  DetectEngineThreadCtx *det_ctx = NULL;
1275  HtpState *http_state = NULL;
1276  Flow f;
1277  uint8_t http1_buf[] =
1278  "GET /index.html HTTP/1.0\r\n"
1279  "Host: www.openinfosecfoundation.org\r\n"
1280  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1281  "Content-Type: text/html\r\n"
1282  "Content-Length: 46\r\n"
1283  "\r\n"
1284  "This is dummy body1";
1285  uint8_t http2_buf[] =
1286  "This is dummy message body2";
1287  uint32_t http1_len = sizeof(http1_buf) - 1;
1288  uint32_t http2_len = sizeof(http2_buf) - 1;
1289  int result = 0;
1291 
1292  memset(&th_v, 0, sizeof(th_v));
1293  memset(&f, 0, sizeof(f));
1294  memset(&ssn, 0, sizeof(ssn));
1295 
1296  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1297  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1298 
1299  FLOW_INITIALIZE(&f);
1300  f.protoctx = (void *)&ssn;
1301  f.proto = IPPROTO_TCP;
1302  f.flags |= FLOW_IPV4;
1303 
1304  p1->flow = &f;
1308  p2->flow = &f;
1312  f.alproto = ALPROTO_HTTP1;
1313 
1314  StreamTcpInitConfig(true);
1315 
1317  if (de_ctx == NULL)
1318  goto end;
1319 
1320  de_ctx->flags |= DE_QUIET;
1321 
1322  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1323  "(msg:\"http client body test\"; "
1324  "content:\"body1This\"; http_client_body; "
1325  "sid:1;)");
1326  FAIL_IF_NULL(s);
1327 
1329  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1330 
1331  int r = AppLayerParserParse(
1332  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1333  if (r != 0) {
1334  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1335  result = 0;
1336  goto end;
1337  }
1338 
1339  http_state = f.alstate;
1340  if (http_state == NULL) {
1341  printf("no http state: ");
1342  result = 0;
1343  goto end;
1344  }
1345 
1346  /* do detect */
1347  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1348 
1349  if ((PacketAlertCheck(p1, 1))) {
1350  printf("sid 1 didn't match but should have");
1351  goto end;
1352  }
1353 
1354  r = AppLayerParserParse(
1355  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1356  if (r != 0) {
1357  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1358  result = 0;
1359  goto end;
1360  }
1361 
1362  /* do detect */
1363  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1364 
1365  if (!(PacketAlertCheck(p2, 1))) {
1366  printf("sid 1 didn't match but should have");
1367  goto end;
1368  }
1369 
1370  result = 1;
1371 end:
1372  if (alp_tctx != NULL)
1374  if (det_ctx != NULL) {
1375  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1376  }
1377  if (de_ctx != NULL)
1379 
1380  StreamTcpFreeConfig(true);
1381  FLOW_DESTROY(&f);
1382  UTHFreePackets(&p1, 1);
1383  UTHFreePackets(&p2, 1);
1384  StatsThreadCleanup(&th_v);
1385  return result;
1386 }
1387 
1388 /**
1389  *\test Test that the http_client_body content matches against a http request
1390  * against a case insensitive pattern.
1391  */
1392 static int DetectHttpClientBodyTest10(void)
1393 {
1394  TcpSession ssn;
1395  Packet *p1 = NULL;
1396  Packet *p2 = NULL;
1397  ThreadVars th_v;
1398  DetectEngineCtx *de_ctx = NULL;
1399  DetectEngineThreadCtx *det_ctx = NULL;
1400  HtpState *http_state = NULL;
1401  Flow f;
1402  uint8_t http1_buf[] =
1403  "GET /index.html HTTP/1.0\r\n"
1404  "Host: www.openinfosecfoundation.org\r\n"
1405  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1406  "Content-Type: text/html\r\n"
1407  "Content-Length: 46\r\n"
1408  "\r\n"
1409  "This is dummy bodY1";
1410  uint8_t http2_buf[] =
1411  "This is dummy message body2";
1412  uint32_t http1_len = sizeof(http1_buf) - 1;
1413  uint32_t http2_len = sizeof(http2_buf) - 1;
1414  int result = 0;
1416 
1417  memset(&th_v, 0, sizeof(th_v));
1418  memset(&f, 0, sizeof(f));
1419  memset(&ssn, 0, sizeof(ssn));
1420 
1421  p1 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1422  p2 = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1423 
1424  FLOW_INITIALIZE(&f);
1425  f.protoctx = (void *)&ssn;
1426  f.proto = IPPROTO_TCP;
1427  f.flags |= FLOW_IPV4;
1428 
1429  p1->flow = &f;
1433  p2->flow = &f;
1437  f.alproto = ALPROTO_HTTP1;
1438 
1439  StreamTcpInitConfig(true);
1440 
1442  if (de_ctx == NULL)
1443  goto end;
1444 
1445  de_ctx->flags |= DE_QUIET;
1446 
1447  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1448  "(msg:\"http client body test\"; "
1449  "content:\"body1This\"; http_client_body; nocase;"
1450  "sid:1;)");
1451  FAIL_IF_NULL(s);
1452 
1454  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1455 
1456  int r = AppLayerParserParse(
1457  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http1_buf, http1_len);
1458  if (r != 0) {
1459  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1460  result = 0;
1461  goto end;
1462  }
1463 
1464  http_state = f.alstate;
1465  if (http_state == NULL) {
1466  printf("no http state: \n");
1467  result = 0;
1468  goto end;
1469  }
1470 
1471  /* do detect */
1472  SigMatchSignatures(&th_v, de_ctx, det_ctx, p1);
1473 
1474  if ((PacketAlertCheck(p1, 1))) {
1475  printf("sid 1 didn't match but should have\n");
1476  goto end;
1477  }
1478 
1479  r = AppLayerParserParse(
1480  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http2_buf, http2_len);
1481  if (r != 0) {
1482  printf("toserver chunk 1 returned %" PRId32 ", expected 0: \n", r);
1483  result = 0;
1484  goto end;
1485  }
1486 
1487  /* do detect */
1488  SigMatchSignatures(&th_v, de_ctx, det_ctx, p2);
1489 
1490  if (!(PacketAlertCheck(p2, 1))) {
1491  printf("sid 1 didn't match but should have");
1492  goto end;
1493  }
1494 
1495  result = 1;
1496 end:
1497  if (alp_tctx != NULL)
1499  if (det_ctx != NULL) {
1500  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1501  }
1502  if (de_ctx != NULL)
1504 
1505  StreamTcpFreeConfig(true);
1506  FLOW_DESTROY(&f);
1507  UTHFreePackets(&p1, 1);
1508  UTHFreePackets(&p2, 1);
1509  StatsThreadCleanup(&th_v);
1510  return result;
1511 }
1512 
1513 /**
1514  *\test Test that the negated http_client_body content matches against a
1515  * http request which doesn't hold the content.
1516  */
1517 static int DetectHttpClientBodyTest11(void)
1518 {
1519  TcpSession ssn;
1520  Packet *p = NULL;
1521  ThreadVars th_v;
1522  DetectEngineCtx *de_ctx = NULL;
1523  DetectEngineThreadCtx *det_ctx = NULL;
1524  HtpState *http_state = NULL;
1525  Flow f;
1526  uint8_t http_buf[] =
1527  "GET /index.html HTTP/1.0\r\n"
1528  "Host: www.openinfosecfoundation.org\r\n"
1529  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1530  "Content-Type: text/html\r\n"
1531  "Content-Length: 26\r\n"
1532  "\r\n"
1533  "This is dummy message body";
1534  uint32_t http_len = sizeof(http_buf) - 1;
1535  int result = 0;
1537 
1538  memset(&th_v, 0, sizeof(th_v));
1539  memset(&f, 0, sizeof(f));
1540  memset(&ssn, 0, sizeof(ssn));
1541 
1542  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1543 
1544  FLOW_INITIALIZE(&f);
1545  f.protoctx = (void *)&ssn;
1546  f.proto = IPPROTO_TCP;
1547  f.flags |= FLOW_IPV4;
1548 
1549  p->flow = &f;
1553  f.alproto = ALPROTO_HTTP1;
1554 
1555  StreamTcpInitConfig(true);
1556 
1558  if (de_ctx == NULL)
1559  goto end;
1560 
1561  de_ctx->flags |= DE_QUIET;
1562 
1563  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1564  "(msg:\"http client body test\"; "
1565  "content:!\"message1\"; http_client_body; "
1566  "sid:1;)");
1567  FAIL_IF_NULL(s);
1568 
1570  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1571 
1572  int r = AppLayerParserParse(
1573  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
1574  if (r != 0) {
1575  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1576  result = 0;
1577  goto end;
1578  }
1579 
1580  http_state = f.alstate;
1581  if (http_state == NULL) {
1582  printf("no http state: ");
1583  result = 0;
1584  goto end;
1585  }
1586 
1587  /* do detect */
1588  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1589 
1590  if (!(PacketAlertCheck(p, 1))) {
1591  printf("sid 1 didn't match but should have");
1592  goto end;
1593  }
1594 
1595  result = 1;
1596 end:
1597  if (alp_tctx != NULL)
1599  if (det_ctx != NULL) {
1600  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1601  }
1602  if (de_ctx != NULL)
1604 
1605  StreamTcpFreeConfig(true);
1606  FLOW_DESTROY(&f);
1607  UTHFreePackets(&p, 1);
1608  StatsThreadCleanup(&th_v);
1609  return result;
1610 }
1611 
1612 /**
1613  *\test Negative test that the negated http_client_body content matches against a
1614  * http request which holds hold the content.
1615  */
1616 static int DetectHttpClientBodyTest12(void)
1617 {
1618  TcpSession ssn;
1619  Packet *p = NULL;
1620  ThreadVars th_v;
1621  DetectEngineCtx *de_ctx = NULL;
1622  DetectEngineThreadCtx *det_ctx = NULL;
1623  HtpState *http_state = NULL;
1624  Flow f;
1625  uint8_t http_buf[] =
1626  "GET /index.html HTTP/1.0\r\n"
1627  "Host: www.openinfosecfoundation.org\r\n"
1628  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1629  "Content-Type: text/html\r\n"
1630  "Content-Length: 26\r\n"
1631  "\r\n"
1632  "This is dummy message body";
1633  uint32_t http_len = sizeof(http_buf) - 1;
1634  int result = 0;
1636 
1637  memset(&th_v, 0, sizeof(th_v));
1638  memset(&f, 0, sizeof(f));
1639  memset(&ssn, 0, sizeof(ssn));
1640 
1641  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1642 
1643  FLOW_INITIALIZE(&f);
1644  f.protoctx = (void *)&ssn;
1645  f.proto = IPPROTO_TCP;
1646  f.flags |= FLOW_IPV4;
1647 
1648  p->flow = &f;
1652  f.alproto = ALPROTO_HTTP1;
1653 
1654  StreamTcpInitConfig(true);
1655 
1657  if (de_ctx == NULL)
1658  goto end;
1659 
1660  de_ctx->flags |= DE_QUIET;
1661 
1662  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any "
1663  "(msg:\"http client body test\"; "
1664  "content:!\"message\"; http_client_body; "
1665  "sid:1;)");
1666  FAIL_IF_NULL(s);
1667 
1669  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1670 
1671  int r = AppLayerParserParse(
1672  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
1673  if (r != 0) {
1674  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1675  result = 0;
1676  goto end;
1677  }
1678 
1679  http_state = f.alstate;
1680  if (http_state == NULL) {
1681  printf("no http state: ");
1682  result = 0;
1683  goto end;
1684  }
1685 
1686  /* do detect */
1687  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1688 
1689  if ((PacketAlertCheck(p, 1))) {
1690  printf("sid 1 didn't match but should have");
1691  goto end;
1692  }
1693 
1694  result = 1;
1695 end:
1696  if (alp_tctx != NULL)
1698  if (det_ctx != NULL) {
1699  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1700  }
1701  if (de_ctx != NULL)
1703 
1704  StreamTcpFreeConfig(true);
1705  FLOW_DESTROY(&f);
1706  UTHFreePackets(&p, 1);
1707  StatsThreadCleanup(&th_v);
1708  return result;
1709 }
1710 
1711 /**
1712  *\test Test that the http_client_body content matches against a http request
1713  * which holds the content.
1714  */
1715 static int DetectHttpClientBodyTest13(void)
1716 {
1717  TcpSession ssn;
1718  Packet *p = NULL;
1719  ThreadVars th_v;
1720  DetectEngineCtx *de_ctx = NULL;
1721  DetectEngineThreadCtx *det_ctx = NULL;
1722  HtpState *http_state = NULL;
1723  Flow f;
1724  uint8_t http_buf[] =
1725  "GET /index.html HTTP/1.0\r\n"
1726  "Host: www.openinfosecfoundation.org\r\n"
1727  "User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.9.1.7) Gecko/20091221 Firefox/3.5.7\r\n"
1728  "Content-Type: text/html\r\n"
1729  "Content-Length: 55\r\n"
1730  "\r\n"
1731  "longbufferabcdefghijklmnopqrstuvwxyz0123456789bufferend";
1732  uint32_t http_len = sizeof(http_buf) - 1;
1733  int result = 0;
1735 
1736  memset(&th_v, 0, sizeof(th_v));
1737  memset(&f, 0, sizeof(f));
1738  memset(&ssn, 0, sizeof(ssn));
1739 
1740  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1741 
1742  FLOW_INITIALIZE(&f);
1743  f.protoctx = (void *)&ssn;
1744  f.proto = IPPROTO_TCP;
1745  f.flags |= FLOW_IPV4;
1746 
1747  p->flow = &f;
1751  f.alproto = ALPROTO_HTTP1;
1752 
1753  StreamTcpInitConfig(true);
1754 
1756  if (de_ctx == NULL)
1757  goto end;
1758 
1759  de_ctx->flags |= DE_QUIET;
1760 
1762  "alert http any any -> any any "
1763  "(msg:\"http client body test\"; "
1764  "content:\"abcdefghijklmnopqrstuvwxyz0123456789\"; http_client_body; "
1765  "sid:1;)");
1766  FAIL_IF_NULL(s);
1767 
1769  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1770 
1771  int r = AppLayerParserParse(
1772  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, http_buf, http_len);
1773  if (r != 0) {
1774  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1775  result = 0;
1776  goto end;
1777  }
1778 
1779  http_state = f.alstate;
1780  if (http_state == NULL) {
1781  printf("no http state: ");
1782  result = 0;
1783  goto end;
1784  }
1785 
1786  /* do detect */
1787  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1788 
1789  if (!(PacketAlertCheck(p, 1))) {
1790  printf("sid 1 didn't match but should have");
1791  goto end;
1792  }
1793 
1794  result = 1;
1795 end:
1796  if (alp_tctx != NULL)
1798  if (det_ctx != NULL) {
1799  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1800  }
1801  if (de_ctx != NULL)
1803 
1804  StreamTcpFreeConfig(true);
1805  FLOW_DESTROY(&f);
1806  UTHFreePackets(&p, 1);
1807  StatsThreadCleanup(&th_v);
1808  return result;
1809 }
1810 
1811 /** \test multiple http transactions and body chunks of request handling */
1812 static int DetectHttpClientBodyTest14(void)
1813 {
1814  int result = 0;
1815  Signature *s = NULL;
1816  DetectEngineThreadCtx *det_ctx = NULL;
1817  ThreadVars th_v;
1818  Flow f;
1819  TcpSession ssn;
1820  Packet *p = NULL;
1821  uint8_t httpbuf1[] = "POST / HTTP/1.1\r\n";
1822  uint8_t httpbuf2[] = "User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
1823  uint8_t httpbuf3[] = "Cookie: dummy\r\n\r\n";
1824  uint8_t httpbuf4[] = "Body one!!";
1825  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
1826  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
1827  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
1828  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
1829  uint8_t httpbuf5[] = "GET /?var=val HTTP/1.1\r\n";
1830  uint8_t httpbuf6[] = "User-Agent: Firefox/1.0\r\n";
1831  uint8_t httpbuf7[] = "Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
1832  uint32_t httplen5 = sizeof(httpbuf5) - 1; /* minus the \0 */
1833  uint32_t httplen6 = sizeof(httpbuf6) - 1; /* minus the \0 */
1834  uint32_t httplen7 = sizeof(httpbuf7) - 1; /* minus the \0 */
1836 
1837  memset(&th_v, 0, sizeof(th_v));
1838  memset(&f, 0, sizeof(f));
1839  memset(&ssn, 0, sizeof(ssn));
1840 
1841  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1842 
1843  FLOW_INITIALIZE(&f);
1844  f.protoctx = (void *)&ssn;
1845  f.proto = IPPROTO_TCP;
1846  f.flags |= FLOW_IPV4;
1847 
1848  p->flow = &f;
1852  f.alproto = ALPROTO_HTTP1;
1853 
1854  StreamTcpInitConfig(true);
1855 
1857  if (de_ctx == NULL) {
1858  goto end;
1859  }
1860 
1861  de_ctx->flags |= DE_QUIET;
1862 
1863  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;)");
1864  if (s == NULL) {
1865  printf("sig parse failed: ");
1866  goto end;
1867  }
1868  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;)");
1869  if (s == NULL) {
1870  printf("sig2 parse failed: ");
1871  goto end;
1872  }
1873 
1875  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1876 
1877  int r = AppLayerParserParse(
1878  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf1, httplen1);
1879  if (r != 0) {
1880  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
1881  goto end;
1882  }
1883 
1884  /* do detect */
1885  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1886  if (PacketAlertCheck(p, 1)) {
1887  printf("sig 1 alerted: ");
1888  goto end;
1889  }
1890  p->alerts.cnt = 0;
1891 
1892  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
1893  if (r != 0) {
1894  printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
1895  goto end;
1896  }
1897 
1898  /* do detect */
1899  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1900  if (PacketAlertCheck(p, 1)) {
1901  printf("sig 1 alerted (2): ");
1902  goto end;
1903  }
1904  p->alerts.cnt = 0;
1905 
1906  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
1907  if (r != 0) {
1908  printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
1909  goto end;
1910  }
1911 
1912  /* do detect */
1913  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1914  if (PacketAlertCheck(p, 1)) {
1915  printf("signature matched, but shouldn't have: ");
1916  goto end;
1917  }
1918  p->alerts.cnt = 0;
1919 
1920  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf4, httplen4);
1921  if (r != 0) {
1922  printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
1923  result = 0;
1924  goto end;
1925  }
1926 
1927  /* do detect */
1928  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1929  if (!(PacketAlertCheck(p, 1))) {
1930  printf("sig 1 didn't alert: ");
1931  goto end;
1932  }
1933  p->alerts.cnt = 0;
1934 
1935  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf5, httplen5);
1936  if (r != 0) {
1937  printf("toserver chunk 5 returned %" PRId32 ", expected 0: ", r);
1938  goto end;
1939  }
1940 
1941  /* do detect */
1942  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1943  if (PacketAlertCheck(p, 1)) {
1944  printf("sig 1 alerted (5): ");
1945  goto end;
1946  }
1947  p->alerts.cnt = 0;
1948 
1949  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf6, httplen6);
1950  if (r != 0) {
1951  printf("toserver chunk 6 returned %" PRId32 ", expected 0: ", r);
1952  goto end;
1953  }
1954 
1955  /* do detect */
1956  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1957  if ((PacketAlertCheck(p, 1)) || (PacketAlertCheck(p, 2))) {
1958  printf("sig 1 alerted (request 2, chunk 6): ");
1959  goto end;
1960  }
1961  p->alerts.cnt = 0;
1962 
1963  SCLogDebug("sending data chunk 7");
1964 
1965  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf7, httplen7);
1966  if (r != 0) {
1967  printf("toserver chunk 7 returned %" PRId32 ", expected 0: ", r);
1968  goto end;
1969  }
1970 
1971  /* do detect */
1972  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1973  if (!(PacketAlertCheck(p, 2))) {
1974  printf("signature 2 didn't match, but should have: ");
1975  goto end;
1976  }
1977  p->alerts.cnt = 0;
1978 
1979  HtpState *htp_state = f.alstate;
1980  if (htp_state == NULL) {
1981  printf("no http state: ");
1982  result = 0;
1983  goto end;
1984  }
1985 
1986  if (AppLayerParserGetTxCnt(&f, htp_state) != 2) {
1987  printf("The http app layer doesn't have 2 transactions, but it should: ");
1988  goto end;
1989  }
1990 
1991  result = 1;
1992 end:
1993  if (alp_tctx != NULL)
1995  if (det_ctx != NULL) {
1996  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1997  }
1998  if (de_ctx != NULL) {
2000  }
2001 
2002  StreamTcpFreeConfig(true);
2003  FLOW_DESTROY(&f);
2004  UTHFreePacket(p);
2005  StatsThreadCleanup(&th_v);
2006  return result;
2007 }
2008 
2009 /** \test multiple http transactions and body chunks of request handling */
2010 static int DetectHttpClientBodyTest15(void)
2011 {
2012  int result = 0;
2013  Signature *s = NULL;
2014  DetectEngineThreadCtx *det_ctx = NULL;
2015  ThreadVars th_v;
2016  Flow f;
2017  TcpSession ssn;
2018  Packet *p = NULL;
2019  uint8_t httpbuf1[] = "POST / HTTP/1.1\r\n";
2020  uint8_t httpbuf2[] = "User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
2021  uint8_t httpbuf3[] = "Cookie: dummy\r\n\r\n";
2022  uint8_t httpbuf4[] = "Body one!!";
2023  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
2024  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
2025  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
2026  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
2027  uint8_t httpbuf5[] = "GET /?var=val HTTP/1.1\r\n";
2028  uint8_t httpbuf6[] = "User-Agent: Firefox/1.0\r\n";
2029  uint8_t httpbuf7[] = "Cookie: dummy2\r\nContent-Length: 10\r\n\r\nBody two!!";
2030  uint32_t httplen5 = sizeof(httpbuf5) - 1; /* minus the \0 */
2031  uint32_t httplen6 = sizeof(httpbuf6) - 1; /* minus the \0 */
2032  uint32_t httplen7 = sizeof(httpbuf7) - 1; /* minus the \0 */
2034 
2035  memset(&th_v, 0, sizeof(th_v));
2036  memset(&f, 0, sizeof(f));
2037  memset(&ssn, 0, sizeof(ssn));
2038 
2039  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
2040 
2041  FLOW_INITIALIZE(&f);
2042  f.protoctx = (void *)&ssn;
2043  f.proto = IPPROTO_TCP;
2044  f.flags |= FLOW_IPV4;
2045 
2046  p->flow = &f;
2050  f.alproto = ALPROTO_HTTP1;
2051 
2052  StreamTcpInitConfig(true);
2053 
2055  if (de_ctx == NULL) {
2056  goto end;
2057  }
2058 
2059  de_ctx->flags |= DE_QUIET;
2060 
2061  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;)");
2062  if (s == NULL) {
2063  printf("sig parse failed: ");
2064  goto end;
2065  }
2066  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;)");
2067  if (s == NULL) {
2068  printf("sig2 parse failed: ");
2069  goto end;
2070  }
2071 
2073  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
2074 
2075  int r = AppLayerParserParse(
2076  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf1, httplen1);
2077  if (r != 0) {
2078  printf("toserver chunk 1 returned %" PRId32 ", expected 0: ", r);
2079  goto end;
2080  }
2081 
2082  /* do detect */
2083  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2084  if (PacketAlertCheck(p, 1)) {
2085  printf("sig 1 alerted: ");
2086  goto end;
2087  }
2088  p->alerts.cnt = 0;
2089 
2090  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
2091  if (r != 0) {
2092  printf("toserver chunk 2 returned %" PRId32 ", expected 0: ", r);
2093  goto end;
2094  }
2095 
2096  /* do detect */
2097  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2098  if (PacketAlertCheck(p, 1)) {
2099  printf("sig 1 alerted (2): ");
2100  goto end;
2101  }
2102  p->alerts.cnt = 0;
2103 
2104  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
2105  if (r != 0) {
2106  printf("toserver chunk 3 returned %" PRId32 ", expected 0: ", r);
2107  goto end;
2108  }
2109 
2110  /* do detect */
2111  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2112  if (PacketAlertCheck(p, 1)) {
2113  printf("signature matched, but shouldn't have: ");
2114  goto end;
2115  }
2116  p->alerts.cnt = 0;
2117 
2118  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf4, httplen4);
2119  if (r != 0) {
2120  printf("toserver chunk 4 returned %" PRId32 ", expected 0: ", r);
2121  result = 0;
2122  goto end;
2123  }
2124 
2125  /* do detect */
2126  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2127  if (!(PacketAlertCheck(p, 1))) {
2128  printf("sig 1 didn't alert: ");
2129  goto end;
2130  }
2131  p->alerts.cnt = 0;
2132 
2133  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf5, httplen5);
2134  if (r != 0) {
2135  printf("toserver chunk 5 returned %" PRId32 ", expected 0: ", r);
2136  goto end;
2137  }
2138 
2139  /* do detect */
2140  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2141  if (PacketAlertCheck(p, 1)) {
2142  printf("sig 1 alerted (5): ");
2143  goto end;
2144  }
2145  p->alerts.cnt = 0;
2146 
2147  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf6, httplen6);
2148  if (r != 0) {
2149  printf("toserver chunk 6 returned %" PRId32 ", expected 0: ", r);
2150  goto end;
2151  }
2152 
2153  /* do detect */
2154  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2155  if ((PacketAlertCheck(p, 1)) || (PacketAlertCheck(p, 2))) {
2156  printf("sig 1 alerted (request 2, chunk 6): ");
2157  goto end;
2158  }
2159  p->alerts.cnt = 0;
2160 
2161  SCLogDebug("sending data chunk 7");
2162 
2163  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf7, httplen7);
2164  if (r != 0) {
2165  printf("toserver chunk 7 returned %" PRId32 ", expected 0: ", r);
2166  goto end;
2167  }
2168 
2169  /* do detect */
2170  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
2171  if (!(PacketAlertCheck(p, 2))) {
2172  printf("signature 2 didn't match, but should have: ");
2173  goto end;
2174  }
2175  p->alerts.cnt = 0;
2176 
2177  HtpState *htp_state = f.alstate;
2178  if (htp_state == NULL) {
2179  printf("no http state: ");
2180  result = 0;
2181  goto end;
2182  }
2183 
2184  /* hardcoded check of the transactions and it's client body chunks */
2185  if (AppLayerParserGetTxCnt(&f, htp_state) != 2) {
2186  printf("The http app layer doesn't have 2 transactions, but it should: ");
2187  goto end;
2188  }
2189 
2190  htp_tx_t *t1 = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, 0);
2191  htp_tx_t *t2 = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, 1);
2192 
2193  HtpTxUserData *htud = (HtpTxUserData *) htp_tx_get_user_data(t1);
2194 
2195  HtpBodyChunk *cur = htud->request_body.first;
2196  if (htud->request_body.first == NULL) {
2197  SCLogDebug("No body data in t1 (it should be removed only when the tx is destroyed): ");
2198  goto end;
2199  }
2200 
2202  (uint8_t *)"Body one!!", 10) != 1)
2203  {
2204  SCLogDebug("Body data in t1 is not correctly set: ");
2205  goto end;
2206  }
2207 
2208  htud = (HtpTxUserData *) htp_tx_get_user_data(t2);
2209 
2210  cur = htud->request_body.first;
2211  if (htud->request_body.first == NULL) {
2212  SCLogDebug("No body data in t1 (it should be removed only when the tx is destroyed): ");
2213  goto end;
2214  }
2215 
2217  (uint8_t *)"Body two!!", 10) != 1)
2218  {
2219  SCLogDebug("Body data in t1 is not correctly set: ");
2220  goto end;
2221  }
2222 
2223  result = 1;
2224 end:
2225  if (alp_tctx != NULL)
2227  if (det_ctx != NULL) {
2228  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
2229  }
2230  if (de_ctx != NULL) {
2232  }
2233 
2234  StreamTcpFreeConfig(true);
2235  FLOW_DESTROY(&f);
2236  UTHFreePacket(p);
2237  StatsThreadCleanup(&th_v);
2238  return result;
2239 }
2240 
2241 static int DetectHttpClientBodyTest22(void)
2242 {
2245  de_ctx->flags |= DE_QUIET;
2247  "alert icmp any any -> any any "
2248  "(content:\"one\"; content:\"two\"; http_client_body; "
2249  "content:\"three\"; distance:10; http_client_body; content:\"four\"; sid:1;)");
2250  FAIL_IF_NULL(s);
2252  FAIL_IF(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL);
2253  SigMatch *sm = DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id);
2254  FAIL_IF_NULL(sm);
2255 
2256  DetectContentData *cd1 =
2258  DetectContentData *cd2 =
2260  DetectContentData *hcbd1 =
2261  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2262  ->prev->ctx;
2263  DetectContentData *hcbd2 =
2264  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2265  FAIL_IF(cd1->flags != 0);
2266  FAIL_IF(memcmp(cd1->content, "one", cd1->content_len) != 0);
2267  FAIL_IF(cd2->flags != 0);
2268  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2270  FAIL_IF(memcmp(hcbd1->content, "two", hcbd1->content_len) != 0);
2272  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2273 
2278 
2280  PASS;
2281 }
2282 
2283 static int DetectHttpClientBodyTest23(void)
2284 {
2287  de_ctx->flags |= DE_QUIET;
2288 
2290  "alert icmp any any -> any any "
2291  "(content:\"one\"; http_client_body; pcre:/two/; "
2292  "content:\"three\"; distance:10; http_client_body; content:\"four\"; sid:1;)");
2293  FAIL_IF_NULL(s);
2295  FAIL_IF_NULL(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id));
2296 
2297  DetectPcreData *pd1 =
2299  ->prev->ctx;
2300  DetectContentData *cd2 =
2302  ->ctx;
2303  DetectContentData *hcbd1 =
2304  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2305  ->prev->ctx;
2306  DetectContentData *hcbd2 =
2307  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2308  FAIL_IF(pd1->flags != 0);
2309  FAIL_IF(cd2->flags != 0);
2310  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2312  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2314  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2318 
2320  PASS;
2321 }
2322 
2323 static int DetectHttpClientBodyTest24(void)
2324 {
2327  de_ctx->flags |= DE_QUIET;
2328  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2329  "(content:\"one\"; http_client_body; pcre:/two/; "
2330  "content:\"three\"; distance:10; within:15; "
2331  "http_client_body; content:\"four\"; sid:1;)");
2332  FAIL_IF_NULL(s);
2333 
2335  FAIL_IF_NULL(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id));
2336 
2337  DetectPcreData *pd1 =
2339  ->prev->ctx;
2340  DetectContentData *cd2 =
2342  ->ctx;
2343  DetectContentData *hcbd1 =
2344  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2345  ->prev->ctx;
2346  DetectContentData *hcbd2 =
2347  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2348  FAIL_IF(pd1->flags != 0);
2349  FAIL_IF(cd2->flags != 0);
2350  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2352  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2354  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2355 
2359 
2361  PASS;
2362 }
2363 
2364 static int DetectHttpClientBodyTest25(void)
2365 {
2368  de_ctx->flags |= DE_QUIET;
2369  Signature *s =
2370  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2371  "(content:\"one\"; http_client_body; pcre:/two/; "
2372  "content:\"three\"; distance:10; http_client_body; "
2373  "content:\"four\"; distance:10; sid:1;)");
2374  FAIL_IF_NULL(s);
2376  FAIL_IF_NULL(DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id));
2377 
2378  DetectPcreData *pd1 =
2380  ->prev->ctx;
2381  DetectContentData *cd2 =
2383  ->ctx;
2384  DetectContentData *hcbd1 =
2385  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2386  ->prev->ctx;
2387  DetectContentData *hcbd2 =
2388  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2390  FAIL_IF(cd2->flags != DETECT_CONTENT_DISTANCE);
2391  FAIL_IF(memcmp(cd2->content, "four", cd2->content_len) != 0);
2393  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2395  FAIL_IF(memcmp(hcbd2->content, "three", hcbd1->content_len) != 0);
2396 
2400 
2402  PASS;
2403 }
2404 
2405 static int DetectHttpClientBodyTest26(void)
2406 {
2407  DetectEngineCtx *de_ctx = NULL;
2408  int result = 0;
2409 
2410  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2411  goto end;
2412 
2413  de_ctx->flags |= DE_QUIET;
2415  "alert icmp any any -> any any "
2416  "(content:\"one\"; offset:10; http_client_body; pcre:/two/; "
2417  "content:\"three\"; distance:10; http_client_body; within:10; "
2418  "content:\"four\"; distance:10; sid:1;)");
2419  if (de_ctx->sig_list == NULL) {
2420  printf("de_ctx->sig_list == NULL\n");
2421  goto end;
2422  }
2423 
2425  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] == NULL\n");
2426  goto end;
2427  }
2428 
2429  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2430  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2431  goto end;
2432  }
2433 
2434  DetectPcreData *pd1 =
2436  ->prev->ctx;
2437  DetectContentData *cd2 =
2439  ->ctx;
2440  DetectContentData *hcbd1 =
2441  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2442  ->prev->ctx;
2443  DetectContentData *hcbd2 =
2444  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2445  if (pd1->flags != (DETECT_PCRE_RELATIVE_NEXT) || cd2->flags != DETECT_CONTENT_DISTANCE ||
2446  memcmp(cd2->content, "four", cd2->content_len) != 0 ||
2448  memcmp(hcbd1->content, "one", hcbd1->content_len) != 0 ||
2449  hcbd2->flags !=
2451  memcmp(hcbd2->content, "three", hcbd1->content_len) != 0) {
2452  printf ("failed: http_client_body incorrect flags");
2453  goto end;
2454  }
2455 
2456  if (DETECT_CONTENT_IS_SINGLE(cd2) ||
2457  DETECT_CONTENT_IS_SINGLE(hcbd1) ||
2458  DETECT_CONTENT_IS_SINGLE(hcbd2)) {
2459  goto end;
2460  }
2461 
2462  result = 1;
2463 
2464  end:
2466  return result;
2467 }
2468 
2469 static int DetectHttpClientBodyTest27(void)
2470 {
2471  DetectEngineCtx *de_ctx = NULL;
2472  int result = 0;
2473 
2474  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2475  goto end;
2476 
2477  de_ctx->flags |= DE_QUIET;
2479  "alert icmp any any -> any any "
2480  "(content:\"one\"; offset:10; http_client_body; pcre:/two/; "
2481  "content:\"three\"; distance:10; http_client_body; within:10; "
2482  "content:\"four\"; distance:10; sid:1;)");
2483  FAIL_IF_NULL(s);
2484 
2485  result = 1;
2486 
2487  end:
2489  return result;
2490 }
2491 
2492 static int DetectHttpClientBodyTest28(void)
2493 {
2494  DetectEngineCtx *de_ctx = NULL;
2495  int result = 0;
2496 
2497  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2498  goto end;
2499 
2500  de_ctx->flags |= DE_QUIET;
2501  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2502  "(content:\"one\"; http_client_body; pcre:/two/; "
2503  "content:\"three\"; http_client_body; depth:10; "
2504  "content:\"four\"; distance:10; sid:1;)");
2505  if (de_ctx->sig_list == NULL) {
2506  printf("de_ctx->sig_list == NULL\n");
2507  goto end;
2508  }
2509 
2511  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] == NULL\n");
2512  goto end;
2513  }
2514 
2515  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2516  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2517  goto end;
2518  }
2519 
2520  DetectPcreData *pd1 =
2522  ->prev->ctx;
2523  DetectContentData *cd2 =
2525  ->ctx;
2526  DetectContentData *hcbd1 =
2527  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2528  ->prev->ctx;
2529  DetectContentData *hcbd2 =
2530  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2531  if (pd1->flags != (DETECT_PCRE_RELATIVE_NEXT) || cd2->flags != DETECT_CONTENT_DISTANCE ||
2532  memcmp(cd2->content, "four", cd2->content_len) != 0 || hcbd1->flags != 0 ||
2533  memcmp(hcbd1->content, "one", hcbd1->content_len) != 0 ||
2535  memcmp(hcbd2->content, "three", hcbd1->content_len) != 0) {
2536  goto end;
2537  }
2538 
2539  if (DETECT_CONTENT_IS_SINGLE(cd2) ||
2540  !DETECT_CONTENT_IS_SINGLE(hcbd1) ||
2541  DETECT_CONTENT_IS_SINGLE(hcbd2)) {
2542  goto end;
2543  }
2544 
2545  result = 1;
2546 
2547  end:
2549  return result;
2550 }
2551 
2552 static int DetectHttpClientBodyTest29(void)
2553 {
2554  DetectEngineCtx *de_ctx = NULL;
2555  int result = 0;
2556 
2557  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2558  goto end;
2559 
2560  de_ctx->flags |= DE_QUIET;
2561  Signature *s =
2562  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2563  "(content:\"one\"; http_client_body; "
2564  "content:\"two\"; distance:0; http_client_body; sid:1;)");
2565  if (de_ctx->sig_list == NULL) {
2566  printf("de_ctx->sig_list == NULL\n");
2567  goto end;
2568  }
2569 
2571  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2572  goto end;
2573  }
2574 
2575  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2576  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2577  goto end;
2578  }
2579 
2580  DetectContentData *hcbd1 =
2581  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2582  ->prev->ctx;
2583  DetectContentData *hcbd2 =
2584  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2586  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2588  FAIL_IF(memcmp(hcbd2->content, "two", hcbd1->content_len) != 0);
2589 
2590  result = 1;
2591 
2592  end:
2594  return result;
2595 }
2596 
2597 static int DetectHttpClientBodyTest30(void)
2598 {
2599  DetectEngineCtx *de_ctx = NULL;
2600  int result = 0;
2601 
2602  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2603  goto end;
2604 
2605  de_ctx->flags |= DE_QUIET;
2606  Signature *s =
2607  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2608  "(content:\"one\"; http_client_body; "
2609  "content:\"two\"; within:5; http_client_body; sid:1;)");
2610  if (de_ctx->sig_list == NULL) {
2611  printf("de_ctx->sig_list == NULL\n");
2612  goto end;
2613  }
2614 
2616  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2617  goto end;
2618  }
2619 
2620  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2621  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2622  goto end;
2623  }
2624 
2625  DetectContentData *hcbd1 =
2626  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2627  ->prev->ctx;
2628  DetectContentData *hcbd2 =
2629  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2631  FAIL_IF(memcmp(hcbd1->content, "one", hcbd1->content_len) != 0);
2632  FAIL_IF(hcbd2->flags != DETECT_CONTENT_WITHIN);
2633  FAIL_IF(memcmp(hcbd2->content, "two", hcbd1->content_len) != 0);
2634 
2635  result = 1;
2636 
2637  end:
2639  return result;
2640 }
2641 
2642 static int DetectHttpClientBodyTest31(void)
2643 {
2644  DetectEngineCtx *de_ctx = NULL;
2645  int result = 0;
2646 
2647  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2648  goto end;
2649 
2650  de_ctx->flags |= DE_QUIET;
2651  Signature *s =
2652  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2653  "(content:\"one\"; within:5; http_client_body; sid:1;)");
2654  FAIL_IF_NULL(s);
2655 
2656  result = 1;
2657 
2658  end:
2660  return result;
2661 }
2662 
2663 static int DetectHttpClientBodyTest32(void)
2664 {
2665  DetectEngineCtx *de_ctx = NULL;
2666  int result = 0;
2667 
2668  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2669  goto end;
2670 
2671  de_ctx->flags |= DE_QUIET;
2672  Signature *s =
2673  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2674  "(content:\"one\"; http_client_body; within:5; sid:1;)");
2675  FAIL_IF_NULL(s);
2676 
2677  result = 1;
2678 
2679  end:
2681  return result;
2682 }
2683 
2684 static int DetectHttpClientBodyTest33(void)
2685 {
2686  DetectEngineCtx *de_ctx = NULL;
2687  int result = 0;
2688 
2689  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2690  goto end;
2691 
2692  de_ctx->flags |= DE_QUIET;
2693  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2694  "(content:\"one\"; within:5; sid:1;)");
2695  FAIL_IF_NULL(s);
2696 
2697  result = 1;
2698 
2699  end:
2701  return result;
2702 }
2703 
2704 static int DetectHttpClientBodyTest34(void)
2705 {
2706  DetectEngineCtx *de_ctx = NULL;
2707  int result = 0;
2708 
2709  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2710  goto end;
2711 
2712  de_ctx->flags |= DE_QUIET;
2713  Signature *s =
2714  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2715  "(pcre:/one/P; "
2716  "content:\"two\"; within:5; http_client_body; sid:1;)");
2717  if (de_ctx->sig_list == NULL) {
2718  printf("de_ctx->sig_list == NULL\n");
2719  goto end;
2720  }
2721 
2723  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2724  goto end;
2725  }
2726 
2727  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2728  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2729  goto end;
2730  }
2731 
2732  if (DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id) == NULL ||
2733  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->type != DETECT_CONTENT ||
2734  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev == NULL ||
2735  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev->type !=
2736  DETECT_PCRE) {
2737 
2738  goto end;
2739  }
2740 
2741  DetectPcreData *pd1 =
2742  (DetectPcreData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2743  ->prev->ctx;
2744  DetectContentData *hcbd2 =
2745  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2748  FAIL_IF(memcmp(hcbd2->content, "two", hcbd2->content_len) != 0);
2749 
2750  result = 1;
2751 
2752  end:
2754  return result;
2755 }
2756 
2757 static int DetectHttpClientBodyTest35(void)
2758 {
2759  DetectEngineCtx *de_ctx = NULL;
2760  int result = 0;
2761 
2762  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2763  goto end;
2764 
2765  de_ctx->flags |= DE_QUIET;
2766  Signature *s = DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2767  "(content:\"two\"; http_client_body; "
2768  "pcre:/one/PR; sid:1;)");
2769  if (de_ctx->sig_list == NULL) {
2770  printf("de_ctx->sig_list == NULL\n");
2771  goto end;
2772  }
2773 
2775  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2776  goto end;
2777  }
2778 
2779  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2780  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2781  goto end;
2782  }
2783 
2784  if (DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id) == NULL ||
2785  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->type != DETECT_PCRE ||
2786  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev == NULL ||
2787  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev->type !=
2788  DETECT_CONTENT) {
2789 
2790  goto end;
2791  }
2792 
2793  DetectContentData *hcbd1 =
2794  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2795  ->prev->ctx;
2796  DetectPcreData *pd2 =
2797  (DetectPcreData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2798  FAIL_IF(pd2->flags != (DETECT_PCRE_RELATIVE));
2800  FAIL_IF(memcmp(hcbd1->content, "two", hcbd1->content_len) != 0);
2801 
2802  result = 1;
2803 
2804  end:
2806  return result;
2807 }
2808 
2809 static int DetectHttpClientBodyTest36(void)
2810 {
2811  DetectEngineCtx *de_ctx = NULL;
2812  int result = 0;
2813 
2814  if ( (de_ctx = DetectEngineCtxInit()) == NULL)
2815  goto end;
2816 
2817  de_ctx->flags |= DE_QUIET;
2818  Signature *s =
2819  DetectEngineAppendSig(de_ctx, "alert icmp any any -> any any "
2820  "(pcre:/one/P; "
2821  "content:\"two\"; distance:5; http_client_body; sid:1;)");
2822  if (de_ctx->sig_list == NULL) {
2823  printf("de_ctx->sig_list == NULL\n");
2824  goto end;
2825  }
2826 
2828  printf("de_ctx->sig_list->init_data->smlists[DETECT_SM_LIST_PMATCH] != NULL\n");
2829  goto end;
2830  }
2831 
2832  if (DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL) {
2833  printf("DetectBufferGetFirstSigMatch(s, g_http_client_body_buffer_id) == NULL\n");
2834  goto end;
2835  }
2836 
2837  if (DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id) == NULL ||
2838  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->type != DETECT_CONTENT ||
2839  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev == NULL ||
2840  DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->prev->type !=
2841  DETECT_PCRE) {
2842 
2843  goto end;
2844  }
2845 
2846  DetectPcreData *pd1 =
2847  (DetectPcreData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)
2848  ->prev->ctx;
2849  DetectContentData *hcbd2 =
2850  (DetectContentData *)DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id)->ctx;
2853  FAIL_IF(memcmp(hcbd2->content, "two", hcbd2->content_len) != 0);
2854 
2855  result = 1;
2856 
2857  end:
2859  return result;
2860 }
2861 
2862 static int DetectHttpClientBodyIsdataatParseTest(void)
2863 {
2866  de_ctx->flags |= DE_QUIET;
2867 
2869  "alert tcp any any -> any any ("
2870  "content:\"one\"; http_client_body; "
2871  "isdataat:!4,relative; sid:1;)");
2872  FAIL_IF_NULL(s);
2873 
2874  SigMatch *sm = DetectBufferGetLastSigMatch(s, g_http_client_body_buffer_id);
2875  FAIL_IF_NULL(sm);
2877 
2878  DetectIsdataatData *data = (DetectIsdataatData *)sm->ctx;
2881  FAIL_IF(data->flags & ISDATAAT_RAWBYTES);
2882 
2884  PASS;
2885 }
2886 
2888 {
2889  UtRegisterTest("DetectHttpClientBodyParserTest01", DetectHttpClientBodyParserTest01);
2890  UtRegisterTest("DetectHttpClientBodyParserTest02", DetectHttpClientBodyParserTest02);
2891  UtRegisterTest("DetectHttpClientBodyTest01", DetectHttpClientBodyTest01);
2892  UtRegisterTest("DetectHttpClientBodyTest02", DetectHttpClientBodyTest02);
2893  UtRegisterTest("DetectHttpClientBodyTest03", DetectHttpClientBodyTest03);
2894  UtRegisterTest("DetectHttpClientBodyTest05", DetectHttpClientBodyTest05);
2895  UtRegisterTest("DetectHttpClientBodyTest06", DetectHttpClientBodyTest06);
2896  UtRegisterTest("DetectHttpClientBodyTest07", DetectHttpClientBodyTest07);
2897  UtRegisterTest("DetectHttpClientBodyTest08", DetectHttpClientBodyTest08);
2898  UtRegisterTest("DetectHttpClientBodyTest09", DetectHttpClientBodyTest09);
2899  UtRegisterTest("DetectHttpClientBodyTest10", DetectHttpClientBodyTest10);
2900  UtRegisterTest("DetectHttpClientBodyTest11", DetectHttpClientBodyTest11);
2901  UtRegisterTest("DetectHttpClientBodyTest12", DetectHttpClientBodyTest12);
2902  UtRegisterTest("DetectHttpClientBodyTest13", DetectHttpClientBodyTest13);
2903  UtRegisterTest("DetectHttpClientBodyTest14", DetectHttpClientBodyTest14);
2904  UtRegisterTest("DetectHttpClientBodyTest15", DetectHttpClientBodyTest15);
2905 
2906  UtRegisterTest("DetectHttpClientBodyTest22", DetectHttpClientBodyTest22);
2907  UtRegisterTest("DetectHttpClientBodyTest23", DetectHttpClientBodyTest23);
2908  UtRegisterTest("DetectHttpClientBodyTest24", DetectHttpClientBodyTest24);
2909  UtRegisterTest("DetectHttpClientBodyTest25", DetectHttpClientBodyTest25);
2910  UtRegisterTest("DetectHttpClientBodyTest26", DetectHttpClientBodyTest26);
2911  UtRegisterTest("DetectHttpClientBodyTest27", DetectHttpClientBodyTest27);
2912  UtRegisterTest("DetectHttpClientBodyTest28", DetectHttpClientBodyTest28);
2913  UtRegisterTest("DetectHttpClientBodyTest29", DetectHttpClientBodyTest29);
2914  UtRegisterTest("DetectHttpClientBodyTest30", DetectHttpClientBodyTest30);
2915  UtRegisterTest("DetectHttpClientBodyTest31", DetectHttpClientBodyTest31);
2916  UtRegisterTest("DetectHttpClientBodyTest32", DetectHttpClientBodyTest32);
2917  UtRegisterTest("DetectHttpClientBodyTest33", DetectHttpClientBodyTest33);
2918  UtRegisterTest("DetectHttpClientBodyTest34", DetectHttpClientBodyTest34);
2919  UtRegisterTest("DetectHttpClientBodyTest35", DetectHttpClientBodyTest35);
2920  UtRegisterTest("DetectHttpClientBodyTest36", DetectHttpClientBodyTest36);
2921 
2922  UtRegisterTest("DetectHttpClientBodyIsdataatParseTest",
2923  DetectHttpClientBodyIsdataatParseTest);
2924 
2925  UtRegisterTest("DetectEngineHttpClientBodyTest01",
2926  DetectEngineHttpClientBodyTest01);
2927  UtRegisterTest("DetectEngineHttpClientBodyTest02",
2928  DetectEngineHttpClientBodyTest02);
2929  UtRegisterTest("DetectEngineHttpClientBodyTest03",
2930  DetectEngineHttpClientBodyTest03);
2931  UtRegisterTest("DetectEngineHttpClientBodyTest04",
2932  DetectEngineHttpClientBodyTest04);
2933  UtRegisterTest("DetectEngineHttpClientBodyTest05",
2934  DetectEngineHttpClientBodyTest05);
2935  UtRegisterTest("DetectEngineHttpClientBodyTest06",
2936  DetectEngineHttpClientBodyTest06);
2937  UtRegisterTest("DetectEngineHttpClientBodyTest07",
2938  DetectEngineHttpClientBodyTest07);
2939  UtRegisterTest("DetectEngineHttpClientBodyTest08",
2940  DetectEngineHttpClientBodyTest08);
2941  UtRegisterTest("DetectEngineHttpClientBodyTest09",
2942  DetectEngineHttpClientBodyTest09);
2943  UtRegisterTest("DetectEngineHttpClientBodyTest10",
2944  DetectEngineHttpClientBodyTest10);
2945  UtRegisterTest("DetectEngineHttpClientBodyTest11",
2946  DetectEngineHttpClientBodyTest11);
2947  UtRegisterTest("DetectEngineHttpClientBodyTest12",
2948  DetectEngineHttpClientBodyTest12);
2949  UtRegisterTest("DetectEngineHttpClientBodyTest13",
2950  DetectEngineHttpClientBodyTest13);
2951  UtRegisterTest("DetectEngineHttpClientBodyTest14",
2952  DetectEngineHttpClientBodyTest14);
2953  UtRegisterTest("DetectEngineHttpClientBodyTest15",
2954  DetectEngineHttpClientBodyTest15);
2955  UtRegisterTest("DetectEngineHttpClientBodyTest16",
2956  DetectEngineHttpClientBodyTest16);
2957  UtRegisterTest("DetectEngineHttpClientBodyTest17",
2958  DetectEngineHttpClientBodyTest17);
2959  UtRegisterTest("DetectEngineHttpClientBodyTest18",
2960  DetectEngineHttpClientBodyTest18);
2961  UtRegisterTest("DetectEngineHttpClientBodyTest19",
2962  DetectEngineHttpClientBodyTest19);
2963  UtRegisterTest("DetectEngineHttpClientBodyTest20",
2964  DetectEngineHttpClientBodyTest20);
2965  UtRegisterTest("DetectEngineHttpClientBodyTest21",
2966  DetectEngineHttpClientBodyTest21);
2967  UtRegisterTest("DetectEngineHttpClientBodyTest22",
2968  DetectEngineHttpClientBodyTest22);
2969  UtRegisterTest("DetectEngineHttpClientBodyTest23",
2970  DetectEngineHttpClientBodyTest23);
2971  UtRegisterTest("DetectEngineHttpClientBodyTest24",
2972  DetectEngineHttpClientBodyTest24);
2973  UtRegisterTest("DetectEngineHttpClientBodyTest25",
2974  DetectEngineHttpClientBodyTest25);
2975  UtRegisterTest("DetectEngineHttpClientBodyTest26",
2976  DetectEngineHttpClientBodyTest26);
2977  UtRegisterTest("DetectEngineHttpClientBodyTest27",
2978  DetectEngineHttpClientBodyTest27);
2979  UtRegisterTest("DetectEngineHttpClientBodyTest28",
2980  DetectEngineHttpClientBodyTest28);
2981  UtRegisterTest("DetectEngineHttpClientBodyTest29",
2982  DetectEngineHttpClientBodyTest29);
2983 
2984  UtRegisterTest("DetectEngineHttpClientBodyTest30",
2985  DetectEngineHttpClientBodyTest30);
2986  UtRegisterTest("DetectEngineHttpClientBodyTest31",
2987  DetectEngineHttpClientBodyTest31);
2988 }
2989 
2990 #endif
2991 
2992 /**
2993  * @}
2994  */
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:913
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:2887
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:932
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:2416
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:3439
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:1244
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
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:3596
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:941
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:934
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
StatsThreadCleanup
void StatsThreadCleanup(ThreadVars *tv)
Definition: counters.c:1324
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