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