Go to the documentation of this file.
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)
224 if (h_user_agent != NULL) {
231 if (h_x_forwarded_for != NULL) {
240 if (h_content_type != NULL) {
245 char *p = strchr(
string,
';');
248 jb_set_string(js,
"http_content_type",
string);
251 if (h_content_range != NULL) {
252 jb_open_object(js,
"content_range");
255 HTTPContentRange crparsed;
257 if (crparsed.start >= 0)
258 jb_set_uint(js,
"start", crparsed.start);
259 if (crparsed.end >= 0)
260 jb_set_uint(js,
"end", crparsed.end);
261 if (crparsed.size >= 0)
262 jb_set_uint(js,
"size", crparsed.size);
269 static void EveHttpLogJSONExtended(JsonBuilder *js, htp_tx_t *tx)
272 const htp_header_t *h_referer = NULL;
276 if (h_referer != NULL) {
296 jb_set_uint(js,
"status", (uint32_t)resp);
303 if (h_location != NULL) {
312 static void EveHttpLogJSONHeaders(
313 JsonBuilder *js, uint32_t direction, htp_tx_t *tx,
LogHttpFileCtx *http_ctx)
320 JsonBuilderMark mark = { 0, 0, 0 };
321 jb_get_mark(js, &mark);
322 bool array_empty =
true;
324 for (
size_t i = 0; i < n; i++) {
326 if ((http_ctx->
flags & direction) == 0 && http_ctx->
fields != 0) {
329 if ((http_ctx->
fields & (1ULL << f)) != 0) {
352 name[size_name] =
'\0';
353 jb_set_string(js,
"name",
name);
358 value[size_value] =
'\0';
359 jb_set_string(js,
"value", value);
363 jb_restore_mark(js, &mark);
370 static void BodyPrintableBuffer(JsonBuilder *js,
HtpBody *body,
const char *key)
374 const uint8_t *body_data;
375 uint32_t body_data_len;
376 uint64_t body_offset;
379 &body_data_len, &body_offset) == 0) {
383 uint8_t printable_buf[body_data_len + 1];
386 jb_set_string(js, key, (
char *)printable_buf);
399 BodyPrintableBuffer(js, &htud->
request_body,
"http_request_body_printable");
400 BodyPrintableBuffer(js, &htud->
response_body,
"http_response_body_printable");
406 static void BodyBase64Buffer(JsonBuilder *js,
HtpBody *body,
const char *key)
409 const uint8_t *body_data;
410 uint32_t body_data_len;
411 uint64_t body_offset;
414 &body_data_len, &body_offset) == 0) {
418 jb_set_base64(js, key, body_data, body_data_len);
430 BodyBase64Buffer(js, &htud->
request_body,
"http_request_body");
431 BodyBase64Buffer(js, &htud->
response_body,
"http_response_body");
438 static void EveHttpLogJSON(
JsonHttpLogThread *aft, JsonBuilder *js, htp_tx_t *tx, uint64_t tx_id)
441 jb_open_object(js,
"http");
443 EveHttpLogJSONBasic(js, tx);
445 EveHttpLogJSONExtended(js, tx);
454 static int JsonHttpLogger(
ThreadVars *
tv,
void *thread_data,
const Packet *p,
Flow *f,
void *alstate,
void *txptr, uint64_t tx_id)
458 htp_tx_t *tx = txptr;
466 SCLogDebug(
"got a HTTP request and now logging !!");
468 EveHttpLogJSON(jhl, js, tx, tx_id);
481 jb_set_string(js,
"xff", buffer);
485 jb_set_string(js,
"dest_ip", buffer);
487 jb_set_string(js,
"src_ip", buffer);
506 EveHttpLogJSONBasic(js, tx);
507 EveHttpLogJSONExtended(js, tx);
515 static void OutputHttpLogDeinitSub(
OutputCtx *output_ctx)
533 memset(http_ctx, 0x00,
sizeof(*http_ctx));
547 if (extended != NULL) {
554 if (all_headers != NULL) {
555 if (strncmp(all_headers,
"both", 4) == 0) {
558 }
else if (strncmp(all_headers,
"request", 7) == 0) {
560 }
else if (strncmp(all_headers,
"response", 8) == 0) {
568 SCLogWarning(
"No need for custom as dump-all-headers is already present");
576 http_ctx->
fields |= (1ULL << f);
586 if (http_ctx->
xff_cfg != NULL) {
593 output_ctx->
data = http_ctx;
594 output_ctx->
DeInit = OutputHttpLogDeinitSub;
599 result.
ctx = output_ctx;
604 static TmEcode JsonHttpLogThreadInit(
ThreadVars *t,
const void *initdata,
void **data)
612 SCLogDebug(
"Error getting context for EveLogHTTP. \"initdata\" argument NULL");
652 OutputHttpLogInitSub,
ALPROTO_HTTP1, JsonHttpLogger, JsonHttpLogThreadInit,
653 JsonHttpLogThreadDeinit);
#define htp_header_value_len(h)
@ HTTP_FIELD_CONTENT_LOCATION
void EveHttpLogJSONBodyPrintable(JsonBuilder *js, Flow *f, uint64_t tx_id)
#define htp_tx_request_uri(tx)
#define MAX_SIZE_HEADER_NAME
@ HTTP_FIELD_ACCEPT_RANGES
struct HtpBodyChunk_ * next
@ HTTP_FIELD_X_FLASH_VERSION
#define htp_headers_get_index(headers, index)
void FreeEveThreadCtx(OutputJsonThreadCtx *ctx)
#define MAX_SIZE_HEADER_VALUE
void OutputJsonBuilderBuffer(ThreadVars *tv, const Packet *p, Flow *f, JsonBuilder *js, OutputJsonThreadCtx *ctx)
struct LogHttpFileCtx_ LogHttpFileCtx
#define htp_tx_request_protocol(tx)
#define TAILQ_FOREACH(var, head, field)
#define htp_tx_response_headers(tx)
#define htp_tx_response_header(tx, header)
OutputJsonThreadCtx * CreateEveThreadCtx(ThreadVars *t, OutputJsonCtx *ctx)
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)
@ HTTP_FIELD_CONTENT_ENCODING
@ HTTP_FIELD_WWW_AUTHENTICATE
int StreamingBufferGetData(const StreamingBuffer *sb, const uint8_t **data, uint32_t *data_len, uint64_t *stream_offset)
@ HTTP_FIELD_CONTENT_LENGTH
#define htp_tx_request_method(tx)
#define htp_tx_response_status(tx)
@ HTTP_FIELD_X_BLUECOAT_VIA
bool EveHttpAddMetadata(const Flow *f, uint64_t tx_id, JsonBuilder *js)
LogHttpFileCtx * httplog_ctx
int ConfValIsTrue(const char *val)
Check if a value is true.
#define htp_headers_size(headers)
@ HTTP_FIELD_CACHE_CONTROL
#define htp_header_value(h)
const char * config_field
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)
OutputJsonThreadCtx * ctx
@ HTTP_FIELD_CONTENT_RANGE
@ HTTP_FIELD_ACCEPT_LANGUAGE
#define htp_tx_request_headers(tx)
@ HTTP_FIELD_LAST_MODIFIED
@ HTTP_FIELD_AUTHORIZATION
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
#define htp_header_name(h)
Per thread variable structure.
#define SCLogWarning(...)
Macro used to log WARNING messages.
@ HTTP_FIELD_ACCEPT_ENCODING
void EveHttpLogJSONBodyBase64(JsonBuilder *js, Flow *f, uint64_t tx_id)
JsonBuilder * CreateEveHeaderWithTxId(const Packet *p, enum OutputJsonLogDirection dir, const char *event_type, JsonAddrInfo *addr, uint64_t tx_id, OutputJsonCtx *eve_ctx)
#define htp_tx_request_hostname(tx)
struct @129 http_fields[]
#define htp_header_value_ptr(h)
#define FLOW_PKT_TOCLIENT
void * AppLayerParserGetTx(uint8_t ipproto, AppProto alproto, void *alstate, uint64_t tx_id)
#define htp_header_name_len(h)
ConfNode * ConfNodeLookupChild(const ConfNode *node, const char *name)
Lookup a child configuration node by name.
void(* DeInit)(struct OutputCtx_ *)
#define LOG_HTTP_REQ_HEADERS
#define htp_tx_response_message_len(tx)
@ HTTP_FIELD_PROXY_AUTHORIZATION
struct JsonHttpLogThread_ JsonHttpLogThread
#define htp_tx_request_port_number(tx)
@ HTTP_FIELD_TRUE_CLIENT_IP
int HTPParseContentRange(const bstr *rawvalue, HTTPContentRange *range)
@ HTTP_FIELD_CONTENT_LANGUAGE
@ HTTP_FIELD_X_FORWARDED_PROTO
void BytesToStringBuffer(const uint8_t *bytes, size_t nbytes, char *outstr, size_t outlen)
Turn byte array into string.
@ HTTP_FIELD_MAX_FORWARDS
#define LOG_HTTP_EXTENDED
@ HTTP_FIELD_TRANSFER_ENCODING
void JsonHttpLogRegister(void)
@ HTTP_FIELD_ACCEPT_DATETIME
void HttpXFFGetCfg(ConfNode *conf, HttpXFFCfg *result)
Function to return XFF configuration from a configuration node.
@ HTTP_FIELD_ACCEPT_CHARSET
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.
#define htp_tx_response_status_number(tx)
#define htp_header_name_ptr(h)
@ HTTP_FIELD_PROXY_AUTHENTICATE
@ HTTP_FIELD_CONTENT_TYPE
@ HTTP_FIELD_X_AUTHENTICATED_USER
StreamingBufferRegion region
@ HTTP_FIELD_X_REQUESTED_WITH
#define LOG_HTTP_RES_HEADERS
#define htp_tx_request_header(tx, header)
HttpXFFCfg * parent_xff_cfg
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.