53 #define DEFAULT_LOG_FILENAME "http.log"
55 #define MODULE_NAME "LogHttpLog"
57 #define OUTPUT_BUFFER_SIZE 65535
61 static void LogHttpLogDeInitCtx(
OutputCtx *);
71 #define LOG_HTTP_CF_REQUEST_HOST 'h'
72 #define LOG_HTTP_CF_REQUEST_PROTOCOL 'H'
73 #define LOG_HTTP_CF_REQUEST_METHOD 'm'
74 #define LOG_HTTP_CF_REQUEST_URI 'u'
75 #define LOG_HTTP_CF_REQUEST_TIME 't'
76 #define LOG_HTTP_CF_REQUEST_HEADER 'i'
77 #define LOG_HTTP_CF_REQUEST_COOKIE 'C'
78 #define LOG_HTTP_CF_REQUEST_LEN 'b'
79 #define LOG_HTTP_CF_RESPONSE_STATUS 's'
80 #define LOG_HTTP_CF_RESPONSE_HEADER 'o'
81 #define LOG_HTTP_CF_RESPONSE_LEN 'B'
90 #define LOG_HTTP_DEFAULT 0
91 #define LOG_HTTP_EXTENDED 1
92 #define LOG_HTTP_CUSTOM 2
103 static uint32_t GetCookieValue(uint8_t *rawcookies, uint32_t rawcookies_len,
char *cookiename,
104 uint8_t **cookievalue)
106 uint8_t *p = rawcookies;
109 while (p < rawcookies + rawcookies_len) {
110 if (cv == NULL && *p ==
'=') {
112 }
else if (cv != NULL && (*p ==
';' || p == rawcookies + rawcookies_len - 1) ) {
115 if (strlen(cookiename) == (
unsigned int) (cv-cn-1) &&
116 strncmp(cookiename, (
char *) cn, cv-cn-1) == 0) {
118 return (uint32_t) (p-cv);
137 uint8_t *cvalue = NULL;
138 uint32_t cvalue_len = 0;
140 htp_header_t *h_request_hdr;
141 htp_header_t *h_response_hdr;
143 for (i = 0; i < httplog_ctx->
cf->
cf_n; i++) {
144 h_request_hdr = NULL;
145 h_response_hdr = NULL;
162 snprintf(buf,
sizeof(buf),
"%06u", (
unsigned int)
SCTIME_USECS(
ts));
164 (uint8_t *)buf,
MIN(strlen(buf), 6));
169 aft->
buffer->
size, (uint8_t *)srcip,strlen(srcip));
174 aft->
buffer->
size, (uint8_t *)dstip,strlen(dstip));
186 if (tx->request_method != NULL) {
188 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_method),
189 bstr_len(tx->request_method));
196 if (tx->request_uri != NULL) {
198 if (datalen == 0 || datalen > bstr_len(tx->request_uri)) {
199 datalen = bstr_len(tx->request_uri);
202 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_uri),
210 if (tx->request_hostname != NULL)
213 if (datalen == 0 || datalen > bstr_len(tx->request_hostname)) {
214 datalen = bstr_len(tx->request_hostname);
217 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_hostname),
225 if (tx->request_protocol != NULL) {
227 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_protocol),
228 bstr_len(tx->request_protocol));
235 if (tx->request_headers != NULL) {
236 h_request_hdr = htp_table_get_c(tx->request_headers, node->
data);
238 if (h_request_hdr != NULL) {
240 if (datalen == 0 || datalen > bstr_len(h_request_hdr->value)) {
241 datalen = bstr_len(h_request_hdr->value);
244 aft->
buffer->
size, (uint8_t *)bstr_ptr(h_request_hdr->value),
252 if (tx->request_headers != NULL) {
253 h_request_hdr = htp_table_get_c(tx->request_headers,
"Cookie");
254 if (h_request_hdr != NULL) {
255 cvalue_len = GetCookieValue((uint8_t *) bstr_ptr(h_request_hdr->value),
256 bstr_len(h_request_hdr->value), (
char *) node->
data,
260 if (cvalue_len > 0 && cvalue != NULL) {
262 if (datalen == 0 || datalen > cvalue_len) {
263 datalen = cvalue_len;
277 if (tx->response_status != NULL) {
279 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->response_status),
280 bstr_len(tx->response_status));
287 if (tx->response_headers != NULL) {
288 h_response_hdr = htp_table_get_c(tx->response_headers,
291 if (h_response_hdr != NULL) {
293 if (datalen == 0 || datalen > bstr_len(h_response_hdr->value)) {
294 datalen = bstr_len(h_response_hdr->value);
297 aft->
buffer->
size, (uint8_t *)bstr_ptr(h_response_hdr->value),
310 SCLogDebug(
"No matching parameter %%%c for custom http log.", node->
type);
322 htp_header_t *h_referer = NULL;
323 if (tx->request_headers != NULL) {
324 h_referer = htp_table_get_c(tx->request_headers,
"referer");
326 if (h_referer != NULL) {
328 (uint8_t *)bstr_ptr(h_referer->value),
329 bstr_len(h_referer->value));
337 if (tx->request_method != NULL) {
339 (uint8_t *)bstr_ptr(tx->request_method),
340 bstr_len(tx->request_method));
345 if (tx->request_protocol != NULL) {
347 (uint8_t *)bstr_ptr(tx->request_protocol),
348 bstr_len(tx->request_protocol));
355 if (tx->response_status != NULL) {
357 (uint8_t *)bstr_ptr(tx->response_status),
358 bstr_len(tx->response_status));
360 if ((tx->response_status_number > 300) && ((tx->response_status_number) < 303)) {
361 htp_header_t *h_location = htp_table_get_c(tx->response_headers,
"location");
362 if (h_location != NULL) {
366 (uint8_t *)bstr_ptr(h_location->value),
367 bstr_len(h_location->value));
390 char srcip[46], dstip[46];
424 SCLogDebug(
"got a HTTP request and now logging !!");
430 LogHttpLogCustom(aft, tx, p->
ts, srcip, sp, dstip, dp);
436 if (tx->request_hostname != NULL) {
438 (uint8_t *)bstr_ptr(tx->request_hostname),
439 bstr_len(tx->request_hostname));
446 if (tx->request_uri != NULL) {
448 (uint8_t *)bstr_ptr(tx->request_uri),
449 bstr_len(tx->request_uri));
454 htp_header_t *h_user_agent = NULL;
455 if (tx->request_headers != NULL) {
456 h_user_agent = htp_table_get_c(tx->request_headers,
"user-agent");
458 if (h_user_agent != NULL) {
460 (uint8_t *)bstr_ptr(h_user_agent->value),
461 bstr_len(h_user_agent->value));
466 LogHttpLogExtended(aft, tx);
472 "%s:%" PRIu16
" -> %s:%" PRIu16
"\n",
473 srcip, sp, dstip, dp);
496 r = LogHttpLogIPWrapper(
tv, thread_data, p, f, (
HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET);
498 r = LogHttpLogIPWrapper(
tv, thread_data, p, f, (
HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET6);
512 SCLogDebug(
"Error getting context for LogHTTPLog. \"initdata\" argument NULL");
518 if (aft->
buffer == NULL) {
553 if(file_ctx == NULL) {
564 if (
unlikely(httplog_ctx == NULL)) {
576 if (custom != NULL && customformat != NULL &&
ConfValIsTrue(custom)) {
579 if (!httplog_ctx->
cf) {
590 if (extended == NULL) {
604 output_ctx->
data = httplog_ctx;
605 output_ctx->
DeInit = LogHttpLogDeInitCtx;
612 result.
ctx = output_ctx;
617 SCLogError(
"Syntax error in custom http log format string.");
626 static void LogHttpLogDeInitCtx(
OutputCtx *output_ctx)