Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payload buffer v1 #2021

Merged
merged 2 commits into from
Apr 25, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
31 changes: 24 additions & 7 deletions src/output-json-alert.c
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
#include "threadvars.h"
#include "util-debug.h"

#include "util-misc.h"
#include "util-unittest.h"
#include "util-unittest-helper.h"

Expand Down Expand Up @@ -83,6 +84,7 @@
typedef struct AlertJsonOutputCtx_ {
LogFileCtx* file_ctx;
uint8_t flags;
uint32_t payload_buffer_size;
HttpXFFCfg *xff_cfg;
} AlertJsonOutputCtx;

Expand Down Expand Up @@ -285,7 +287,7 @@ static int AlertJson(ThreadVars *tv, JsonAlertLogThread *aft, const Packet *p)
(void *)payload);

if (json_output_ctx->flags & LOG_JSON_PAYLOAD_BASE64) {
unsigned long len = JSON_STREAM_BUFFER_SIZE * 2;
unsigned long len = json_output_ctx->payload_buffer_size * 2;
uint8_t encoded[len];
Base64Encode(payload->buffer, payload->offset, encoded, &len);
json_object_set_new(js, "payload", json_string((char *)encoded));
Expand Down Expand Up @@ -479,17 +481,17 @@ static TmEcode JsonAlertLogThreadInit(ThreadVars *t, void *initdata, void **data
return TM_ECODE_FAILED;
}

aft->payload_buffer = MemBufferCreateNew(JSON_STREAM_BUFFER_SIZE);
if (aft->payload_buffer == NULL) {
SCFree(aft);
return TM_ECODE_FAILED;
}

/** Use the Output Context (file pointer and mutex) */
AlertJsonOutputCtx *json_output_ctx = ((OutputCtx *)initdata)->data;
aft->file_ctx = json_output_ctx->file_ctx;
aft->json_output_ctx = json_output_ctx;

aft->payload_buffer = MemBufferCreateNew(json_output_ctx->payload_buffer_size);
if (aft->payload_buffer == NULL) {
SCFree(aft);
return TM_ECODE_FAILED;
}

*data = (void *)aft;
return TM_ECODE_OK;
}
Expand Down Expand Up @@ -556,8 +558,11 @@ static void XffSetup(AlertJsonOutputCtx *json_output_ctx, ConfNode *conf)

json_output_ctx->xff_cfg = xff_cfg;

uint32_t payload_buffer_size = JSON_STREAM_BUFFER_SIZE;

if (conf != NULL) {
const char *payload = ConfNodeLookupChildValue(conf, "payload");
const char *payload_buffer_value = ConfNodeLookupChildValue(conf, "payload-buffer-size");
const char *packet = ConfNodeLookupChildValue(conf, "packet");
const char *payload_printable = ConfNodeLookupChildValue(conf, "payload-printable");
const char *http = ConfNodeLookupChildValue(conf, "http");
Expand Down Expand Up @@ -595,12 +600,24 @@ static void XffSetup(AlertJsonOutputCtx *json_output_ctx, ConfNode *conf)
json_output_ctx->flags |= LOG_JSON_PAYLOAD_BASE64;
}
}
if (payload_buffer_value != NULL) {
uint32_t value;
if (ParseSizeStringU32(payload_buffer_value, &value) < 0) {
SCLogError(SC_ERR_ALERT_PAYLOAD_BUFFER, "Error parsing "
"payload-buffer-size - %s. Killing engine",
payload_buffer_value);
exit(EXIT_FAILURE);
} else {
payload_buffer_size = value;
}
}
if (packet != NULL) {
if (ConfValIsTrue(packet)) {
json_output_ctx->flags |= LOG_JSON_PACKET;
}
}

json_output_ctx->payload_buffer_size = payload_buffer_size;
HttpXFFGetCfg(conf, xff_cfg);
}
}
Expand Down
1 change: 1 addition & 0 deletions src/util-error.c
Original file line number Diff line number Diff line change
Expand Up @@ -317,6 +317,7 @@ const char * SCErrorToString(SCError err)
CASE_CODE (SC_ERR_DEPRECATED_CONF);
CASE_CODE (SC_WARN_FASTER_CAPTURE_AVAILABLE);
CASE_CODE (SC_WARN_POOR_RULE);
CASE_CODE (SC_ERR_ALERT_PAYLOAD_BUFFER);
}

return "UNKNOWN_ERROR";
Expand Down
1 change: 1 addition & 0 deletions src/util-error.h
Original file line number Diff line number Diff line change
Expand Up @@ -307,6 +307,7 @@ typedef enum {
SC_ERR_DEPRECATED_CONF, /**< Deprecated configuration parameter. */
SC_WARN_FASTER_CAPTURE_AVAILABLE,
SC_WARN_POOR_RULE,
SC_ERR_ALERT_PAYLOAD_BUFFER,
} SCError;

const char *SCErrorToString(SCError);
Expand Down
15 changes: 8 additions & 7 deletions suricata.yaml.in
Original file line number Diff line number Diff line change
Expand Up @@ -118,13 +118,14 @@ outputs:
# batch-size: 10 ## number of entry to keep in buffer
types:
- alert:
# payload: yes # enable dumping payload in Base64
# payload-printable: yes # enable dumping payload in printable (lossy) format
# packet: yes # enable dumping of packet (without stream segments)
# http: yes # enable dumping of http fields
# tls: yes # enable dumping of tls fields
# ssh: yes # enable dumping of ssh fields
# smtp: yes # enable dumping of smtp fields
# payload: yes # enable dumping payload in Base64
# payload-buffer-size: 4kb # max size of payload buffer to output in eve-log
# payload-printable: yes # enable dumping payload in printable (lossy) format
# packet: yes # enable dumping of packet (without stream segments)
# http: yes # enable dumping of http fields
# tls: yes # enable dumping of tls fields
# ssh: yes # enable dumping of ssh fields
# smtp: yes # enable dumping of smtp fields

# HTTP X-Forwarded-For support by adding an extra field or overwriting
# the source or destination IP address (depending on flow direction)
Expand Down