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  }
224 
225  jb_open_object(js, "alert");
226 
227  jb_set_string(js, "action", action);
228  jb_set_uint(js, "gid", pa->s->gid);
229  jb_set_uint(js, "signature_id", pa->s->id);
230  jb_set_uint(js, "rev", pa->s->rev);
231  /* TODO: JsonBuilder should handle unprintable characters like
232  * SCJsonString. */
233  jb_set_string(js, "signature", pa->s->msg ? pa->s->msg: "");
234  jb_set_string(js, "category", pa->s->class_msg ? pa->s->class_msg: "");
235  jb_set_uint(js, "severity", pa->s->prio);
236 
237  if (p->tenant_id > 0) {
238  jb_set_uint(js, "tenant_id", p->tenant_id);
239  }
240 
241  if (addr && pa->s->flags & SIG_FLAG_HAS_TARGET) {
242  AlertJsonSourceTarget(p, pa, js, addr);
243  }
244 
245  if ((flags & LOG_JSON_REFERENCE)) {
246  AlertJsonReference(pa, js);
247  }
248 
250  AlertJsonMetadata(pa, js);
251  }
252 
253  if (flags & LOG_JSON_RULE) {
254  jb_set_string(js, "rule", pa->s->sig_str);
255  }
256  if (xff_buffer && xff_buffer[0]) {
257  jb_set_string(js, "xff", xff_buffer);
258  }
259 
260  jb_close(js);
261 }
262 
263 static void AlertJsonTunnel(const Packet *p, JsonBuilder *js)
264 {
265  if (p->root == NULL) {
266  return;
267  }
268 
269  jb_open_object(js, "tunnel");
270 
271  enum PktSrcEnum pkt_src;
272  uint64_t pcap_cnt;
274  JsonAddrInfoInit(p->root, 0, &addr);
275  pcap_cnt = p->root->pcap_cnt;
276  pkt_src = p->root->pkt_src;
277 
278  jb_set_string(js, "src_ip", addr.src_ip);
279  jb_set_uint(js, "src_port", addr.sp);
280  jb_set_string(js, "dest_ip", addr.dst_ip);
281  jb_set_uint(js, "dest_port", addr.dp);
282  jb_set_string(js, "proto", addr.proto);
283 
284  jb_set_uint(js, "depth", p->recursion_level);
285  if (pcap_cnt != 0) {
286  jb_set_uint(js, "pcap_cnt", pcap_cnt);
287  }
288  jb_set_string(js, "pkt_src", PktSrcToString(pkt_src));
289  jb_close(js);
290 }
291 
292 static void AlertAddPayload(AlertJsonOutputCtx *json_output_ctx, JsonBuilder *js, const Packet *p)
293 {
294  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
295  jb_set_base64(js, "payload", p->payload, p->payload_len);
296  }
297  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_LENGTH) {
298  jb_set_uint(js, "payload_length", p->payload_len);
299  }
300 
301  if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
302  uint8_t printable_buf[p->payload_len + 1];
303  uint32_t offset = 0;
304  PrintStringsToBuffer(printable_buf, &offset,
305  p->payload_len + 1,
306  p->payload, p->payload_len);
307  printable_buf[p->payload_len] = '\0';
308  jb_set_string(js, "payload_printable", (char *)printable_buf);
309  }
310 }
311 
312 static void AlertAddAppLayer(const Packet *p, JsonBuilder *jb,
313  const uint64_t tx_id, const uint16_t option_flags)
314 {
315  const AppProto proto = FlowGetAppProtocol(p->flow);
317  JsonBuilderMark mark = { 0, 0, 0 };
318  if (al && al->LogTx) {
319  void *state = FlowGetAppState(p->flow);
320  if (state) {
321  void *tx = AppLayerParserGetTx(p->flow->proto, proto, state, tx_id);
322  if (tx) {
323  jb_get_mark(jb, &mark);
324  switch (proto) {
325  // first check some protocols need special options for alerts logging
326  case ALPROTO_WEBSOCKET:
327  if (option_flags &
329  bool pp = (option_flags & LOG_JSON_WEBSOCKET_PAYLOAD) != 0;
330  bool pb64 = (option_flags & LOG_JSON_WEBSOCKET_PAYLOAD_BASE64) != 0;
331  if (!SCWebSocketLogDetails(tx, jb, pp, pb64)) {
332  jb_restore_mark(jb, &mark);
333  }
334  // nothing more to log or do
335  return;
336  }
337  }
338  if (!al->LogTx(tx, jb)) {
339  jb_restore_mark(jb, &mark);
340  }
341  }
342  }
343  return;
344  }
345  switch (proto) {
346  case ALPROTO_HTTP1:
347  // TODO: Could result in an empty http object being logged.
348  jb_open_object(jb, "http");
349  if (EveHttpAddMetadata(p->flow, tx_id, jb)) {
350  if (option_flags & LOG_JSON_HTTP_BODY) {
351  EveHttpLogJSONBodyPrintable(jb, p->flow, tx_id);
352  }
353  if (option_flags & LOG_JSON_HTTP_BODY_BASE64) {
354  EveHttpLogJSONBodyBase64(jb, p->flow, tx_id);
355  }
356  }
357  jb_close(jb);
358  break;
359  case ALPROTO_SMTP:
360  jb_get_mark(jb, &mark);
361  jb_open_object(jb, "smtp");
362  if (EveSMTPAddMetadata(p->flow, tx_id, jb)) {
363  jb_close(jb);
364  } else {
365  jb_restore_mark(jb, &mark);
366  }
367  jb_get_mark(jb, &mark);
368  jb_open_object(jb, "email");
369  if (EveEmailAddMetadata(p->flow, tx_id, jb)) {
370  jb_close(jb);
371  } else {
372  jb_restore_mark(jb, &mark);
373  }
374  break;
375  case ALPROTO_NFS:
376  /* rpc */
377  jb_get_mark(jb, &mark);
378  jb_open_object(jb, "rpc");
379  if (EveNFSAddMetadataRPC(p->flow, tx_id, jb)) {
380  jb_close(jb);
381  } else {
382  jb_restore_mark(jb, &mark);
383  }
384  /* nfs */
385  jb_get_mark(jb, &mark);
386  jb_open_object(jb, "nfs");
387  if (EveNFSAddMetadata(p->flow, tx_id, jb)) {
388  jb_close(jb);
389  } else {
390  jb_restore_mark(jb, &mark);
391  }
392  break;
393  case ALPROTO_SMB:
394  jb_get_mark(jb, &mark);
395  jb_open_object(jb, "smb");
396  if (EveSMBAddMetadata(p->flow, tx_id, jb)) {
397  jb_close(jb);
398  } else {
399  jb_restore_mark(jb, &mark);
400  }
401  break;
402  case ALPROTO_IKE:
403  jb_get_mark(jb, &mark);
404  if (!EveIKEAddMetadata(p->flow, tx_id, jb)) {
405  jb_restore_mark(jb, &mark);
406  }
407  break;
408  case ALPROTO_DCERPC: {
409  void *state = FlowGetAppState(p->flow);
410  if (state) {
411  void *tx = AppLayerParserGetTx(p->flow->proto, proto, state, tx_id);
412  if (tx) {
413  jb_get_mark(jb, &mark);
414  jb_open_object(jb, "dcerpc");
415  if (p->proto == IPPROTO_TCP) {
416  if (!rs_dcerpc_log_json_record_tcp(state, tx, jb)) {
417  jb_restore_mark(jb, &mark);
418  }
419  } else {
420  if (!rs_dcerpc_log_json_record_udp(state, tx, jb)) {
421  jb_restore_mark(jb, &mark);
422  }
423  }
424  jb_close(jb);
425  }
426  }
427  break;
428  }
429  default:
430  break;
431  }
432 }
433 
434 static void AlertAddFiles(const Packet *p, JsonBuilder *jb, const uint64_t tx_id)
435 {
436  const uint8_t direction =
437  (p->flowflags & FLOW_PKT_TOSERVER) ? STREAM_TOSERVER : STREAM_TOCLIENT;
438  FileContainer *ffc = NULL;
439  if (p->flow->alstate != NULL) {
440  void *tx = AppLayerParserGetTx(p->flow->proto, p->flow->alproto, p->flow->alstate, tx_id);
441  if (tx) {
442  AppLayerGetFileState files = AppLayerParserGetTxFiles(p->flow, tx, direction);
443  ffc = files.fc;
444  }
445  }
446  if (ffc != NULL) {
447  File *file = ffc->head;
448  bool isopen = false;
449  while (file) {
450  if (!isopen) {
451  isopen = true;
452  jb_open_array(jb, "files");
453  }
454  jb_start_object(jb);
455  EveFileInfo(jb, file, tx_id, file->flags);
456  jb_close(jb);
457  file = file->next;
458  }
459  if (isopen) {
460  jb_close(jb);
461  }
462  }
463 }
464 
465 static void AlertAddFrame(
466  const Packet *p, const int64_t frame_id, JsonBuilder *jb, MemBuffer *buffer)
467 {
468  if (p->flow == NULL || (p->proto == IPPROTO_TCP && p->flow->protoctx == NULL))
469  return;
470 
471  FramesContainer *frames_container = AppLayerFramesGetContainer(p->flow);
472  if (frames_container == NULL)
473  return;
474 
475  Frames *frames = NULL;
476  TcpStream *stream = NULL;
477  if (p->proto == IPPROTO_TCP) {
478  TcpSession *ssn = p->flow->protoctx;
479  if (PKT_IS_TOSERVER(p)) {
480  stream = &ssn->client;
481  frames = &frames_container->toserver;
482  } else {
483  stream = &ssn->server;
484  frames = &frames_container->toclient;
485  }
486  Frame *frame = FrameGetById(frames, frame_id);
487  if (frame != NULL) {
488  FrameJsonLogOneFrame(IPPROTO_TCP, frame, p->flow, stream, p, jb, buffer);
489  }
490  } else if (p->proto == IPPROTO_UDP) {
491  if (PKT_IS_TOSERVER(p)) {
492  frames = &frames_container->toserver;
493  } else {
494  frames = &frames_container->toclient;
495  }
496  Frame *frame = FrameGetById(frames, frame_id);
497  if (frame != NULL) {
498  FrameJsonLogOneFrame(IPPROTO_UDP, frame, p->flow, NULL, p, jb, buffer);
499  }
500  }
501 }
502 
503 /**
504  * \brief Build verdict object
505  *
506  * \param p Pointer to Packet current being logged
507  *
508  */
509 void EveAddVerdict(JsonBuilder *jb, const Packet *p)
510 {
511  jb_open_object(jb, "verdict");
512 
513  /* add verdict info */
515  // check rule to define type of reject packet sent
516  if (EngineModeIsIPS()) {
517  JB_SET_STRING(jb, "action", "drop");
518  } else {
519  JB_SET_STRING(jb, "action", "alert");
520  }
522  JB_SET_STRING(jb, "reject-target", "to_client");
523  } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
524  JB_SET_STRING(jb, "reject-target", "to_server");
525  } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
526  JB_SET_STRING(jb, "reject-target", "both");
527  }
528  jb_open_array(jb, "reject");
529  switch (p->proto) {
530  case IPPROTO_UDP:
531  case IPPROTO_ICMP:
532  case IPPROTO_ICMPV6:
533  jb_append_string(jb, "icmp-prohib");
534  break;
535  case IPPROTO_TCP:
536  jb_append_string(jb, "tcp-reset");
537  break;
538  }
539  jb_close(jb);
540 
541  } else if (PacketCheckAction(p, ACTION_DROP) && EngineModeIsIPS()) {
542  JB_SET_STRING(jb, "action", "drop");
543  } else if (p->alerts.alerts[p->alerts.cnt].action & ACTION_PASS) {
544  JB_SET_STRING(jb, "action", "pass");
545  } else {
546  // TODO make sure we don't have a situation where this wouldn't work
547  JB_SET_STRING(jb, "action", "alert");
548  }
549 
550  /* Close verdict */
551  jb_close(jb);
552 }
553 
556  uint64_t last_re;
557 };
558 
559 static int AlertJsonStreamDataCallback(
560  void *cb_data, const uint8_t *input, const uint32_t input_len, const uint64_t input_offset)
561 {
562  struct AlertJsonStreamDataCallbackData *cbd = cb_data;
563  if (input_offset > cbd->last_re) {
565  cbd->payload, "[%" PRIu64 " bytes missing]", input_offset - cbd->last_re);
566  }
567 
568  int done = 0;
569  uint32_t written = MemBufferWriteRaw(cbd->payload, input, input_len);
570  if (written < input_len)
571  done = 1;
572  cbd->last_re = input_offset + input_len;
573  return done;
574 }
575 
576 /** \internal
577  * \brief try to log stream data into payload/payload_printable
578  * \retval true stream data logged
579  * \retval false stream data not logged
580  */
581 static bool AlertJsonStreamData(const AlertJsonOutputCtx *json_output_ctx, JsonAlertLogThread *aft,
582  Flow *f, const Packet *p, JsonBuilder *jb)
583 {
584  TcpSession *ssn = f->protoctx;
585  TcpStream *stream = (PKT_IS_TOSERVER(p)) ? &ssn->client : &ssn->server;
586 
587  MemBufferReset(aft->payload_buffer);
589  .last_re = STREAM_BASE_OFFSET(stream) };
590  uint64_t unused = 0;
591  StreamReassembleLog(ssn, stream, AlertJsonStreamDataCallback, &cbd, STREAM_BASE_OFFSET(stream),
592  &unused, false);
593  if (cbd.payload->offset) {
594  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
595  jb_set_base64(jb, "payload", cbd.payload->buffer, cbd.payload->offset);
596  }
597  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_LENGTH) {
598  jb_set_uint(jb, "payload_length", cbd.payload->offset);
599  }
600 
601  if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
602  uint8_t printable_buf[cbd.payload->offset + 1];
603  uint32_t offset = 0;
604  PrintStringsToBuffer(printable_buf, &offset, cbd.payload->offset + 1,
605  cbd.payload->buffer, cbd.payload->offset);
606  jb_set_string(jb, "payload_printable", (char *)printable_buf);
607  }
608  return true;
609  }
610  return false;
611 }
612 
613 static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
614 {
615  AlertJsonOutputCtx *json_output_ctx = aft->json_output_ctx;
616 
617  if (p->alerts.cnt == 0 && !(p->flags & PKT_HAS_TAG))
618  return TM_ECODE_OK;
619 
620  for (int i = 0; i < p->alerts.cnt; i++) {
621  const PacketAlert *pa = &p->alerts.alerts[i];
622  if (unlikely(pa->s == NULL)) {
623  continue;
624  }
625 
626  /* First initialize the address info (5-tuple). */
628  JsonAddrInfoInit(p, LOG_DIR_PACKET, &addr);
629 
630  /* Check for XFF, overwriting address info if needed. */
631  HttpXFFCfg *xff_cfg = json_output_ctx->xff_cfg != NULL ? json_output_ctx->xff_cfg
632  : json_output_ctx->parent_xff_cfg;
633  int have_xff_ip = 0;
634  char xff_buffer[XFF_MAXLEN];
635  xff_buffer[0] = 0;
636  if ((xff_cfg != NULL) && !(xff_cfg->flags & XFF_DISABLED) && p->flow != NULL) {
637  if (FlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) {
638  if (pa->flags & PACKET_ALERT_FLAG_TX) {
639  have_xff_ip = HttpXFFGetIPFromTx(p->flow, pa->tx_id, xff_cfg,
640  xff_buffer, XFF_MAXLEN);
641  } else {
642  have_xff_ip = HttpXFFGetIP(p->flow, xff_cfg, xff_buffer,
643  XFF_MAXLEN);
644  }
645  }
646 
647  if (have_xff_ip && xff_cfg->flags & XFF_OVERWRITE) {
648  if (p->flowflags & FLOW_PKT_TOCLIENT) {
649  strlcpy(addr.dst_ip, xff_buffer, JSON_ADDR_LEN);
650  } else {
651  strlcpy(addr.src_ip, xff_buffer, JSON_ADDR_LEN);
652  }
653  /* Clear have_xff_ip so the xff field does not get
654  * logged below. */
655  have_xff_ip = false;
656  }
657  if (have_xff_ip && !(xff_cfg->flags & XFF_EXTRADATA)) {
658  // reset xff_buffer so as not to log it
659  xff_buffer[0] = 0;
660  }
661  }
662 
663  JsonBuilder *jb =
664  CreateEveHeader(p, LOG_DIR_PACKET, "alert", &addr, json_output_ctx->eve_ctx);
665  if (unlikely(jb == NULL))
666  return TM_ECODE_OK;
667 
668 
669  /* alert */
670  AlertJsonHeader(p, pa, jb, json_output_ctx->flags, &addr, xff_buffer);
671 
672  if (PacketIsTunnel(p)) {
673  AlertJsonTunnel(p, jb);
674  }
675 
676  if (p->flow != NULL) {
677  if (pa->flags & PACKET_ALERT_FLAG_TX) {
678  if (json_output_ctx->flags & LOG_JSON_APP_LAYER) {
679  AlertAddAppLayer(p, jb, pa->tx_id, json_output_ctx->flags);
680  }
681  /* including fileinfo data is configured by the metadata setting */
682  if (json_output_ctx->flags & LOG_JSON_RULE_METADATA) {
683  AlertAddFiles(p, jb, pa->tx_id);
684  }
685  }
686 
687  EveAddAppProto(p->flow, jb);
688 
689  if (p->flowflags & FLOW_PKT_TOSERVER) {
690  jb_set_string(jb, "direction", "to_server");
691  } else {
692  jb_set_string(jb, "direction", "to_client");
693  }
694 
695  if (json_output_ctx->flags & LOG_JSON_FLOW) {
696  jb_open_object(jb, "flow");
697  EveAddFlow(p->flow, jb);
698  if (p->flowflags & FLOW_PKT_TOCLIENT) {
699  jb_set_string(jb, "src_ip", addr.dst_ip);
700  jb_set_string(jb, "dest_ip", addr.src_ip);
701  if (addr.sp > 0) {
702  jb_set_uint(jb, "src_port", addr.dp);
703  jb_set_uint(jb, "dest_port", addr.sp);
704  }
705  } else {
706  jb_set_string(jb, "src_ip", addr.src_ip);
707  jb_set_string(jb, "dest_ip", addr.dst_ip);
708  if (addr.sp > 0) {
709  jb_set_uint(jb, "src_port", addr.sp);
710  jb_set_uint(jb, "dest_port", addr.dp);
711  }
712  }
713  jb_close(jb);
714  }
715  }
716 
717  /* payload */
718  if (json_output_ctx->flags &
720  int stream = (p->proto == IPPROTO_TCP) ?
722  1 : 0) : 0;
723  // should be impossible, as stream implies flow
724  DEBUG_VALIDATE_BUG_ON(stream && p->flow == NULL);
725 
726  /* Is this a stream? If so, pack part of it into the payload field */
727  if (stream && p->flow != NULL) {
728  const bool stream_data_logged =
729  AlertJsonStreamData(json_output_ctx, aft, p->flow, p, jb);
730  if (!stream_data_logged && p->payload_len) {
731  /* Fallback on packet payload */
732  AlertAddPayload(json_output_ctx, jb, p);
733  }
734  } else {
735  /* This is a single packet and not a stream */
736  AlertAddPayload(json_output_ctx, jb, p);
737  }
738 
739  jb_set_uint(jb, "stream", stream);
740  }
741 
742  if (pa->flags & PACKET_ALERT_FLAG_FRAME) {
743  AlertAddFrame(p, pa->frame_id, jb, aft->payload_buffer);
744  }
745 
746  /* base64-encoded full packet */
747  if (json_output_ctx->flags & LOG_JSON_PACKET) {
748  EvePacket(p, jb, 0);
749  }
750 
752  if (pcap_filename != NULL) {
753  jb_set_string(jb, "capture_file", pcap_filename);
754  }
755 
756  if (json_output_ctx->flags & LOG_JSON_VERDICT) {
757  EveAddVerdict(jb, p);
758  }
759 
760  OutputJsonBuilderBuffer(tv, p, p->flow, jb, aft->ctx);
761  jb_free(jb);
762  }
763 
764  if ((p->flags & PKT_HAS_TAG) && (json_output_ctx->flags &
766  JsonBuilder *packetjs =
767  CreateEveHeader(p, LOG_DIR_PACKET, "packet", NULL, json_output_ctx->eve_ctx);
768  if (unlikely(packetjs != NULL)) {
769  EvePacket(p, packetjs, 0);
770  OutputJsonBuilderBuffer(tv, p, p->flow, packetjs, aft->ctx);
771  jb_free(packetjs);
772  }
773  }
774 
775  return TM_ECODE_OK;
776 }
777 
778 static int AlertJsonDecoderEvent(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
779 {
780  AlertJsonOutputCtx *json_output_ctx = aft->json_output_ctx;
781  char timebuf[64];
782 
783  if (p->alerts.cnt == 0)
784  return TM_ECODE_OK;
785 
786  CreateIsoTimeString(p->ts, timebuf, sizeof(timebuf));
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 = jb_new_object();
795  if (unlikely(jb == NULL)) {
796  return TM_ECODE_OK;
797  }
798 
799  /* just the timestamp, no tuple */
800  jb_set_string(jb, "timestamp", timebuf);
801 
802  AlertJsonHeader(p, pa, jb, json_output_ctx->flags, NULL, NULL);
803 
804  OutputJsonBuilderBuffer(tv, p, p->flow, jb, aft->ctx);
805  jb_free(jb);
806  }
807 
808  return TM_ECODE_OK;
809 }
810 
811 static int JsonAlertLogger(ThreadVars *tv, void *thread_data, const Packet *p)
812 {
813  JsonAlertLogThread *aft = thread_data;
814 
815  if (PacketIsIPv4(p) || PacketIsIPv6(p)) {
816  return AlertJson(tv, aft, p);
817  } else if (p->alerts.cnt > 0) {
818  return AlertJsonDecoderEvent(tv, aft, p);
819  }
820  return 0;
821 }
822 
823 static bool JsonAlertLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
824 {
825  return (p->alerts.cnt || (p->flags & PKT_HAS_TAG));
826 }
827 
828 static TmEcode JsonAlertLogThreadInit(ThreadVars *t, const void *initdata, void **data)
829 {
831  if (unlikely(aft == NULL))
832  return TM_ECODE_FAILED;
833 
834  if (initdata == NULL)
835  {
836  SCLogDebug("Error getting context for EveLogAlert. \"initdata\" argument NULL");
837  goto error_exit;
838  }
839 
840  /** Use the Output Context (file pointer and mutex) */
841  AlertJsonOutputCtx *json_output_ctx = ((OutputCtx *)initdata)->data;
842 
843  aft->payload_buffer = MemBufferCreateNew(json_output_ctx->payload_buffer_size);
844  if (aft->payload_buffer == NULL) {
845  goto error_exit;
846  }
847  aft->ctx = CreateEveThreadCtx(t, json_output_ctx->eve_ctx);
848  if (!aft->ctx) {
849  goto error_exit;
850  }
851 
852  aft->json_output_ctx = json_output_ctx;
853 
854  *data = (void *)aft;
855  return TM_ECODE_OK;
856 
857 error_exit:
858  if (aft->payload_buffer != NULL) {
860  }
861  SCFree(aft);
862  return TM_ECODE_FAILED;
863 }
864 
865 static TmEcode JsonAlertLogThreadDeinit(ThreadVars *t, void *data)
866 {
867  JsonAlertLogThread *aft = (JsonAlertLogThread *)data;
868  if (aft == NULL) {
869  return TM_ECODE_OK;
870  }
871 
873  FreeEveThreadCtx(aft->ctx);
874 
875  /* clear memory */
876  memset(aft, 0, sizeof(JsonAlertLogThread));
877 
878  SCFree(aft);
879  return TM_ECODE_OK;
880 }
881 
882 static void JsonAlertLogDeInitCtxSub(OutputCtx *output_ctx)
883 {
884  SCLogDebug("cleaning up sub output_ctx %p", output_ctx);
885 
886  AlertJsonOutputCtx *json_output_ctx = (AlertJsonOutputCtx *) output_ctx->data;
887 
888  if (json_output_ctx != NULL) {
889  HttpXFFCfg *xff_cfg = json_output_ctx->xff_cfg;
890  if (xff_cfg != NULL) {
891  SCFree(xff_cfg);
892  }
893  SCFree(json_output_ctx);
894  }
895  SCFree(output_ctx);
896 }
897 
898 static void SetFlag(const ConfNode *conf, const char *name, uint16_t flag, uint16_t *out_flags)
899 {
900  DEBUG_VALIDATE_BUG_ON(conf == NULL);
901  const char *setting = ConfNodeLookupChildValue(conf, name);
902  if (setting != NULL) {
903  if (ConfValIsTrue(setting)) {
904  *out_flags |= flag;
905  } else {
906  *out_flags &= ~flag;
907  }
908  }
909 }
910 
911 static void JsonAlertLogSetupMetadata(AlertJsonOutputCtx *json_output_ctx,
912  ConfNode *conf)
913 {
914  static bool warn_no_meta = false;
915  uint32_t payload_buffer_size = JSON_STREAM_BUFFER_SIZE;
916  uint16_t flags = METADATA_DEFAULTS;
917 
918  if (conf != NULL) {
919  /* Check for metadata to enable/disable. */
920  ConfNode *metadata = ConfNodeLookupChild(conf, "metadata");
921  if (metadata != NULL) {
922  if (metadata->val != NULL && ConfValIsFalse(metadata->val)) {
924  } else if (ConfNodeHasChildren(metadata)) {
925  ConfNode *rule_metadata = ConfNodeLookupChild(metadata, "rule");
926  if (rule_metadata) {
927  SetFlag(rule_metadata, "raw", LOG_JSON_RULE, &flags);
928  SetFlag(rule_metadata, "metadata", LOG_JSON_RULE_METADATA,
929  &flags);
930  SetFlag(rule_metadata, "reference", LOG_JSON_REFERENCE, &flags);
931  }
932  SetFlag(metadata, "flow", LOG_JSON_FLOW, &flags);
933  SetFlag(metadata, "app-layer", LOG_JSON_APP_LAYER, &flags);
934  }
935  }
936 
937  /* Non-metadata toggles. */
938  SetFlag(conf, "payload", LOG_JSON_PAYLOAD_BASE64, &flags);
939  SetFlag(conf, "packet", LOG_JSON_PACKET, &flags);
940  SetFlag(conf, "tagged-packets", LOG_JSON_TAGGED_PACKETS, &flags);
941  SetFlag(conf, "payload-printable", LOG_JSON_PAYLOAD, &flags);
942  SetFlag(conf, "http-body-printable", LOG_JSON_HTTP_BODY, &flags);
943  SetFlag(conf, "http-body", LOG_JSON_HTTP_BODY_BASE64, &flags);
944  SetFlag(conf, "websocket-payload-printable", LOG_JSON_WEBSOCKET_PAYLOAD, &flags);
945  SetFlag(conf, "websocket-payload", LOG_JSON_WEBSOCKET_PAYLOAD_BASE64, &flags);
946  SetFlag(conf, "verdict", LOG_JSON_VERDICT, &flags);
947  SetFlag(conf, "payload-length", LOG_JSON_PAYLOAD_LENGTH, &flags);
948 
949  /* Check for obsolete flags and warn that they have no effect. */
950  static const char *deprecated_flags[] = { "http", "tls", "ssh", "smtp", "dnp3", "app-layer",
951  "flow", NULL };
952  for (int i = 0; deprecated_flags[i] != NULL; i++) {
953  if (ConfNodeLookupChildValue(conf, deprecated_flags[i]) != NULL) {
954  SCLogWarning("Found deprecated eve-log.alert flag \"%s\", this flag has no effect",
955  deprecated_flags[i]);
956  }
957  }
958 
959  const char *payload_buffer_value = ConfNodeLookupChildValue(conf, "payload-buffer-size");
960 
961  if (payload_buffer_value != NULL) {
962  uint32_t value;
963  if (ParseSizeStringU32(payload_buffer_value, &value) < 0) {
964  SCLogError("Error parsing "
965  "payload-buffer-size - %s. Killing engine",
966  payload_buffer_value);
967  exit(EXIT_FAILURE);
968  } else {
969  payload_buffer_size = value;
970  }
971  }
972 
973  if (!warn_no_meta && flags & JSON_BODY_LOGGING) {
974  if (((flags & LOG_JSON_APP_LAYER) == 0)) {
975  SCLogWarning("HTTP body logging has been configured, however, "
976  "metadata logging has not been enabled. HTTP body logging will be "
977  "disabled.");
979  warn_no_meta = true;
980  }
981  }
982  }
983 
986  }
987 
988  json_output_ctx->payload_buffer_size = payload_buffer_size;
989  json_output_ctx->flags |= flags;
990 }
991 
992 static HttpXFFCfg *JsonAlertLogGetXffCfg(ConfNode *conf)
993 {
994  HttpXFFCfg *xff_cfg = NULL;
995  if (conf != NULL && ConfNodeLookupChild(conf, "xff") != NULL) {
996  xff_cfg = SCCalloc(1, sizeof(HttpXFFCfg));
997  if (likely(xff_cfg != NULL)) {
998  HttpXFFGetCfg(conf, xff_cfg);
999  }
1000  }
1001  return xff_cfg;
1002 }
1003 
1004 /**
1005  * \brief Create a new LogFileCtx for "fast" output style.
1006  * \param conf The configuration node for this output.
1007  * \return A LogFileCtx pointer on success, NULL on failure.
1008  */
1009 static OutputInitResult JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
1010 {
1011  OutputInitResult result = { NULL, false };
1012  OutputJsonCtx *ajt = parent_ctx->data;
1013  AlertJsonOutputCtx *json_output_ctx = NULL;
1014 
1015  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
1016  if (unlikely(output_ctx == NULL))
1017  return result;
1018 
1019  json_output_ctx = SCCalloc(1, sizeof(AlertJsonOutputCtx));
1020  if (unlikely(json_output_ctx == NULL)) {
1021  goto error;
1022  }
1023 
1024  json_output_ctx->file_ctx = ajt->file_ctx;
1025  json_output_ctx->eve_ctx = ajt;
1026 
1027  JsonAlertLogSetupMetadata(json_output_ctx, conf);
1028  json_output_ctx->xff_cfg = JsonAlertLogGetXffCfg(conf);
1029  if (json_output_ctx->xff_cfg == NULL) {
1030  json_output_ctx->parent_xff_cfg = ajt->xff_cfg;
1031  }
1032 
1033  output_ctx->data = json_output_ctx;
1034  output_ctx->DeInit = JsonAlertLogDeInitCtxSub;
1035 
1036  result.ctx = output_ctx;
1037  result.ok = true;
1038  return result;
1039 
1040 error:
1041  if (json_output_ctx != NULL) {
1042  SCFree(json_output_ctx);
1043  }
1044  if (output_ctx != NULL) {
1045  SCFree(output_ctx);
1046  }
1047 
1048  return result;
1049 }
1050 
1052 {
1053  OutputRegisterPacketSubModule(LOGGER_JSON_ALERT, "eve-log", MODULE_NAME, "eve-log.alert",
1054  JsonAlertLogInitCtxSub, JsonAlertLogger, JsonAlertLogCondition, JsonAlertLogThreadInit,
1055  JsonAlertLogThreadDeinit);
1056 }
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:495
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:394
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:668
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
CreateIsoTimeString
void CreateIsoTimeString(const SCTime_t ts, char *str, size_t size)
Definition: util-time.c:209
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:592
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:556
Packet_::payload
uint8_t * payload
Definition: decode.h:571
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:265
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:510
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
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:268
CreateEveThreadCtx
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
Definition: output-json-common.c:29
AlertJsonStreamDataCallbackData::payload
MemBuffer * payload
Definition: output-json-alert.c:555
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:504
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:572
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:586
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:502
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:637
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
Packet_::ts
SCTime_t ts
Definition: decode.h:521
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:664
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:824
JsonAlertLogThread
struct JsonAlertLogThread_ JsonAlertLogThread
output-json-email-common.h
util-time.h
OutputInitResult_::ok
bool ok
Definition: output.h:48
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:425
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:602
stream.h
DetectReference_::reference_len
uint16_t reference_len
Definition: detect-reference.h:41
JsonAddrInfo_
Definition: output-json.h:47
Packet_
Definition: decode.h:473
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:1087
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:662
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:512
Packet_::tenant_id
uint32_t tenant_id
Definition: decode.h:631
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:509
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
MemBufferFree
void MemBufferFree(MemBuffer *buffer)
Definition: util-buffer.c:81
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
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:958
EveAddAppProto
void EveAddAppProto(Flow *f, JsonBuilder *js)
Definition: output-json-flow.c:169
Signature_::rev
uint32_t rev
Definition: detect.h:638
ALPROTO_WEBSOCKET
@ ALPROTO_WEBSOCKET
Definition: app-layer-protos.h:59
TcpSession_::client
TcpStream client
Definition: stream-tcp-private.h:295
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:32
Signature_::prio
int prio
Definition: detect.h:639
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:619
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:294
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:666
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:577
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:636
Packet_::recursion_level
uint8_t recursion_level
Definition: decode.h:498
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:110
PacketAlert_
Definition: decode.h:239
MemBufferWriteString
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
Definition: util-buffer.c:125
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:1190
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:1257
Signature_::msg
char * msg
Definition: detect.h:659
flow.h
DetectEngineSetParseMetadata
void DetectEngineSetParseMetadata(void)
Definition: detect-engine.c:4929
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:1905
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:1051
AlertJsonStreamDataCallbackData
Definition: output-json-alert.c:554
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