70 #define MAX_SIZE_HEADER_NAME 256
71 #define MAX_SIZE_HEADER_VALUE 2048
73 #define LOG_HTTP_DEFAULT 0
74 #define LOG_HTTP_EXTENDED 1
75 #define LOG_HTTP_REQUEST 2
76 #define LOG_HTTP_ARRAY 4
77 #define LOG_HTTP_REQ_HEADERS 8
78 #define LOG_HTTP_RES_HEADERS 16
163 {
"accept_range",
"accept-range", 0 },
165 {
"allow",
"allow", 0 },
166 {
"connection",
"connection", 0 },
167 {
"content_encoding",
"content-encoding", 0 },
168 {
"content_language",
"content-language", 0 },
169 {
"content_length",
"content-length", 0 },
170 {
"content_location",
"content-location", 0 },
171 {
"content_md5",
"content-md5", 0 },
172 {
"content_range",
"content-range", 0 },
173 {
"content_type",
"content-type", 0 },
174 {
"date",
"date", 0 },
175 {
"etag",
"etags", 0 },
176 {
"expires",
"expires" , 0 },
177 {
"last_modified",
"last-modified", 0 },
178 {
"link",
"link", 0 },
179 {
"location",
"location", 0 },
180 {
"proxy_authenticate",
"proxy-authenticate", 0 },
182 {
"refresh",
"refresh", 0 },
183 {
"retry_after",
"retry-after", 0 },
184 {
"server",
"server", 0 },
185 {
"set_cookie",
"set-cookie", 0 },
186 {
"trailer",
"trailer", 0 },
187 {
"transfer_encoding",
"transfer-encoding", 0 },
188 {
"upgrade",
"upgrade", 0 },
189 {
"vary",
"vary", 0 },
190 {
"warning",
"warning", 0 },
191 {
"www_authenticate",
"www-authenticate", 0 },
197 static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
200 if (tx->request_hostname != NULL) {
201 jb_set_string_from_bytes(
202 js,
"hostname", bstr_ptr(tx->request_hostname), bstr_len(tx->request_hostname));
211 if (tx->request_port_number >= 0) {
212 jb_set_uint(js,
"http_port", tx->request_port_number);
216 if (tx->request_uri != NULL) {
217 jb_set_string_from_bytes(js,
"url", bstr_ptr(tx->request_uri), bstr_len(tx->request_uri));
220 if (tx->request_headers != NULL) {
222 htp_header_t *h_user_agent = htp_table_get_c(tx->request_headers,
"user-agent");
223 if (h_user_agent != NULL) {
224 jb_set_string_from_bytes(js,
"http_user_agent", bstr_ptr(h_user_agent->value),
225 bstr_len(h_user_agent->value));
229 htp_header_t *h_x_forwarded_for = htp_table_get_c(tx->request_headers,
"x-forwarded-for");
230 if (h_x_forwarded_for != NULL) {
231 jb_set_string_from_bytes(js,
"xff", bstr_ptr(h_x_forwarded_for->value),
232 bstr_len(h_x_forwarded_for->value));
237 if (tx->response_headers != NULL) {
238 htp_header_t *h_content_type = htp_table_get_c(tx->response_headers,
"content-type");
239 if (h_content_type != NULL) {
240 const size_t size = bstr_len(h_content_type->value) * 2 + 1;
242 BytesToStringBuffer(bstr_ptr(h_content_type->value), bstr_len(h_content_type->value),
string, size);
243 char *p = strchr(
string,
';');
246 jb_set_string(js,
"http_content_type",
string);
248 htp_header_t *h_content_range = htp_table_get_c(tx->response_headers,
"content-range");
249 if (h_content_range != NULL) {
250 jb_open_object(js,
"content_range");
251 jb_set_string_from_bytes(
252 js,
"raw", bstr_ptr(h_content_range->value), bstr_len(h_content_range->value));
253 HTTPContentRange crparsed;
255 if (crparsed.start >= 0)
256 jb_set_uint(js,
"start", crparsed.start);
257 if (crparsed.end >= 0)
258 jb_set_uint(js,
"end", crparsed.end);
259 if (crparsed.size >= 0)
260 jb_set_uint(js,
"size", crparsed.size);
267 static void EveHttpLogJSONCustom(
LogHttpFileCtx *http_ctx, JsonBuilder *js, htp_tx_t *tx)
274 if ((http_ctx->
fields & (1ULL<<f)) != 0)
282 htp_header_t *h_field = NULL;
285 if (tx->request_headers != NULL) {
286 h_field = htp_table_get_c(tx->request_headers,
290 if (tx->response_headers != NULL) {
291 h_field = htp_table_get_c(tx->response_headers,
295 if (h_field != NULL) {
296 c = bstr_util_strdup_to_c(h_field->value);
307 static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
310 htp_header_t *h_referer = NULL;
311 if (tx->request_headers != NULL) {
312 h_referer = htp_table_get_c(tx->request_headers,
"referer");
314 if (h_referer != NULL) {
315 jb_set_string_from_bytes(
316 js,
"http_refer", bstr_ptr(h_referer->value), bstr_len(h_referer->value));
320 if (tx->request_method != NULL) {
321 jb_set_string_from_bytes(
322 js,
"http_method", bstr_ptr(tx->request_method), bstr_len(tx->request_method));
326 if (tx->request_protocol != NULL) {
327 jb_set_string_from_bytes(
328 js,
"protocol", bstr_ptr(tx->request_protocol), bstr_len(tx->request_protocol));
332 if (tx->response_status != NULL) {
333 const size_t status_size = bstr_len(tx->response_status) * 2 + 1;
334 char status_string[status_size];
336 status_string, status_size);
337 unsigned int val = strtoul(status_string, NULL, 10);
338 jb_set_uint(js,
"status", val);
340 htp_header_t *h_location = htp_table_get_c(tx->response_headers,
"location");
341 if (h_location != NULL) {
342 jb_set_string_from_bytes(
343 js,
"redirect", bstr_ptr(h_location->value), bstr_len(h_location->value));
348 jb_set_uint(js,
"length", tx->response_message_len);
351 static void EveHttpLogJSONHeaders(JsonBuilder *js, uint32_t direction, htp_tx_t *tx)
354 tx->request_headers : tx->response_headers;
357 size_t n = htp_table_size(headers);
359 for (
size_t i = 0; i < n; i++) {
360 htp_header_t * h = htp_table_get_index(headers, i, NULL);
367 memcpy(name, bstr_ptr(h->name), size_name);
368 name[size_name] =
'\0';
369 jb_set_string(js,
"name", name);
372 memcpy(value, bstr_ptr(h->value), size_value);
373 value[size_value] =
'\0';
374 jb_set_string(js,
"value", value);
381 static void BodyPrintableBuffer(JsonBuilder *js,
HtpBody *body,
const char *key)
385 const uint8_t *body_data;
386 uint32_t body_data_len;
387 uint64_t body_offset;
390 &body_data_len, &body_offset) == 0) {
394 uint8_t printable_buf[body_data_len + 1];
396 sizeof(printable_buf),
397 body_data, body_data_len);
399 jb_set_string(js, key, (
char *)printable_buf);
412 BodyPrintableBuffer(js, &htud->
request_body,
"http_request_body_printable");
413 BodyPrintableBuffer(js, &htud->
response_body,
"http_response_body_printable");
419 static void BodyBase64Buffer(JsonBuilder *js,
HtpBody *body,
const char *key)
422 const uint8_t *body_data;
423 uint32_t body_data_len;
424 uint64_t body_offset;
427 &body_data_len, &body_offset) == 0) {
431 jb_set_base64(js, key, body_data, body_data_len);
443 BodyBase64Buffer(js, &htud->
request_body,
"http_request_body");
444 BodyBase64Buffer(js, &htud->
response_body,
"http_response_body");
451 static void EveHttpLogJSON(
JsonHttpLogThread *aft, JsonBuilder *js, htp_tx_t *tx, uint64_t tx_id)
454 jb_open_object(js,
"http");
456 EveHttpLogJSONBasic(js, tx);
458 if (http_ctx->
fields != 0)
459 EveHttpLogJSONCustom(http_ctx, js, tx);
461 EveHttpLogJSONExtended(js, tx);
470 static int JsonHttpLogger(
ThreadVars *
tv,
void *thread_data,
const Packet *p,
Flow *f,
void *alstate,
void *txptr, uint64_t tx_id)
474 htp_tx_t *tx = txptr;
482 SCLogDebug(
"got a HTTP request and now logging !!");
484 EveHttpLogJSON(jhl, js, tx, tx_id);
497 jb_set_string(js,
"xff", buffer);
501 jb_set_string(js,
"dest_ip", buffer);
503 jb_set_string(js,
"src_ip", buffer);
522 EveHttpLogJSONBasic(js, tx);
523 EveHttpLogJSONExtended(js, tx);
531 static void OutputHttpLogDeinitSub(
OutputCtx *output_ctx)
549 memset(http_ctx, 0x00,
sizeof(*http_ctx));
563 if (extended != NULL) {
577 http_ctx->
fields |= (1ULL << f);
584 conf,
"dump-all-headers");
585 if (all_headers != NULL) {
586 if (strncmp(all_headers,
"both", 4) == 0) {
589 }
else if (strncmp(all_headers,
"request", 7) == 0) {
591 }
else if (strncmp(all_headers,
"response", 8) == 0) {
599 if (http_ctx->
xff_cfg != NULL) {
606 output_ctx->
data = http_ctx;
607 output_ctx->
DeInit = OutputHttpLogDeinitSub;
612 result.
ctx = output_ctx;
617 static TmEcode JsonHttpLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
625 SCLogDebug(
"Error getting context for EveLogHTTP. \"initdata\" argument NULL");
665 OutputHttpLogInitSub,
ALPROTO_HTTP1, JsonHttpLogger, JsonHttpLogThreadInit,
666 JsonHttpLogThreadDeinit, NULL);