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