suricata
output-json-alert.c
Go to the documentation of this file.
1 /* Copyright (C) 2013-2024 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  * \file
20  *
21  * \author Tom DeCanio <td@npulsetech.com>
22  *
23  * Logs alerts in JSON format.
24  *
25  */
26 
27 #include "suricata-common.h"
28 #include "packet.h"
29 #include "detect.h"
30 #include "flow.h"
31 #include "conf.h"
32 
33 #include "stream.h"
34 #include "threadvars.h"
35 #include "util-debug.h"
36 #include "stream-tcp.h"
37 
38 #include "util-logopenfile.h"
39 #include "util-misc.h"
40 #include "util-time.h"
41 
42 #include "detect-engine.h"
43 #include "detect-metadata.h"
44 #include "app-layer-parser.h"
45 #include "app-layer-htp-xff.h"
46 #include "app-layer-ftp.h"
47 #include "app-layer-frames.h"
48 #include "log-pcap.h"
49 
50 #include "output.h"
51 #include "output-json.h"
52 #include "output-json-alert.h"
53 #include "output-json-http.h"
54 #include "rust.h"
55 #include "output-json-smtp.h"
57 #include "output-json-nfs.h"
58 #include "output-json-smb.h"
59 #include "output-json-flow.h"
60 #include "output-json-ike.h"
61 #include "output-json-frame.h"
62 
63 #include "util-print.h"
64 #include "util-optimize.h"
65 #include "util-buffer.h"
66 #include "util-reference-config.h"
67 #include "util-validate.h"
68 
69 #include "action-globals.h"
70 
71 #define MODULE_NAME "JsonAlertLog"
72 
73 #define LOG_JSON_PAYLOAD BIT_U16(0)
74 #define LOG_JSON_PACKET BIT_U16(1)
75 #define LOG_JSON_PAYLOAD_BASE64 BIT_U16(2)
76 #define LOG_JSON_TAGGED_PACKETS BIT_U16(3)
77 #define LOG_JSON_APP_LAYER BIT_U16(4)
78 #define LOG_JSON_FLOW BIT_U16(5)
79 #define LOG_JSON_HTTP_BODY BIT_U16(6)
80 #define LOG_JSON_HTTP_BODY_BASE64 BIT_U16(7)
81 #define LOG_JSON_RULE_METADATA BIT_U16(8)
82 #define LOG_JSON_RULE BIT_U16(9)
83 #define LOG_JSON_VERDICT BIT_U16(10)
84 #define LOG_JSON_WEBSOCKET_PAYLOAD BIT_U16(11)
85 #define LOG_JSON_WEBSOCKET_PAYLOAD_BASE64 BIT_U16(12)
86 #define LOG_JSON_PAYLOAD_LENGTH BIT_U16(13)
87 #define LOG_JSON_REFERENCE BIT_U16(14)
88 
89 #define METADATA_DEFAULTS ( LOG_JSON_FLOW | \
90  LOG_JSON_APP_LAYER | \
91  LOG_JSON_RULE_METADATA)
92 
93 #define JSON_BODY_LOGGING \
94  (LOG_JSON_HTTP_BODY | LOG_JSON_HTTP_BODY_BASE64 | LOG_JSON_WEBSOCKET_PAYLOAD | \
95  LOG_JSON_WEBSOCKET_PAYLOAD_BASE64)
96 
97 #define JSON_STREAM_BUFFER_SIZE 4096
98 
99 typedef struct AlertJsonOutputCtx_ {
101  uint16_t flags;
107 
108 typedef struct JsonAlertLogThread_ {
113 
114 static void AlertJsonSourceTarget(const Packet *p, const PacketAlert *pa,
115  JsonBuilder *js, JsonAddrInfo *addr)
116 {
117  jb_open_object(js, "source");
118  if (pa->s->flags & SIG_FLAG_DEST_IS_TARGET) {
119  jb_set_string(js, "ip", addr->src_ip);
120  switch (p->proto) {
121  case IPPROTO_ICMP:
122  case IPPROTO_ICMPV6:
123  break;
124  case IPPROTO_UDP:
125  case IPPROTO_TCP:
126  case IPPROTO_SCTP:
127  jb_set_uint(js, "port", addr->sp);
128  break;
129  }
130  } else if (pa->s->flags & SIG_FLAG_SRC_IS_TARGET) {
131  jb_set_string(js, "ip", addr->dst_ip);
132  switch (p->proto) {
133  case IPPROTO_ICMP:
134  case IPPROTO_ICMPV6:
135  break;
136  case IPPROTO_UDP:
137  case IPPROTO_TCP:
138  case IPPROTO_SCTP:
139  jb_set_uint(js, "port", addr->dp);
140  break;
141  }
142  }
143  jb_close(js);
144 
145  jb_open_object(js, "target");
146  if (pa->s->flags & SIG_FLAG_DEST_IS_TARGET) {
147  jb_set_string(js, "ip", addr->dst_ip);
148  switch (p->proto) {
149  case IPPROTO_ICMP:
150  case IPPROTO_ICMPV6:
151  break;
152  case IPPROTO_UDP:
153  case IPPROTO_TCP:
154  case IPPROTO_SCTP:
155  jb_set_uint(js, "port", addr->dp);
156  break;
157  }
158  } else if (pa->s->flags & SIG_FLAG_SRC_IS_TARGET) {
159  jb_set_string(js, "ip", addr->src_ip);
160  switch (p->proto) {
161  case IPPROTO_ICMP:
162  case IPPROTO_ICMPV6:
163  break;
164  case IPPROTO_UDP:
165  case IPPROTO_TCP:
166  case IPPROTO_SCTP:
167  jb_set_uint(js, "port", addr->sp);
168  break;
169  }
170  }
171  jb_close(js);
172 }
173 
174 static void AlertJsonReference(const PacketAlert *pa, JsonBuilder *jb)
175 {
176  if (!pa->s->references) {
177  return;
178  }
179 
180  const DetectReference *kv = pa->s->references;
181  jb_open_array(jb, "references");
182  while (kv) {
183  /* Note that the key and reference sizes have been bound
184  * checked during parsing
185  */
186  const size_t size_needed = kv->key_len + kv->reference_len + 1;
187  char kv_store[size_needed];
188  snprintf(kv_store, size_needed, "%s%s", kv->key, kv->reference);
189  jb_append_string(jb, kv_store);
190  kv = kv->next;
191  }
192  jb_close(jb);
193 }
194 
195 static void AlertJsonMetadata(const PacketAlert *pa, JsonBuilder *js)
196 {
197  if (pa->s->metadata && pa->s->metadata->json_str) {
198  jb_set_formatted(js, pa->s->metadata->json_str);
199  }
200 }
201 
202 void AlertJsonHeader(const Packet *p, const PacketAlert *pa, JsonBuilder *js, uint16_t flags,
203  JsonAddrInfo *addr, char *xff_buffer)
204 {
205  const char *action = "allowed";
206  /* use packet action if rate_filter modified the action */
209  action = "blocked";
210  }
211  } else {
212  if (pa->action & ACTION_REJECT_ANY) {
213  action = "blocked";
214  } else if ((pa->action & ACTION_DROP) && EngineModeIsIPS()) {
215  action = "blocked";
216  }
217  }
218 
219  /* Add tx_id to root element for correlation with other events. */
220  /* json_object_del(js, "tx_id"); */
221  if (pa->flags & PACKET_ALERT_FLAG_TX) {
222  jb_set_uint(js, "tx_id", pa->tx_id);
223  }
225  jb_set_bool(js, "tx_guessed", true);
226  }
227 
228  jb_open_object(js, "alert");
229 
230  jb_set_string(js, "action", action);
231  jb_set_uint(js, "gid", pa->s->gid);
232  jb_set_uint(js, "signature_id", pa->s->id);
233  jb_set_uint(js, "rev", pa->s->rev);
234  /* TODO: JsonBuilder should handle unprintable characters like
235  * SCJsonString. */
236  jb_set_string(js, "signature", pa->s->msg ? pa->s->msg: "");
237  jb_set_string(js, "category", pa->s->class_msg ? pa->s->class_msg: "");
238  jb_set_uint(js, "severity", pa->s->prio);
239 
240  if (p->tenant_id > 0) {
241  jb_set_uint(js, "tenant_id", p->tenant_id);
242  }
243 
244  if (addr && pa->s->flags & SIG_FLAG_HAS_TARGET) {
245  AlertJsonSourceTarget(p, pa, js, addr);
246  }
247 
248  if ((flags & LOG_JSON_REFERENCE)) {
249  AlertJsonReference(pa, js);
250  }
251 
253  AlertJsonMetadata(pa, js);
254  }
255 
256  if (flags & LOG_JSON_RULE) {
257  jb_set_string(js, "rule", pa->s->sig_str);
258  }
259  if (xff_buffer && xff_buffer[0]) {
260  jb_set_string(js, "xff", xff_buffer);
261  }
262 
263  jb_close(js);
264 }
265 
266 static void AlertJsonTunnel(const Packet *p, JsonBuilder *js)
267 {
268  if (p->root == NULL) {
269  return;
270  }
271 
272  jb_open_object(js, "tunnel");
273 
274  enum PktSrcEnum pkt_src;
275  uint64_t pcap_cnt;
277  JsonAddrInfoInit(p->root, 0, &addr);
278  pcap_cnt = p->root->pcap_cnt;
279  pkt_src = p->root->pkt_src;
280 
281  jb_set_string(js, "src_ip", addr.src_ip);
282  jb_set_uint(js, "src_port", addr.sp);
283  jb_set_string(js, "dest_ip", addr.dst_ip);
284  jb_set_uint(js, "dest_port", addr.dp);
285  jb_set_string(js, "proto", addr.proto);
286 
287  jb_set_uint(js, "depth", p->recursion_level);
288  if (pcap_cnt != 0) {
289  jb_set_uint(js, "pcap_cnt", pcap_cnt);
290  }
291  jb_set_string(js, "pkt_src", PktSrcToString(pkt_src));
292  jb_close(js);
293 }
294 
295 static void AlertAddPayload(AlertJsonOutputCtx *json_output_ctx, JsonBuilder *js, const Packet *p)
296 {
297  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
298  jb_set_base64(js, "payload", p->payload, p->payload_len);
299  }
300  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_LENGTH) {
301  jb_set_uint(js, "payload_length", p->payload_len);
302  }
303 
304  if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
305  uint8_t printable_buf[p->payload_len + 1];
306  uint32_t offset = 0;
307  PrintStringsToBuffer(printable_buf, &offset,
308  p->payload_len + 1,
309  p->payload, p->payload_len);
310  printable_buf[p->payload_len] = '\0';
311  jb_set_string(js, "payload_printable", (char *)printable_buf);
312  }
313 }
314 
315 static void AlertAddAppLayer(const Packet *p, JsonBuilder *jb,
316  const uint64_t tx_id, const uint16_t option_flags)
317 {
318  const AppProto proto = FlowGetAppProtocol(p->flow);
320  JsonBuilderMark mark = { 0, 0, 0 };
321  if (al && al->LogTx) {
322  void *state = FlowGetAppState(p->flow);
323  if (state) {
324  void *tx = AppLayerParserGetTx(p->flow->proto, proto, state, tx_id);
325  if (tx) {
326  jb_get_mark(jb, &mark);
327  switch (proto) {
328  // first check some protocols need special options for alerts logging
329  case ALPROTO_WEBSOCKET:
330  if (option_flags &
332  bool pp = (option_flags & LOG_JSON_WEBSOCKET_PAYLOAD) != 0;
333  bool pb64 = (option_flags & LOG_JSON_WEBSOCKET_PAYLOAD_BASE64) != 0;
334  if (!SCWebSocketLogDetails(tx, jb, pp, pb64)) {
335  jb_restore_mark(jb, &mark);
336  }
337  // nothing more to log or do
338  return;
339  }
340  }
341  if (!al->LogTx(tx, jb)) {
342  jb_restore_mark(jb, &mark);
343  }
344  }
345  }
346  return;
347  }
348  switch (proto) {
349  case ALPROTO_HTTP1:
350  // TODO: Could result in an empty http object being logged.
351  jb_open_object(jb, "http");
352  if (EveHttpAddMetadata(p->flow, tx_id, jb)) {
353  if (option_flags & LOG_JSON_HTTP_BODY) {
354  EveHttpLogJSONBodyPrintable(jb, p->flow, tx_id);
355  }
356  if (option_flags & LOG_JSON_HTTP_BODY_BASE64) {
357  EveHttpLogJSONBodyBase64(jb, p->flow, tx_id);
358  }
359  }
360  jb_close(jb);
361  break;
362  case ALPROTO_SMTP:
363  jb_get_mark(jb, &mark);
364  jb_open_object(jb, "smtp");
365  if (EveSMTPAddMetadata(p->flow, tx_id, jb)) {
366  jb_close(jb);
367  } else {
368  jb_restore_mark(jb, &mark);
369  }
370  jb_get_mark(jb, &mark);
371  jb_open_object(jb, "email");
372  if (EveEmailAddMetadata(p->flow, tx_id, jb)) {
373  jb_close(jb);
374  } else {
375  jb_restore_mark(jb, &mark);
376  }
377  break;
378  case ALPROTO_NFS:
379  /* rpc */
380  jb_get_mark(jb, &mark);
381  jb_open_object(jb, "rpc");
382  if (EveNFSAddMetadataRPC(p->flow, tx_id, jb)) {
383  jb_close(jb);
384  } else {
385  jb_restore_mark(jb, &mark);
386  }
387  /* nfs */
388  jb_get_mark(jb, &mark);
389  jb_open_object(jb, "nfs");
390  if (EveNFSAddMetadata(p->flow, tx_id, jb)) {
391  jb_close(jb);
392  } else {
393  jb_restore_mark(jb, &mark);
394  }
395  break;
396  case ALPROTO_SMB:
397  jb_get_mark(jb, &mark);
398  jb_open_object(jb, "smb");
399  if (EveSMBAddMetadata(p->flow, tx_id, jb)) {
400  jb_close(jb);
401  } else {
402  jb_restore_mark(jb, &mark);
403  }
404  break;
405  case ALPROTO_IKE:
406  jb_get_mark(jb, &mark);
407  if (!EveIKEAddMetadata(p->flow, tx_id, jb)) {
408  jb_restore_mark(jb, &mark);
409  }
410  break;
411  case ALPROTO_DCERPC: {
412  void *state = FlowGetAppState(p->flow);
413  if (state) {
414  void *tx = AppLayerParserGetTx(p->flow->proto, proto, state, tx_id);
415  if (tx) {
416  jb_get_mark(jb, &mark);
417  jb_open_object(jb, "dcerpc");
418  if (p->proto == IPPROTO_TCP) {
419  if (!rs_dcerpc_log_json_record_tcp(state, tx, jb)) {
420  jb_restore_mark(jb, &mark);
421  }
422  } else {
423  if (!rs_dcerpc_log_json_record_udp(state, tx, jb)) {
424  jb_restore_mark(jb, &mark);
425  }
426  }
427  jb_close(jb);
428  }
429  }
430  break;
431  }
432  default:
433  break;
434  }
435 }
436 
437 static void AlertAddFiles(const Packet *p, JsonBuilder *jb, const uint64_t tx_id)
438 {
439  const uint8_t direction =
440  (p->flowflags & FLOW_PKT_TOSERVER) ? STREAM_TOSERVER : STREAM_TOCLIENT;
441  FileContainer *ffc = NULL;
442  if (p->flow->alstate != NULL) {
443  void *tx = AppLayerParserGetTx(p->flow->proto, p->flow->alproto, p->flow->alstate, tx_id);
444  if (tx) {
445  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, direction);
446  ffc = files.fc;
447  }
448  }
449  if (ffc != NULL) {
450  File *file = ffc->head;
451  bool isopen = false;
452  while (file) {
453  if (!isopen) {
454  isopen = true;
455  jb_open_array(jb, "files");
456  }
457  jb_start_object(jb);
458  EveFileInfo(jb, file, tx_id, file->flags);
459  jb_close(jb);
460  file = file->next;
461  }
462  if (isopen) {
463  jb_close(jb);
464  }
465  }
466 }
467 
468 static void AlertAddFrame(
469  const Packet *p, const int64_t frame_id, JsonBuilder *jb, MemBuffer *buffer)
470 {
471  if (p->flow == NULL || (p->proto == IPPROTO_TCP && p->flow->protoctx == NULL))
472  return;
473 
474  FramesContainer *frames_container = AppLayerFramesGetContainer(p->flow);
475  if (frames_container == NULL)
476  return;
477 
478  Frames *frames = NULL;
479  TcpStream *stream = NULL;
480  if (p->proto == IPPROTO_TCP) {
481  TcpSession *ssn = p->flow->protoctx;
482  if (PKT_IS_TOSERVER(p)) {
483  stream = &ssn->client;
484  frames = &frames_container->toserver;
485  } else {
486  stream = &ssn->server;
487  frames = &frames_container->toclient;
488  }
489  Frame *frame = FrameGetById(frames, frame_id);
490  if (frame != NULL) {
491  FrameJsonLogOneFrame(IPPROTO_TCP, frame, p->flow, stream, p, jb, buffer);
492  }
493  } else if (p->proto == IPPROTO_UDP) {
494  if (PKT_IS_TOSERVER(p)) {
495  frames = &frames_container->toserver;
496  } else {
497  frames = &frames_container->toclient;
498  }
499  Frame *frame = FrameGetById(frames, frame_id);
500  if (frame != NULL) {
501  FrameJsonLogOneFrame(IPPROTO_UDP, frame, p->flow, NULL, p, jb, buffer);
502  }
503  }
504 }
505 
506 /**
507  * \brief Build verdict object
508  *
509  * \param p Pointer to Packet current being logged
510  *
511  */
512 void EveAddVerdict(JsonBuilder *jb, const Packet *p)
513 {
514  jb_open_object(jb, "verdict");
515 
516  /* add verdict info */
518  // check rule to define type of reject packet sent
519  if (EngineModeIsIPS()) {
520  JB_SET_STRING(jb, "action", "drop");
521  } else {
522  JB_SET_STRING(jb, "action", "alert");
523  }
525  JB_SET_STRING(jb, "reject-target", "to_client");
526  } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
527  JB_SET_STRING(jb, "reject-target", "to_server");
528  } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
529  JB_SET_STRING(jb, "reject-target", "both");
530  }
531  jb_open_array(jb, "reject");
532  switch (p->proto) {
533  case IPPROTO_UDP:
534  case IPPROTO_ICMP:
535  case IPPROTO_ICMPV6:
536  jb_append_string(jb, "icmp-prohib");
537  break;
538  case IPPROTO_TCP:
539  jb_append_string(jb, "tcp-reset");
540  break;
541  }
542  jb_close(jb);
543 
544  } else if (PacketCheckAction(p, ACTION_DROP) && EngineModeIsIPS()) {
545  JB_SET_STRING(jb, "action", "drop");
546  } else if (p->alerts.alerts[p->alerts.cnt].action & ACTION_PASS) {
547  JB_SET_STRING(jb, "action", "pass");
548  } else {
549  // TODO make sure we don't have a situation where this wouldn't work
550  JB_SET_STRING(jb, "action", "alert");
551  }
552 
553  /* Close verdict */
554  jb_close(jb);
555 }
556 
559  uint64_t last_re;
560 };
561 
562 static int AlertJsonStreamDataCallback(
563  void *cb_data, const uint8_t *input, const uint32_t input_len, const uint64_t input_offset)
564 {
565  struct AlertJsonStreamDataCallbackData *cbd = cb_data;
566  if (input_offset > cbd->last_re) {
568  cbd->payload, "[%" PRIu64 " bytes missing]", input_offset - cbd->last_re);
569  }
570 
571  int done = 0;
572  uint32_t written = MemBufferWriteRaw(cbd->payload, input, input_len);
573  if (written < input_len)
574  done = 1;
575  cbd->last_re = input_offset + input_len;
576  return done;
577 }
578 
579 /** \internal
580  * \brief try to log stream data into payload/payload_printable
581  * \retval true stream data logged
582  * \retval false stream data not logged
583  */
584 static bool AlertJsonStreamData(const AlertJsonOutputCtx *json_output_ctx, JsonAlertLogThread *aft,
585  Flow *f, const Packet *p, JsonBuilder *jb)
586 {
587  TcpSession *ssn = f->protoctx;
588  TcpStream *stream = (PKT_IS_TOSERVER(p)) ? &ssn->client : &ssn->server;
589 
590  MemBufferReset(aft->payload_buffer);
592  .last_re = STREAM_BASE_OFFSET(stream) };
593  uint64_t unused = 0;
594  StreamReassembleLog(ssn, stream, AlertJsonStreamDataCallback, &cbd, STREAM_BASE_OFFSET(stream),
595  &unused, false);
596  if (cbd.payload->offset) {
597  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
598  jb_set_base64(jb, "payload", cbd.payload->buffer, cbd.payload->offset);
599  }
600  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_LENGTH) {
601  jb_set_uint(jb, "payload_length", cbd.payload->offset);
602  }
603 
604  if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
605  uint8_t printable_buf[cbd.payload->offset + 1];
606  uint32_t offset = 0;
607  PrintStringsToBuffer(printable_buf, &offset, cbd.payload->offset + 1,
608  cbd.payload->buffer, cbd.payload->offset);
609  jb_set_string(jb, "payload_printable", (char *)printable_buf);
610  }
611  return true;
612  }
613  return false;
614 }
615 
616 static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
617 {
618  AlertJsonOutputCtx *json_output_ctx = aft->json_output_ctx;
619 
620  if (p->alerts.cnt == 0 && !(p->flags & PKT_HAS_TAG))
621  return TM_ECODE_OK;
622 
623  for (int i = 0; i < p->alerts.cnt; i++) {
624  const PacketAlert *pa = &p->alerts.alerts[i];
625  if (unlikely(pa->s == NULL)) {
626  continue;
627  }
628 
629  /* First initialize the address info (5-tuple). */
631  JsonAddrInfoInit(p, LOG_DIR_PACKET, &addr);
632 
633  /* Check for XFF, overwriting address info if needed. */
634  HttpXFFCfg *xff_cfg = json_output_ctx->xff_cfg != NULL ? json_output_ctx->xff_cfg
635  : json_output_ctx->parent_xff_cfg;
636  int have_xff_ip = 0;
637  char xff_buffer[XFF_MAXLEN];
638  xff_buffer[0] = 0;
639  if ((xff_cfg != NULL) && !(xff_cfg->flags & XFF_DISABLED) && p->flow != NULL) {
640  if (FlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) {
641  if (pa->flags & PACKET_ALERT_FLAG_TX) {
642  have_xff_ip = HttpXFFGetIPFromTx(p->flow, pa->tx_id, xff_cfg,
643  xff_buffer, XFF_MAXLEN);
644  } else {
645  have_xff_ip = HttpXFFGetIP(p->flow, xff_cfg, xff_buffer,
646  XFF_MAXLEN);
647  }
648  }
649 
650  if (have_xff_ip && xff_cfg->flags & XFF_OVERWRITE) {
651  if (p->flowflags & FLOW_PKT_TOCLIENT) {
652  strlcpy(addr.dst_ip, xff_buffer, JSON_ADDR_LEN);
653  } else {
654  strlcpy(addr.src_ip, xff_buffer, JSON_ADDR_LEN);
655  }
656  /* Clear have_xff_ip so the xff field does not get
657  * logged below. */
658  have_xff_ip = false;
659  }
660  if (have_xff_ip && !(xff_cfg->flags & XFF_EXTRADATA)) {
661  // reset xff_buffer so as not to log it
662  xff_buffer[0] = 0;
663  }
664  }
665 
666  JsonBuilder *jb =
667  CreateEveHeader(p, LOG_DIR_PACKET, "alert", &addr, json_output_ctx->eve_ctx);
668  if (unlikely(jb == NULL))
669  return TM_ECODE_OK;
670 
671 
672  /* alert */
673  AlertJsonHeader(p, pa, jb, json_output_ctx->flags, &addr, xff_buffer);
674 
675  if (PacketIsTunnel(p)) {
676  AlertJsonTunnel(p, jb);
677  }
678 
679  if (p->flow != NULL) {
680  if (pa->flags & PACKET_ALERT_FLAG_TX) {
681  if (json_output_ctx->flags & LOG_JSON_APP_LAYER) {
682  AlertAddAppLayer(p, jb, pa->tx_id, json_output_ctx->flags);
683  }
684  /* including fileinfo data is configured by the metadata setting */
685  if (json_output_ctx->flags & LOG_JSON_RULE_METADATA) {
686  AlertAddFiles(p, jb, pa->tx_id);
687  }
688  }
689 
690  EveAddAppProto(p->flow, jb);
691 
692  if (p->flowflags & FLOW_PKT_TOSERVER) {
693  jb_set_string(jb, "direction", "to_server");
694  } else {
695  jb_set_string(jb, "direction", "to_client");
696  }
697 
698  if (json_output_ctx->flags & LOG_JSON_FLOW) {
699  jb_open_object(jb, "flow");
700  EveAddFlow(p->flow, jb);
701  if (p->flowflags & FLOW_PKT_TOCLIENT) {
702  jb_set_string(jb, "src_ip", addr.dst_ip);
703  jb_set_string(jb, "dest_ip", addr.src_ip);
704  if (addr.sp > 0) {
705  jb_set_uint(jb, "src_port", addr.dp);
706  jb_set_uint(jb, "dest_port", addr.sp);
707  }
708  } else {
709  jb_set_string(jb, "src_ip", addr.src_ip);
710  jb_set_string(jb, "dest_ip", addr.dst_ip);
711  if (addr.sp > 0) {
712  jb_set_uint(jb, "src_port", addr.sp);
713  jb_set_uint(jb, "dest_port", addr.dp);
714  }
715  }
716  jb_close(jb);
717  }
718  }
719 
720  /* payload */
721  if (json_output_ctx->flags &
723  int stream = (p->proto == IPPROTO_TCP) ?
725  1 : 0) : 0;
726  // should be impossible, as stream implies flow
727  DEBUG_VALIDATE_BUG_ON(stream && p->flow == NULL);
728 
729  /* Is this a stream? If so, pack part of it into the payload field */
730  if (stream && p->flow != NULL) {
731  const bool stream_data_logged =
732  AlertJsonStreamData(json_output_ctx, aft, p->flow, p, jb);
733  if (!stream_data_logged && p->payload_len) {
734  /* Fallback on packet payload */
735  AlertAddPayload(json_output_ctx, jb, p);
736  }
737  } else {
738  /* This is a single packet and not a stream */
739  AlertAddPayload(json_output_ctx, jb, p);
740  }
741 
742  jb_set_uint(jb, "stream", stream);
743  }
744 
745  if (pa->flags & PACKET_ALERT_FLAG_FRAME) {
746  AlertAddFrame(p, pa->frame_id, jb, aft->payload_buffer);
747  }
748 
749  /* base64-encoded full packet */
750  if (json_output_ctx->flags & LOG_JSON_PACKET) {
751  EvePacket(p, jb, 0);
752  }
753 
755  if (pcap_filename != NULL) {
756  jb_set_string(jb, "capture_file", pcap_filename);
757  }
758 
759  if (json_output_ctx->flags & LOG_JSON_VERDICT) {
760  EveAddVerdict(jb, p);
761  }
762 
763  OutputJsonBuilderBuffer(tv, p, p->flow, jb, aft->ctx);
764  jb_free(jb);
765  }
766 
767  if ((p->flags & PKT_HAS_TAG) && (json_output_ctx->flags &
769  JsonBuilder *packetjs =
770  CreateEveHeader(p, LOG_DIR_PACKET, "packet", NULL, json_output_ctx->eve_ctx);
771  if (unlikely(packetjs != NULL)) {
772  EvePacket(p, packetjs, 0);
773  OutputJsonBuilderBuffer(tv, p, p->flow, packetjs, aft->ctx);
774  jb_free(packetjs);
775  }
776  }
777 
778  return TM_ECODE_OK;
779 }
780 
781 static int AlertJsonDecoderEvent(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
782 {
783  AlertJsonOutputCtx *json_output_ctx = aft->json_output_ctx;
784 
785  if (p->alerts.cnt == 0)
786  return TM_ECODE_OK;
787 
788  for (int i = 0; i < p->alerts.cnt; i++) {
789  const PacketAlert *pa = &p->alerts.alerts[i];
790  if (unlikely(pa->s == NULL)) {
791  continue;
792  }
793 
794  JsonBuilder *jb =
795  CreateEveHeader(p, LOG_DIR_PACKET, "alert", NULL, json_output_ctx->eve_ctx);
796  if (unlikely(jb == NULL))
797  return TM_ECODE_OK;
798 
799  AlertJsonHeader(p, pa, jb, json_output_ctx->flags, NULL, NULL);
800 
801  if (PacketIsTunnel(p)) {
802  AlertJsonTunnel(p, jb);
803  }
804 
805  /* base64-encoded full packet */
806  if (json_output_ctx->flags & LOG_JSON_PACKET) {
807  EvePacket(p, jb, 0);
808  }
809 
811  if (pcap_filename != NULL) {
812  jb_set_string(jb, "capture_file", pcap_filename);
813  }
814 
815  if (json_output_ctx->flags & LOG_JSON_VERDICT) {
816  EveAddVerdict(jb, p);
817  }
818 
819  OutputJsonBuilderBuffer(tv, p, p->flow, jb, aft->ctx);
820  jb_free(jb);
821  }
822 
823  return TM_ECODE_OK;
824 }
825 
826 static int JsonAlertLogger(ThreadVars *tv, void *thread_data, const Packet *p)
827 {
828  JsonAlertLogThread *aft = thread_data;
829 
830  if (PacketIsIPv4(p) || PacketIsIPv6(p)) {
831  return AlertJson(tv, aft, p);
832  } else if (p->alerts.cnt > 0) {
833  return AlertJsonDecoderEvent(tv, aft, p);
834  }
835  return 0;
836 }
837 
838 static bool JsonAlertLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
839 {
840  return (p->alerts.cnt || (p->flags & PKT_HAS_TAG));
841 }
842 
843 static TmEcode JsonAlertLogThreadInit(ThreadVars *t, const void *initdata, void **data)
844 {
846  if (unlikely(aft == NULL))
847  return TM_ECODE_FAILED;
848 
849  if (initdata == NULL)
850  {
851  SCLogDebug("Error getting context for EveLogAlert. \"initdata\" argument NULL");
852  goto error_exit;
853  }
854 
855  /** Use the Output Context (file pointer and mutex) */
856  AlertJsonOutputCtx *json_output_ctx = ((OutputCtx *)initdata)->data;
857 
858  aft->payload_buffer = MemBufferCreateNew(json_output_ctx->payload_buffer_size);
859  if (aft->payload_buffer == NULL) {
860  goto error_exit;
861  }
862  aft->ctx = CreateEveThreadCtx(t, json_output_ctx->eve_ctx);
863  if (!aft->ctx) {
864  goto error_exit;
865  }
866 
867  aft->json_output_ctx = json_output_ctx;
868 
869  *data = (void *)aft;
870  return TM_ECODE_OK;
871 
872 error_exit:
873  if (aft->payload_buffer != NULL) {
875  }
876  SCFree(aft);
877  return TM_ECODE_FAILED;
878 }
879 
880 static TmEcode JsonAlertLogThreadDeinit(ThreadVars *t, void *data)
881 {
882  JsonAlertLogThread *aft = (JsonAlertLogThread *)data;
883  if (aft == NULL) {
884  return TM_ECODE_OK;
885  }
886 
888  FreeEveThreadCtx(aft->ctx);
889 
890  /* clear memory */
891  memset(aft, 0, sizeof(JsonAlertLogThread));
892 
893  SCFree(aft);
894  return TM_ECODE_OK;
895 }
896 
897 static void JsonAlertLogDeInitCtxSub(OutputCtx *output_ctx)
898 {
899  SCLogDebug("cleaning up sub output_ctx %p", output_ctx);
900 
901  AlertJsonOutputCtx *json_output_ctx = (AlertJsonOutputCtx *) output_ctx->data;
902 
903  if (json_output_ctx != NULL) {
904  HttpXFFCfg *xff_cfg = json_output_ctx->xff_cfg;
905  if (xff_cfg != NULL) {
906  SCFree(xff_cfg);
907  }
908  SCFree(json_output_ctx);
909  }
910  SCFree(output_ctx);
911 }
912 
913 static void SetFlag(const ConfNode *conf, const char *name, uint16_t flag, uint16_t *out_flags)
914 {
915  DEBUG_VALIDATE_BUG_ON(conf == NULL);
916  const char *setting = ConfNodeLookupChildValue(conf, name);
917  if (setting != NULL) {
918  if (ConfValIsTrue(setting)) {
919  *out_flags |= flag;
920  } else {
921  *out_flags &= ~flag;
922  }
923  }
924 }
925 
926 static void JsonAlertLogSetupMetadata(AlertJsonOutputCtx *json_output_ctx,
927  ConfNode *conf)
928 {
929  static bool warn_no_meta = false;
930  uint32_t payload_buffer_size = JSON_STREAM_BUFFER_SIZE;
931  uint16_t flags = METADATA_DEFAULTS;
932 
933  if (conf != NULL) {
934  /* Check for metadata to enable/disable. */
935  ConfNode *metadata = ConfNodeLookupChild(conf, "metadata");
936  if (metadata != NULL) {
937  if (metadata->val != NULL && ConfValIsFalse(metadata->val)) {
939  } else if (ConfNodeHasChildren(metadata)) {
940  ConfNode *rule_metadata = ConfNodeLookupChild(metadata, "rule");
941  if (rule_metadata) {
942  SetFlag(rule_metadata, "raw", LOG_JSON_RULE, &flags);
943  SetFlag(rule_metadata, "metadata", LOG_JSON_RULE_METADATA,
944  &flags);
945  SetFlag(rule_metadata, "reference", LOG_JSON_REFERENCE, &flags);
946  }
947  SetFlag(metadata, "flow", LOG_JSON_FLOW, &flags);
948  SetFlag(metadata, "app-layer", LOG_JSON_APP_LAYER, &flags);
949  }
950  }
951 
952  /* Non-metadata toggles. */
953  SetFlag(conf, "payload", LOG_JSON_PAYLOAD_BASE64, &flags);
954  SetFlag(conf, "packet", LOG_JSON_PACKET, &flags);
955  SetFlag(conf, "tagged-packets", LOG_JSON_TAGGED_PACKETS, &flags);
956  SetFlag(conf, "payload-printable", LOG_JSON_PAYLOAD, &flags);
957  SetFlag(conf, "http-body-printable", LOG_JSON_HTTP_BODY, &flags);
958  SetFlag(conf, "http-body", LOG_JSON_HTTP_BODY_BASE64, &flags);
959  SetFlag(conf, "websocket-payload-printable", LOG_JSON_WEBSOCKET_PAYLOAD, &flags);
960  SetFlag(conf, "websocket-payload", LOG_JSON_WEBSOCKET_PAYLOAD_BASE64, &flags);
961  SetFlag(conf, "verdict", LOG_JSON_VERDICT, &flags);
962  SetFlag(conf, "payload-length", LOG_JSON_PAYLOAD_LENGTH, &flags);
963 
964  /* Check for obsolete flags and warn that they have no effect. */
965  static const char *deprecated_flags[] = { "http", "tls", "ssh", "smtp", "dnp3", "app-layer",
966  "flow", NULL };
967  for (int i = 0; deprecated_flags[i] != NULL; i++) {
968  if (ConfNodeLookupChildValue(conf, deprecated_flags[i]) != NULL) {
969  SCLogWarning("Found deprecated eve-log.alert flag \"%s\", this flag has no effect",
970  deprecated_flags[i]);
971  }
972  }
973 
974  const char *payload_buffer_value = ConfNodeLookupChildValue(conf, "payload-buffer-size");
975 
976  if (payload_buffer_value != NULL) {
977  uint32_t value;
978  if (ParseSizeStringU32(payload_buffer_value, &value) < 0) {
979  SCLogError("Error parsing "
980  "payload-buffer-size - %s. Killing engine",
981  payload_buffer_value);
982  exit(EXIT_FAILURE);
983  } else {
984  payload_buffer_size = value;
985  }
986  }
987 
988  if (!warn_no_meta && flags & JSON_BODY_LOGGING) {
989  if (((flags & LOG_JSON_APP_LAYER) == 0)) {
990  SCLogWarning("HTTP body logging has been configured, however, "
991  "metadata logging has not been enabled. HTTP body logging will be "
992  "disabled.");
994  warn_no_meta = true;
995  }
996  }
997  }
998 
1001  }
1002 
1003  json_output_ctx->payload_buffer_size = payload_buffer_size;
1004  json_output_ctx->flags |= flags;
1005 }
1006 
1007 static HttpXFFCfg *JsonAlertLogGetXffCfg(ConfNode *conf)
1008 {
1009  HttpXFFCfg *xff_cfg = NULL;
1010  if (conf != NULL && ConfNodeLookupChild(conf, "xff") != NULL) {
1011  xff_cfg = SCCalloc(1, sizeof(HttpXFFCfg));
1012  if (likely(xff_cfg != NULL)) {
1013  HttpXFFGetCfg(conf, xff_cfg);
1014  }
1015  }
1016  return xff_cfg;
1017 }
1018 
1019 /**
1020  * \brief Create a new LogFileCtx for "fast" output style.
1021  * \param conf The configuration node for this output.
1022  * \return A LogFileCtx pointer on success, NULL on failure.
1023  */
1024 static OutputInitResult JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
1025 {
1026  OutputInitResult result = { NULL, false };
1027  OutputJsonCtx *ajt = parent_ctx->data;
1028  AlertJsonOutputCtx *json_output_ctx = NULL;
1029 
1030  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
1031  if (unlikely(output_ctx == NULL))
1032  return result;
1033 
1034  json_output_ctx = SCCalloc(1, sizeof(AlertJsonOutputCtx));
1035  if (unlikely(json_output_ctx == NULL)) {
1036  goto error;
1037  }
1038 
1039  json_output_ctx->file_ctx = ajt->file_ctx;
1040  json_output_ctx->eve_ctx = ajt;
1041 
1042  JsonAlertLogSetupMetadata(json_output_ctx, conf);
1043  json_output_ctx->xff_cfg = JsonAlertLogGetXffCfg(conf);
1044  if (json_output_ctx->xff_cfg == NULL) {
1045  json_output_ctx->parent_xff_cfg = ajt->xff_cfg;
1046  }
1047 
1048  output_ctx->data = json_output_ctx;
1049  output_ctx->DeInit = JsonAlertLogDeInitCtxSub;
1050 
1051  result.ctx = output_ctx;
1052  result.ok = true;
1053  return result;
1054 
1055 error:
1056  if (json_output_ctx != NULL) {
1057  SCFree(json_output_ctx);
1058  }
1059  if (output_ctx != NULL) {
1060  SCFree(output_ctx);
1061  }
1062 
1063  return result;
1064 }
1065 
1067 {
1068  OutputRegisterPacketSubModule(LOGGER_JSON_ALERT, "eve-log", MODULE_NAME, "eve-log.alert",
1069  JsonAlertLogInitCtxSub, JsonAlertLogger, JsonAlertLogCondition, JsonAlertLogThreadInit,
1070  JsonAlertLogThreadDeinit);
1071 }
XFF_MAXLEN
#define XFF_MAXLEN
Definition: app-layer-htp-xff.h:39
PacketCheckAction
bool PacketCheckAction(const Packet *p, const uint8_t a)
Definition: packet.c:49
Packet_::proto
uint8_t proto
Definition: decode.h:498
TcpStream_
Definition: stream-tcp-private.h:106
FileContainer_
Definition: util-file.h:113
DetectMetadataHead::json_str
char * json_str
Definition: detect-metadata.h:40
detect-engine.h
PACKET_ALERT_FLAG_STREAM_MATCH
#define PACKET_ALERT_FLAG_STREAM_MATCH
Definition: decode.h:253
EveSMTPAddMetadata
bool EveSMTPAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-smtp.c:96
PacketAlert_::s
const struct Signature_ * s
Definition: decode.h:243
EveHttpLogJSONBodyPrintable
void EveHttpLogJSONBodyPrintable(JsonBuilder *js, Flow *f, uint64_t tx_id)
Definition: output-json-http.c:390
ALPROTO_IKE
@ ALPROTO_IKE
Definition: app-layer-protos.h:49
EvePacket
void EvePacket(const Packet *p, JsonBuilder *js, uint32_t max_length)
Jsonify a packet.
Definition: output-json.c:422
OutputJsonCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json.h:85
MemBuffer_::buffer
uint8_t buffer[]
Definition: util-buffer.h:30
Signature_::sig_str
char * sig_str
Definition: detect.h:670
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
ALPROTO_DCERPC
@ ALPROTO_DCERPC
Definition: app-layer-protos.h:38
PACKET_ALERT_FLAG_TX
#define PACKET_ALERT_FLAG_TX
Definition: decode.h:255
XFF_EXTRADATA
#define XFF_EXTRADATA
Definition: app-layer-htp-xff.h:31
ConfNode_::val
char * val
Definition: conf.h:34
stream-tcp.h
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
OutputRegisterPacketSubModule
void OutputRegisterPacketSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, PacketLogger PacketLogFunc, PacketLogCondition PacketConditionFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a packet output sub-module.
Definition: output.c:206
ACTION_PASS
#define ACTION_PASS
Definition: action-globals.h:34
ACTION_REJECT
#define ACTION_REJECT
Definition: action-globals.h:31
LOG_JSON_RULE
#define LOG_JSON_RULE
Definition: output-json-alert.c:82
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:595
AlertJsonOutputCtx_::file_ctx
LogFileCtx * file_ctx
Definition: output-json-alert.c:100
AlertJsonOutputCtx_::parent_xff_cfg
HttpXFFCfg * parent_xff_cfg
Definition: output-json-alert.c:104
FreeEveThreadCtx
void FreeEveThreadCtx(OutputJsonThreadCtx *ctx)
Definition: output-json-common.c:58
Flow_::proto
uint8_t proto
Definition: flow.h:378
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:81
AlertJsonStreamDataCallbackData::last_re
uint64_t last_re
Definition: output-json-alert.c:559
Packet_::payload
uint8_t * payload
Definition: decode.h:574
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:267
SIG_FLAG_DEST_IS_TARGET
#define SIG_FLAG_DEST_IS_TARGET
Definition: detect.h:281
SCEveJsonSimpleGetLogger
EveJsonSimpleAppLayerLogger * SCEveJsonSimpleGetLogger(AppProto alproto)
Definition: output.c:836
action-globals.h
FramesContainer::toserver
Frames toserver
Definition: app-layer-frames.h:72
Packet_::flags
uint32_t flags
Definition: decode.h:513
LOGGER_JSON_ALERT
@ LOGGER_JSON_ALERT
Definition: suricata-common.h:480
OutputJsonCtx_
Definition: output-json.h:81
Frame
Definition: app-layer-frames.h:43
Flow_
Flow data structure.
Definition: flow.h:356
LogFileCtx_
Definition: util-logopenfile.h:72
OutputJsonBuilderBuffer
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:958
output-json-frame.h
EveNFSAddMetadata
bool EveNFSAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
Definition: output-json-nfs.c:62
PacketAlerts_::alerts
PacketAlert * alerts
Definition: decode.h:270
CreateEveThreadCtx
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
Definition: output-json-common.c:29
AlertJsonStreamDataCallbackData::payload
MemBuffer * payload
Definition: output-json-alert.c:558
json_addr_info_zero
const JsonAddrInfo json_addr_info_zero
Definition: output-json.c:81
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:232
rust.h
Frames
Definition: app-layer-frames.h:58
ACTION_REJECT_ANY
#define ACTION_REJECT_ANY
Definition: action-globals.h:37
FramesContainer
Definition: app-layer-frames.h:71
EveFileInfo
void EveFileInfo(JsonBuilder *jb, const File *ff, const uint64_t tx_id, const uint16_t flags)
Definition: output-json.c:124
ACTION_DROP_REJECT
#define ACTION_DROP_REJECT
Definition: action-globals.h:39
proto
uint8_t proto
Definition: decode-template.h:0
AlertJsonOutputCtx_::eve_ctx
OutputJsonCtx * eve_ctx
Definition: output-json-alert.c:105
app-layer-ftp.h
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:507
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:81
Flow_::protoctx
void * protoctx
Definition: flow.h:446
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:575
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:589
MemBuffer_::offset
uint32_t offset
Definition: util-buffer.h:29
EveHttpAddMetadata
bool EveHttpAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-http.c:498
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:536
HttpXFFGetIP
int HttpXFFGetIP(const Flow *f, HttpXFFCfg *xff_cfg, char *dstbuf, int dstbuflen)
Function to return XFF IP if any. The caller needs to lock the flow.
Definition: app-layer-htp-xff.c:180
OutputCtx_::data
void * data
Definition: tm-modules.h:87
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:80
PcapLogGetFilename
char * PcapLogGetFilename(void)
Definition: log-pcap.c:1766
PrintStringsToBuffer
void PrintStringsToBuffer(uint8_t *dst_buf, uint32_t *dst_buf_offset_ptr, uint32_t dst_buf_size, const uint8_t *src_buf, const uint32_t src_buf_len)
Definition: util-print.c:194
AppLayerParserGetTxFiles
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *tx, const uint8_t direction)
Definition: app-layer-parser.c:854
PacketAlert_::tx_id
uint64_t tx_id
Definition: decode.h:244
OutputCtx_
Definition: tm-modules.h:84
app-layer-htp-xff.h
PacketAlert_::action
uint8_t action
Definition: decode.h:241
strlcpy
size_t strlcpy(char *dst, const char *src, size_t siz)
Definition: util-strlcpyu.c:43
JSON_BODY_LOGGING
#define JSON_BODY_LOGGING
Definition: output-json-alert.c:93
OutputJsonThreadCtx_
Definition: output-json.h:89
Signature_::gid
uint32_t gid
Definition: detect.h:639
ACTION_REJECT_DST
#define ACTION_REJECT_DST
Definition: action-globals.h:32
JsonAddrInfo_::dp
Port dp
Definition: output-json.h:51
FramesContainer::toclient
Frames toclient
Definition: app-layer-frames.h:73
JsonAlertLogThread_::ctx
OutputJsonThreadCtx * ctx
Definition: output-json-alert.c:111
util-debug.h
JB_SET_STRING
#define JB_SET_STRING(jb, key, val)
Definition: rust.h:26
output-json-flow.h
MODULE_NAME
#define MODULE_NAME
Definition: output-json-alert.c:71
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:234
OutputInitResult_::ctx
OutputCtx * ctx
Definition: output.h:47
LOG_JSON_APP_LAYER
#define LOG_JSON_APP_LAYER
Definition: output-json-alert.c:77
LOG_JSON_WEBSOCKET_PAYLOAD
#define LOG_JSON_WEBSOCKET_PAYLOAD
Definition: output-json-alert.c:84
output-json.h
FrameGetById
Frame * FrameGetById(Frames *frames, const int64_t id)
Definition: app-layer-frames.c:114
DetectReference_::key_len
uint16_t key_len
Definition: detect-reference.h:40
ALPROTO_SMTP
@ ALPROTO_SMTP
Definition: app-layer-protos.h:32
EveIKEAddMetadata
bool EveIKEAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-ike.c:65
LOG_JSON_PAYLOAD
#define LOG_JSON_PAYLOAD
Definition: output-json-alert.c:73
STREAM_BASE_OFFSET
#define STREAM_BASE_OFFSET(stream)
Definition: stream-tcp-private.h:144
PktSrcEnum
PktSrcEnum
Definition: decode.h:50
util-reference-config.h
AlertJsonOutputCtx_::flags
uint16_t flags
Definition: output-json-alert.c:101
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:806
util-print.h
Signature_::references
DetectReference * references
Definition: detect.h:666
FileContainer_::head
File * head
Definition: util-file.h:114
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
PktSrcToString
const char * PktSrcToString(enum PktSrcEnum pkt_src)
Definition: decode.c:825
JsonAlertLogThread
struct JsonAlertLogThread_ JsonAlertLogThread
output-json-email-common.h
util-time.h
OutputInitResult_::ok
bool ok
Definition: output.h:48
PACKET_ALERT_FLAG_TX_GUESSED
#define PACKET_ALERT_FLAG_TX_GUESSED
Definition: decode.h:261
SCLogWarning
#define SCLogWarning(...)
Macro used to log WARNING messages.
Definition: util-debug.h:249
EveHttpLogJSONBodyBase64
void EveHttpLogJSONBodyBase64(JsonBuilder *js, Flow *f, uint64_t tx_id)
Definition: output-json-http.c:421
app-layer-parser.h
JsonAlertLogThread_
Definition: output-json-alert.c:108
DetectReference_
Signature reference list.
Definition: detect-reference.h:30
Signature_::flags
uint32_t flags
Definition: detect.h:604
stream.h
DetectReference_::reference_len
uint16_t reference_len
Definition: detect-reference.h:41
JsonAddrInfo_
Definition: output-json.h:47
Packet_
Definition: decode.h:476
AppLayerFramesGetContainer
FramesContainer * AppLayerFramesGetContainer(Flow *f)
Definition: app-layer-parser.c:173
DetectReference_::reference
char * reference
Definition: detect-reference.h:34
JSON_STREAM_BUFFER_SIZE
#define JSON_STREAM_BUFFER_SIZE
Definition: output-json-alert.c:97
LOG_JSON_PAYLOAD_BASE64
#define LOG_JSON_PAYLOAD_BASE64
Definition: output-json-alert.c:75
conf.h
SIG_FLAG_HAS_TARGET
#define SIG_FLAG_HAS_TARGET
Definition: detect.h:283
XFF_OVERWRITE
#define XFF_OVERWRITE
Definition: app-layer-htp-xff.h:33
AlertJsonHeader
void AlertJsonHeader(const Packet *p, const PacketAlert *pa, JsonBuilder *js, uint16_t flags, JsonAddrInfo *addr, char *xff_buffer)
Definition: output-json-alert.c:202
LOG_JSON_PAYLOAD_LENGTH
#define LOG_JSON_PAYLOAD_LENGTH
Definition: output-json-alert.c:86
TmEcode
TmEcode
Definition: tm-threads-common.h:79
SIG_FLAG_SRC_IS_TARGET
#define SIG_FLAG_SRC_IS_TARGET
Definition: detect.h:279
EveNFSAddMetadataRPC
bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
Definition: output-json-nfs.c:50
HttpXFFCfg_
Definition: app-layer-htp-xff.h:41
AlertJsonOutputCtx_::payload_buffer_size
uint32_t payload_buffer_size
Definition: output-json-alert.c:102
ConfNodeHasChildren
bool ConfNodeHasChildren(const ConfNode *node)
Check if a node has any children.
Definition: conf.c:762
MemBuffer_
Definition: util-buffer.h:27
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:233
EveJsonSimpleAppLayerLogger
Definition: output.h:166
DetectReference_::next
struct DetectReference_ * next
Definition: detect-reference.h:43
LOG_JSON_TAGGED_PACKETS
#define LOG_JSON_TAGGED_PACKETS
Definition: output-json-alert.c:76
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1094
AlertJsonOutputCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json-alert.c:103
log-pcap.h
PacketAlert_::frame_id
int64_t frame_id
Definition: decode.h:245
JsonAddrInfo_::proto
char proto[JSON_PROTO_LEN]
Definition: output-json.h:52
Signature_::class_msg
char * class_msg
Definition: detect.h:664
ConfNodeLookupChild
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
Definition: conf.c:781
PacketAlert_::flags
uint8_t flags
Definition: decode.h:242
ACTION_REJECT_BOTH
#define ACTION_REJECT_BOTH
Definition: action-globals.h:33
File_::flags
uint16_t flags
Definition: util-file.h:80
PACKET_ALERT_RATE_FILTER_MODIFIED
#define PACKET_ALERT_RATE_FILTER_MODIFIED
Definition: decode.h:257
File_
Definition: util-file.h:79
OutputInitResult_
Definition: output.h:46
app-layer-frames.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:515
Packet_::tenant_id
uint32_t tenant_id
Definition: decode.h:634
EveEmailAddMetadata
bool EveEmailAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-email-common.c:191
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-json.h:37
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
LOG_JSON_WEBSOCKET_PAYLOAD_BASE64
#define LOG_JSON_WEBSOCKET_PAYLOAD_BASE64
Definition: output-json-alert.c:85
JsonAddrInfo_::sp
Port sp
Definition: output-json.h:50
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:90
pcap_filename
char pcap_filename[PATH_MAX]
Definition: source-pcap-file-helper.c:116
EveJsonSimpleAppLayerLogger::LogTx
EveJsonSimpleTxLogFunc LogTx
Definition: output.h:167
JSON_ADDR_LEN
#define JSON_ADDR_LEN
Definition: output-json.h:43
AlertJsonOutputCtx_
Definition: output-json-alert.c:99
detect-metadata.h
JsonAlertLogThread_::json_output_ctx
AlertJsonOutputCtx * json_output_ctx
Definition: output-json-alert.c:110
output-json-nfs.h
packet.h
EveAddVerdict
void EveAddVerdict(JsonBuilder *jb, const Packet *p)
Build verdict object.
Definition: output-json-alert.c:512
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
MemBufferFree
void MemBufferFree(MemBuffer *buffer)
Definition: util-buffer.c:86
LOG_JSON_VERDICT
#define LOG_JSON_VERDICT
Definition: output-json-alert.c:83
File_::next
struct File_ * next
Definition: util-file.h:92
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
EveAddAppProto
void EveAddAppProto(Flow *f, JsonBuilder *js)
Definition: output-json-flow.c:169
Signature_::rev
uint32_t rev
Definition: detect.h:640
ALPROTO_WEBSOCKET
@ ALPROTO_WEBSOCKET
Definition: app-layer-protos.h:59
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:297
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
Signature_::prio
int prio
Definition: detect.h:641
ParseSizeStringU32
int ParseSizeStringU32(const char *size, uint32_t *res)
Definition: util-misc.c:173
output-json-alert.h
util-optimize.h
threadvars.h
util-validate.h
Packet_::root
struct Packet_ * root
Definition: decode.h:622
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:296
JsonAddrInfo_::src_ip
char src_ip[JSON_ADDR_LEN]
Definition: output-json.h:48
HttpXFFCfg_::flags
uint8_t flags
Definition: app-layer-htp-xff.h:42
Signature_::metadata
DetectMetadataHead * metadata
Definition: detect.h:668
PACKET_ALERT_FLAG_FRAME
#define PACKET_ALERT_FLAG_FRAME
Definition: decode.h:259
SCLogError
#define SCLogError(...)
Macro used to log ERROR messages.
Definition: util-debug.h:261
AlertJsonOutputCtx
struct AlertJsonOutputCtx_ AlertJsonOutputCtx
JsonAlertLogThread_::payload_buffer
MemBuffer * payload_buffer
Definition: output-json-alert.c:109
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Packet_::pkt_src
uint8_t pkt_src
Definition: decode.h:580
DetectReference_::key
char * key
Definition: detect-reference.h:32
ConfNode_
Definition: conf.h:32
util-logopenfile.h
Flow_::alstate
void * alstate
Definition: flow.h:481
Signature_::id
uint32_t id
Definition: detect.h:638
Packet_::recursion_level
uint8_t recursion_level
Definition: decode.h:501
LOG_JSON_HTTP_BODY_BASE64
#define LOG_JSON_HTTP_BODY_BASE64
Definition: output-json-alert.c:80
output-json-ike.h
util-buffer.h
LOG_JSON_PACKET
#define LOG_JSON_PACKET
Definition: output-json-alert.c:74
ConfValIsFalse
int ConfValIsFalse(const char *val)
Check if a value is false.
Definition: conf.c:561
FrameJsonLogOneFrame
void FrameJsonLogOneFrame(const uint8_t ipproto, const Frame *frame, Flow *f, const TcpStream *stream, const Packet *p, JsonBuilder *jb, MemBuffer *buffer)
log a single frame
Definition: output-json-frame.c:253
JsonAddrInfo_::dst_ip
char dst_ip[JSON_ADDR_LEN]
Definition: output-json.h:49
OutputJsonCtx_::file_ctx
LogFileCtx * file_ctx
Definition: output-json.h:82
LOG_JSON_HTTP_BODY
#define LOG_JSON_HTTP_BODY
Definition: output-json-alert.c:79
METADATA_DEFAULTS
#define METADATA_DEFAULTS
Definition: output-json-alert.c:89
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:228
LOG_JSON_FLOW
#define LOG_JSON_FLOW
Definition: output-json-alert.c:78
MemBufferWriteRaw
uint32_t MemBufferWriteRaw(MemBuffer *dst, const uint8_t *raw, const uint32_t raw_len)
Write a raw buffer to the MemBuffer dst.
Definition: util-buffer.c:115
PacketAlert_
Definition: decode.h:239
MemBufferWriteString
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
Definition: util-buffer.c:130
JsonAddrInfoInit
void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddrInfo *addr)
Definition: output-json.c:459
HttpXFFGetCfg
void HttpXFFGetCfg(ConfNode *conf, HttpXFFCfg *result)
Function to return XFF configuration from a configuration node.
Definition: app-layer-htp-xff.c:205
output-json-smb.h
ALPROTO_SMB
@ ALPROTO_SMB
Definition: app-layer-protos.h:37
likely
#define likely(expr)
Definition: util-optimize.h:32
IPPROTO_SCTP
#define IPPROTO_SCTP
Definition: decode.h:1194
HttpXFFGetIPFromTx
int HttpXFFGetIPFromTx(const Flow *f, uint64_t tx_id, HttpXFFCfg *xff_cfg, char *dstbuf, int dstbuflen)
Function to return XFF IP if any in the selected transaction. The caller needs to lock the flow.
Definition: app-layer-htp-xff.c:116
output-json-smtp.h
TcpSession_
Definition: stream-tcp-private.h:283
output-json-http.h
util-misc.h
PKT_HAS_TAG
#define PKT_HAS_TAG
Definition: decode.h:1261
Signature_::msg
char * msg
Definition: detect.h:661
flow.h
DetectEngineSetParseMetadata
void DetectEngineSetParseMetadata(void)
Definition: detect-engine.c:4947
EveSMBAddMetadata
bool EveSMBAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
Definition: output-json-smb.c:34
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:455
StreamReassembleLog
int StreamReassembleLog(const TcpSession *ssn, const TcpStream *stream, StreamReassembleRawFunc Callback, void *cb_data, const uint64_t progress_in, uint64_t *progress_out, const bool eof)
Definition: stream-tcp-reassemble.c:1969
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
LOG_JSON_RULE_METADATA
#define LOG_JSON_RULE_METADATA
Definition: output-json-alert.c:81
XFF_DISABLED
#define XFF_DISABLED
Definition: app-layer-htp-xff.h:29
PACKET_ALERT_FLAG_STATE_MATCH
#define PACKET_ALERT_FLAG_STATE_MATCH
Definition: decode.h:251
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:102
LOG_JSON_REFERENCE
#define LOG_JSON_REFERENCE
Definition: output-json-alert.c:87
ALPROTO_NFS
@ ALPROTO_NFS
Definition: app-layer-protos.h:45
MemBufferCreateNew
MemBuffer * MemBufferCreateNew(uint32_t size)
Definition: util-buffer.c:32
output.h
JsonAlertLogRegister
void JsonAlertLogRegister(void)
Definition: output-json-alert.c:1066
AlertJsonStreamDataCallbackData
Definition: output-json-alert.c:557
EveAddFlow
void EveAddFlow(Flow *f, JsonBuilder *js)
Definition: output-json-flow.c:190
ConfNodeLookupChildValue
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:809