suricata
output-json-http.c
Go to the documentation of this file.
1 /* Copyright (C) 2007-2021 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  * Implements HTTP JSON logging portion of the engine.
24  */
25 
26 #include "suricata-common.h"
27 #include "debug.h"
28 #include "detect.h"
29 #include "pkt-var.h"
30 #include "conf.h"
31 
32 #include "threads.h"
33 #include "threadvars.h"
34 #include "tm-threads.h"
35 
36 #include "util-print.h"
37 #include "util-unittest.h"
38 
39 #include "util-debug.h"
40 
41 #include "output.h"
42 #include "app-layer-htp.h"
43 #include "app-layer-htp-file.h"
44 #include "app-layer-htp-xff.h"
45 #include "app-layer.h"
46 #include "app-layer-parser.h"
47 #include "util-privs.h"
48 #include "util-buffer.h"
49 #include "util-proto-name.h"
50 #include "util-logopenfile.h"
51 #include "util-time.h"
52 #include "output-json.h"
53 #include "output-json-alert.h"
54 #include "output-json-http.h"
55 #include "util-byte.h"
56 
57 typedef struct LogHttpFileCtx_ {
58  uint32_t flags; /** Store mode */
59  uint64_t fields;/** Store fields */
64 
65 typedef struct JsonHttpLogThread_ {
67  uint32_t uri_cnt;
70 
71 #define MAX_SIZE_HEADER_NAME 256
72 #define MAX_SIZE_HEADER_VALUE 2048
73 
74 #define LOG_HTTP_DEFAULT 0
75 #define LOG_HTTP_EXTENDED 1
76 #define LOG_HTTP_REQUEST 2 /* request field */
77 #define LOG_HTTP_ARRAY 4 /* require array handling */
78 #define LOG_HTTP_REQ_HEADERS 8
79 #define LOG_HTTP_RES_HEADERS 16
80 
81 typedef enum {
137 
138 struct {
139  const char *config_field;
140  const char *htp_field;
141  uint32_t flags;
142 } http_fields[] = {
143  { "accept", "accept", LOG_HTTP_REQUEST },
144  { "accept_charset", "accept-charset", LOG_HTTP_REQUEST },
145  { "accept_encoding", "accept-encoding", LOG_HTTP_REQUEST },
146  { "accept_language", "accept-language", LOG_HTTP_REQUEST },
147  { "accept_datetime", "accept-datetime", LOG_HTTP_REQUEST },
148  { "authorization", "authorization", LOG_HTTP_REQUEST },
149  { "cache_control", "cache-control", LOG_HTTP_REQUEST },
150  { "cookie", "cookie", LOG_HTTP_REQUEST|LOG_HTTP_ARRAY },
151  { "from", "from", LOG_HTTP_REQUEST },
152  { "max_forwards", "max-forwards", LOG_HTTP_REQUEST },
153  { "origin", "origin", LOG_HTTP_REQUEST },
154  { "pragma", "pragma", LOG_HTTP_REQUEST },
155  { "proxy_authorization", "proxy-authorization", LOG_HTTP_REQUEST },
156  { "range", "range", LOG_HTTP_REQUEST },
157  { "te", "te", LOG_HTTP_REQUEST },
158  { "via", "via", LOG_HTTP_REQUEST },
159  { "x_requested_with", "x-requested-with", LOG_HTTP_REQUEST },
160  { "dnt", "dnt", LOG_HTTP_REQUEST },
161  { "x_forwarded_proto", "x-forwarded-proto", LOG_HTTP_REQUEST },
162  { "x_authenticated_user", "x-authenticated-user", LOG_HTTP_REQUEST },
163  { "x_flash_version", "x-flash-version", LOG_HTTP_REQUEST },
164  { "accept_range", "accept-range", 0 },
165  { "age", "age", 0 },
166  { "allow", "allow", 0 },
167  { "connection", "connection", 0 },
168  { "content_encoding", "content-encoding", 0 },
169  { "content_language", "content-language", 0 },
170  { "content_length", "content-length", 0 },
171  { "content_location", "content-location", 0 },
172  { "content_md5", "content-md5", 0 },
173  { "content_range", "content-range", 0 },
174  { "content_type", "content-type", 0 },
175  { "date", "date", 0 },
176  { "etag", "etags", 0 },
177  { "expires", "expires" , 0 },
178  { "last_modified", "last-modified", 0 },
179  { "link", "link", 0 },
180  { "location", "location", 0 },
181  { "proxy_authenticate", "proxy-authenticate", 0 },
182  { "referrer", "referrer", LOG_HTTP_EXTENDED },
183  { "refresh", "refresh", 0 },
184  { "retry_after", "retry-after", 0 },
185  { "server", "server", 0 },
186  { "set_cookie", "set-cookie", 0 },
187  { "trailer", "trailer", 0 },
188  { "transfer_encoding", "transfer-encoding", 0 },
189  { "upgrade", "upgrade", 0 },
190  { "vary", "vary", 0 },
191  { "warning", "warning", 0 },
192  { "www_authenticate", "www-authenticate", 0 },
193  { "true_client_ip", "true-client-ip", LOG_HTTP_REQUEST },
194  { "org_src_ip", "org-src-ip", LOG_HTTP_REQUEST },
195  { "x_bluecoat_via", "x-bluecoat-via", LOG_HTTP_REQUEST },
196 };
197 
198 static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
199 {
200  /* hostname */
201  if (tx->request_hostname != NULL) {
202  jb_set_string_from_bytes(
203  js, "hostname", bstr_ptr(tx->request_hostname), bstr_len(tx->request_hostname));
204  }
205 
206  /* port */
207  /* NOTE: this field will be set ONLY if the port is present in the
208  * hostname. It may be present in the header "Host" or in the URL.
209  * There is no connection (from the suricata point of view) between this
210  * port and the TCP destination port of the flow.
211  */
212  if (tx->request_port_number >= 0) {
213  jb_set_uint(js, "http_port", tx->request_port_number);
214  }
215 
216  /* uri */
217  if (tx->request_uri != NULL) {
218  jb_set_string_from_bytes(js, "url", bstr_ptr(tx->request_uri), bstr_len(tx->request_uri));
219  }
220 
221  if (tx->request_headers != NULL) {
222  /* user agent */
223  htp_header_t *h_user_agent = htp_table_get_c(tx->request_headers, "user-agent");
224  if (h_user_agent != NULL) {
225  jb_set_string_from_bytes(js, "http_user_agent", bstr_ptr(h_user_agent->value),
226  bstr_len(h_user_agent->value));
227  }
228 
229  /* x-forwarded-for */
230  htp_header_t *h_x_forwarded_for = htp_table_get_c(tx->request_headers, "x-forwarded-for");
231  if (h_x_forwarded_for != NULL) {
232  jb_set_string_from_bytes(js, "xff", bstr_ptr(h_x_forwarded_for->value),
233  bstr_len(h_x_forwarded_for->value));
234  }
235  }
236 
237  /* content-type */
238  if (tx->response_headers != NULL) {
239  htp_header_t *h_content_type = htp_table_get_c(tx->response_headers, "content-type");
240  if (h_content_type != NULL) {
241  const size_t size = bstr_len(h_content_type->value) * 2 + 1;
242  char string[size];
243  BytesToStringBuffer(bstr_ptr(h_content_type->value), bstr_len(h_content_type->value), string, size);
244  char *p = strchr(string, ';');
245  if (p != NULL)
246  *p = '\0';
247  jb_set_string(js, "http_content_type", string);
248  }
249  htp_header_t *h_content_range = htp_table_get_c(tx->response_headers, "content-range");
250  if (h_content_range != NULL) {
251  jb_open_object(js, "content_range");
252  jb_set_string_from_bytes(
253  js, "raw", bstr_ptr(h_content_range->value), bstr_len(h_content_range->value));
254  HTTPContentRange crparsed;
255  if (HTPParseContentRange(h_content_range->value, &crparsed) == 0) {
256  if (crparsed.start >= 0)
257  jb_set_uint(js, "start", crparsed.start);
258  if (crparsed.end >= 0)
259  jb_set_uint(js, "end", crparsed.end);
260  if (crparsed.size >= 0)
261  jb_set_uint(js, "size", crparsed.size);
262  }
263  jb_close(js);
264  }
265  }
266 }
267 
268 static void EveHttpLogJSONCustom(LogHttpFileCtx *http_ctx, JsonBuilder *js, htp_tx_t *tx)
269 {
270  char *c;
271  HttpField f;
272 
273  for (f = HTTP_FIELD_ACCEPT; f < HTTP_FIELD_SIZE; f++)
274  {
275  if ((http_ctx->fields & (1ULL<<f)) != 0)
276  {
277  /* prevent logging a field twice if extended logging is
278  enabled */
279  if (((http_ctx->flags & LOG_HTTP_EXTENDED) == 0) ||
280  ((http_ctx->flags & LOG_HTTP_EXTENDED) !=
281  (http_fields[f].flags & LOG_HTTP_EXTENDED)))
282  {
283  htp_header_t *h_field = NULL;
284  if ((http_fields[f].flags & LOG_HTTP_REQUEST) != 0)
285  {
286  if (tx->request_headers != NULL) {
287  h_field = htp_table_get_c(tx->request_headers,
288  http_fields[f].htp_field);
289  }
290  } else {
291  if (tx->response_headers != NULL) {
292  h_field = htp_table_get_c(tx->response_headers,
293  http_fields[f].htp_field);
294  }
295  }
296  if (h_field != NULL) {
297  c = bstr_util_strdup_to_c(h_field->value);
298  if (c != NULL) {
299  jb_set_string(js, http_fields[f].config_field, c);
300  SCFree(c);
301  }
302  }
303  }
304  }
305  }
306 }
307 
308 static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
309 {
310  /* referer */
311  htp_header_t *h_referer = NULL;
312  if (tx->request_headers != NULL) {
313  h_referer = htp_table_get_c(tx->request_headers, "referer");
314  }
315  if (h_referer != NULL) {
316  jb_set_string_from_bytes(
317  js, "http_refer", bstr_ptr(h_referer->value), bstr_len(h_referer->value));
318  }
319 
320  /* method */
321  if (tx->request_method != NULL) {
322  jb_set_string_from_bytes(
323  js, "http_method", bstr_ptr(tx->request_method), bstr_len(tx->request_method));
324  }
325 
326  /* protocol */
327  if (tx->request_protocol != NULL) {
328  jb_set_string_from_bytes(
329  js, "protocol", bstr_ptr(tx->request_protocol), bstr_len(tx->request_protocol));
330  }
331 
332  /* response status */
333  if (tx->response_status != NULL) {
334  const size_t status_size = bstr_len(tx->response_status) * 2 + 1;
335  char status_string[status_size];
336  BytesToStringBuffer(bstr_ptr(tx->response_status), bstr_len(tx->response_status),
337  status_string, status_size);
338  unsigned int val = strtoul(status_string, NULL, 10);
339  jb_set_uint(js, "status", val);
340 
341  htp_header_t *h_location = htp_table_get_c(tx->response_headers, "location");
342  if (h_location != NULL) {
343  jb_set_string_from_bytes(
344  js, "redirect", bstr_ptr(h_location->value), bstr_len(h_location->value));
345  }
346  }
347 
348  /* length */
349  jb_set_uint(js, "length", tx->response_message_len);
350 }
351 
352 static void EveHttpLogJSONHeaders(JsonBuilder *js, uint32_t direction, htp_tx_t *tx)
353 {
354  htp_table_t * headers = direction & LOG_HTTP_REQ_HEADERS ?
355  tx->request_headers : tx->response_headers;
356  char name[MAX_SIZE_HEADER_NAME] = {0};
357  char value[MAX_SIZE_HEADER_VALUE] = {0};
358  size_t n = htp_table_size(headers);
359  jb_open_array(js, direction & LOG_HTTP_REQ_HEADERS ? "request_headers" : "response_headers");
360  for (size_t i = 0; i < n; i++) {
361  htp_header_t * h = htp_table_get_index(headers, i, NULL);
362  if (h == NULL) {
363  continue;
364  }
365  jb_start_object(js);
366  size_t size_name = bstr_len(h->name) < MAX_SIZE_HEADER_NAME - 1 ?
367  bstr_len(h->name) : MAX_SIZE_HEADER_NAME - 1;
368  memcpy(name, bstr_ptr(h->name), size_name);
369  name[size_name] = '\0';
370  jb_set_string(js, "name", name);
371  size_t size_value = bstr_len(h->value) < MAX_SIZE_HEADER_VALUE - 1 ?
372  bstr_len(h->value) : MAX_SIZE_HEADER_VALUE - 1;
373  memcpy(value, bstr_ptr(h->value), size_value);
374  value[size_value] = '\0';
375  jb_set_string(js, "value", value);
376  jb_close(js);
377  }
378  // Close array.
379  jb_close(js);
380 }
381 
382 static void BodyPrintableBuffer(JsonBuilder *js, HtpBody *body, const char *key)
383 {
384  if (body->sb != NULL && body->sb->buf != NULL) {
385  uint32_t offset = 0;
386  const uint8_t *body_data;
387  uint32_t body_data_len;
388  uint64_t body_offset;
389 
390  if (StreamingBufferGetData(body->sb, &body_data,
391  &body_data_len, &body_offset) == 0) {
392  return;
393  }
394 
395  uint8_t printable_buf[body_data_len + 1];
396  PrintStringsToBuffer(printable_buf, &offset,
397  sizeof(printable_buf),
398  body_data, body_data_len);
399  if (offset > 0) {
400  jb_set_string(js, key, (char *)printable_buf);
401  }
402  }
403 }
404 
405 void EveHttpLogJSONBodyPrintable(JsonBuilder *js, Flow *f, uint64_t tx_id)
406 {
407  HtpState *htp_state = (HtpState *)FlowGetAppState(f);
408  if (htp_state) {
409  htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, tx_id);
410  if (tx) {
411  HtpTxUserData *htud = (HtpTxUserData *)htp_tx_get_user_data(tx);
412  if (htud != NULL) {
413  BodyPrintableBuffer(js, &htud->request_body, "http_request_body_printable");
414  BodyPrintableBuffer(js, &htud->response_body, "http_response_body_printable");
415  }
416  }
417  }
418 }
419 
420 static void BodyBase64Buffer(JsonBuilder *js, HtpBody *body, const char *key)
421 {
422  if (body->sb != NULL && body->sb->buf != NULL) {
423  const uint8_t *body_data;
424  uint32_t body_data_len;
425  uint64_t body_offset;
426 
427  if (StreamingBufferGetData(body->sb, &body_data,
428  &body_data_len, &body_offset) == 0) {
429  return;
430  }
431 
432  jb_set_base64(js, key, body_data, body_data_len);
433  }
434 }
435 
436 void EveHttpLogJSONBodyBase64(JsonBuilder *js, Flow *f, uint64_t tx_id)
437 {
438  HtpState *htp_state = (HtpState *)FlowGetAppState(f);
439  if (htp_state) {
440  htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, tx_id);
441  if (tx) {
442  HtpTxUserData *htud = (HtpTxUserData *)htp_tx_get_user_data(tx);
443  if (htud != NULL) {
444  BodyBase64Buffer(js, &htud->request_body, "http_request_body");
445  BodyBase64Buffer(js, &htud->response_body, "http_response_body");
446  }
447  }
448  }
449 }
450 
451 /* JSON format logging */
452 static void EveHttpLogJSON(JsonHttpLogThread *aft, JsonBuilder *js, htp_tx_t *tx, uint64_t tx_id)
453 {
454  LogHttpFileCtx *http_ctx = aft->httplog_ctx;
455  jb_open_object(js, "http");
456 
457  EveHttpLogJSONBasic(js, tx);
458  /* log custom fields if configured */
459  if (http_ctx->fields != 0)
460  EveHttpLogJSONCustom(http_ctx, js, tx);
461  if (http_ctx->flags & LOG_HTTP_EXTENDED)
462  EveHttpLogJSONExtended(js, tx);
463  if (http_ctx->flags & LOG_HTTP_REQ_HEADERS)
464  EveHttpLogJSONHeaders(js, LOG_HTTP_REQ_HEADERS, tx);
465  if (http_ctx->flags & LOG_HTTP_RES_HEADERS)
466  EveHttpLogJSONHeaders(js, LOG_HTTP_RES_HEADERS, tx);
467 
468  jb_close(js);
469 }
470 
471 static int JsonHttpLogger(ThreadVars *tv, void *thread_data, const Packet *p, Flow *f, void *alstate, void *txptr, uint64_t tx_id)
472 {
473  SCEnter();
474 
475  htp_tx_t *tx = txptr;
476  JsonHttpLogThread *jhl = (JsonHttpLogThread *)thread_data;
477 
478  JsonBuilder *js = CreateEveHeaderWithTxId(
479  p, LOG_DIR_FLOW, "http", NULL, tx_id, jhl->httplog_ctx->eve_ctx);
480  if (unlikely(js == NULL))
481  return TM_ECODE_OK;
482 
483  SCLogDebug("got a HTTP request and now logging !!");
484 
485  EveHttpLogJSON(jhl, js, tx, tx_id);
486  HttpXFFCfg *xff_cfg = jhl->httplog_ctx->xff_cfg != NULL ?
488 
489  /* xff header */
490  if ((xff_cfg != NULL) && !(xff_cfg->flags & XFF_DISABLED) && p->flow != NULL) {
491  int have_xff_ip = 0;
492  char buffer[XFF_MAXLEN];
493 
494  have_xff_ip = HttpXFFGetIPFromTx(p->flow, tx_id, xff_cfg, buffer, XFF_MAXLEN);
495 
496  if (have_xff_ip) {
497  if (xff_cfg->flags & XFF_EXTRADATA) {
498  jb_set_string(js, "xff", buffer);
499  }
500  else if (xff_cfg->flags & XFF_OVERWRITE) {
501  if (p->flowflags & FLOW_PKT_TOCLIENT) {
502  jb_set_string(js, "dest_ip", buffer);
503  } else {
504  jb_set_string(js, "src_ip", buffer);
505  }
506  }
507  }
508  }
509 
510  OutputJsonBuilderBuffer(js, jhl->ctx);
511  jb_free(js);
512 
514 }
515 
516 bool EveHttpAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
517 {
518  HtpState *htp_state = (HtpState *)FlowGetAppState(f);
519  if (htp_state) {
520  htp_tx_t *tx = AppLayerParserGetTx(IPPROTO_TCP, ALPROTO_HTTP1, htp_state, tx_id);
521 
522  if (tx) {
523  EveHttpLogJSONBasic(js, tx);
524  EveHttpLogJSONExtended(js, tx);
525  return true;
526  }
527  }
528 
529  return false;
530 }
531 
532 static void OutputHttpLogDeinitSub(OutputCtx *output_ctx)
533 {
534  LogHttpFileCtx *http_ctx = output_ctx->data;
535  if (http_ctx->xff_cfg) {
536  SCFree(http_ctx->xff_cfg);
537  }
538  SCFree(http_ctx);
539  SCFree(output_ctx);
540 }
541 
542 static OutputInitResult OutputHttpLogInitSub(ConfNode *conf, OutputCtx *parent_ctx)
543 {
544  OutputInitResult result = { NULL, false };
545  OutputJsonCtx *ojc = parent_ctx->data;
546 
547  LogHttpFileCtx *http_ctx = SCCalloc(1, sizeof(LogHttpFileCtx));
548  if (unlikely(http_ctx == NULL))
549  return result;
550  memset(http_ctx, 0x00, sizeof(*http_ctx));
551 
552  OutputCtx *output_ctx = SCCalloc(1, sizeof(OutputCtx));
553  if (unlikely(output_ctx == NULL)) {
554  SCFree(http_ctx);
555  return result;
556  }
557 
558  http_ctx->flags = LOG_HTTP_DEFAULT;
559  http_ctx->eve_ctx = ojc;
560 
561  if (conf) {
562  const char *extended = ConfNodeLookupChildValue(conf, "extended");
563 
564  if (extended != NULL) {
565  if (ConfValIsTrue(extended)) {
566  http_ctx->flags = LOG_HTTP_EXTENDED;
567  }
568  }
569 
570  ConfNode *custom;
571  if ((custom = ConfNodeLookupChild(conf, "custom")) != NULL) {
572  ConfNode *field;
573  TAILQ_FOREACH(field, &custom->head, next)
574  {
575  if (field != NULL)
576  {
577  HttpField f;
578  for (f = HTTP_FIELD_ACCEPT; f < HTTP_FIELD_SIZE; f++)
579  {
580  if ((strcmp(http_fields[f].config_field,
581  field->val) == 0) ||
582  (strcasecmp(http_fields[f].htp_field,
583  field->val) == 0))
584  {
585  http_ctx->fields |= (1ULL<<f);
586  break;
587  }
588  }
589  }
590  }
591  }
592  const char *all_headers = ConfNodeLookupChildValue(
593  conf, "dump-all-headers");
594  if (all_headers != NULL) {
595  if (strncmp(all_headers, "both", 4) == 0) {
596  http_ctx->flags |= LOG_HTTP_REQ_HEADERS;
597  http_ctx->flags |= LOG_HTTP_RES_HEADERS;
598  } else if (strncmp(all_headers, "request", 7) == 0) {
599  http_ctx->flags |= LOG_HTTP_REQ_HEADERS;
600  } else if (strncmp(all_headers, "response", 8) == 0) {
601  http_ctx->flags |= LOG_HTTP_RES_HEADERS;
602  }
603  }
604  }
605 
606  if (conf != NULL && ConfNodeLookupChild(conf, "xff") != NULL) {
607  http_ctx->xff_cfg = SCCalloc(1, sizeof(HttpXFFCfg));
608  if (http_ctx->xff_cfg != NULL) {
609  HttpXFFGetCfg(conf, http_ctx->xff_cfg);
610  }
611  } else if (ojc->xff_cfg) {
612  http_ctx->parent_xff_cfg = ojc->xff_cfg;
613  }
614 
615  output_ctx->data = http_ctx;
616  output_ctx->DeInit = OutputHttpLogDeinitSub;
617 
618  /* enable the logger for the app layer */
620 
621  result.ctx = output_ctx;
622  result.ok = true;
623  return result;
624 }
625 
626 static TmEcode JsonHttpLogThreadInit(ThreadVars *t, const void *initdata, void **data)
627 {
628  JsonHttpLogThread *aft = SCCalloc(1, sizeof(JsonHttpLogThread));
629  if (unlikely(aft == NULL))
630  return TM_ECODE_FAILED;
631 
632  if(initdata == NULL)
633  {
634  SCLogDebug("Error getting context for EveLogHTTP. \"initdata\" argument NULL");
635  goto error_exit;
636  }
637 
638  /* Use the Output Context (file pointer and mutex) */
639  aft->httplog_ctx = ((OutputCtx *)initdata)->data; //TODO
640 
641  aft->ctx = CreateEveThreadCtx(t, aft->httplog_ctx->eve_ctx);
642  if (!aft->ctx) {
643  goto error_exit;
644  }
645 
646  *data = (void *)aft;
647  return TM_ECODE_OK;
648 
649 error_exit:
650  SCFree(aft);
651  return TM_ECODE_FAILED;
652 }
653 
654 static TmEcode JsonHttpLogThreadDeinit(ThreadVars *t, void *data)
655 {
656  JsonHttpLogThread *aft = (JsonHttpLogThread *)data;
657  if (aft == NULL) {
658  return TM_ECODE_OK;
659  }
660 
661  FreeEveThreadCtx(aft->ctx);
662 
663  /* clear memory */
664  memset(aft, 0, sizeof(JsonHttpLogThread));
665 
666  SCFree(aft);
667  return TM_ECODE_OK;
668 }
669 
671 {
672  /* register as child of eve-log */
673  OutputRegisterTxSubModule(LOGGER_JSON_HTTP, "eve-log", "JsonHttpLog", "eve-log.http",
674  OutputHttpLogInitSub, ALPROTO_HTTP1, JsonHttpLogger, JsonHttpLogThreadInit,
675  JsonHttpLogThreadDeinit, NULL);
676 }
XFF_MAXLEN
#define XFF_MAXLEN
Definition: app-layer-htp-xff.h:39
util-byte.h
tm-threads.h
HTTP_FIELD_SIZE
@ HTTP_FIELD_SIZE
Definition: output-json-http.c:135
HTTP_FIELD_CONTENT_LOCATION
@ HTTP_FIELD_CONTENT_LOCATION
Definition: output-json-http.c:110
JsonHttpLogThread_
Definition: output-json-http.c:65
EveHttpLogJSONBodyPrintable
void EveHttpLogJSONBodyPrintable(JsonBuilder *js, Flow *f, uint64_t tx_id)
Definition: output-json-http.c:405
OutputJsonCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json.h:85
offset
uint64_t offset
Definition: util-streaming-buffer.h:0
XFF_EXTRADATA
#define XFF_EXTRADATA
Definition: app-layer-htp-xff.h:31
MAX_SIZE_HEADER_NAME
#define MAX_SIZE_HEADER_NAME
Definition: output-json-http.c:71
ConfNode_::val
char * val
Definition: conf.h:34
HtpBody_::sb
StreamingBuffer * sb
Definition: app-layer-htp.h:195
unlikely
#define unlikely(expr)
Definition: util-optimize.h:35
HTTP_FIELD_ALLOW
@ HTTP_FIELD_ALLOW
Definition: output-json-http.c:105
HTTP_FIELD_ACCEPT_RANGES
@ HTTP_FIELD_ACCEPT_RANGES
Definition: output-json-http.c:103
SCLogDebug
#define SCLogDebug(...)
Definition: util-debug.h:298
next
struct HtpBodyChunk_ * next
Definition: app-layer-htp.h:0
HTTP_FIELD_X_FLASH_VERSION
@ HTTP_FIELD_X_FLASH_VERSION
Definition: output-json-http.c:102
FreeEveThreadCtx
void FreeEveThreadCtx(OutputJsonThreadCtx *ctx)
Definition: output-json-common.c:73
HTTP_FIELD_REFERRER
@ HTTP_FIELD_REFERRER
Definition: output-json-http.c:121
StreamingBuffer_::buf
uint8_t * buf
Definition: util-streaming-buffer.h:98
MAX_SIZE_HEADER_VALUE
#define MAX_SIZE_HEADER_VALUE
Definition: output-json-http.c:72
threads.h
OutputJsonCtx_
Definition: output-json.h:81
Flow_
Flow data structure.
Definition: flow.h:353
LogHttpFileCtx
struct LogHttpFileCtx_ LogHttpFileCtx
OutputJsonBuilderBuffer
int OutputJsonBuilderBuffer(JsonBuilder *js, OutputJsonThreadCtx *ctx)
Definition: output-json.c:972
LOG_HTTP_ARRAY
#define LOG_HTTP_ARRAY
Definition: output-json-http.c:77
TAILQ_FOREACH
#define TAILQ_FOREACH(var, head, field)
Definition: queue.h:253
HTTP_FIELD_EXPIRES
@ HTTP_FIELD_EXPIRES
Definition: output-json-http.c:116
CreateEveThreadCtx
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
Definition: output-json-common.c:44
http_fields
struct @131 http_fields[]
HtpTxUserData_::request_body
HtpBody request_body
Definition: app-layer-htp.h:229
HTTP_FIELD_FROM
@ HTTP_FIELD_FROM
Definition: output-json-http.c:90
HTTP_FIELD_CONTENT_ENCODING
@ HTTP_FIELD_CONTENT_ENCODING
Definition: output-json-http.c:107
HTTP_FIELD_WWW_AUTHENTICATE
@ HTTP_FIELD_WWW_AUTHENTICATE
Definition: output-json-http.c:131
StreamingBufferGetData
int StreamingBufferGetData(const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t *stream_offset)
Definition: util-streaming-buffer.c:832
HTTP_FIELD_WARNING
@ HTTP_FIELD_WARNING
Definition: output-json-http.c:130
HTTP_FIELD_COOKIE
@ HTTP_FIELD_COOKIE
Definition: output-json-http.c:89
HTTP_FIELD_CONTENT_LENGTH
@ HTTP_FIELD_CONTENT_LENGTH
Definition: output-json-http.c:109
util-privs.h
LogHttpFileCtx_::xff_cfg
HttpXFFCfg * xff_cfg
Definition: output-json-http.c:60
Packet_::flowflags
uint8_t flowflags
Definition: decode.h:458
TM_ECODE_FAILED
@ TM_ECODE_FAILED
Definition: tm-threads-common.h:83
HTTP_FIELD_ETAG
@ HTTP_FIELD_ETAG
Definition: output-json-http.c:115
HTTP_FIELD_X_BLUECOAT_VIA
@ HTTP_FIELD_X_BLUECOAT_VIA
Definition: output-json-http.c:134
util-unittest.h
HTTP_FIELD_AGE
@ HTTP_FIELD_AGE
Definition: output-json-http.c:104
HTPParseContentRange
int HTPParseContentRange(bstr *rawvalue, HTTPContentRange *range)
Definition: app-layer-htp-file.c:164
EveHttpAddMetadata
bool EveHttpAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
Definition: output-json-http.c:516
HtpState_
Definition: app-layer-htp.h:247
JsonHttpLogThread_::httplog_ctx
LogHttpFileCtx * httplog_ctx
Definition: output-json-http.c:66
ConfValIsTrue
int ConfValIsTrue(const char *val)
Check if a value is true.
Definition: conf.c:565
FlowGetAppState
void * FlowGetAppState(const Flow *f)
Definition: flow.c:1125
HTTP_FIELD_CACHE_CONTROL
@ HTTP_FIELD_CACHE_CONTROL
Definition: output-json-http.c:88
OutputCtx_::data
void * data
Definition: tm-modules.h:81
config_field
const char * config_field
Definition: output-json-http.c:139
TM_ECODE_OK
@ TM_ECODE_OK
Definition: tm-threads-common.h:82
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:228
JsonHttpLogThread_::ctx
OutputJsonThreadCtx * ctx
Definition: output-json-http.c:68
OutputCtx_
Definition: tm-modules.h:78
app-layer-htp-xff.h
JsonHttpLogThread_::uri_cnt
uint32_t uri_cnt
Definition: output-json-http.c:67
app-layer-htp-file.h
OutputJsonThreadCtx_
Definition: output-json.h:89
HTTP_FIELD_RETRY_AFTER
@ HTTP_FIELD_RETRY_AFTER
Definition: output-json-http.c:123
HTTP_FIELD_UPGRADE
@ HTTP_FIELD_UPGRADE
Definition: output-json-http.c:128
HTTP_FIELD_CONTENT_RANGE
@ HTTP_FIELD_CONTENT_RANGE
Definition: output-json-http.c:112
HTTP_FIELD_ACCEPT
@ HTTP_FIELD_ACCEPT
Definition: output-json-http.c:82
HTTP_FIELD_PRAGMA
@ HTTP_FIELD_PRAGMA
Definition: output-json-http.c:93
HTTP_FIELD_ACCEPT_LANGUAGE
@ HTTP_FIELD_ACCEPT_LANGUAGE
Definition: output-json-http.c:85
HTTP_FIELD_LOCATION
@ HTTP_FIELD_LOCATION
Definition: output-json-http.c:119
HTTP_FIELD_DATE
@ HTTP_FIELD_DATE
Definition: output-json-http.c:114
app-layer-htp.h
LOG_HTTP_DEFAULT
#define LOG_HTTP_DEFAULT
Definition: output-json-http.c:74
HTTP_FIELD_ORIGIN
@ HTTP_FIELD_ORIGIN
Definition: output-json-http.c:92
util-debug.h
htp_field
const char * htp_field
Definition: output-json-http.c:140
HTTP_FIELD_ORG_SRC_IP
@ HTTP_FIELD_ORG_SRC_IP
Definition: output-json-http.c:133
OutputInitResult_::ctx
OutputCtx * ctx
Definition: output.h:49
HTTP_FIELD_LAST_MODIFIED
@ HTTP_FIELD_LAST_MODIFIED
Definition: output-json-http.c:117
HTTP_FIELD_AUTHORIZATION
@ HTTP_FIELD_AUTHORIZATION
Definition: output-json-http.c:87
output-json.h
LOG_HTTP_REQUEST
#define LOG_HTTP_REQUEST
Definition: output-json-http.c:76
AppLayerParserRegisterLogger
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Definition: app-layer-parser.c:484
util-print.h
HTTP_FIELD_RANGE
@ HTTP_FIELD_RANGE
Definition: output-json-http.c:95
SCEnter
#define SCEnter(...)
Definition: util-debug.h:300
detect.h
ThreadVars_
Per thread variable structure.
Definition: threadvars.h:58
pkt-var.h
HttpField
HttpField
Definition: output-json-http.c:81
HTTP_FIELD_LINK
@ HTTP_FIELD_LINK
Definition: output-json-http.c:118
util-time.h
OutputInitResult_::ok
bool ok
Definition: output.h:50
HTTP_FIELD_ACCEPT_ENCODING
@ HTTP_FIELD_ACCEPT_ENCODING
Definition: output-json-http.c:84
EveHttpLogJSONBodyBase64
void EveHttpLogJSONBodyBase64(JsonBuilder *js, Flow *f, uint64_t tx_id)
Definition: output-json-http.c:436
app-layer-parser.h
LOGGER_JSON_HTTP
@ LOGGER_JSON_HTTP
Definition: suricata-common.h:445
HTTP_FIELD_SERVER
@ HTTP_FIELD_SERVER
Definition: output-json-http.c:124
CreateEveHeaderWithTxId
JsonBuilder * CreateEveHeaderWithTxId(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx)
Definition: output-json.c:917
HTTP_FIELD_CONNECTION
@ HTTP_FIELD_CONNECTION
Definition: output-json-http.c:106
HTTP_FIELD_TE
@ HTTP_FIELD_TE
Definition: output-json-http.c:96
HTTP_FIELD_SET_COOKIE
@ HTTP_FIELD_SET_COOKIE
Definition: output-json-http.c:125
Packet_
Definition: decode.h:427
conf.h
HTTP_FIELD_TRAILER
@ HTTP_FIELD_TRAILER
Definition: output-json-http.c:126
XFF_OVERWRITE
#define XFF_OVERWRITE
Definition: app-layer-htp-xff.h:33
TmEcode
TmEcode
Definition: tm-threads-common.h:81
HttpXFFCfg_
Definition: app-layer-htp-xff.h:41
util-proto-name.h
FLOW_PKT_TOCLIENT
#define FLOW_PKT_TOCLIENT
Definition: flow.h:226
HtpTxUserData_::response_body
HtpBody response_body
Definition: app-layer-htp.h:230
AppLayerParserGetTx
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
Definition: app-layer-parser.c:1116
HTTP_FIELD_CONTENT_MD5
@ HTTP_FIELD_CONTENT_MD5
Definition: output-json-http.c:111
ConfNodeLookupChild
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
Definition: conf.c:814
HTTP_FIELD_DNT
@ HTTP_FIELD_DNT
Definition: output-json-http.c:99
OutputInitResult_
Definition: output.h:48
Packet_::flow
struct Flow_ * flow
Definition: decode.h:464
HtpBody_
Definition: app-layer-htp.h:191
suricata-common.h
OutputCtx_::DeInit
void(* DeInit)(struct OutputCtx_ *)
Definition: tm-modules.h:84
LOG_HTTP_REQ_HEADERS
#define LOG_HTTP_REQ_HEADERS
Definition: output-json-http.c:78
ALPROTO_HTTP1
@ ALPROTO_HTTP1
Definition: app-layer-protos.h:30
HTTP_FIELD_PROXY_AUTHORIZATION
@ HTTP_FIELD_PROXY_AUTHORIZATION
Definition: output-json-http.c:94
JsonHttpLogThread
struct JsonHttpLogThread_ JsonHttpLogThread
HTTP_FIELD_VARY
@ HTTP_FIELD_VARY
Definition: output-json-http.c:129
HtpTxUserData_
Definition: app-layer-htp.h:214
OutputRegisterTxSubModule
void OutputRegisterTxSubModule(LoggerId id, const char *parent_name, const char *name, const char *conf_name, OutputInitSubFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit, ThreadExitPrintStatsFunc ThreadExitPrintStats)
Definition: output.c:412
tv
ThreadVars * tv
Definition: fuzz_decodepcapfile.c:29
HTTP_FIELD_TRUE_CLIENT_IP
@ HTTP_FIELD_TRUE_CLIENT_IP
Definition: output-json-http.c:132
output-json-alert.h
threadvars.h
LOG_DIR_FLOW
@ LOG_DIR_FLOW
Definition: output-json.h:40
HTTP_FIELD_CONTENT_LANGUAGE
@ HTTP_FIELD_CONTENT_LANGUAGE
Definition: output-json-http.c:108
HttpXFFCfg_::flags
uint8_t flags
Definition: app-layer-htp-xff.h:42
SCFree
#define SCFree(p)
Definition: util-mem.h:61
ConfNode_
Definition: conf.h:32
util-logopenfile.h
LogHttpFileCtx_::fields
uint64_t fields
Definition: output-json-http.c:59
HTTP_FIELD_X_FORWARDED_PROTO
@ HTTP_FIELD_X_FORWARDED_PROTO
Definition: output-json-http.c:100
util-buffer.h
BytesToStringBuffer
void BytesToStringBuffer(const uint8_t *bytes, size_t nbytes, char *outstr, size_t outlen)
Turn byte array into string.
Definition: util-byte.c:85
HTTP_FIELD_MAX_FORWARDS
@ HTTP_FIELD_MAX_FORWARDS
Definition: output-json-http.c:91
LOG_HTTP_EXTENDED
#define LOG_HTTP_EXTENDED
Definition: output-json-http.c:75
HTTP_FIELD_TRANSFER_ENCODING
@ HTTP_FIELD_TRANSFER_ENCODING
Definition: output-json-http.c:127
JsonHttpLogRegister
void JsonHttpLogRegister(void)
Definition: output-json-http.c:670
HTTP_FIELD_ACCEPT_DATETIME
@ HTTP_FIELD_ACCEPT_DATETIME
Definition: output-json-http.c:86
HTTP_FIELD_VIA
@ HTTP_FIELD_VIA
Definition: output-json-http.c:97
HttpXFFGetCfg
void HttpXFFGetCfg(ConfNode *conf, HttpXFFCfg *result)
Function to return XFF configuration from a configuration node.
Definition: app-layer-htp-xff.c:202
LogHttpFileCtx_::eve_ctx
OutputJsonCtx * eve_ctx
Definition: output-json-http.c:62
HTTP_FIELD_ACCEPT_CHARSET
@ HTTP_FIELD_ACCEPT_CHARSET
Definition: output-json-http.c:83
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:113
HTTP_FIELD_REFRESH
@ HTTP_FIELD_REFRESH
Definition: output-json-http.c:122
HTTP_FIELD_PROXY_AUTHENTICATE
@ HTTP_FIELD_PROXY_AUTHENTICATE
Definition: output-json-http.c:120
HTTP_FIELD_CONTENT_TYPE
@ HTTP_FIELD_CONTENT_TYPE
Definition: output-json-http.c:113
output-json-http.h
LogHttpFileCtx_::flags
uint32_t flags
Definition: log-httplog.c:87
HTTP_FIELD_X_AUTHENTICATED_USER
@ HTTP_FIELD_X_AUTHENTICATED_USER
Definition: output-json-http.c:101
flags
uint32_t flags
Definition: output-json-http.c:141
LogHttpFileCtx_
Definition: log-httplog.c:85
SCCalloc
#define SCCalloc(nm, sz)
Definition: util-mem.h:53
SCReturnInt
#define SCReturnInt(x)
Definition: util-debug.h:304
XFF_DISABLED
#define XFF_DISABLED
Definition: app-layer-htp-xff.h:29
HTTP_FIELD_X_REQUESTED_WITH
@ HTTP_FIELD_X_REQUESTED_WITH
Definition: output-json-http.c:98
debug.h
LOG_HTTP_RES_HEADERS
#define LOG_HTTP_RES_HEADERS
Definition: output-json-http.c:79
output.h
app-layer.h
LogHttpFileCtx_::parent_xff_cfg
HttpXFFCfg * parent_xff_cfg
Definition: output-json-http.c:61
ConfNodeLookupChildValue
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.
Definition: conf.c:842