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 "threads.h"
35 #include "tm-threads.h"
36 #include "threadvars.h"
37 #include "util-debug.h"
38 
39 #include "util-logopenfile.h"
40 #include "util-misc.h"
41 #include "util-time.h"
42 #include "util-unittest.h"
43 #include "util-unittest-helper.h"
44 
45 #include "detect-parse.h"
46 #include "detect-engine.h"
47 #include "detect-engine-mpm.h"
48 #include "detect-reference.h"
49 #include "detect-metadata.h"
50 #include "app-layer-parser.h"
51 #include "app-layer-dnp3.h"
52 #include "app-layer-htp.h"
53 #include "app-layer-htp-xff.h"
54 #include "app-layer-ftp.h"
55 #include "app-layer-frames.h"
57 #include "util-syslog.h"
58 #include "log-pcap.h"
59 
60 #include "output.h"
61 #include "output-json.h"
62 #include "output-json-alert.h"
63 #include "output-json-dnp3.h"
64 #include "output-json-dns.h"
65 #include "output-json-http.h"
66 #include "output-json-tls.h"
67 #include "output-json-ssh.h"
68 #include "rust.h"
69 #include "output-json-smtp.h"
71 #include "output-json-nfs.h"
72 #include "output-json-smb.h"
73 #include "output-json-flow.h"
74 #include "output-json-sip.h"
75 #include "output-json-rfb.h"
76 #include "output-json-mqtt.h"
77 #include "output-json-ike.h"
78 #include "output-json-modbus.h"
79 #include "output-json-frame.h"
80 #include "output-json-quic.h"
81 
82 #include "util-byte.h"
83 #include "util-privs.h"
84 #include "util-print.h"
85 #include "util-proto-name.h"
86 #include "util-optimize.h"
87 #include "util-buffer.h"
88 #include "util-validate.h"
89 
90 #include "action-globals.h"
91 
92 #define MODULE_NAME "JsonAlertLog"
93 
94 #define LOG_JSON_PAYLOAD BIT_U16(0)
95 #define LOG_JSON_PACKET BIT_U16(1)
96 #define LOG_JSON_PAYLOAD_BASE64 BIT_U16(2)
97 #define LOG_JSON_TAGGED_PACKETS BIT_U16(3)
98 #define LOG_JSON_APP_LAYER BIT_U16(4)
99 #define LOG_JSON_FLOW BIT_U16(5)
100 #define LOG_JSON_HTTP_BODY BIT_U16(6)
101 #define LOG_JSON_HTTP_BODY_BASE64 BIT_U16(7)
102 #define LOG_JSON_RULE_METADATA BIT_U16(8)
103 #define LOG_JSON_RULE BIT_U16(9)
104 #define LOG_JSON_VERDICT BIT_U16(10)
105 
106 #define METADATA_DEFAULTS ( LOG_JSON_FLOW | \
107  LOG_JSON_APP_LAYER | \
108  LOG_JSON_RULE_METADATA)
109 
110 #define JSON_BODY_LOGGING (LOG_JSON_HTTP_BODY | LOG_JSON_HTTP_BODY_BASE64)
111 
112 #define JSON_STREAM_BUFFER_SIZE 4096
113 
114 typedef struct AlertJsonOutputCtx_ {
116  uint16_t flags;
122 
123 typedef struct JsonAlertLogThread_ {
128 
129 /* Callback function to pack payload contents from a stream into a buffer
130  * so we can report them in JSON output. */
131 static int AlertJsonDumpStreamSegmentCallback(
132  const Packet *p, TcpSegment *seg, void *data, const uint8_t *buf, uint32_t buflen)
133 {
134  MemBuffer *payload = (MemBuffer *)data;
135  MemBufferWriteRaw(payload, buf, buflen);
136 
137  return 1;
138 }
139 
140 static void AlertJsonTls(const Flow *f, JsonBuilder *js)
141 {
142  SSLState *ssl_state = (SSLState *)FlowGetAppState(f);
143  if (ssl_state) {
144  jb_open_object(js, "tls");
145 
146  JsonTlsLogJSONExtended(js, ssl_state);
147 
148  jb_close(js);
149  }
150 
151  return;
152 }
153 
154 static void AlertJsonSsh(const Flow *f, JsonBuilder *js)
155 {
156  void *ssh_state = FlowGetAppState(f);
157  if (ssh_state) {
158  JsonBuilderMark mark = { 0, 0, 0 };
159  void *tx_ptr = rs_ssh_state_get_tx(ssh_state, 0);
160  jb_get_mark(js, &mark);
161  jb_open_object(js, "ssh");
162  if (rs_ssh_log_json(tx_ptr, js)) {
163  jb_close(js);
164  } else {
165  jb_restore_mark(js, &mark);
166  }
167  }
168 
169  return;
170 }
171 
172 static void AlertJsonHttp2(const Flow *f, const uint64_t tx_id, JsonBuilder *js)
173 {
174  void *h2_state = FlowGetAppState(f);
175  if (h2_state) {
176  void *tx_ptr = rs_http2_state_get_tx(h2_state, tx_id);
177  if (tx_ptr) {
178  JsonBuilderMark mark = { 0, 0, 0 };
179  jb_get_mark(js, &mark);
180  jb_open_object(js, "http");
181  if (rs_http2_log_json(tx_ptr, js)) {
182  jb_close(js);
183  } else {
184  jb_restore_mark(js, &mark);
185  }
186  }
187  }
188 
189  return;
190 }
191 
192 static void AlertJsonDnp3(const Flow *f, const uint64_t tx_id, JsonBuilder *js)
193 {
194  DNP3State *dnp3_state = (DNP3State *)FlowGetAppState(f);
195  if (dnp3_state) {
197  dnp3_state, tx_id);
198  if (tx) {
199  JsonBuilderMark mark = { 0, 0, 0 };
200  jb_get_mark(js, &mark);
201  bool logged = false;
202  jb_open_object(js, "dnp3");
203  if (tx->is_request && tx->done) {
204  jb_open_object(js, "request");
205  JsonDNP3LogRequest(js, tx);
206  jb_close(js);
207  logged = true;
208  }
209  if (!tx->is_request && tx->done) {
210  jb_open_object(js, "response");
211  JsonDNP3LogResponse(js, tx);
212  jb_close(js);
213  logged = true;
214  }
215  if (logged) {
216  /* Close dnp3 object. */
217  jb_close(js);
218  } else {
219  jb_restore_mark(js, &mark);
220  }
221  }
222  }
223 }
224 
225 static void AlertJsonDns(const Flow *f, const uint64_t tx_id, JsonBuilder *js)
226 {
227  void *dns_state = (void *)FlowGetAppState(f);
228  if (dns_state) {
229  void *txptr = AppLayerParserGetTx(f->proto, ALPROTO_DNS,
230  dns_state, tx_id);
231  if (txptr) {
232  jb_open_object(js, "dns");
233  JsonBuilder *qjs = JsonDNSLogQuery(txptr);
234  if (qjs != NULL) {
235  jb_set_object(js, "query", qjs);
236  jb_free(qjs);
237  }
238  JsonBuilder *ajs = JsonDNSLogAnswer(txptr);
239  if (ajs != NULL) {
240  jb_set_object(js, "answer", ajs);
241  jb_free(ajs);
242  }
243  jb_close(js);
244  }
245  }
246  return;
247 }
248 
249 static void AlertJsonSNMP(const Flow *f, const uint64_t tx_id, JsonBuilder *js)
250 {
251  void *snmp_state = (void *)FlowGetAppState(f);
252  if (snmp_state != NULL) {
253  void *tx = AppLayerParserGetTx(f->proto, ALPROTO_SNMP, snmp_state,
254  tx_id);
255  if (tx != NULL) {
256  jb_open_object(js, "snmp");
257  rs_snmp_log_json_response(js, tx);
258  jb_close(js);
259  }
260  }
261 }
262 
263 static void AlertJsonRDP(const Flow *f, const uint64_t tx_id, JsonBuilder *js)
264 {
265  void *rdp_state = (void *)FlowGetAppState(f);
266  if (rdp_state != NULL) {
267  void *tx = AppLayerParserGetTx(f->proto, ALPROTO_RDP, rdp_state,
268  tx_id);
269  if (tx != NULL) {
270  JsonBuilderMark mark = { 0, 0, 0 };
271  jb_get_mark(js, &mark);
272  if (!rs_rdp_to_json(tx, js)) {
273  jb_restore_mark(js, &mark);
274  }
275  }
276  }
277 }
278 
279 static void AlertJsonBitTorrentDHT(const Flow *f, const uint64_t tx_id, JsonBuilder *js)
280 {
281  void *bittorrent_dht_state = (void *)FlowGetAppState(f);
282  if (bittorrent_dht_state != NULL) {
283  void *tx =
284  AppLayerParserGetTx(f->proto, ALPROTO_BITTORRENT_DHT, bittorrent_dht_state, tx_id);
285  if (tx != NULL) {
286  JsonBuilderMark mark = { 0, 0, 0 };
287  jb_get_mark(js, &mark);
288  jb_open_object(js, "bittorrent_dht");
289  if (rs_bittorrent_dht_logger_log(tx, js)) {
290  jb_close(js);
291  } else {
292  jb_restore_mark(js, &mark);
293  }
294  }
295  }
296 }
297 
298 static void AlertJsonSourceTarget(const Packet *p, const PacketAlert *pa,
299  JsonBuilder *js, JsonAddrInfo *addr)
300 {
301  jb_open_object(js, "source");
302  if (pa->s->flags & SIG_FLAG_DEST_IS_TARGET) {
303  jb_set_string(js, "ip", addr->src_ip);
304  switch (p->proto) {
305  case IPPROTO_ICMP:
306  case IPPROTO_ICMPV6:
307  break;
308  case IPPROTO_UDP:
309  case IPPROTO_TCP:
310  case IPPROTO_SCTP:
311  jb_set_uint(js, "port", addr->sp);
312  break;
313  }
314  } else if (pa->s->flags & SIG_FLAG_SRC_IS_TARGET) {
315  jb_set_string(js, "ip", addr->dst_ip);
316  switch (p->proto) {
317  case IPPROTO_ICMP:
318  case IPPROTO_ICMPV6:
319  break;
320  case IPPROTO_UDP:
321  case IPPROTO_TCP:
322  case IPPROTO_SCTP:
323  jb_set_uint(js, "port", addr->dp);
324  break;
325  }
326  }
327  jb_close(js);
328 
329  jb_open_object(js, "target");
330  if (pa->s->flags & SIG_FLAG_DEST_IS_TARGET) {
331  jb_set_string(js, "ip", addr->dst_ip);
332  switch (p->proto) {
333  case IPPROTO_ICMP:
334  case IPPROTO_ICMPV6:
335  break;
336  case IPPROTO_UDP:
337  case IPPROTO_TCP:
338  case IPPROTO_SCTP:
339  jb_set_uint(js, "port", addr->dp);
340  break;
341  }
342  } else if (pa->s->flags & SIG_FLAG_SRC_IS_TARGET) {
343  jb_set_string(js, "ip", addr->src_ip);
344  switch (p->proto) {
345  case IPPROTO_ICMP:
346  case IPPROTO_ICMPV6:
347  break;
348  case IPPROTO_UDP:
349  case IPPROTO_TCP:
350  case IPPROTO_SCTP:
351  jb_set_uint(js, "port", addr->sp);
352  break;
353  }
354  }
355  jb_close(js);
356 }
357 
358 static void AlertJsonMetadata(AlertJsonOutputCtx *json_output_ctx,
359  const PacketAlert *pa, JsonBuilder *js)
360 {
361  if (pa->s->metadata && pa->s->metadata->json_str) {
362  jb_set_formatted(js, pa->s->metadata->json_str);
363  }
364 }
365 
366 void AlertJsonHeader(void *ctx, const Packet *p, const PacketAlert *pa, JsonBuilder *js,
367  uint16_t flags, JsonAddrInfo *addr, char *xff_buffer)
368 {
369  AlertJsonOutputCtx *json_output_ctx = (AlertJsonOutputCtx *)ctx;
370  const char *action = "allowed";
371  /* use packet action if rate_filter modified the action */
374  action = "blocked";
375  }
376  } else {
377  if (pa->action & ACTION_REJECT_ANY) {
378  action = "blocked";
379  } else if ((pa->action & ACTION_DROP) && EngineModeIsIPS()) {
380  action = "blocked";
381  }
382  }
383 
384  /* Add tx_id to root element for correlation with other events. */
385  /* json_object_del(js, "tx_id"); */
386  if (pa->flags & PACKET_ALERT_FLAG_TX) {
387  jb_set_uint(js, "tx_id", pa->tx_id);
388  }
389 
390  jb_open_object(js, "alert");
391 
392  jb_set_string(js, "action", action);
393  jb_set_uint(js, "gid", pa->s->gid);
394  jb_set_uint(js, "signature_id", pa->s->id);
395  jb_set_uint(js, "rev", pa->s->rev);
396  /* TODO: JsonBuilder should handle unprintable characters like
397  * SCJsonString. */
398  jb_set_string(js, "signature", pa->s->msg ? pa->s->msg: "");
399  jb_set_string(js, "category", pa->s->class_msg ? pa->s->class_msg: "");
400  jb_set_uint(js, "severity", pa->s->prio);
401 
402  if (p->tenant_id > 0) {
403  jb_set_uint(js, "tenant_id", p->tenant_id);
404  }
405 
406  if (addr && pa->s->flags & SIG_FLAG_HAS_TARGET) {
407  AlertJsonSourceTarget(p, pa, js, addr);
408  }
409 
410  if ((json_output_ctx != NULL) && (flags & LOG_JSON_RULE_METADATA)) {
411  AlertJsonMetadata(json_output_ctx, pa, js);
412  }
413 
414  if (flags & LOG_JSON_RULE) {
415  jb_set_string(js, "rule", pa->s->sig_str);
416  }
417  if (xff_buffer && xff_buffer[0]) {
418  jb_set_string(js, "xff", xff_buffer);
419  }
420 
421  jb_close(js);
422 }
423 
424 static void AlertJsonTunnel(const Packet *p, JsonBuilder *js)
425 {
426  if (p->root == NULL) {
427  return;
428  }
429 
430  jb_open_object(js, "tunnel");
431 
432  enum PktSrcEnum pkt_src;
433  uint64_t pcap_cnt;
435  JsonAddrInfoInit(p->root, 0, &addr);
436  pcap_cnt = p->root->pcap_cnt;
437  pkt_src = p->root->pkt_src;
438 
439  jb_set_string(js, "src_ip", addr.src_ip);
440  jb_set_uint(js, "src_port", addr.sp);
441  jb_set_string(js, "dest_ip", addr.dst_ip);
442  jb_set_uint(js, "dest_port", addr.dp);
443  jb_set_string(js, "proto", addr.proto);
444 
445  jb_set_uint(js, "depth", p->recursion_level);
446  if (pcap_cnt != 0) {
447  jb_set_uint(js, "pcap_cnt", pcap_cnt);
448  }
449  jb_set_string(js, "pkt_src", PktSrcToString(pkt_src));
450  jb_close(js);
451 }
452 
453 static void AlertAddPayload(AlertJsonOutputCtx *json_output_ctx, JsonBuilder *js, const Packet *p)
454 {
455  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
456  jb_set_base64(js, "payload", p->payload, p->payload_len);
457  }
458 
459  if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
460  uint8_t printable_buf[p->payload_len + 1];
461  uint32_t offset = 0;
462  PrintStringsToBuffer(printable_buf, &offset,
463  p->payload_len + 1,
464  p->payload, p->payload_len);
465  printable_buf[p->payload_len] = '\0';
466  jb_set_string(js, "payload_printable", (char *)printable_buf);
467  }
468 }
469 
470 static void AlertAddAppLayer(const Packet *p, JsonBuilder *jb,
471  const uint64_t tx_id, const uint16_t option_flags)
472 {
473  const AppProto proto = FlowGetAppProtocol(p->flow);
474  JsonBuilderMark mark = { 0, 0, 0 };
475  switch (proto) {
476  case ALPROTO_HTTP1:
477  // TODO: Could result in an empty http object being logged.
478  jb_open_object(jb, "http");
479  if (EveHttpAddMetadata(p->flow, tx_id, jb)) {
480  if (option_flags & LOG_JSON_HTTP_BODY) {
481  EveHttpLogJSONBodyPrintable(jb, p->flow, tx_id);
482  }
483  if (option_flags & LOG_JSON_HTTP_BODY_BASE64) {
484  EveHttpLogJSONBodyBase64(jb, p->flow, tx_id);
485  }
486  }
487  jb_close(jb);
488  break;
489  case ALPROTO_TLS:
490  AlertJsonTls(p->flow, jb);
491  break;
492  case ALPROTO_SSH:
493  AlertJsonSsh(p->flow, jb);
494  break;
495  case ALPROTO_SMTP:
496  jb_get_mark(jb, &mark);
497  jb_open_object(jb, "smtp");
498  if (EveSMTPAddMetadata(p->flow, tx_id, jb)) {
499  jb_close(jb);
500  } else {
501  jb_restore_mark(jb, &mark);
502  }
503  jb_get_mark(jb, &mark);
504  jb_open_object(jb, "email");
505  if (EveEmailAddMetadata(p->flow, tx_id, jb)) {
506  jb_close(jb);
507  } else {
508  jb_restore_mark(jb, &mark);
509  }
510  break;
511  case ALPROTO_NFS:
512  /* rpc */
513  jb_get_mark(jb, &mark);
514  jb_open_object(jb, "rpc");
515  if (EveNFSAddMetadataRPC(p->flow, tx_id, jb)) {
516  jb_close(jb);
517  } else {
518  jb_restore_mark(jb, &mark);
519  }
520  /* nfs */
521  jb_get_mark(jb, &mark);
522  jb_open_object(jb, "nfs");
523  if (EveNFSAddMetadata(p->flow, tx_id, jb)) {
524  jb_close(jb);
525  } else {
526  jb_restore_mark(jb, &mark);
527  }
528  break;
529  case ALPROTO_SMB:
530  jb_get_mark(jb, &mark);
531  jb_open_object(jb, "smb");
532  if (EveSMBAddMetadata(p->flow, tx_id, jb)) {
533  jb_close(jb);
534  } else {
535  jb_restore_mark(jb, &mark);
536  }
537  break;
538  case ALPROTO_SIP:
539  JsonSIPAddMetadata(jb, p->flow, tx_id);
540  break;
541  case ALPROTO_RFB:
542  jb_get_mark(jb, &mark);
543  if (!JsonRFBAddMetadata(p->flow, tx_id, jb)) {
544  jb_restore_mark(jb, &mark);
545  }
546  break;
547  case ALPROTO_FTPDATA:
548  jb_get_mark(jb, &mark);
549  jb_open_object(jb, "ftp_data");
550  EveFTPDataAddMetadata(p->flow, jb);
551  jb_close(jb);
552  break;
553  case ALPROTO_DNP3:
554  AlertJsonDnp3(p->flow, tx_id, jb);
555  break;
556  case ALPROTO_HTTP2:
557  AlertJsonHttp2(p->flow, tx_id, jb);
558  break;
559  case ALPROTO_DNS:
560  AlertJsonDns(p->flow, tx_id, jb);
561  break;
562  case ALPROTO_IKE:
563  jb_get_mark(jb, &mark);
564  if (!EveIKEAddMetadata(p->flow, tx_id, jb)) {
565  jb_restore_mark(jb, &mark);
566  }
567  break;
568  case ALPROTO_MQTT:
569  jb_get_mark(jb, &mark);
570  if (!JsonMQTTAddMetadata(p->flow, tx_id, jb)) {
571  jb_restore_mark(jb, &mark);
572  }
573  break;
574  case ALPROTO_QUIC:
575  jb_get_mark(jb, &mark);
576  if (!JsonQuicAddMetadata(p->flow, tx_id, jb)) {
577  jb_restore_mark(jb, &mark);
578  }
579  break;
580  case ALPROTO_SNMP:
581  AlertJsonSNMP(p->flow, tx_id, jb);
582  break;
583  case ALPROTO_RDP:
584  AlertJsonRDP(p->flow, tx_id, jb);
585  break;
586  case ALPROTO_MODBUS:
587  jb_get_mark(jb, &mark);
588  if (!JsonModbusAddMetadata(p->flow, tx_id, jb)) {
589  jb_restore_mark(jb, &mark);
590  }
591  break;
593  AlertJsonBitTorrentDHT(p->flow, tx_id, jb);
594  break;
595  default:
596  break;
597  }
598 }
599 
600 static void AlertAddFiles(const Packet *p, JsonBuilder *jb, const uint64_t tx_id)
601 {
602  const uint8_t direction =
603  (p->flowflags & FLOW_PKT_TOSERVER) ? STREAM_TOSERVER : STREAM_TOCLIENT;
604  FileContainer *ffc = NULL;
605  if (p->flow->alstate != NULL) {
606  void *tx = AppLayerParserGetTx(p->flow->proto, p->flow->alproto, p->flow->alstate, tx_id);
607  if (tx) {
608  AppLayerGetFileState files =
609  AppLayerParserGetTxFiles(p->flow, p->flow->alstate, tx, direction);
610  ffc = files.fc;
611  }
612  }
613  if (ffc != NULL) {
614  File *file = ffc->head;
615  bool isopen = false;
616  while (file) {
617  if (!isopen) {
618  isopen = true;
619  jb_open_array(jb, "files");
620  }
621  jb_start_object(jb);
622  EveFileInfo(jb, file, tx_id, file->flags);
623  jb_close(jb);
624  file = file->next;
625  }
626  if (isopen) {
627  jb_close(jb);
628  }
629  }
630 }
631 
632 static void AlertAddFrame(const Packet *p, JsonBuilder *jb, const int64_t frame_id)
633 {
634  if (p->flow == NULL || (p->proto == IPPROTO_TCP && p->flow->protoctx == NULL))
635  return;
636 
637  FramesContainer *frames_container = AppLayerFramesGetContainer(p->flow);
638  if (frames_container == NULL)
639  return;
640 
641  Frames *frames = NULL;
642  TcpStream *stream = NULL;
643  if (p->proto == IPPROTO_TCP) {
644  TcpSession *ssn = p->flow->protoctx;
645  if (PKT_IS_TOSERVER(p)) {
646  stream = &ssn->client;
647  frames = &frames_container->toserver;
648  } else {
649  stream = &ssn->server;
650  frames = &frames_container->toclient;
651  }
652  Frame *frame = FrameGetById(frames, frame_id);
653  if (frame != NULL) {
654  FrameJsonLogOneFrame(IPPROTO_TCP, frame, p->flow, stream, p, jb);
655  }
656  } else if (p->proto == IPPROTO_UDP) {
657  if (PKT_IS_TOSERVER(p)) {
658  frames = &frames_container->toserver;
659  } else {
660  frames = &frames_container->toclient;
661  }
662  Frame *frame = FrameGetById(frames, frame_id);
663  if (frame != NULL) {
664  FrameJsonLogOneFrame(IPPROTO_UDP, frame, p->flow, NULL, p, jb);
665  }
666  }
667 }
668 
669 /**
670  * \brief Build verdict object
671  *
672  * \param p Pointer to Packet current being logged
673  *
674  */
675 void EveAddVerdict(JsonBuilder *jb, const Packet *p)
676 {
677  jb_open_object(jb, "verdict");
678 
679  /* add verdict info */
681  // check rule to define type of reject packet sent
682  if (EngineModeIsIPS()) {
683  JB_SET_STRING(jb, "action", "drop");
684  } else {
685  JB_SET_STRING(jb, "action", "alert");
686  }
688  JB_SET_STRING(jb, "reject-target", "to_client");
689  } else if (PacketCheckAction(p, ACTION_REJECT_DST)) {
690  JB_SET_STRING(jb, "reject-target", "to_server");
691  } else if (PacketCheckAction(p, ACTION_REJECT_BOTH)) {
692  JB_SET_STRING(jb, "reject-target", "both");
693  }
694  jb_open_array(jb, "reject");
695  switch (p->proto) {
696  case IPPROTO_UDP:
697  case IPPROTO_ICMP:
698  case IPPROTO_ICMPV6:
699  jb_append_string(jb, "icmp-prohib");
700  break;
701  case IPPROTO_TCP:
702  jb_append_string(jb, "tcp-reset");
703  break;
704  }
705  jb_close(jb);
706 
707  } else if (PacketCheckAction(p, ACTION_DROP) && EngineModeIsIPS()) {
708  JB_SET_STRING(jb, "action", "drop");
709  } else if (p->alerts.alerts[p->alerts.cnt].action & ACTION_PASS) {
710  JB_SET_STRING(jb, "action", "pass");
711  } else {
712  // TODO make sure we don't have a situation where this wouldn't work
713  JB_SET_STRING(jb, "action", "alert");
714  }
715 
716  /* Close verdict */
717  jb_close(jb);
718 }
719 
720 static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
721 {
722  MemBuffer *payload = aft->payload_buffer;
723  AlertJsonOutputCtx *json_output_ctx = aft->json_output_ctx;
724 
725  if (p->alerts.cnt == 0 && !(p->flags & PKT_HAS_TAG))
726  return TM_ECODE_OK;
727 
728  for (int i = 0; i < p->alerts.cnt; i++) {
729  const PacketAlert *pa = &p->alerts.alerts[i];
730  if (unlikely(pa->s == NULL)) {
731  continue;
732  }
733 
734  /* First initialize the address info (5-tuple). */
736  JsonAddrInfoInit(p, LOG_DIR_PACKET, &addr);
737 
738  /* Check for XFF, overwriting address info if needed. */
739  HttpXFFCfg *xff_cfg = json_output_ctx->xff_cfg != NULL ? json_output_ctx->xff_cfg
740  : json_output_ctx->parent_xff_cfg;
741  int have_xff_ip = 0;
742  char xff_buffer[XFF_MAXLEN];
743  xff_buffer[0] = 0;
744  if ((xff_cfg != NULL) && !(xff_cfg->flags & XFF_DISABLED) && p->flow != NULL) {
745  if (FlowGetAppProtocol(p->flow) == ALPROTO_HTTP1) {
746  if (pa->flags & PACKET_ALERT_FLAG_TX) {
747  have_xff_ip = HttpXFFGetIPFromTx(p->flow, pa->tx_id, xff_cfg,
748  xff_buffer, XFF_MAXLEN);
749  } else {
750  have_xff_ip = HttpXFFGetIP(p->flow, xff_cfg, xff_buffer,
751  XFF_MAXLEN);
752  }
753  }
754 
755  if (have_xff_ip && xff_cfg->flags & XFF_OVERWRITE) {
756  if (p->flowflags & FLOW_PKT_TOCLIENT) {
757  strlcpy(addr.dst_ip, xff_buffer, JSON_ADDR_LEN);
758  } else {
759  strlcpy(addr.src_ip, xff_buffer, JSON_ADDR_LEN);
760  }
761  /* Clear have_xff_ip so the xff field does not get
762  * logged below. */
763  have_xff_ip = false;
764  }
765  if (have_xff_ip && !(xff_cfg->flags & XFF_EXTRADATA)) {
766  // reset xff_buffer so as not to log it
767  xff_buffer[0] = 0;
768  }
769  }
770 
771  JsonBuilder *jb =
772  CreateEveHeader(p, LOG_DIR_PACKET, "alert", &addr, json_output_ctx->eve_ctx);
773  if (unlikely(jb == NULL))
774  return TM_ECODE_OK;
775 
776 
777  /* alert */
778  AlertJsonHeader(json_output_ctx, p, pa, jb, json_output_ctx->flags, &addr, xff_buffer);
779 
780  if (IS_TUNNEL_PKT(p)) {
781  AlertJsonTunnel(p, jb);
782  }
783 
784  if (p->flow != NULL) {
785  if (json_output_ctx->flags & LOG_JSON_APP_LAYER) {
786  AlertAddAppLayer(p, jb, pa->tx_id, json_output_ctx->flags);
787  }
788  /* including fileinfo data is configured by the metadata setting */
789  if (json_output_ctx->flags & LOG_JSON_RULE_METADATA) {
790  AlertAddFiles(p, jb, pa->tx_id);
791  }
792 
793  EveAddAppProto(p->flow, jb);
794 
795  if (p->flowflags & FLOW_PKT_TOSERVER) {
796  jb_set_string(jb, "direction", "to_server");
797  } else {
798  jb_set_string(jb, "direction", "to_client");
799  }
800 
801  if (json_output_ctx->flags & LOG_JSON_FLOW) {
802  jb_open_object(jb, "flow");
803  EveAddFlow(p->flow, jb);
804  if (p->flowflags & FLOW_PKT_TOCLIENT) {
805  jb_set_string(jb, "src_ip", addr.dst_ip);
806  jb_set_string(jb, "dest_ip", addr.src_ip);
807  if (addr.sp > 0) {
808  jb_set_uint(jb, "src_port", addr.dp);
809  jb_set_uint(jb, "dest_port", addr.sp);
810  }
811  } else {
812  jb_set_string(jb, "src_ip", addr.src_ip);
813  jb_set_string(jb, "dest_ip", addr.dst_ip);
814  if (addr.sp > 0) {
815  jb_set_uint(jb, "src_port", addr.sp);
816  jb_set_uint(jb, "dest_port", addr.dp);
817  }
818  }
819  jb_close(jb);
820  }
821  }
822 
823  /* payload */
824  if (json_output_ctx->flags & (LOG_JSON_PAYLOAD | LOG_JSON_PAYLOAD_BASE64)) {
825  int stream = (p->proto == IPPROTO_TCP) ?
827  1 : 0) : 0;
828 
829  /* Is this a stream? If so, pack part of it into the payload field */
830  if (stream) {
831  uint8_t flag;
832 
833  MemBufferReset(payload);
834 
835  if (p->flowflags & FLOW_PKT_TOSERVER) {
836  flag = STREAM_DUMP_TOCLIENT;
837  } else {
838  flag = STREAM_DUMP_TOSERVER;
839  }
840 
841  StreamSegmentForEach((const Packet *)p, flag,
842  AlertJsonDumpStreamSegmentCallback,
843  (void *)payload);
844  if (payload->offset) {
845  if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
846  jb_set_base64(jb, "payload", payload->buffer, payload->offset);
847  }
848 
849  if (json_output_ctx->flags & LOG_JSON_PAYLOAD) {
850  uint8_t printable_buf[payload->offset + 1];
851  uint32_t offset = 0;
852  PrintStringsToBuffer(printable_buf, &offset,
853  sizeof(printable_buf),
854  payload->buffer, payload->offset);
855  jb_set_string(jb, "payload_printable", (char *)printable_buf);
856  }
857  } else if (p->payload_len) {
858  /* Fallback on packet payload */
859  AlertAddPayload(json_output_ctx, jb, p);
860  }
861  } else {
862  /* This is a single packet and not a stream */
863  AlertAddPayload(json_output_ctx, jb, p);
864  }
865 
866  jb_set_uint(jb, "stream", stream);
867  }
868 
869  if (pa->flags & PACKET_ALERT_FLAG_FRAME) {
870  AlertAddFrame(p, jb, pa->frame_id);
871  }
872 
873  /* base64-encoded full packet */
874  if (json_output_ctx->flags & LOG_JSON_PACKET) {
875  EvePacket(p, jb, 0);
876  }
877 
879  if (pcap_filename != NULL) {
880  jb_set_string(jb, "capture_file", pcap_filename);
881  }
882 
883  if (json_output_ctx->flags & LOG_JSON_VERDICT) {
884  EveAddVerdict(jb, p);
885  }
886 
887  OutputJsonBuilderBuffer(jb, aft->ctx);
888  jb_free(jb);
889  }
890 
891  if ((p->flags & PKT_HAS_TAG) && (json_output_ctx->flags &
893  JsonBuilder *packetjs =
894  CreateEveHeader(p, LOG_DIR_PACKET, "packet", NULL, json_output_ctx->eve_ctx);
895  if (unlikely(packetjs != NULL)) {
896  EvePacket(p, packetjs, 0);
897  OutputJsonBuilderBuffer(packetjs, aft->ctx);
898  jb_free(packetjs);
899  }
900  }
901 
902  return TM_ECODE_OK;
903 }
904 
905 static int AlertJsonDecoderEvent(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
906 {
907  AlertJsonOutputCtx *json_output_ctx = aft->json_output_ctx;
908  char timebuf[64];
909 
910  if (p->alerts.cnt == 0)
911  return TM_ECODE_OK;
912 
913  CreateIsoTimeString(p->ts, timebuf, sizeof(timebuf));
914 
915  for (int i = 0; i < p->alerts.cnt; i++) {
916  const PacketAlert *pa = &p->alerts.alerts[i];
917  if (unlikely(pa->s == NULL)) {
918  continue;
919  }
920 
921  JsonBuilder *jb = jb_new_object();
922  if (unlikely(jb == NULL)) {
923  return TM_ECODE_OK;
924  }
925 
926  /* just the timestamp, no tuple */
927  jb_set_string(jb, "timestamp", timebuf);
928 
929  AlertJsonHeader(json_output_ctx, p, pa, jb, json_output_ctx->flags, NULL, NULL);
930 
931  OutputJsonBuilderBuffer(jb, aft->ctx);
932  jb_free(jb);
933  }
934 
935  return TM_ECODE_OK;
936 }
937 
938 static int JsonAlertLogger(ThreadVars *tv, void *thread_data, const Packet *p)
939 {
940  JsonAlertLogThread *aft = thread_data;
941 
942  if (PKT_IS_IPV4(p) || PKT_IS_IPV6(p)) {
943  return AlertJson(tv, aft, p);
944  } else if (p->alerts.cnt > 0) {
945  return AlertJsonDecoderEvent(tv, aft, p);
946  }
947  return 0;
948 }
949 
950 static int JsonAlertLogCondition(ThreadVars *tv, void *thread_data, const Packet *p)
951 {
952  if (p->alerts.cnt || (p->flags & PKT_HAS_TAG)) {
953  return TRUE;
954  }
955  return FALSE;
956 }
957 
958 static TmEcode JsonAlertLogThreadInit(ThreadVars *t, const void *initdata, void **data)
959 {
961  if (unlikely(aft == NULL))
962  return TM_ECODE_FAILED;
963 
964  if (initdata == NULL)
965  {
966  SCLogDebug("Error getting context for EveLogAlert. \"initdata\" argument NULL");
967  goto error_exit;
968  }
969 
970  /** Use the Output Context (file pointer and mutex) */
971  AlertJsonOutputCtx *json_output_ctx = ((OutputCtx *)initdata)->data;
972 
973  aft->payload_buffer = MemBufferCreateNew(json_output_ctx->payload_buffer_size);
974  if (aft->payload_buffer == NULL) {
975  goto error_exit;
976  }
977  aft->ctx = CreateEveThreadCtx(t, json_output_ctx->eve_ctx);
978  if (!aft->ctx) {
979  goto error_exit;
980  }
981 
982  aft->json_output_ctx = json_output_ctx;
983 
984  *data = (void *)aft;
985  return TM_ECODE_OK;
986 
987 error_exit:
988  if (aft->payload_buffer != NULL) {
990  }
991  SCFree(aft);
992  return TM_ECODE_FAILED;
993 }
994 
995 static TmEcode JsonAlertLogThreadDeinit(ThreadVars *t, void *data)
996 {
997  JsonAlertLogThread *aft = (JsonAlertLogThread *)data;
998  if (aft == NULL) {
999  return TM_ECODE_OK;
1000  }
1001 
1003  FreeEveThreadCtx(aft->ctx);
1004 
1005  /* clear memory */
1006  memset(aft, 0, sizeof(JsonAlertLogThread));
1007 
1008  SCFree(aft);
1009  return TM_ECODE_OK;
1010 }
1011 
1012 static void JsonAlertLogDeInitCtxSub(OutputCtx *output_ctx)
1013 {
1014  SCLogDebug("cleaning up sub output_ctx %p", output_ctx);
1015 
1016  AlertJsonOutputCtx *json_output_ctx = (AlertJsonOutputCtx *) output_ctx->data;
1017 
1018  if (json_output_ctx != NULL) {
1019  HttpXFFCfg *xff_cfg = json_output_ctx->xff_cfg;
1020  if (xff_cfg != NULL) {
1021  SCFree(xff_cfg);
1022  }
1023  SCFree(json_output_ctx);
1024  }
1025  SCFree(output_ctx);
1026 }
1027 
1028 static void SetFlag(const ConfNode *conf, const char *name, uint16_t flag, uint16_t *out_flags)
1029 {
1030  DEBUG_VALIDATE_BUG_ON(conf == NULL);
1031  const char *setting = ConfNodeLookupChildValue(conf, name);
1032  if (setting != NULL) {
1033  if (ConfValIsTrue(setting)) {
1034  *out_flags |= flag;
1035  } else {
1036  *out_flags &= ~flag;
1037  }
1038  }
1039 }
1040 
1041 #define DEFAULT_LOG_FILENAME "alert.json"
1043 static void JsonAlertLogSetupMetadata(AlertJsonOutputCtx *json_output_ctx,
1044  ConfNode *conf)
1045 {
1046  static bool warn_no_meta = false;
1047  uint32_t payload_buffer_size = JSON_STREAM_BUFFER_SIZE;
1048  uint16_t flags = METADATA_DEFAULTS;
1049 
1050  if (conf != NULL) {
1051  /* Check for metadata to enable/disable. */
1052  ConfNode *metadata = ConfNodeLookupChild(conf, "metadata");
1053  if (metadata != NULL) {
1054  if (metadata->val != NULL && ConfValIsFalse(metadata->val)) {
1056  } else if (ConfNodeHasChildren(metadata)) {
1057  ConfNode *rule_metadata = ConfNodeLookupChild(metadata, "rule");
1058  if (rule_metadata) {
1059  SetFlag(rule_metadata, "raw", LOG_JSON_RULE, &flags);
1060  SetFlag(rule_metadata, "metadata", LOG_JSON_RULE_METADATA,
1061  &flags);
1062  }
1063  SetFlag(metadata, "flow", LOG_JSON_FLOW, &flags);
1064  SetFlag(metadata, "app-layer", LOG_JSON_APP_LAYER, &flags);
1065  }
1066  }
1067 
1068  /* Non-metadata toggles. */
1069  SetFlag(conf, "payload", LOG_JSON_PAYLOAD_BASE64, &flags);
1070  SetFlag(conf, "packet", LOG_JSON_PACKET, &flags);
1071  SetFlag(conf, "tagged-packets", LOG_JSON_TAGGED_PACKETS, &flags);
1072  SetFlag(conf, "payload-printable", LOG_JSON_PAYLOAD, &flags);
1073  SetFlag(conf, "http-body-printable", LOG_JSON_HTTP_BODY, &flags);
1074  SetFlag(conf, "http-body", LOG_JSON_HTTP_BODY_BASE64, &flags);
1075  SetFlag(conf, "verdict", LOG_JSON_VERDICT, &flags);
1076 
1077  /* Check for obsolete flags and warn that they have no effect. */
1078  static const char *deprecated_flags[] = { "http", "tls", "ssh", "smtp", "dnp3", "app-layer",
1079  "flow", NULL };
1080  for (int i = 0; deprecated_flags[i] != NULL; i++) {
1081  if (ConfNodeLookupChildValue(conf, deprecated_flags[i]) != NULL) {
1082  SCLogWarning("Found deprecated eve-log.alert flag \"%s\", this flag has no effect",
1083  deprecated_flags[i]);
1084  }
1085  }
1086 
1087  const char *payload_buffer_value = ConfNodeLookupChildValue(conf, "payload-buffer-size");
1088 
1089  if (payload_buffer_value != NULL) {
1090  uint32_t value;
1091  if (ParseSizeStringU32(payload_buffer_value, &value) < 0) {
1092  SCLogError("Error parsing "
1093  "payload-buffer-size - %s. Killing engine",
1094  payload_buffer_value);
1095  exit(EXIT_FAILURE);
1096  } else {
1097  payload_buffer_size = value;
1098  }
1099  }
1100 
1101  if (!warn_no_meta && flags & JSON_BODY_LOGGING) {
1102  if (((flags & LOG_JSON_APP_LAYER) == 0)) {
1103  SCLogWarning("HTTP body logging has been configured, however, "
1104  "metadata logging has not been enabled. HTTP body logging will be "
1105  "disabled.");
1107  warn_no_meta = true;
1108  }
1109  }
1110 
1111  json_output_ctx->payload_buffer_size = payload_buffer_size;
1112  }
1113 
1114  if (flags & LOG_JSON_RULE_METADATA) {
1116  }
1117 
1118  json_output_ctx->flags |= flags;
1119 }
1120 
1121 static HttpXFFCfg *JsonAlertLogGetXffCfg(ConfNode *conf)
1122 {
1123  HttpXFFCfg *xff_cfg = NULL;
1124  if (conf != NULL && ConfNodeLookupChild(conf, "xff") != NULL) {
1125  xff_cfg = SCCalloc(1, sizeof(HttpXFFCfg));
1126  if (likely(xff_cfg != NULL)) {
1127  HttpXFFGetCfg(conf, xff_cfg);
1128  }
1129  }
1130  return xff_cfg;
1131 }
1132 
1133 /**
1134  * \brief Create a new LogFileCtx for "fast" output style.
1135  * \param conf The configuration node for this output.
1136  * \return A LogFileCtx pointer on success, NULL on failure.
1137  */
1138 static OutputInitResult JsonAlertLogInitCtxSub(ConfNode *conf, OutputCtx *parent_ctx)
1139 {
1140  OutputInitResult result = { NULL, false };
1141  OutputJsonCtx *ajt = parent_ctx->data;
1142  AlertJsonOutputCtx *json_output_ctx = NULL;
1143 
1144  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
1145  if (unlikely(output_ctx == NULL))
1146  return result;
1147 
1148  json_output_ctx = SCMalloc(sizeof(AlertJsonOutputCtx));
1149  if (unlikely(json_output_ctx == NULL)) {
1150  goto error;
1151  }
1152  memset(json_output_ctx, 0, sizeof(AlertJsonOutputCtx));
1153 
1154  json_output_ctx->file_ctx = ajt->file_ctx;
1155  json_output_ctx->eve_ctx = ajt;
1156 
1157  JsonAlertLogSetupMetadata(json_output_ctx, conf);
1158  json_output_ctx->xff_cfg = JsonAlertLogGetXffCfg(conf);
1159  if (json_output_ctx->xff_cfg == NULL) {
1160  json_output_ctx->parent_xff_cfg = ajt->xff_cfg;
1161  }
1162 
1163  output_ctx->data = json_output_ctx;
1164  output_ctx->DeInit = JsonAlertLogDeInitCtxSub;
1165 
1166  result.ctx = output_ctx;
1167  result.ok = true;
1168  return result;
1169 
1170 error:
1171  if (json_output_ctx != NULL) {
1172  SCFree(json_output_ctx);
1173  }
1174  if (output_ctx != NULL) {
1175  SCFree(output_ctx);
1176  }
1177 
1178  return result;
1179 }
1180 
1182 {
1184  "eve-log.alert", JsonAlertLogInitCtxSub, JsonAlertLogger,
1185  JsonAlertLogCondition, JsonAlertLogThreadInit, JsonAlertLogThreadDeinit,
1186  NULL);
1187 }
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
util-byte.h
tm-threads.h
FrameJsonLogOneFrame
void FrameJsonLogOneFrame(const uint8_t ipproto, const Frame *frame, const Flow *f, const TcpStream *stream, const Packet *p, JsonBuilder *jb)
log a single frame
Definition: output-json-frame.c:226
Packet_::proto
uint8_t proto
Definition: decode.h:452
SSLState_
SSLv[2.0|3.[0|1|2|3]] state structure.
Definition: app-layer-ssl.h:284
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:277
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:267
EveHttpLogJSONBodyPrintable
void EveHttpLogJSONBodyPrintable(JsonBuilder *js, Flow *f, uint64_t tx_id)
Definition: output-json-http.c:390
ALPROTO_IKE
@ ALPROTO_IKE
Definition: app-layer-protos.h:49
OutputJsonCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json.h:85
output-json-modbus.h
Signature_::sig_str
char * sig_str
Definition: detect.h:652
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
STREAM_DUMP_TOSERVER
#define STREAM_DUMP_TOSERVER
Definition: stream.h:33
PACKET_ALERT_FLAG_TX
#define PACKET_ALERT_FLAG_TX
Definition: decode.h:279
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
ALPROTO_DNS
@ ALPROTO_DNS
Definition: app-layer-protos.h:41
PKT_IS_IPV6
#define PKT_IS_IPV6(p)
Definition: decode.h:246
ConfNode_::val
char * val
Definition: conf.h:34
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
ALPROTO_TLS
@ ALPROTO_TLS
Definition: app-layer-protos.h:33
output-json-mqtt.h
LOG_JSON_RULE
#define LOG_JSON_RULE
Definition: output-json-alert.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:269
Packet_::pcap_cnt
uint64_t pcap_cnt
Definition: decode.h:598
AlertJsonOutputCtx_::file_ctx
LogFileCtx * file_ctx
Definition: output-json-alert.c:115
DNP3Transaction_::done
uint8_t done
Definition: app-layer-dnp3.h:220
AlertJsonOutputCtx_::parent_xff_cfg
HttpXFFCfg * parent_xff_cfg
Definition: output-json-alert.c:119
ALPROTO_MODBUS
@ ALPROTO_MODBUS
Definition: app-layer-protos.h:42
FreeEveThreadCtx
void FreeEveThreadCtx(OutputJsonThreadCtx *ctx)
Definition: output-json-common.c:58
Flow_::proto
uint8_t proto
Definition: flow.h:369
StreamSegmentForEach
int StreamSegmentForEach(const Packet *p, uint8_t flag, StreamSegmentCallback CallbackFunc, void *data)
Definition: stream.c:40
AppProto
uint16_t AppProto
Definition: app-layer-protos.h:80
ALPROTO_QUIC
@ ALPROTO_QUIC
Definition: app-layer-protos.h:51
Packet_::payload
uint8_t * payload
Definition: decode.h:577
PacketAlerts_::cnt
uint16_t cnt
Definition: decode.h:289
SIG_FLAG_DEST_IS_TARGET
#define SIG_FLAG_DEST_IS_TARGET
Definition: detect.h:269
JsonDNSLogAnswer
JsonBuilder * JsonDNSLogAnswer(void *txptr)
Definition: output-json-dns.c:295
action-globals.h
JsonModbusAddMetadata
bool JsonModbusAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-modbus.c:139
FramesContainer::toserver
Frames toserver
Definition: app-layer-frames.h:74
Packet_::flags
uint32_t flags
Definition: decode.h:467
threads.h
LOGGER_JSON_ALERT
@ LOGGER_JSON_ALERT
Definition: suricata-common.h:474
OutputJsonCtx_
Definition: output-json.h:81
Frame
Definition: app-layer-frames.h:45
Flow_
Flow data structure.
Definition: flow.h:347
util-syslog.h
logged
int logged
Definition: app-layer-htp.h:1
LogFileCtx_
Definition: util-logopenfile.h:72
JsonQuicAddMetadata
bool JsonQuicAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-quic.c:143
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:927
PacketAlerts_::alerts
PacketAlert * alerts
Definition: decode.h:292
output-json-tls.h
CreateEveThreadCtx
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
Definition: output-json-common.c:29
ALPROTO_SIP
@ ALPROTO_SIP
Definition: app-layer-protos.h:54
json_addr_info_zero
const JsonAddrInfo json_addr_info_zero
Definition: output-json.c:89
FLOW_PKT_TOSERVER
#define FLOW_PKT_TOSERVER
Definition: flow.h:221
output-json-sip.h
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:131
util-privs.h
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:120
ALPROTO_SSH
@ ALPROTO_SSH
Definition: app-layer-protos.h:34
app-layer-ftp.h
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:461
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:85
Flow_::protoctx
void * protoctx
Definition: flow.h:437
Packet_::payload_len
uint16_t payload_len
Definition: decode.h:578
Packet_::alerts
PacketAlerts alerts
Definition: decode.h:592
util-unittest.h
MemBuffer_::offset
uint32_t offset
Definition: util-buffer.h:30
EveHttpAddMetadata
bool EveHttpAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-http.c:498
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:537
util-unittest-helper.h
HttpXFFGetIP
int HttpXFFGetIP(const Flow *f, HttpXFFCfg *xff_cfg, char *dstbuf, int dstbuflen)
Function to return XFF IP if any. The caller needs to lock the flow.
Definition: app-layer-htp-xff.c:180
OutputCtx_::data
void * data
Definition: tm-modules.h:87
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:84
PcapLogGetFilename
char * PcapLogGetFilename(void)
Definition: log-pcap.c:1887
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:230
PacketAlert_::tx_id
uint64_t tx_id
Definition: decode.h:268
OutputCtx_
Definition: tm-modules.h:84
app-layer-htp-xff.h
PacketAlert_::action
uint8_t action
Definition: decode.h:265
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:110
OutputJsonThreadCtx_
Definition: output-json.h:89
JsonDNSLogQuery
JsonBuilder * JsonDNSLogQuery(void *txptr)
Definition: output-json-dns.c:266
detect-reference.h
ALPROTO_SNMP
@ ALPROTO_SNMP
Definition: app-layer-protos.h:53
Signature_::gid
uint32_t gid
Definition: detect.h:618
output-json-dnp3.h
ACTION_REJECT_DST
#define ACTION_REJECT_DST
Definition: action-globals.h:32
JsonAddrInfo_::dp
Port dp
Definition: output-json.h:53
app-layer-htp.h
FramesContainer::toclient
Frames toclient
Definition: app-layer-frames.h:75
JsonAlertLogThread_::ctx
OutputJsonThreadCtx * ctx
Definition: output-json-alert.c:126
util-debug.h
JB_SET_STRING
#define JB_SET_STRING(jb, key, val)
Definition: rust.h:28
output-json-flow.h
MODULE_NAME
#define MODULE_NAME
Definition: output-json-alert.c:92
PKT_IS_TOSERVER
#define PKT_IS_TOSERVER(p)
Definition: decode.h:251
JsonRFBAddMetadata
bool JsonRFBAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-rfb.c:49
OutputInitResult_::ctx
OutputCtx * ctx
Definition: output.h:47
output-json-rfb.h
LOG_JSON_APP_LAYER
#define LOG_JSON_APP_LAYER
Definition: output-json-alert.c:98
Packet_::ts
SCTime_t ts
Definition: decode.h:475
ALPROTO_DNP3
@ ALPROTO_DNP3
Definition: app-layer-protos.h:44
app-layer-dnp3.h
output-json.h
FrameGetById
Frame * FrameGetById(Frames *frames, const int64_t id)
Definition: app-layer-frames.c:86
MemBufferWriteRaw
#define MemBufferWriteRaw(dst, raw_buffer, raw_buffer_len)
Write a raw buffer to the MemBuffer dst.
Definition: util-buffer.h:133
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:94
PktSrcEnum
PktSrcEnum
Definition: decode.h:53
AlertJsonOutputCtx_::flags
uint16_t flags
Definition: output-json-alert.c:116
CreateEveHeader
JsonBuilder * CreateEveHeader(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, OutputJsonCtx *eve_ctx)
Definition: output-json.c:786
util-print.h
detect-engine-mpm.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:740
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
JsonDNP3LogResponse
void JsonDNP3LogResponse(JsonBuilder *js, DNP3Transaction *dnp3tx)
Definition: output-json-dnp3.c:174
EveHttpLogJSONBodyBase64
void EveHttpLogJSONBodyBase64(JsonBuilder *js, Flow *f, uint64_t tx_id)
Definition: output-json-http.c:421
app-layer-parser.h
JsonAlertLogThread_
Definition: output-json-alert.c:123
TRUE
#define TRUE
Definition: suricata-common.h:33
FALSE
#define FALSE
Definition: suricata-common.h:34
Signature_::flags
uint32_t flags
Definition: detect.h:583
stream.h
JsonAddrInfo_
Definition: output-json.h:49
TcpSegment
Definition: stream-tcp-private.h:72
Packet_
Definition: decode.h:430
AppLayerFramesGetContainer
FramesContainer * AppLayerFramesGetContainer(Flow *f)
Definition: app-layer-parser.c:183
ALPROTO_RDP
@ ALPROTO_RDP
Definition: app-layer-protos.h:60
JSON_STREAM_BUFFER_SIZE
#define JSON_STREAM_BUFFER_SIZE
Definition: output-json-alert.c:112
LOG_JSON_PAYLOAD_BASE64
#define LOG_JSON_PAYLOAD_BASE64
Definition: output-json-alert.c:96
conf.h
SIG_FLAG_HAS_TARGET
#define SIG_FLAG_HAS_TARGET
Definition: detect.h:271
XFF_OVERWRITE
#define XFF_OVERWRITE
Definition: app-layer-htp-xff.h:33
TmEcode
TmEcode
Definition: tm-threads-common.h:83
SIG_FLAG_SRC_IS_TARGET
#define SIG_FLAG_SRC_IS_TARGET
Definition: detect.h:267
EveNFSAddMetadataRPC
bool EveNFSAddMetadataRPC(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
Definition: output-json-nfs.c:50
IS_TUNNEL_PKT
#define IS_TUNNEL_PKT(p)
Definition: decode.h:794
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:366
HttpXFFCfg_
Definition: app-layer-htp-xff.h:41
AlertJsonOutputCtx_::payload_buffer_size
uint32_t payload_buffer_size
Definition: output-json-alert.c:117
ALPROTO_HTTP2
@ ALPROTO_HTTP2
Definition: app-layer-protos.h:61
util-proto-name.h
ConfNodeHasChildren
bool ConfNodeHasChildren(const ConfNode *node)
Check if a node has any children.
Definition: conf.c:767
MemBuffer_
Definition: util-buffer.h:27
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:222
LOG_JSON_TAGGED_PACKETS
#define LOG_JSON_TAGGED_PACKETS
Definition: output-json-alert.c:97
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1127
EveEmailAddMetadata
bool EveEmailAddMetadata(const Flow *f, uint32_t tx_id, JsonBuilder *js)
Definition: output-json-email-common.c:379
AlertJsonOutputCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json-alert.c:118
log-pcap.h
PacketAlert_::frame_id
int64_t frame_id
Definition: decode.h:269
JsonAddrInfo_::proto
char proto[JSON_PROTO_LEN]
Definition: output-json.h:54
Signature_::class_msg
char * class_msg
Definition: detect.h:646
ConfNodeLookupChild
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
Definition: conf.c:786
DNP3Transaction_::is_request
bool is_request
Definition: app-layer-dnp3.h:209
PacketAlert_::flags
uint8_t flags
Definition: decode.h:266
ACTION_REJECT_BOTH
#define ACTION_REJECT_BOTH
Definition: action-globals.h:33
File_::flags
uint16_t flags
Definition: util-file.h:80
MemBufferReset
#define MemBufferReset(mem_buffer)
Reset the mem buffer.
Definition: util-buffer.h:42
PACKET_ALERT_RATE_FILTER_MODIFIED
#define PACKET_ALERT_RATE_FILTER_MODIFIED
Definition: decode.h:281
File_
Definition: util-file.h:79
OutputInitResult_
Definition: output.h:46
app-layer-frames.h
Packet_::flow
struct Flow_ * flow
Definition: decode.h:469
Packet_::tenant_id
uint32_t tenant_id
Definition: decode.h:634
LOG_DIR_PACKET
@ LOG_DIR_PACKET
Definition: output-json.h:39
flags
uint8_t flags
Definition: decode-gre.h:0
suricata-common.h
JsonAddrInfo_::sp
Port sp
Definition: output-json.h:52
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:90
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:216
pcap_filename
char pcap_filename[PATH_MAX]
Definition: source-pcap-file-helper.c:116
JSON_ADDR_LEN
#define JSON_ADDR_LEN
Definition: output-json.h:45
AlertJsonOutputCtx_
Definition: output-json-alert.c:114
detect-metadata.h
JsonAlertLogThread_::json_output_ctx
AlertJsonOutputCtx * json_output_ctx
Definition: output-json-alert.c:125
output-json-nfs.h
packet.h
EveAddVerdict
void EveAddVerdict(JsonBuilder *jb, const Packet *p)
Build verdict object.
Definition: output-json-alert.c:675
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
MemBufferFree
void MemBufferFree(MemBuffer *buffer)
Definition: util-buffer.c:87
LOG_JSON_VERDICT
#define LOG_JSON_VERDICT
Definition: output-json-alert.c:104
File_::next
struct File_ * next
Definition: util-file.h:92
ACTION_DROP
#define ACTION_DROP
Definition: action-globals.h:30
ALPROTO_FTPDATA
@ ALPROTO_FTPDATA
Definition: app-layer-protos.h:47
EveAddAppProto
void EveAddAppProto(Flow *f, JsonBuilder *js)
Definition: output-json-flow.c:169
Signature_::rev
uint32_t rev
Definition: detect.h:619
util-classification-config.h
EvePacket
void EvePacket(const Packet *p, JsonBuilder *js, unsigned long max_length)
Jsonify a packet.
Definition: output-json.c:439
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:620
ParseSizeStringU32
int ParseSizeStringU32(const char *size, uint32_t *res)
Definition: util-misc.c:181
output-json-alert.h
util-optimize.h
threadvars.h
util-validate.h
output-json-dns.h
SCMalloc
#define SCMalloc(sz)
Definition: util-mem.h:47
Packet_::root
struct Packet_ * root
Definition: decode.h:622
TcpSession_::server
TcpStream server
Definition: stream-tcp-private.h:294
JsonAddrInfo_::src_ip
char src_ip[JSON_ADDR_LEN]
Definition: output-json.h:50
HttpXFFCfg_::flags
uint8_t flags
Definition: app-layer-htp-xff.h:42
Signature_::metadata
DetectMetadataHead * metadata
Definition: detect.h:650
PACKET_ALERT_FLAG_FRAME
#define PACKET_ALERT_FLAG_FRAME
Definition: decode.h:283
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:124
SCFree
#define SCFree(p)
Definition: util-mem.h:61
Packet_::pkt_src
uint8_t pkt_src
Definition: decode.h:583
ConfNode_
Definition: conf.h:32
util-logopenfile.h
Flow_::alstate
void * alstate
Definition: flow.h:472
Signature_::id
uint32_t id
Definition: detect.h:617
STREAM_DUMP_TOCLIENT
#define STREAM_DUMP_TOCLIENT
Definition: stream.h:32
Packet_::recursion_level
uint8_t recursion_level
Definition: decode.h:455
LOG_JSON_HTTP_BODY_BASE64
#define LOG_JSON_HTTP_BODY_BASE64
Definition: output-json-alert.c:101
output-json-ike.h
detect-parse.h
util-buffer.h
LOG_JSON_PACKET
#define LOG_JSON_PACKET
Definition: output-json-alert.c:95
ALPROTO_MQTT
@ ALPROTO_MQTT
Definition: app-layer-protos.h:56
ConfValIsFalse
int ConfValIsFalse(const char *val)
Check if a value is false.
Definition: conf.c:562
JsonAddrInfo_::dst_ip
char dst_ip[JSON_ADDR_LEN]
Definition: output-json.h:51
EveFTPDataAddMetadata
void EveFTPDataAddMetadata(const Flow *f, JsonBuilder *jb)
Definition: app-layer-ftp.c:1408
output-json-ssh.h
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:100
METADATA_DEFAULTS
#define METADATA_DEFAULTS
Definition: output-json-alert.c:106
DNP3State_
Per flow DNP3 state.
Definition: app-layer-dnp3.h:232
EngineModeIsIPS
int EngineModeIsIPS(void)
Definition: suricata.c:228
LOG_JSON_FLOW
#define LOG_JSON_FLOW
Definition: output-json-alert.c:99
JsonDNP3LogRequest
void JsonDNP3LogRequest(JsonBuilder *js, DNP3Transaction *dnp3tx)
Definition: output-json-dnp3.c:143
ALPROTO_RFB
@ ALPROTO_RFB
Definition: app-layer-protos.h:55
PacketAlert_
Definition: decode.h:263
JsonAddrInfoInit
void JsonAddrInfoInit(const Packet *p, enum OutputJsonLogDirection dir, JsonAddrInfo *addr)
Definition: output-json.c:476
ALPROTO_BITTORRENT_DHT
@ ALPROTO_BITTORRENT_DHT
Definition: app-layer-protos.h:62
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:928
AppLayerParserGetTxFiles
AppLayerGetFileState AppLayerParserGetTxFiles(const Flow *f, void *state, void *tx, const uint8_t direction)
Definition: app-layer-parser.c:890
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
MemBuffer_::buffer
uint8_t * buffer
Definition: util-buffer.h:28
TcpSession_
Definition: stream-tcp-private.h:283
output-json-http.h
util-misc.h
PKT_HAS_TAG
#define PKT_HAS_TAG
Definition: decode.h:993
Signature_::msg
char * msg
Definition: detect.h:643
flow.h
DetectEngineSetParseMetadata
void DetectEngineSetParseMetadata(void)
Definition: detect-engine.c:4872
EveSMBAddMetadata
bool EveSMBAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *jb)
Definition: output-json-smb.c:34
JsonTlsLogJSONExtended
void JsonTlsLogJSONExtended(JsonBuilder *tjs, SSLState *state)
Definition: output-json-tls.c:395
Flow_::alproto
AppProto alproto
application level protocol
Definition: flow.h:446
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
LOG_JSON_RULE_METADATA
#define LOG_JSON_RULE_METADATA
Definition: output-json-alert.c:102
XFF_DISABLED
#define XFF_DISABLED
Definition: app-layer-htp-xff.h:29
PKT_IS_IPV4
#define PKT_IS_IPV4(p)
Definition: decode.h:245
PACKET_ALERT_FLAG_STATE_MATCH
#define PACKET_ALERT_FLAG_STATE_MATCH
Definition: decode.h:275
output-json-quic.h
JsonSIPAddMetadata
void JsonSIPAddMetadata(JsonBuilder *js, const Flow *f, uint64_t tx_id)
Definition: output-json-sip.c:51
JsonMQTTAddMetadata
bool JsonMQTTAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-mqtt.c:62
DEBUG_VALIDATE_BUG_ON
#define DEBUG_VALIDATE_BUG_ON(exp)
Definition: util-validate.h:104
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:1181
DNP3Transaction_
DNP3 transaction.
Definition: app-layer-dnp3.h:205
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:814