71 #define MAX_SIZE_HEADER_NAME 256
72 #define MAX_SIZE_HEADER_VALUE 2048
74 #define LOG_HTTP_DEFAULT 0
75 #define LOG_HTTP_EXTENDED 1
76 #define LOG_HTTP_REQUEST 2
77 #define LOG_HTTP_ARRAY 4
78 #define LOG_HTTP_REQ_HEADERS 8
79 #define LOG_HTTP_RES_HEADERS 16
164 {
"accept_range",
"accept-range", 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 },
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 },
198 static void EveHttpLogJSONBasic(JsonBuilder *js, htp_tx_t *tx)
225 if (h_user_agent != NULL) {
226 jb_set_string_from_bytes(js,
"http_user_agent", bstr_ptr(h_user_agent->value),
227 (uint32_t)bstr_len(h_user_agent->value));
231 htp_header_t *h_x_forwarded_for =
233 if (h_x_forwarded_for != NULL) {
234 jb_set_string_from_bytes(js,
"xff", bstr_ptr(h_x_forwarded_for->value),
235 (uint32_t)bstr_len(h_x_forwarded_for->value));
242 if (h_content_type != NULL) {
243 const size_t size = bstr_len(h_content_type->value) * 2 + 1;
245 BytesToStringBuffer(bstr_ptr(h_content_type->value), bstr_len(h_content_type->value),
string, size);
246 char *p = strchr(
string,
';');
249 jb_set_string(js,
"http_content_type",
string);
251 htp_header_t *h_content_range =
253 if (h_content_range != NULL) {
254 jb_open_object(js,
"content_range");
255 jb_set_string_from_bytes(js,
"raw", bstr_ptr(h_content_range->value),
256 (uint32_t)bstr_len(h_content_range->value));
257 HTTPContentRange crparsed;
259 if (crparsed.start >= 0)
260 jb_set_uint(js,
"start", crparsed.start);
261 if (crparsed.end >= 0)
262 jb_set_uint(js,
"end", crparsed.end);
263 if (crparsed.size >= 0)
264 jb_set_uint(js,
"size", crparsed.size);
271 static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
274 htp_header_t *h_referer = NULL;
278 if (h_referer != NULL) {
279 jb_set_string_from_bytes(
280 js,
"http_refer", bstr_ptr(h_referer->value), (uint32_t)bstr_len(h_referer->value));
300 jb_set_uint(js,
"status", (uint32_t)resp);
307 if (h_location != NULL) {
308 jb_set_string_from_bytes(
309 js,
"redirect", bstr_ptr(h_location->value), (uint32_t)bstr_len(h_location->value));
316 static void EveHttpLogJSONHeaders(
317 JsonBuilder *js, uint32_t direction, htp_tx_t *tx,
LogHttpFileCtx *http_ctx)
323 size_t n = htp_table_size(headers);
324 JsonBuilderMark mark = { 0, 0, 0 };
325 jb_get_mark(js, &mark);
326 bool array_empty =
true;
328 for (
size_t i = 0; i < n; i++) {
329 htp_header_t *h = htp_table_get_index(headers, i, NULL);
330 if ((http_ctx->
flags & direction) == 0 && http_ctx->
fields != 0) {
333 if ((http_ctx->
fields & (1ULL << f)) != 0) {
339 if (bstr_cmp_c_nocase(h->name,
http_fields[f].htp_field) == 0) {
354 memcpy(
name, bstr_ptr(h->name), size_name);
355 name[size_name] =
'\0';
356 jb_set_string(js,
"name",
name);
359 memcpy(value, bstr_ptr(h->value), size_value);
360 value[size_value] =
'\0';
361 jb_set_string(js,
"value", value);
365 jb_restore_mark(js, &mark);
372 static void BodyPrintableBuffer(JsonBuilder *js,
HtpBody *body,
const char *key)
376 const uint8_t *body_data;
377 uint32_t body_data_len;
378 uint64_t body_offset;
381 &body_data_len, &body_offset) == 0) {
385 uint8_t printable_buf[body_data_len + 1];
388 jb_set_string(js, key, (
char *)printable_buf);
401 BodyPrintableBuffer(js, &htud->
request_body,
"http_request_body_printable");
402 BodyPrintableBuffer(js, &htud->
response_body,
"http_response_body_printable");
408 static void BodyBase64Buffer(JsonBuilder *js,
HtpBody *body,
const char *key)
411 const uint8_t *body_data;
412 uint32_t body_data_len;
413 uint64_t body_offset;
416 &body_data_len, &body_offset) == 0) {
420 jb_set_base64(js, key, body_data, body_data_len);
432 BodyBase64Buffer(js, &htud->
request_body,
"http_request_body");
433 BodyBase64Buffer(js, &htud->
response_body,
"http_response_body");
440 static void EveHttpLogJSON(
JsonHttpLogThread *aft, JsonBuilder *js, htp_tx_t *tx, uint64_t tx_id)
443 jb_open_object(js,
"http");
445 EveHttpLogJSONBasic(js, tx);
447 EveHttpLogJSONExtended(js, tx);
456 static int JsonHttpLogger(
ThreadVars *
tv,
void *thread_data,
const Packet *p,
Flow *f,
void *alstate,
void *txptr, uint64_t tx_id)
460 htp_tx_t *tx = txptr;
468 SCLogDebug(
"got a HTTP request and now logging !!");
470 EveHttpLogJSON(jhl, js, tx, tx_id);
483 jb_set_string(js,
"xff", buffer);
487 jb_set_string(js,
"dest_ip", buffer);
489 jb_set_string(js,
"src_ip", buffer);
508 EveHttpLogJSONBasic(js, tx);
509 EveHttpLogJSONExtended(js, tx);
517 static void OutputHttpLogDeinitSub(
OutputCtx *output_ctx)
535 memset(http_ctx, 0x00,
sizeof(*http_ctx));
549 if (extended != NULL) {
556 if (all_headers != NULL) {
557 if (strncmp(all_headers,
"both", 4) == 0) {
560 }
else if (strncmp(all_headers,
"request", 7) == 0) {
562 }
else if (strncmp(all_headers,
"response", 8) == 0) {
570 SCLogWarning(
"No need for custom as dump-all-headers is already present");
578 http_ctx->
fields |= (1ULL << f);
588 if (http_ctx->
xff_cfg != NULL) {
595 output_ctx->
data = http_ctx;
596 output_ctx->
DeInit = OutputHttpLogDeinitSub;
601 result.
ctx = output_ctx;
606 static TmEcode JsonHttpLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
614 SCLogDebug(
"Error getting context for EveLogHTTP. \"initdata\" argument NULL");
654 OutputHttpLogInitSub,
ALPROTO_HTTP1, JsonHttpLogger, JsonHttpLogThreadInit,
655 JsonHttpLogThreadDeinit);