suricata
detect-engine-state.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  * \defgroup sigstate State support
20  *
21  * State is stored in the ::DetectEngineState structure. This is
22  * basically a container for storage item of type ::DeStateStore.
23  * They contains an array of ::DeStateStoreItem which store the
24  * state of match for an individual signature identified by
25  * DeStateStoreItem::sid.
26  *
27  * @{
28  */
29 
30 /**
31  * \file
32  *
33  * \author Victor Julien <victor@inliniac.net>
34  * \author Anoop Saldanha <anoopsaldanha@gmail.com>
35  *
36  * \brief State based signature handling.
37  */
38 
39 #include "suricata-common.h"
40 
41 #include "decode.h"
42 
43 #include "detect.h"
44 #include "detect-engine.h"
45 #include "detect-parse.h"
46 #include "detect-engine-state.h"
47 #include "detect-engine-build.h"
48 
49 #include "detect-flowvar.h"
50 
51 #include "stream-tcp.h"
52 #include "stream-tcp-private.h"
53 #include "stream-tcp-reassemble.h"
54 
55 #include "app-layer.h"
56 #include "app-layer-parser.h"
57 #include "app-layer-protos.h"
58 #include "app-layer-htp.h"
59 
60 #include "util-unittest-helper.h"
61 #include "util-profiling.h"
62 
63 #include "flow-util.h"
64 
65 static inline int StateIsValid(uint16_t alproto, void *alstate)
66 {
67  if (alstate != NULL) {
68  if (alproto == ALPROTO_HTTP1) {
69  HtpState *htp_state = (HtpState *)alstate;
70  if (htp_state->conn != NULL) {
71  return 1;
72  }
73  } else {
74  return 1;
75  }
76  }
77  return 0;
78 }
79 
80 static DeStateStore *DeStateStoreAlloc(void)
81 {
82  DeStateStore *d = SCCalloc(1, sizeof(DeStateStore));
83  if (unlikely(d == NULL))
84  return NULL;
85 
86  return d;
87 }
88 
89 #ifdef DEBUG_VALIDATION
90 static int DeStateSearchState(DetectEngineState *state, uint8_t direction, SigIntId num)
91 {
92  DetectEngineStateDirection *dir_state = &state->dir_state[direction & STREAM_TOSERVER ? 0 : 1];
93  DeStateStore *tx_store = dir_state->head;
94  SigIntId store_cnt;
95  SigIntId state_cnt = 0;
96 
97  for (; tx_store != NULL; tx_store = tx_store->next) {
98  SCLogDebug("tx_store %p", tx_store);
99  for (store_cnt = 0;
100  store_cnt < DE_STATE_CHUNK_SIZE && state_cnt < dir_state->cnt;
101  store_cnt++, state_cnt++)
102  {
103  DeStateStoreItem *item = &tx_store->store[store_cnt];
104  if (item->sid == num) {
105  SCLogDebug("sid %u already in state: %p %p %p %u %u, direction %s",
106  num, state, dir_state, tx_store, state_cnt,
107  store_cnt, direction & STREAM_TOSERVER ? "toserver" : "toclient");
108  return 1;
109  }
110  }
111  }
112  return 0;
113 }
114 #endif
115 
116 static void DeStateSignatureAppend(DetectEngineState *state,
117  const Signature *s, uint32_t inspect_flags, uint8_t direction)
118 {
119  SCEnter();
120 
121  DetectEngineStateDirection *dir_state =
122  &state->dir_state[(direction & STREAM_TOSERVER) ? 0 : 1];
123 
124 #ifdef DEBUG_VALIDATION
125  BUG_ON(DeStateSearchState(state, direction, s->iid));
126 #endif
127  DeStateStore *store = dir_state->tail;
128  if (store == NULL) {
129  store = DeStateStoreAlloc();
130  dir_state->head = store;
131  dir_state->cur = store;
132  dir_state->tail = store;
133  } else if (dir_state->cur) {
134  store = dir_state->cur;
135  } else {
136  store = DeStateStoreAlloc();
137  if (store != NULL) {
138  dir_state->tail->next = store;
139  dir_state->tail = store;
140  dir_state->cur = store;
141  }
142  }
143  if (store == NULL)
144  SCReturn;
145 
146  SigIntId idx = dir_state->cnt % DE_STATE_CHUNK_SIZE;
147  store->store[idx].sid = s->iid;
148  store->store[idx].flags = inspect_flags;
149  dir_state->cnt++;
150  /* if current chunk is full, progress cur */
151  if (dir_state->cnt % DE_STATE_CHUNK_SIZE == 0) {
152  dir_state->cur = dir_state->cur->next;
153  }
154 
155  SCReturn;
156 }
157 
159 {
161  if (unlikely(d == NULL))
162  return NULL;
163 
164  return d;
165 }
166 
168 {
169  DeStateStore *store;
170  DeStateStore *store_next;
171  int i = 0;
172 
173  for (i = 0; i < 2; i++) {
174  store = state->dir_state[i].head;
175  while (store != NULL) {
176  store_next = store->next;
177  SCFree(store);
178  store = store_next;
179  }
180  }
181  SCFree(state);
182 }
183 
184 static void StoreFileNoMatchCnt(DetectEngineState *de_state, uint16_t file_no_match, uint8_t direction)
185 {
186  de_state->dir_state[(direction & STREAM_TOSERVER) ? 0 : 1].filestore_cnt += file_no_match;
187 }
188 
189 static bool StoreFilestoreSigsCantMatch(const SigGroupHead *sgh, const DetectEngineState *de_state, uint8_t direction)
190 {
191  if (de_state->dir_state[(direction & STREAM_TOSERVER) ? 0 : 1].filestore_cnt ==
192  sgh->filestore_cnt)
193  return true;
194  else
195  return false;
196 }
197 
198 static void StoreStateTxHandleFiles(const SigGroupHead *sgh, Flow *f, DetectEngineState *destate,
199  const uint8_t flow_flags, void *tx, const uint64_t tx_id, const uint16_t file_no_match)
200 {
201  SCLogDebug("tx %"PRIu64", file_no_match %u", tx_id, file_no_match);
202  StoreFileNoMatchCnt(destate, file_no_match, flow_flags);
203  if (StoreFilestoreSigsCantMatch(sgh, destate, flow_flags)) {
204  SCLogDebug("filestore sigs can't match");
206  f, flow_flags & (STREAM_TOCLIENT | STREAM_TOSERVER), tx, tx_id);
207  } else {
208  SCLogDebug("filestore sigs can still match");
209  }
210 }
211 
213  const SigGroupHead *sgh,
214  Flow *f, void *tx, uint64_t tx_id,
215  const Signature *s,
216  uint32_t inspect_flags, uint8_t flow_flags,
217  const uint16_t file_no_match)
218 {
220  if (tx_data->de_state == NULL) {
221  tx_data->de_state = DetectEngineStateAlloc();
222  if (tx_data->de_state == NULL)
223  return;
224  SCLogDebug("destate created for %"PRIu64, tx_id);
225  }
226  DeStateSignatureAppend(tx_data->de_state, s, inspect_flags, flow_flags);
227  if (s->flags & SIG_FLAG_TXBOTHDIR) {
228  // add also in the other DetectEngineStateDirection
229  DeStateSignatureAppend(tx_data->de_state, s, inspect_flags,
230  flow_flags ^ (STREAM_TOSERVER | STREAM_TOCLIENT));
231  }
232  StoreStateTxHandleFiles(sgh, f, tx_data->de_state, flow_flags, tx, tx_id, file_no_match);
233 
234  SCLogDebug("Stored for TX %"PRIu64, tx_id);
235 }
236 
237 static inline void ResetTxState(DetectEngineState *s)
238 {
239  if (s) {
240  s->dir_state[0].cnt = 0;
241  s->dir_state[0].filestore_cnt = 0;
242  s->dir_state[0].flags = 0;
243  /* reset 'cur' back to the list head */
244  s->dir_state[0].cur = s->dir_state[0].head;
245 
246  s->dir_state[1].cnt = 0;
247  s->dir_state[1].filestore_cnt = 0;
248  s->dir_state[1].flags = 0;
249  /* reset 'cur' back to the list head */
250  s->dir_state[1].cur = s->dir_state[1].head;
251  }
252 }
253 
254 /** \brief Reset de state for active tx'
255  * To be used on detect engine reload.
256  * \param f write LOCKED flow
257  */
259 {
260  void *alstate = FlowGetAppState(f);
261  if (!StateIsValid(f->alproto, alstate)) {
262  return;
263  }
264 
265  uint64_t inspect_ts = AppLayerParserGetTransactionInspectId(f->alparser, STREAM_TOCLIENT);
266  uint64_t inspect_tc = AppLayerParserGetTransactionInspectId(f->alparser, STREAM_TOSERVER);
267 
268  uint64_t inspect_tx_id = MIN(inspect_ts, inspect_tc);
269 
270  uint64_t total_txs = AppLayerParserGetTxCnt(f, alstate);
271 
272  for ( ; inspect_tx_id < total_txs; inspect_tx_id++) {
273  void *inspect_tx = AppLayerParserGetTx(f->proto, f->alproto, alstate, inspect_tx_id);
274  if (inspect_tx != NULL) {
275  AppLayerTxData *txd = AppLayerParserGetTxData(f->proto, f->alproto, inspect_tx);
276  ResetTxState(txd->de_state);
277  }
278  }
279 }
280 
281 /*********Unittests*********/
282 
283 #ifdef UNITTESTS
284 #include "detect-engine-alert.h"
285 
286 static int DeStateTest01(void)
287 {
288  SCLogDebug("sizeof(DetectEngineState)\t\t%"PRIuMAX,
289  (uintmax_t)sizeof(DetectEngineState));
290  SCLogDebug("sizeof(DeStateStore)\t\t\t%"PRIuMAX,
291  (uintmax_t)sizeof(DeStateStore));
292  SCLogDebug("sizeof(DeStateStoreItem)\t\t%"PRIuMAX"",
293  (uintmax_t)sizeof(DeStateStoreItem));
294 
295  return 1;
296 }
297 
298 static int DeStateTest02(void)
299 {
300  uint8_t direction = STREAM_TOSERVER;
302  FAIL_IF_NULL(state);
303  FAIL_IF_NOT_NULL(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head);
304 
305  Signature s;
306  memset(&s, 0x00, sizeof(s));
307 
308  s.iid = 0;
309  DeStateSignatureAppend(state, &s, 0, direction);
310  s.iid = 11;
311  DeStateSignatureAppend(state, &s, 0, direction);
312  s.iid = 22;
313  DeStateSignatureAppend(state, &s, 0, direction);
314  s.iid = 33;
315  DeStateSignatureAppend(state, &s, 0, direction);
316  s.iid = 44;
317  DeStateSignatureAppend(state, &s, 0, direction);
318  s.iid = 55;
319  DeStateSignatureAppend(state, &s, 0, direction);
320  s.iid = 66;
321  DeStateSignatureAppend(state, &s, 0, direction);
322  s.iid = 77;
323  DeStateSignatureAppend(state, &s, 0, direction);
324  s.iid = 88;
325  DeStateSignatureAppend(state, &s, 0, direction);
326  s.iid = 99;
327  DeStateSignatureAppend(state, &s, 0, direction);
328  s.iid = 100;
329  DeStateSignatureAppend(state, &s, 0, direction);
330  s.iid = 111;
331  DeStateSignatureAppend(state, &s, 0, direction);
332  s.iid = 122;
333  DeStateSignatureAppend(state, &s, 0, direction);
334  s.iid = 133;
335  DeStateSignatureAppend(state, &s, 0, direction);
336  FAIL_IF_NOT(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head ==
337  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
338 
339  s.iid = 144;
340  DeStateSignatureAppend(state, &s, 0, direction);
341 
342  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[14].sid != 144);
343  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head ==
344  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
345  FAIL_IF_NOT(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur == NULL);
346 
347  s.iid = 155;
348  DeStateSignatureAppend(state, &s, 0, direction);
349 
350  FAIL_IF_NOT(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].tail ==
351  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
352 
353  s.iid = 166;
354  DeStateSignatureAppend(state, &s, 0, direction);
355 
356  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head == NULL);
357  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[1].sid != 11);
358  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next == NULL);
359  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[14].sid != 144);
360  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next->store[0].sid != 155);
361  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next->store[1].sid != 166);
362 
363  ResetTxState(state);
364 
365  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head == NULL);
366  FAIL_IF_NOT(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head ==
367  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
368 
369  s.iid = 0;
370  DeStateSignatureAppend(state, &s, 0, direction);
371  s.iid = 11;
372  DeStateSignatureAppend(state, &s, 0, direction);
373  s.iid = 22;
374  DeStateSignatureAppend(state, &s, 0, direction);
375  s.iid = 33;
376  DeStateSignatureAppend(state, &s, 0, direction);
377  s.iid = 44;
378  DeStateSignatureAppend(state, &s, 0, direction);
379  s.iid = 55;
380  DeStateSignatureAppend(state, &s, 0, direction);
381  s.iid = 66;
382  DeStateSignatureAppend(state, &s, 0, direction);
383  s.iid = 77;
384  DeStateSignatureAppend(state, &s, 0, direction);
385  s.iid = 88;
386  DeStateSignatureAppend(state, &s, 0, direction);
387  s.iid = 99;
388  DeStateSignatureAppend(state, &s, 0, direction);
389  s.iid = 100;
390  DeStateSignatureAppend(state, &s, 0, direction);
391  s.iid = 111;
392  DeStateSignatureAppend(state, &s, 0, direction);
393  s.iid = 122;
394  DeStateSignatureAppend(state, &s, 0, direction);
395  s.iid = 133;
396  DeStateSignatureAppend(state, &s, 0, direction);
397  FAIL_IF_NOT(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head ==
398  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
399  s.iid = 144;
400  DeStateSignatureAppend(state, &s, 0, direction);
401  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[14].sid != 144);
402  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head ==
403  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
404  FAIL_IF_NOT(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].tail ==
405  state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].cur);
406  s.iid = 155;
407  DeStateSignatureAppend(state, &s, 0, direction);
408  s.iid = 166;
409  DeStateSignatureAppend(state, &s, 0, direction);
410 
411  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head == NULL);
412  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[1].sid != 11);
413  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next == NULL);
414  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[14].sid != 144);
415  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next->store[0].sid != 155);
416  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->next->store[1].sid != 166);
417 
419 
420  PASS;
421 }
422 
423 static int DeStateTest03(void)
424 {
426  FAIL_IF_NULL(state);
427 
428  Signature s;
429  memset(&s, 0x00, sizeof(s));
430 
431  uint8_t direction = STREAM_TOSERVER;
432 
433  s.iid = 11;
434  DeStateSignatureAppend(state, &s, 0, direction);
435  s.iid = 22;
436  DeStateSignatureAppend(state, &s, BIT_U32(DE_STATE_FLAG_BASE), direction);
437 
438  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head == NULL);
439  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[0].sid != 11);
440  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[0].flags & BIT_U32(DE_STATE_FLAG_BASE));
441  FAIL_IF(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[1].sid != 22);
442  FAIL_IF(!(state->dir_state[direction & STREAM_TOSERVER ? 0 : 1].head->store[1].flags & BIT_U32(DE_STATE_FLAG_BASE)));
443 
445  PASS;
446 }
447 
448 static int DeStateSigTest01(void)
449 {
450  DetectEngineThreadCtx *det_ctx = NULL;
452  Flow f;
453  TcpSession ssn;
454  Packet *p = NULL;
455  uint8_t httpbuf1[] = "POST / HTTP/1.0\r\n";
456  uint8_t httpbuf2[] = "User-Agent: Mozilla/1.0\r\n";
457  uint8_t httpbuf3[] = "Cookie: dummy\r\nContent-Length: 10\r\n\r\n";
458  uint8_t httpbuf4[] = "Http Body!";
459  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
460  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
461  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
462  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
463 
466 
467  memset(&th_v, 0, sizeof(th_v));
469  memset(&f, 0, sizeof(f));
470  memset(&ssn, 0, sizeof(ssn));
471 
472  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
473  FAIL_IF_NULL(p);
474 
475  FLOW_INITIALIZE(&f);
476  f.protoctx = (void *)&ssn;
477  f.proto = IPPROTO_TCP;
478  f.flags |= FLOW_IPV4;
480 
481  p->flow = &f;
485 
486  StreamTcpInitConfig(true);
487 
490  de_ctx->flags |= DE_QUIET;
491 
492  Signature *s = de_ctx->sig_list = SigInit(de_ctx, "alert tcp any any -> any any (content:\"POST\"; http_method; content:\"dummy\"; http_cookie; sid:1; rev:1;)");
493  FAIL_IF_NULL(s);
494 
496  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
497  FAIL_IF_NULL(det_ctx);
498 
499  int r = AppLayerParserParse(
500  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf1, httplen1);
501  FAIL_IF_NOT(r == 0);
502  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
504 
505  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
506  FAIL_IF_NOT(r == 0);
507  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
509 
510  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
511  FAIL_IF_NOT(r == 0);
512  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
514 
515  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf4, httplen4);
516  FAIL_IF_NOT(r == 0);
517  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
519 
520  UTHFreePacket(p);
521  FLOW_DESTROY(&f);
523  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
525  StreamTcpFreeConfig(true);
527  PASS;
528 }
529 
530 /** \test multiple pipelined http transactions */
531 static int DeStateSigTest02(void)
532 {
533  DetectEngineThreadCtx *det_ctx = NULL;
535  Flow f;
536  TcpSession ssn;
537  Packet *p = NULL;
538  uint8_t httpbuf1[] = "POST / HTTP/1.1\r\n";
539  uint8_t httpbuf2[] = "User-Agent: Mozilla/1.0\r\nContent-Length: 10\r\n";
540  uint8_t httpbuf3[] = "Cookie: dummy\r\n\r\n";
541  uint8_t httpbuf4[] = "Http Body!";
542  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
543  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
544  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
545  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
546  uint8_t httpbuf5[] = "GET /?var=val HTTP/1.1\r\n";
547  uint8_t httpbuf6[] = "User-Agent: Firefox/1.0\r\n";
548  uint8_t httpbuf7[] = "Cookie: dummy2\r\nContent-Length: 10\r\n\r\nHttp Body!";
549  uint32_t httplen5 = sizeof(httpbuf5) - 1; /* minus the \0 */
550  uint32_t httplen6 = sizeof(httpbuf6) - 1; /* minus the \0 */
551  uint32_t httplen7 = sizeof(httpbuf7) - 1; /* minus the \0 */
554 
555  memset(&th_v, 0, sizeof(th_v));
557  memset(&f, 0, sizeof(f));
558  memset(&ssn, 0, sizeof(ssn));
559 
560  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
561 
562  FLOW_INITIALIZE(&f);
563  f.protoctx = (void *)&ssn;
564  f.proto = IPPROTO_TCP;
565  f.flags |= FLOW_IPV4;
566 
567  p->flow = &f;
572 
573  StreamTcpInitConfig(true);
574 
577 
578  de_ctx->flags |= DE_QUIET;
579 
580  Signature *s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (flow:to_server; content:\"POST\"; http_method; content:\"/\"; http_uri; content:\"Mozilla\"; http_header; content:\"dummy\"; http_cookie; content:\"body\"; nocase; http_client_body; sid:1; rev:1;)");
581  FAIL_IF_NULL(s);
582  s = DetectEngineAppendSig(de_ctx, "alert tcp any any -> any any (flow:to_server; content:\"GET\"; http_method; content:\"Firefox\"; http_header; content:\"dummy2\"; http_cookie; sid:2; rev:1;)");
583  FAIL_IF_NULL(s);
584 
586  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
587  FAIL_IF_NULL(det_ctx);
588 
589  int r = AppLayerParserParse(
590  NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf1, httplen1);
591  FAIL_IF(r != 0);
592  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
594 
595  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
596  FAIL_IF(r != 0);
597  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
599 
600  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
601  FAIL_IF(r != 0);
602  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
604 
605  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f.alstate, 0);
606  FAIL_IF_NULL(tx);
607 
608  AppLayerTxData *tx_data = AppLayerParserGetTxData(IPPROTO_TCP, ALPROTO_HTTP1, tx);
609  FAIL_IF_NULL(tx_data);
610  DetectEngineState *tx_de_state = tx_data->de_state;
611  FAIL_IF_NULL(tx_de_state);
612  FAIL_IF(tx_de_state->dir_state[0].cnt != 1);
613  /* http_header(mpm): 5, uri: 3, method: 6, cookie: 7 */
614  uint32_t expected_flags = (BIT_U32(5) | BIT_U32(3) | BIT_U32(6) | BIT_U32(4));
615  FAIL_IF(tx_de_state->dir_state[0].head->store[0].flags != expected_flags);
616 
617  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf4, httplen4);
618  FAIL_IF(r != 0);
619  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
620  FAIL_IF(!(PacketAlertCheck(p, 1)));
621 
622  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf5, httplen5);
623  FAIL_IF(r != 0);
624  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
626 
627  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf6, httplen6);
628  FAIL_IF(r != 0);
629  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
630  FAIL_IF((PacketAlertCheck(p, 1)) || (PacketAlertCheck(p, 2)));
631 
632  r = AppLayerParserParse(NULL, alp_tctx, &f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf7, httplen7);
633  FAIL_IF(r != 0);
634  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
635  FAIL_IF(!(PacketAlertCheck(p, 2)));
636 
637  UTHFreePacket(p);
638  FLOW_DESTROY(&f);
640  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
642  StreamTcpFreeConfig(true);
644  PASS;
645 }
646 
647 static int DeStateSigTest03(void)
648 {
649  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
650  "Host: www.server.lan\r\n"
651  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
652  "Content-Length: 215\r\n"
653  "\r\n"
654  "-----------------------------277531038314945\r\n"
655  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
656  "Content-Type: image/jpeg\r\n"
657  "\r\n"
658  "filecontent\r\n"
659  "-----------------------------277531038314945--";
660  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
662  TcpSession ssn;
663  Flow *f = NULL;
664  Packet *p = NULL;
667 
668  memset(&th_v, 0, sizeof(th_v));
670  memset(&ssn, 0, sizeof(ssn));
671 
672  DetectEngineThreadCtx *det_ctx = NULL;
675 
676  de_ctx->flags |= DE_QUIET;
677 
678  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (flow:to_server; content:\"POST\"; http_method; content:\"upload.cgi\"; http_uri; filestore; sid:1; rev:1;)");
679  FAIL_IF_NULL(s);
680 
682  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
683 
684  f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
685  FAIL_IF_NULL(f);
686  f->protoctx = &ssn;
687  f->proto = IPPROTO_TCP;
689 
690  p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
691  FAIL_IF_NULL(p);
692 
693  p->flow = f;
697 
698  StreamTcpInitConfig(true);
699 
701  STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
702  FAIL_IF(r != 0);
703 
704  HtpState *http_state = f->alstate;
705  FAIL_IF_NULL(http_state);
706  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
707  FAIL_IF_NULL(tx);
708  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
709  FAIL_IF_NULL(tx_ud);
710 
711  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
712  FAIL_IF(!(PacketAlertCheck(p, 1)));
713 
714  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
715  FileContainer *fc = files.fc;
716  FAIL_IF_NULL(fc);
717 
718  File *file = fc->head;
719  FAIL_IF_NULL(file);
720 
721  FAIL_IF(!(file->flags & FILE_STORE));
722 
723  UTHFreePacket(p);
724  UTHFreeFlow(f);
725 
727  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
729  StreamTcpFreeConfig(true);
731  PASS;
732 }
733 
734 static int DeStateSigTest04(void)
735 {
736  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
737  "Host: www.server.lan\r\n"
738  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
739  "Content-Length: 215\r\n"
740  "\r\n"
741  "-----------------------------277531038314945\r\n"
742  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
743  "Content-Type: image/jpeg\r\n"
744  "\r\n"
745  "filecontent\r\n"
746  "-----------------------------277531038314945--";
747  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
749  TcpSession ssn;
752 
753  memset(&th_v, 0, sizeof(th_v));
755  memset(&ssn, 0, sizeof(ssn));
756 
757  DetectEngineThreadCtx *det_ctx = NULL;
760  de_ctx->flags |= DE_QUIET;
761 
762  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (content:\"GET\"; http_method; content:\"upload.cgi\"; http_uri; filestore; sid:1; rev:1;)");
763  FAIL_IF_NULL(s);
764 
766  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
767  FAIL_IF_NULL(det_ctx);
768 
769  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
770  FAIL_IF_NULL(f);
771  f->protoctx = &ssn;
772  f->proto = IPPROTO_TCP;
774 
775  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
776  FAIL_IF_NULL(p);
777  p->flow = f;
781 
782  StreamTcpInitConfig(true);
783 
785  STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
786  FAIL_IF(r != 0);
787  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
789 
790  HtpState *http_state = f->alstate;
791  FAIL_IF_NULL(http_state);
792  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
793  FAIL_IF_NULL(tx);
794  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
795  FAIL_IF_NULL(tx_ud);
796 
797  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
798  FileContainer *fc = files.fc;
799  FAIL_IF_NULL(fc);
800  File *file = fc->head;
801  FAIL_IF_NULL(file);
802 
803  FAIL_IF(file->flags & FILE_STORE);
804 
805  UTHFreePacket(p);
806  UTHFreeFlow(f);
808  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
810  StreamTcpFreeConfig(true);
812  PASS;
813 }
814 
815 static int DeStateSigTest05(void)
816 {
817  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
818  "Host: www.server.lan\r\n"
819  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
820  "Content-Length: 215\r\n"
821  "\r\n"
822  "-----------------------------277531038314945\r\n"
823  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
824  "Content-Type: image/jpeg\r\n"
825  "\r\n"
826  "filecontent\r\n"
827  "-----------------------------277531038314945--";
828  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
830  TcpSession ssn;
831 
834 
835  memset(&th_v, 0, sizeof(th_v));
837  memset(&ssn, 0, sizeof(ssn));
838 
839  DetectEngineThreadCtx *det_ctx = NULL;
842  de_ctx->flags |= DE_QUIET;
843 
844  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (content:\"GET\"; http_method; content:\"upload.cgi\"; http_uri; filename:\"nomatch\"; sid:1; rev:1;)");
845  FAIL_IF_NULL(s);
846 
848  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
849 
850  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
851  FAIL_IF_NULL(f);
852  f->protoctx = &ssn;
853  f->proto = IPPROTO_TCP;
855 
856  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
857  FAIL_IF_NULL(p);
858  p->flow = f;
862 
863  StreamTcpInitConfig(true);
864 
866  STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
867  FAIL_IF_NOT(r == 0);
868  HtpState *http_state = f->alstate;
869  FAIL_IF_NULL(http_state);
870  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
871  FAIL_IF_NULL(tx);
872  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
873  FAIL_IF_NULL(tx_ud);
874 
875  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
876  FileContainer *fc = files.fc;
877  FAIL_IF_NULL(fc);
878  File *file = fc->head;
879  FAIL_IF_NULL(file);
880  FAIL_IF(http_state->state_data.file_flags & FLOWFILE_NO_STORE_TS);
881 
882  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
884 
885  /* detect will have set FLOWFILE_NO_STORE_TS, but it won't have had
886  * an opportunity to be applied to the file itself yet */
887  FAIL_IF_NOT(http_state->state_data.file_flags & FLOWFILE_NO_STORE_TS);
888  FAIL_IF(file->flags & FILE_NOSTORE);
889 
890  UTHFreePacket(p);
891  UTHFreeFlow(f);
893  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
895  StreamTcpFreeConfig(true);
897  PASS;
898 }
899 
900 static int DeStateSigTest06(void)
901 {
902  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
903  "Host: www.server.lan\r\n"
904  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
905  "Content-Length: 215\r\n"
906  "\r\n"
907  "-----------------------------277531038314945\r\n"
908  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
909  "Content-Type: image/jpeg\r\n"
910  "\r\n"
911  "filecontent\r\n"
912  "-----------------------------277531038314945--";
913  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
915  TcpSession ssn;
916 
919 
920  memset(&th_v, 0, sizeof(th_v));
922  memset(&ssn, 0, sizeof(ssn));
923 
924  DetectEngineThreadCtx *det_ctx = NULL;
927  de_ctx->flags |= DE_QUIET;
928 
929  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (content:\"POST\"; http_method; content:\"upload.cgi\"; http_uri; filename:\"nomatch\"; filestore; sid:1; rev:1;)");
930  FAIL_IF_NULL(s);
931 
933  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
934  FAIL_IF_NULL(det_ctx);
935 
936  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
937  FAIL_IF_NULL(f);
938  f->protoctx = &ssn;
939  f->proto = IPPROTO_TCP;
941 
942  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
943  FAIL_IF_NULL(p);
944  p->flow = f;
948 
949  StreamTcpInitConfig(true);
950 
952  STREAM_TOSERVER | STREAM_START | STREAM_EOF, httpbuf1, httplen1);
953  FAIL_IF(r != 0);
954  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
956 
957  HtpState *http_state = f->alstate;
958  FAIL_IF_NULL(http_state);
959  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
960  FAIL_IF_NULL(tx);
961  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
962  FAIL_IF_NULL(tx_ud);
963 
964  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
965  FileContainer *fc = files.fc;
966  FAIL_IF_NULL(fc);
967  File *file = fc->head;
968  FAIL_IF_NULL(file);
969  /* detect will have set FLOWFILE_NO_STORE_TS, but it won't have had
970  * an opportunity to be applied to the file itself yet */
971  FAIL_IF_NOT(tx_ud->tx_data.file_flags & FLOWFILE_NO_STORE_TS);
972  FAIL_IF(file->flags & FILE_NOSTORE);
973 
974  UTHFreePacket(p);
975  UTHFreeFlow(f);
977  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
979  StreamTcpFreeConfig(true);
981  PASS;
982 }
983 
984 static int DeStateSigTest07(void)
985 {
986  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
987  "Host: www.server.lan\r\n"
988  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
989  "Content-Length: 215\r\n"
990  "\r\n"
991  "-----------------------------277531038314945\r\n"
992  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
993  "Content-Type: image/jpeg\r\n"
994  "\r\n";
995 
996  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
997  uint8_t httpbuf2[] = "filecontent\r\n"
998  "-----------------------------277531038314945--";
999  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
1000  ThreadVars th_v;
1001  TcpSession ssn;
1002 
1005 
1006  memset(&th_v, 0, sizeof(th_v));
1008  memset(&ssn, 0, sizeof(ssn));
1009 
1010  DetectEngineThreadCtx *det_ctx = NULL;
1013  de_ctx->flags |= DE_QUIET;
1014 
1015  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (content:\"GET\"; http_method; content:\"upload.cgi\"; http_uri; filestore; sid:1; rev:1;)");
1016  FAIL_IF_NULL(s);
1017 
1019  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1020 
1021  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
1022  FAIL_IF_NULL(f);
1023  f->protoctx = &ssn;
1024  f->proto = IPPROTO_TCP;
1025  f->alproto = ALPROTO_HTTP1;
1026 
1027  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1028  FAIL_IF_NULL(p);
1029  p->flow = f;
1033 
1034  StreamTcpInitConfig(true);
1035 
1036  int r = AppLayerParserParse(
1037  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_START, httpbuf1, httplen1);
1038  FAIL_IF(r != 0);
1039  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1040  FAIL_IF(PacketAlertCheck(p, 1));
1041 
1042  r = AppLayerParserParse(
1043  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_EOF, httpbuf2, httplen2);
1044  FAIL_IF(r != 0);
1045  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1046  FAIL_IF(PacketAlertCheck(p, 1));
1047 
1048  HtpState *http_state = f->alstate;
1049  FAIL_IF_NULL(http_state);
1050  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1051  FAIL_IF_NULL(tx);
1052  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
1053  FAIL_IF_NULL(tx_ud);
1054 
1055  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1056  FileContainer *fc = files.fc;
1057  FAIL_IF_NULL(fc);
1058  File *file = fc->head;
1059  FAIL_IF_NULL(file);
1060  FAIL_IF(file->flags & FILE_STORE);
1061 
1062  UTHFreePacket(p);
1063  UTHFreeFlow(f);
1065  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1067  StreamTcpFreeConfig(true);
1069  PASS;
1070 }
1071 
1072 /**
1073  * \test multiple files in a tx
1074  */
1075 static int DeStateSigTest08(void)
1076 {
1077  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
1078  "Host: www.server.lan\r\n"
1079  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1080  "Content-Length: 440\r\n"
1081  "\r\n"
1082  "-----------------------------277531038314945\r\n"
1083  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"AAAApicture1.jpg\"\r\n"
1084  "Content-Type: image/jpeg\r\n"
1085  "\r\n";
1086 
1087  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
1088  uint8_t httpbuf2[] = "file";
1089  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
1090  uint8_t httpbuf3[] = "content\r\n"
1091  "-----------------------------277531038314945\r\n";
1092  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
1093 
1094  uint8_t httpbuf4[] = "Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"BBBBpicture2.jpg\"\r\n"
1095  "Content-Type: image/jpeg\r\n"
1096  "\r\n"
1097  "filecontent2\r\n"
1098  "-----------------------------277531038314945--";
1099  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
1100 
1101  ThreadVars th_v;
1102  TcpSession ssn;
1103 
1106 
1107  memset(&th_v, 0, sizeof(th_v));
1109  memset(&ssn, 0, sizeof(ssn));
1110 
1111  DetectEngineThreadCtx *det_ctx = NULL;
1114  de_ctx->flags |= DE_QUIET;
1115 
1116  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (content:\"POST\"; http_method; content:\"upload.cgi\"; http_uri; filename:\"BBBBpicture\"; filestore; sid:1; rev:1;)");
1117  FAIL_IF_NULL(s);
1118 
1120  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1121 
1122  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
1123  FAIL_IF_NULL(f);
1124  f->protoctx = &ssn;
1125  f->proto = IPPROTO_TCP;
1126  f->alproto = ALPROTO_HTTP1;
1127 
1128  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1129  FAIL_IF_NULL(p);
1130  p->flow = f;
1134 
1135  StreamTcpInitConfig(true);
1136 
1137  /* HTTP request with 1st part of the multipart body */
1138 
1139  int r = AppLayerParserParse(
1140  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_START, httpbuf1, httplen1);
1141  FAIL_IF(r != 0);
1142  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1143  FAIL_IF(PacketAlertCheck(p, 1));
1144 
1145  r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
1146  FAIL_IF(r != 0);
1147  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1148  FAIL_IF(PacketAlertCheck(p, 1));
1149 
1150  HtpState *http_state = f->alstate;
1151  FAIL_IF_NULL(http_state);
1152  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1153  FAIL_IF_NULL(tx);
1154  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
1155  FAIL_IF_NULL(tx_ud);
1156 
1157  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1158  FileContainer *fc = files.fc;
1159  FAIL_IF_NULL(fc);
1160  File *file = fc->head;
1161  FAIL_IF_NULL(file);
1162  FAIL_IF(file->flags & FILE_STORE);
1163 
1164  /* 2nd multipart body file */
1165 
1166  r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
1167  FAIL_IF(r != 0);
1168  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1169  FAIL_IF(PacketAlertCheck(p, 1));
1170 
1171  r = AppLayerParserParse(
1172  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
1173  FAIL_IF(r != 0);
1174  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1176 
1177  http_state = f->alstate;
1178  FAIL_IF_NULL(http_state);
1179  tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1180  FAIL_IF_NULL(tx);
1181  tx_ud = htp_tx_get_user_data(tx);
1182  FAIL_IF_NULL(tx_ud);
1183 
1184  files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1185  fc = files.fc;
1186  FAIL_IF_NULL(fc);
1187  file = fc->head;
1188  FAIL_IF_NULL(file);
1189  file = file->next;
1190  FAIL_IF_NULL(file);
1191  FAIL_IF_NOT(file->flags & FILE_STORE);
1192 
1193  UTHFreePacket(p);
1194  UTHFreeFlow(f);
1196  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1198  StreamTcpFreeConfig(true);
1200  PASS;
1201 }
1202 
1203 /**
1204  * \test multiple files in a tx. Both files should match
1205  */
1206 static int DeStateSigTest09(void)
1207 {
1208  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
1209  "Host: www.server.lan\r\n"
1210  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1211  "Content-Length: 440\r\n"
1212  "\r\n"
1213  "-----------------------------277531038314945\r\n"
1214  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1215  "Content-Type: image/jpeg\r\n"
1216  "\r\n";
1217 
1218  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
1219  uint8_t httpbuf2[] = "file";
1220  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
1221  uint8_t httpbuf3[] = "content\r\n"
1222  "-----------------------------277531038314945\r\n";
1223  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
1224 
1225  uint8_t httpbuf4[] = "Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
1226  "Content-Type: image/jpeg\r\n"
1227  "\r\n"
1228  "filecontent2\r\n"
1229  "-----------------------------277531038314945--";
1230  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
1231 
1232  ThreadVars th_v;
1233  TcpSession ssn;
1234 
1237 
1238  memset(&th_v, 0, sizeof(th_v));
1240  memset(&ssn, 0, sizeof(ssn));
1241 
1242  DetectEngineThreadCtx *det_ctx = NULL;
1245  de_ctx->flags |= DE_QUIET;
1246 
1247  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (content:\"POST\"; http_method; content:\"upload.cgi\"; http_uri; filename:\"somepicture\"; filestore; sid:1; rev:1;)");
1248  FAIL_IF_NULL(s);
1249 
1251  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1252 
1253  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
1254  FAIL_IF_NULL(f);
1255  f->protoctx = &ssn;
1256  f->proto = IPPROTO_TCP;
1257  f->alproto = ALPROTO_HTTP1;
1258 
1259  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1260  FAIL_IF_NULL(p);
1261  p->flow = f;
1265 
1266  StreamTcpInitConfig(true);
1267 
1268  /* HTTP request with 1st part of the multipart body */
1269 
1270  int r = AppLayerParserParse(
1271  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_START, httpbuf1, httplen1);
1272  FAIL_IF(r != 0);
1273  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1275 
1276  r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
1277  FAIL_IF(r != 0);
1278  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1279  FAIL_IF(PacketAlertCheck(p, 1));
1280 
1281  HtpState *http_state = f->alstate;
1282  FAIL_IF_NULL(http_state);
1283  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1284  FAIL_IF_NULL(tx);
1285  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
1286  FAIL_IF_NULL(tx_ud);
1287 
1288  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1289  FileContainer *fc = files.fc;
1290  FAIL_IF_NULL(fc);
1291  File *file = fc->head;
1292  FAIL_IF_NULL(file);
1293  FAIL_IF_NOT(file->flags & FILE_STORE);
1294 
1295  /* 2nd multipart body file */
1296 
1297  r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
1298  FAIL_IF(r != 0);
1299  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1300  FAIL_IF(PacketAlertCheck(p, 1));
1301 
1302  r = AppLayerParserParse(
1303  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
1304  FAIL_IF(r != 0);
1305  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1307 
1308  http_state = f->alstate;
1309  FAIL_IF_NULL(http_state);
1310  tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1311  FAIL_IF_NULL(tx);
1312  tx_ud = htp_tx_get_user_data(tx);
1313  FAIL_IF_NULL(tx_ud);
1314 
1315  files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1316  fc = files.fc;
1317  FAIL_IF_NULL(fc);
1318  file = fc->head;
1319  FAIL_IF_NULL(file);
1320  FAIL_IF_NOT(file->flags & FILE_STORE);
1321 
1322  UTHFreePacket(p);
1323  UTHFreeFlow(f);
1325  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1327  StreamTcpFreeConfig(true);
1329  PASS;
1330 }
1331 
1332 /**
1333  * \test multiple files in a tx. Both files should match. No other matches.
1334  */
1335 static int DeStateSigTest10(void)
1336 {
1337  uint8_t httpbuf1[] = "POST /upload.cgi HTTP/1.1\r\n"
1338  "Host: www.server.lan\r\n"
1339  "Content-Type: multipart/form-data; boundary=---------------------------277531038314945\r\n"
1340  "Content-Length: 440\r\n"
1341  "\r\n"
1342  "-----------------------------277531038314945\r\n"
1343  "Content-Disposition: form-data; name=\"uploadfile_0\"; filename=\"somepicture1.jpg\"\r\n"
1344  "Content-Type: image/jpeg\r\n"
1345  "\r\n";
1346 
1347  uint32_t httplen1 = sizeof(httpbuf1) - 1; /* minus the \0 */
1348  uint8_t httpbuf2[] = "file";
1349  uint32_t httplen2 = sizeof(httpbuf2) - 1; /* minus the \0 */
1350  uint8_t httpbuf3[] = "content\r\n"
1351  "-----------------------------277531038314945\r\n";
1352  uint32_t httplen3 = sizeof(httpbuf3) - 1; /* minus the \0 */
1353 
1354  uint8_t httpbuf4[] = "Content-Disposition: form-data; name=\"uploadfile_1\"; filename=\"somepicture2.jpg\"\r\n"
1355  "Content-Type: image/jpeg\r\n"
1356  "\r\n"
1357  "filecontent2\r\n"
1358  "-----------------------------277531038314945--";
1359  uint32_t httplen4 = sizeof(httpbuf4) - 1; /* minus the \0 */
1360 
1361  ThreadVars th_v;
1362  TcpSession ssn;
1363 
1366 
1367  memset(&th_v, 0, sizeof(th_v));
1369  memset(&ssn, 0, sizeof(ssn));
1370 
1371  DetectEngineThreadCtx *det_ctx = NULL;
1374  de_ctx->flags |= DE_QUIET;
1375 
1376  Signature *s = DetectEngineAppendSig(de_ctx, "alert http any any -> any any (filename:\"somepicture\"; filestore; sid:1; rev:1;)");
1377  FAIL_IF_NULL(s);
1378 
1380  DetectEngineThreadCtxInit(&th_v, (void *)de_ctx, (void *)&det_ctx);
1381 
1382  Flow *f = UTHBuildFlow(AF_INET, "1.2.3.4", "1.2.3.5", 1024, 80);
1383  FAIL_IF_NULL(f);
1384  f->protoctx = &ssn;
1385  f->proto = IPPROTO_TCP;
1386  f->alproto = ALPROTO_HTTP1;
1387 
1388  Packet *p = UTHBuildPacket(NULL, 0, IPPROTO_TCP);
1389  FAIL_IF_NULL(p);
1390  p->flow = f;
1394 
1395  StreamTcpInitConfig(true);
1396 
1397  /* HTTP request with 1st part of the multipart body */
1398 
1399  int r = AppLayerParserParse(
1400  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_START, httpbuf1, httplen1);
1401  FAIL_IF(r != 0);
1402  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1404 
1405  r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf2, httplen2);
1406  FAIL_IF(r != 0);
1407  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1408  FAIL_IF(PacketAlertCheck(p, 1));
1409 
1410  HtpState *http_state = f->alstate;
1411  FAIL_IF_NULL(http_state);
1412  void *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1413  FAIL_IF_NULL(tx);
1414  HtpTxUserData *tx_ud = htp_tx_get_user_data(tx);
1415  FAIL_IF_NULL(tx_ud);
1416 
1417  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1418  FileContainer *fc = files.fc;
1419  FAIL_IF_NULL(fc);
1420  File *file = fc->head;
1421  FAIL_IF_NULL(file);
1422  FAIL_IF_NOT(file->flags & FILE_STORE);
1423 
1424  /* 2nd multipart body file */
1425 
1426  r = AppLayerParserParse(NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER, httpbuf3, httplen3);
1427  FAIL_IF(r != 0);
1428  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1429  FAIL_IF(PacketAlertCheck(p, 1));
1430 
1431  r = AppLayerParserParse(
1432  NULL, alp_tctx, f, ALPROTO_HTTP1, STREAM_TOSERVER | STREAM_EOF, httpbuf4, httplen4);
1433  FAIL_IF(r != 0);
1434  SigMatchSignatures(&th_v, de_ctx, det_ctx, p);
1436 
1437  http_state = f->alstate;
1438  FAIL_IF_NULL(http_state);
1439  tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, f->alstate, 0);
1440  FAIL_IF_NULL(tx);
1441  tx_ud = htp_tx_get_user_data(tx);
1442  FAIL_IF_NULL(tx_ud);
1443 
1444  files = AppLayerParserGetTxFiles(p->flow, tx, STREAM_TOSERVER);
1445  fc = files.fc;
1446  FAIL_IF_NULL(fc);
1447  file = fc->head;
1448  FAIL_IF_NULL(file);
1449  FAIL_IF_NOT(file->flags & FILE_STORE);
1450 
1451  UTHFreePacket(p);
1452  UTHFreeFlow(f);
1454  DetectEngineThreadCtxDeinit(&th_v, (void *)det_ctx);
1456  StreamTcpFreeConfig(true);
1458  PASS;
1459 }
1460 
1461 #endif
1462 
1464 {
1465 #ifdef UNITTESTS
1466  UtRegisterTest("DeStateTest01", DeStateTest01);
1467  UtRegisterTest("DeStateTest02", DeStateTest02);
1468  UtRegisterTest("DeStateTest03", DeStateTest03);
1469  UtRegisterTest("DeStateSigTest01", DeStateSigTest01);
1470  UtRegisterTest("DeStateSigTest02", DeStateSigTest02);
1471  UtRegisterTest("DeStateSigTest03", DeStateSigTest03);
1472  UtRegisterTest("DeStateSigTest04", DeStateSigTest04);
1473  UtRegisterTest("DeStateSigTest05", DeStateSigTest05);
1474  UtRegisterTest("DeStateSigTest06", DeStateSigTest06);
1475  UtRegisterTest("DeStateSigTest07", DeStateSigTest07);
1476  UtRegisterTest("DeStateSigTest08", DeStateSigTest08);
1477  UtRegisterTest("DeStateSigTest09", DeStateSigTest09);
1478  UtRegisterTest("DeStateSigTest10", DeStateSigTest10);
1479 #endif
1480 }
1481 
1482 /**
1483  * @}
1484  */
FileContainer_
Definition: util-file.h:37
DE_STATE_CHUNK_SIZE
#define DE_STATE_CHUNK_SIZE
Definition: detect-engine-state.h:55
detect-engine.h
FAIL_IF_NULL
#define FAIL_IF_NULL(expr)
Fail a test if expression evaluates to NULL.
Definition: util-unittest.h:89
DetectEngineStateDirection_::flags
uint8_t flags
Definition: detect-engine-state.h:91
Flow_::flags
uint64_t flags
Definition: flow.h:408
PKT_HAS_FLOW
#define PKT_HAS_FLOW
Definition: decode.h:1311
flow-util.h
DetectEngineState_
Definition: detect-engine-state.h:95
stream-tcp.h
SigGroupHead_
Container for matching data for a signature group.
Definition: detect.h:1730
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:101
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:282
DetectEngineStateDirection_::cnt
SigIntId cnt
Definition: detect-engine-state.h:89
AppLayerTxData::de_state
DetectEngineState * de_state
Definition: app-layer-parser.h:223
Flow_::proto
uint8_t proto
Definition: flow.h:381
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:144
Packet_::flags
uint32_t flags
Definition: decode.h:562
ssn
TcpSession ssn
Definition: fuzz_dataset.c:31
Flow_
Flow data structure.
Definition: flow.h:359
DetectEngineCtx_
main detection engine ctx
Definition: detect.h:995
FILE_STORE
#define FILE_STORE
Definition: util-file.h:122
DetectEngineCtxFree
void DetectEngineCtxFree(DetectEngineCtx *)
Free a DetectEngineCtx::
Definition: detect-engine.c:2912
DetectEngineState_::dir_state
DetectEngineStateDirection dir_state[2]
Definition: detect-engine-state.h:96
AppLayerParserThreadCtxFree
void AppLayerParserThreadCtxFree(AppLayerParserThreadCtx *tctx)
Destroys the app layer parser thread context obtained using AppLayerParserThreadCtxAlloc().
Definition: app-layer-parser.c:364
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:236
SIG_FLAG_TXBOTHDIR
#define SIG_FLAG_TXBOTHDIR
Definition: detect.h:253
MIN
#define MIN(x, y)
Definition: suricata-common.h:413
DE_QUIET
#define DE_QUIET
Definition: detect.h:334
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:241
SigMatchSignatures
void SigMatchSignatures(ThreadVars *tv, DetectEngineCtx *de_ctx, DetectEngineThreadCtx *det_ctx, Packet *p)
wrapper for old tests
Definition: detect.c:3305
p
Packet * p
Definition: fuzz_dataset.c:30
DetectEngineAppendSig
Signature * DetectEngineAppendSig(DetectEngineCtx *, const char *)
Parse and append a Signature into the Detection Engine Context signature list.
Definition: detect-parse.c:3971
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:547
Flow_::protoctx
void * protoctx
Definition: flow.h:438
DeStateStoreItem_::sid
SigIntId sid
Definition: detect-engine-state.h:77
FLOW_IPV4
#define FLOW_IPV4
Definition: flow.h:99
AppLayerParserGetTransactionInspectId
uint64_t AppLayerParserGetTransactionInspectId(AppLayerParserState *pstate, uint8_t direction)
Definition: app-layer-parser.c:813
DetectEngineStateDirection_::cur
DeStateStore * cur
Definition: detect-engine-state.h:87
HtpState_
Definition: app-layer-htp.h:183
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
AppLayerParserGetTxFiles
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
Definition: app-layer-parser.c:963
detect-flowvar.h
DetectRunStoreStateTx
void DetectRunStoreStateTx(const SigGroupHead *sgh, Flow *f, void *tx, uint64_t tx_id, const Signature *s, uint32_t inspect_flags, uint8_t flow_flags, const uint16_t file_no_match)
Definition: detect-engine-state.c:212
Flow_::alparser
AppLayerParserState * alparser
Definition: flow.h:483
StreamTcpInitConfig
void StreamTcpInitConfig(bool)
To initialize the stream global configuration data.
Definition: stream-tcp.c:496
UTHBuildFlow
Flow * UTHBuildFlow(int family, const char *src, const char *dst, Port sp, Port dp)
Definition: util-unittest-helper.c:494
FLOW_INITIALIZE
#define FLOW_INITIALIZE(f)
Definition: flow-util.h:38
app-layer-htp.h
decode.h
FAIL_IF_NOT_NULL
#define FAIL_IF_NOT_NULL(expr)
Fail a test if expression evaluates to non-NULL.
Definition: util-unittest.h:96
PASS
#define PASS
Pass the test.
Definition: util-unittest.h:105
AppLayerTxData
Definition: app-layer-parser.h:172
de_ctx
DetectEngineCtx * de_ctx
Definition: fuzz_siginit.c:22
DetectEngineThreadCtx_
Definition: detect.h:1316
DeStateStoreItem_::flags
uint32_t flags
Definition: detect-engine-state.h:76
BIT_U32
#define BIT_U32(n)
Definition: suricata-common.h:422
alp_tctx
AppLayerParserThreadCtx * alp_tctx
Definition: fuzz_applayerparserparse.c:24
SCDetectEngineStateFree
void SCDetectEngineStateFree(DetectEngineState *state)
Frees a DetectEngineState object.
Definition: detect-engine-state.c:167
SCEnter
#define SCEnter(...)
Definition: util-debug.h:284
FileContainer_::head
File * head
Definition: util-file.h:38
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:57
DeStateStore_::next
struct DeStateStore_ * next
Definition: detect-engine-state.h:82
HtpState_::conn
htp_conn_t * conn
Definition: app-layer-htp.h:187
DetectEngineThreadCtxInit
TmEcode DetectEngineThreadCtxInit(ThreadVars *tv, void *initdata, void **data)
initialize thread specific detection engine context
Definition: detect-engine.c:3660
HtpTxUserData_::tx_data
AppLayerTxData tx_data
Definition: app-layer-htp.h:178
HtpState_::state_data
AppLayerStateData state_data
Definition: app-layer-htp.h:200
SigInit
Signature * SigInit(DetectEngineCtx *de_ctx, const char *sigstr)
Parses a signature and adds it to the Detection Engine Context.
Definition: detect-parse.c:3624
app-layer-parser.h
BUG_ON
#define BUG_ON(x)
Definition: suricata-common.h:322
util-profiling.h
DetectEngineStateAlloc
DetectEngineState * DetectEngineStateAlloc(void)
Alloc a DetectEngineState object.
Definition: detect-engine-state.c:158
SigIntId
#define SigIntId
Definition: detect-engine-state.h:38
SCReturn
#define SCReturn
Definition: util-debug.h:286
Signature_::flags
uint32_t flags
Definition: detect.h:693
Packet_
Definition: decode.h:516
DE_STATE_FLAG_BASE
#define DE_STATE_FLAG_BASE
Definition: detect-engine-state.h:66
detect-engine-build.h
stream-tcp-private.h
detect-engine-alert.h
detect-engine-state.h
Data structures and function prototypes for keeping state for the detection engine.
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1219
SigGroupBuild
int SigGroupBuild(DetectEngineCtx *de_ctx)
Convert the signature list into the runtime match structure.
Definition: detect-engine-build.c:2300
StatsThreadInit
void StatsThreadInit(StatsThreadContext *stats)
Definition: counters.c:1332
UTHFreeFlow
void UTHFreeFlow(Flow *flow)
Definition: util-unittest-helper.c:499
AppLayerParserThreadCtxAlloc
AppLayerParserThreadCtx * AppLayerParserThreadCtxAlloc(void)
Gets a new app layer protocol's parser thread context.
Definition: app-layer-parser.c:337
FileDisableStoringForTransaction
void FileDisableStoringForTransaction(Flow *f, const uint8_t direction, void *tx, uint64_t tx_id)
disable file storing for files in a transaction
Definition: util-file.c:1127
File_::flags
uint16_t flags
Definition: util-file.h:147
DetectEngineStateDirection_::head
DeStateStore * head
Definition: detect-engine-state.h:86
File_
Definition: util-file.h:146
th_v
ThreadVars * th_v
Definition: fuzz_dataset.c:29
Packet_::flow
struct Flow_ * flow
Definition: decode.h:564
DetectEngineStateResetTxs
void DetectEngineStateResetTxs(Flow *f)
Reset de state for active tx' To be used on detect engine reload.
Definition: detect-engine-state.c:258
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:864
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:1528
AppLayerGetFileState
Definition: util-file.h:44
suricata-common.h
AppLayerGetFileState::fc
FileContainer * fc
Definition: util-file.h:45
DeStateStore_
Definition: detect-engine-state.h:80
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:36
File_::next
struct File_ * next
Definition: util-file.h:159
DetectEngineThreadCtxDeinit
TmEcode DetectEngineThreadCtxDeinit(ThreadVars *tv, void *data)
Definition: detect-engine.c:3905
DetectEngineStateDirection_
Definition: detect-engine-state.h:85
AppLayerParserGetTxData
AppLayerTxData * AppLayerParserGetTxData(uint8_t ipproto, AppProto alproto, void *tx)
Definition: app-layer-parser.c:1420
DetectEngineCtx_::sig_list
Signature * sig_list
Definition: detect.h:1005
HtpTxUserData_
Definition: app-layer-htp.h:153
DetectEngineStateDirection_::filestore_cnt
uint16_t filestore_cnt
Definition: detect-engine-state.h:90
Signature_::iid
SigIntId iid
Definition: detect.h:704
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:470
Flow_::alstate
void * alstate
Definition: flow.h:484
DeStateStore_::store
DeStateStoreItem store[DE_STATE_CHUNK_SIZE]
Definition: detect-engine-state.h:81
detect-parse.h
Signature_
Signature container.
Definition: detect.h:692
FLOW_PKT_ESTABLISHED
#define FLOW_PKT_ESTABLISHED
Definition: flow.h:238
DetectEngineCtxInit
DetectEngineCtx * DetectEngineCtxInit(void)
Definition: detect-engine.c:2873
app-layer-protos.h
FILE_NOSTORE
#define FILE_NOSTORE
Definition: util-file.h:121
DetectEngineCtx_::flags
uint8_t flags
Definition: detect.h:997
AppLayerParserThreadCtx_
Definition: app-layer-parser.c:72
TcpSession_
Definition: stream-tcp-private.h:283
AppLayerTxData::file_flags
uint16_t file_flags
Definition: app-layer-parser.h:192
DeStateStoreItem_
Definition: detect-engine-state.h:75
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:455
DeStateRegisterTests
void DeStateRegisterTests(void)
Definition: detect-engine-state.c:1463
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
ThreadVars_::stats
StatsThreadContext stats
Definition: threadvars.h:120
SigGroupHead_::filestore_cnt
uint16_t filestore_cnt
Definition: detect.h:1736
StatsThreadCleanup
void StatsThreadCleanup(StatsThreadContext *stats)
Definition: counters.c:1428
AppLayerParserGetTxCnt
uint64_t AppLayerParserGetTxCnt(const Flow *f, void *alstate)
Definition: app-layer-parser.c:1212
DetectEngineStateDirection_::tail
DeStateStore * tail
Definition: detect-engine-state.h:88
FLOW_DESTROY
#define FLOW_DESTROY(f)
Definition: flow-util.h:119
AppLayerStateData::file_flags
uint16_t file_flags
Definition: app-layer-parser.h:156
PKT_STREAM_EST
#define PKT_STREAM_EST
Definition: decode.h:1307
app-layer.h
f
Flow f
Definition: fuzz_dataset.c:32