Go to the documentation of this file.
54 #define DEFAULT_LOG_FILENAME "http.log"
56 #define MODULE_NAME "LogHttpLog"
58 #define OUTPUT_BUFFER_SIZE 65535
62 static void LogHttpLogDeInitCtx(
OutputCtx *);
72 #define LOG_HTTP_CF_REQUEST_HOST 'h'
73 #define LOG_HTTP_CF_REQUEST_PROTOCOL 'H'
74 #define LOG_HTTP_CF_REQUEST_METHOD 'm'
75 #define LOG_HTTP_CF_REQUEST_URI 'u'
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));
235 if (h_request_hdr != NULL) {
237 if (datalen == 0 || datalen > bstr_len(h_request_hdr->value)) {
238 datalen = bstr_len(h_request_hdr->value);
241 aft->
buffer->
size, (uint8_t *)bstr_ptr(h_request_hdr->value),
251 if (h_request_hdr != NULL) {
252 cvalue_len = GetCookieValue((uint8_t *)bstr_ptr(h_request_hdr->value),
253 (uint32_t)bstr_len(h_request_hdr->value), (
char *)node->
data, &cvalue);
256 if (cvalue_len > 0 && cvalue != NULL) {
258 if (datalen == 0 || datalen > cvalue_len) {
259 datalen = cvalue_len;
287 if (h_response_hdr != NULL) {
289 if (datalen == 0 || datalen > bstr_len(h_response_hdr->value)) {
290 datalen = bstr_len(h_response_hdr->value);
293 aft->
buffer->
size, (uint8_t *)bstr_ptr(h_response_hdr->value),
307 SCLogDebug(
"No matching parameter %%%c for custom http log.", node->
type);
319 htp_header_t *h_referer = NULL;
323 if (h_referer != NULL) {
325 (uint8_t *)bstr_ptr(h_referer->value),
326 bstr_len(h_referer->value));
360 if (h_location != NULL) {
364 (uint8_t *)bstr_ptr(h_location->value),
365 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);
452 htp_header_t *h_user_agent = NULL;
456 if (h_user_agent != NULL) {
458 (uint8_t *)bstr_ptr(h_user_agent->value),
459 bstr_len(h_user_agent->value));
464 LogHttpLogExtended(aft, tx);
470 "%s:%" PRIu16
" -> %s:%" PRIu16
"\n",
471 srcip, sp, dstip, dp);
488 if (!(PacketIsTCP(p))) {
493 if (PacketIsIPv4(p)) {
494 r = LogHttpLogIPWrapper(
tv, thread_data, p, f, (
HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET);
495 }
else if (PacketIsIPv6(p)) {
496 r = LogHttpLogIPWrapper(
tv, thread_data, p, f, (
HtpState *)state, (htp_tx_t *)tx, tx_id, AF_INET6);
510 SCLogDebug(
"Error getting context for LogHTTPLog. \"initdata\" argument NULL");
516 if (aft->
buffer == NULL) {
549 SCLogWarning(
"The http-log output has been deprecated and will be removed in Suricata 9.0.");
552 if(file_ctx == NULL) {
563 if (
unlikely(httplog_ctx == NULL)) {
575 if (custom != NULL && customformat != NULL &&
ConfValIsTrue(custom)) {
578 if (!httplog_ctx->
cf) {
589 if (extended == NULL) {
603 output_ctx->
data = httplog_ctx;
604 output_ctx->
DeInit = LogHttpLogDeInitCtx;
611 result.
ctx = output_ctx;
616 SCLogError(
"Syntax error in custom http log format string.");
625 static void LogHttpLogDeInitCtx(
OutputCtx *output_ctx)
struct LogHttpLogThread_ LogHttpLogThread
void LogCustomFormatFree(LogCustomFormat *cf)
Frees memory held by a custom format.
#define LOG_HTTP_CF_RESPONSE_STATUS
#define LOG_HTTP_CF_RESPONSE_HEADER
#define htp_tx_request_uri(tx)
#define OUTPUT_BUFFER_SIZE
LogFileCtx * LogFileNewCtx(void)
LogFileNewCtx() Get a new LogFileCtx.
#define LOG_HTTP_EXTENDED
#define htp_tx_request_protocol(tx)
OutputInitResult LogHttpLogInitCtx(ConfNode *conf)
Create a new http log LogFileCtx.
#define htp_tx_response_headers(tx)
int(* Write)(const char *buffer, int buffer_len, struct LogFileCtx_ *fp)
#define htp_tx_request_message_len(tx)
#define LOG_HTTP_CF_REQUEST_URI
#define htp_tx_request_method(tx)
void LogCustomFormatWriteTimestamp(MemBuffer *buffer, const char *fmt, const SCTime_t ts)
Writes a timestamp with given format into a MemBuffer.
#define htp_tx_response_status(tx)
#define LOG_CF_CLIENT_PORT
void OutputRegisterTxModule(LoggerId id, const char *name, const char *conf_name, OutputInitFunc InitFunc, AppProto alproto, TxLogger TxLogFunc, ThreadInitFunc ThreadInit, ThreadDeinitFunc ThreadDeinit)
Register a tx output module.
#define GET_IPV6_DST_ADDR(p)
#define LOG_HTTP_CF_REQUEST_LEN
int ConfValIsTrue(const char *val)
Check if a value is true.
int SCConfLogOpenGeneric(ConfNode *conf, LogFileCtx *log_ctx, const char *default_filename, int rotate)
open a generic output "log file", which may be a regular file or a socket
void LogHttpLogRegister(void)
#define htp_tx_request_headers(tx)
#define LOG_CF_WRITE_STAR_SEPARATOR(buffer)
#define GET_IPV4_DST_ADDR_PTR(p)
#define PKT_IS_TOSERVER(p)
#define LOG_HTTP_CF_REQUEST_HEADER
void AppLayerParserRegisterLogger(uint8_t ipproto, AppProto alproto)
Per thread variable structure.
const char * PrintInet(int af, const void *src, char *dst, socklen_t size)
TmEcode LogHttpLogThreadInit(ThreadVars *, const void *, void **)
#define DEFAULT_LOG_FILENAME
#define LOG_CF_SERVER_PORT
#define SCLogWarning(...)
Macro used to log WARNING messages.
#define htp_tx_request_hostname(tx)
#define LOG_CF_TIMESTAMP_U
void PrintRawUriBuf(char *retbuf, uint32_t *offset, uint32_t retbuflen, uint8_t *buf, size_t buflen)
TmEcode LogHttpLogThreadDeinit(ThreadVars *, void *)
#define LOG_HTTP_CF_REQUEST_METHOD
#define GET_IPV4_SRC_ADDR_PTR(p)
#define LOG_HTTP_CF_REQUEST_PROTOCOL
void(* DeInit)(struct OutputCtx_ *)
#define htp_tx_response_message_len(tx)
void MemBufferFree(MemBuffer *buffer)
#define LOG_HTTP_CF_REQUEST_HOST
int LogFileFreeCtx(LogFileCtx *lf_ctx)
LogFileFreeCtx() Destroy a LogFileCtx (Close the file and free memory)
#define SCLogError(...)
Macro used to log ERROR messages.
#define GET_IPV6_SRC_ADDR(p)
struct LogHttpFileCtx_ LogHttpFileCtx
#define LOG_HTTP_CF_RESPONSE_LEN
void MemBufferWriteString(MemBuffer *dst, const char *fmt,...)
LogHttpFileCtx * httplog_ctx
#define MEMBUFFER_BUFFER(mem_buffer)
Get the MemBuffers underlying buffer.
#define htp_tx_response_status_number(tx)
LogCustomFormat * LogCustomFormatAlloc(void)
Creates a custom format.
int LogHttpLogger(ThreadVars *tv, void *thread_data, const Packet *, Flow *f, void *state, void *tx, uint64_t tx_id)
#define MEMBUFFER_OFFSET(mem_buffer)
Get the MemBuffers current offset.
#define LOG_HTTP_CF_REQUEST_COOKIE
void CreateTimeString(const SCTime_t ts, char *str, size_t size)
MemBuffer * MemBufferCreateNew(uint32_t size)
int LogCustomFormatParse(LogCustomFormat *cf, const char *format)
Parses and saves format nodes for custom format.
const char * ConfNodeLookupChildValue(const ConfNode *node, const char *name)
Lookup the value of a child configuration node by name.