Skip to content
This repository has been archived by the owner on Jan 18, 2024. It is now read-only.

Added support for aschex encoding payload #140

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
13 changes: 13 additions & 0 deletions src/output-plugins/spo_syslog_full.c
Original file line number Diff line number Diff line change
Expand Up @@ -861,6 +861,15 @@ int Syslog_FormatPayload(OpSyslog_Data *data, Packet *p) {
}
break;

case ENCODE_ASCHEX:
if( (aschex_STATIC(p->pkt,p->pkth->caplen,
data->payload_escape_buffer)))
{
/* XXX */
return 1;
}
break;

default:
FatalError("[%s()]: Unknown encoding payload scheme [%d] \n",
__FUNCTION__,
Expand Down Expand Up @@ -1438,6 +1447,10 @@ OpSyslog_Data *OpSyslog_ParseArgs(char *args)
{
op_data->payload_encoding = ENCODE_BASE64;
}
else if(strcasecmp("aschex",stoks[1]) == 0)
{
op_data->payload_encoding = ENCODE_ASCHEX;
}
else
{
LogMessage("Invalid payload_encoding defined [%s], will use HEX encoding by default \n",stoks[1]);
Expand Down
1 change: 1 addition & 0 deletions src/output-plugins/spo_syslog_full.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,7 @@
#define ENCODE_HEX 0x0000
#define ENCODE_ASCII 0x0001
#define ENCODE_BASE64 0x0002
#define ENCODE_ASCHEX 0x0003

#define SYSLOG_MAX_QUERY_SIZE MAX_QUERY_LENGTH

Expand Down
48 changes: 48 additions & 0 deletions src/util.c
Original file line number Diff line number Diff line change
Expand Up @@ -2595,6 +2595,54 @@ u_int32_t fasthex_STATIC(const u_char *xdata, int length,char *retbuf)
return 0;
}

u_int32_t aschex_STATIC(const u_char *xdata, int length, char *retbuf) {
char conv[] = "0123456789ABCDEF";
char *asc_msg;
char *hex_msg;
const u_char *index;
char *ridx;

if (xdata == NULL ||
retbuf == NULL ||
(length *3) + 2 > MAX_QUERY_LENGTH ) {
return 1;
}

asc_msg = malloc(MAX_QUERY_LENGTH);
hex_msg = malloc(MAX_QUERY_LENGTH);
if (asc_msg == NULL || hex_msg == NULL) {
FatalError("aschex_STATIC(): Can't allocate memory\n");
}

/* Obtain ascii msg */
memset(asc_msg, '\0', MAX_QUERY_LENGTH);
index = xdata;
ridx = asc_msg;
while (index < xdata + length) {
if (*index > 0x20 && *index < 0x7F) *ridx++ = *index;
else *ridx++ = '.';
index++;
}

/* Obtain hex msg */
memset(hex_msg, '\0', MAX_QUERY_LENGTH);
index = xdata;
ridx = hex_msg;
while (index < xdata + length) {
*ridx++ = conv[((*index & 0xFF)>>4)];
*ridx++ = conv[((*index & 0xFF)&0x0F)];
index++;
}

/* Concat asc and hex msgs */
snprintf(retbuf, MAX_QUERY_LENGTH, "%s %s", asc_msg, hex_msg);

/* Free local resources */
free(asc_msg);
free(hex_msg);

return 0;
}

/*
* Fatal Integer Parser
Expand Down
1 change: 1 addition & 0 deletions src/util.h
Original file line number Diff line number Diff line change
Expand Up @@ -221,6 +221,7 @@ int GetLocalTimezone();
u_int32_t fasthex_STATIC(const u_char *xdata, int length,char *retbuf);
u_int32_t base64_STATIC(const u_char * xdata, int length,char *output);
u_int32_t ascii_STATIC(const u_char *xdata, int length,char *ret_val);
u_int32_t aschex_STATIC(const u_char *xdata, int length,char *ret_val);

u_int32_t GetTimestampByComponent_STATIC(uint32_t sec, uint32_t usec, int tz,char *buf);
u_int32_t GetTimestampByStruct_STATIC(register const struct timeval *tvp, int tz,char *buf);
Expand Down