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_HEADER 'i'
76 #define LOG_HTTP_CF_REQUEST_COOKIE 'C'
77 #define LOG_HTTP_CF_REQUEST_LEN 'b'
78 #define LOG_HTTP_CF_RESPONSE_STATUS 's'
79 #define LOG_HTTP_CF_RESPONSE_HEADER 'o'
80 #define LOG_HTTP_CF_RESPONSE_LEN 'B'
89 #define LOG_HTTP_DEFAULT 0
90 #define LOG_HTTP_EXTENDED 1
91 #define LOG_HTTP_CUSTOM 2
102 static uint32_t GetCookieValue(uint8_t *rawcookies, uint32_t rawcookies_len,
char *cookiename,
103 uint8_t **cookievalue)
105 uint8_t *p = rawcookies;
108 while (p < rawcookies + rawcookies_len) {
109 if (cv == NULL && *p ==
'=') {
111 }
else if (cv != NULL && (*p ==
';' || p == rawcookies + rawcookies_len - 1) ) {
114 if (strlen(cookiename) == (
unsigned int) (cv-cn-1) &&
115 strncmp(cookiename, (
char *) cn, cv-cn-1) == 0) {
117 return (uint32_t) (p-cv);
136 uint8_t *cvalue = NULL;
137 uint32_t cvalue_len = 0;
139 htp_header_t *h_request_hdr;
140 htp_header_t *h_response_hdr;
142 for (i = 0; i < httplog_ctx->
cf->
cf_n; i++) {
143 h_request_hdr = NULL;
144 h_response_hdr = NULL;
161 snprintf(buf,
sizeof(buf),
"%06u", (
unsigned int)
SCTIME_USECS(
ts));
163 (uint8_t *)buf,
MIN(strlen(buf), 6));
168 aft->
buffer->
size, (uint8_t *)srcip,strlen(srcip));
173 aft->
buffer->
size, (uint8_t *)dstip,strlen(dstip));
185 if (tx->request_method != NULL) {
187 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_method),
188 bstr_len(tx->request_method));
195 if (tx->request_uri != NULL) {
197 if (datalen == 0 || datalen > bstr_len(tx->request_uri)) {
198 datalen = bstr_len(tx->request_uri);
201 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_uri),
209 if (tx->request_hostname != NULL)
212 if (datalen == 0 || datalen > bstr_len(tx->request_hostname)) {
213 datalen = bstr_len(tx->request_hostname);
216 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_hostname),
224 if (tx->request_protocol != NULL) {
226 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->request_protocol),
227 bstr_len(tx->request_protocol));
234 if (tx->request_headers != NULL) {
235 h_request_hdr = htp_table_get_c(tx->request_headers, node->
data);
237 if (h_request_hdr != NULL) {
239 if (datalen == 0 || datalen > bstr_len(h_request_hdr->value)) {
240 datalen = bstr_len(h_request_hdr->value);
243 aft->
buffer->
size, (uint8_t *)bstr_ptr(h_request_hdr->value),
251 if (tx->request_headers != NULL) {
252 h_request_hdr = htp_table_get_c(tx->request_headers,
"Cookie");
253 if (h_request_hdr != NULL) {
254 cvalue_len = GetCookieValue((uint8_t *)bstr_ptr(h_request_hdr->value),
255 (uint32_t)bstr_len(h_request_hdr->value), (
char *)node->
data,
259 if (cvalue_len > 0 && cvalue != NULL) {
261 if (datalen == 0 || datalen > cvalue_len) {
262 datalen = cvalue_len;
276 if (tx->response_status != NULL) {
278 aft->
buffer->
size, (uint8_t *)bstr_ptr(tx->response_status),
279 bstr_len(tx->response_status));
286 if (tx->response_headers != NULL) {
287 h_response_hdr = htp_table_get_c(tx->response_headers,
290 if (h_response_hdr != NULL) {
292 if (datalen == 0 || datalen > bstr_len(h_response_hdr->value)) {
293 datalen = bstr_len(h_response_hdr->value);
296 aft->
buffer->
size, (uint8_t *)bstr_ptr(h_response_hdr->value),
309 SCLogDebug(
"No matching parameter %%%c for custom http log.", node->
type);
321 htp_header_t *h_referer = NULL;
322 if (tx->request_headers != NULL) {
323 h_referer = htp_table_get_c(tx->request_headers,
"referer");
325 if (h_referer != NULL) {
327 (uint8_t *)bstr_ptr(h_referer->value),
328 bstr_len(h_referer->value));
336 if (tx->request_method != NULL) {
338 (uint8_t *)bstr_ptr(tx->request_method),
339 bstr_len(tx->request_method));
344 if (tx->request_protocol != NULL) {
346 (uint8_t *)bstr_ptr(tx->request_protocol),
347 bstr_len(tx->request_protocol));
354 if (tx->response_status != NULL) {
356 (uint8_t *)bstr_ptr(tx->response_status),
357 bstr_len(tx->response_status));
359 if ((tx->response_status_number > 300) && ((tx->response_status_number) < 303)) {
360 htp_header_t *h_location = htp_table_get_c(tx->response_headers,
"location");
361 if (h_location != NULL) {
365 (uint8_t *)bstr_ptr(h_location->value),
366 bstr_len(h_location->value));
389 char srcip[46], dstip[46];
423 SCLogDebug(
"got a HTTP request and now logging !!");
426 MemBufferReset(aft->
buffer);
429 LogHttpLogCustom(aft, tx, p->
ts, srcip, sp, dstip, dp);
435 if (tx->request_hostname != NULL) {
437 (uint8_t *)bstr_ptr(tx->request_hostname),
438 bstr_len(tx->request_hostname));
445 if (tx->request_uri != NULL) {
447 (uint8_t *)bstr_ptr(tx->request_uri),
448 bstr_len(tx->request_uri));
453 htp_header_t *h_user_agent = NULL;
454 if (tx->request_headers != NULL) {
455 h_user_agent = htp_table_get_c(tx->request_headers,
"user-agent");
457 if (h_user_agent != NULL) {
459 (uint8_t *)bstr_ptr(h_user_agent->value),
460 bstr_len(h_user_agent->value));
465 LogHttpLogExtended(aft, tx);
471 "%s:%" PRIu16
" -> %s:%" PRIu16
"\n",
472 srcip, sp, dstip, dp);
489 if (!(PacketIsTCP(p))) {
494 if (PacketIsIPv4(p)) {
495 r = LogHttpLogIPWrapper(
tv, thread_data, p, f, (
HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET);
496 }
else if (PacketIsIPv6(p)) {
497 r = LogHttpLogIPWrapper(
tv, thread_data, p, f, (
HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET6);
511 SCLogDebug(
"Error getting context for LogHTTPLog. \"initdata\" argument NULL");
517 if (aft->
buffer == NULL) {
550 SCLogWarning(
"The http-log output has been deprecated and will be removed in Suricata 9.0.");
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)