2
responses

The endpoint I will be sending logs to expects this format:

{
"timestamp":"2019-08-06T19:00:03Z",
"body":"This is a sample body",
"attributes":{
"token":"some token value",
"log_type":"error",
"(extensible keys)":"(string value)"
}
}

I need to convert Windows eventlogs to the target format and I'm having an issue creating "attributes." Here's my latest attempt, but "attributes" is getting converted to JSON twice which is messing up the format.

Here's my .conf:

Panic Soft
#NoFreeOnExit TRUE

define ROOT C:\Program Files (x86)\nxlog
define CERTDIR %ROOT%\cert
define CONFDIR %ROOT%\conf
define LOGDIR %ROOT%\data
define LOGFILE %LOGDIR%\nxlog.log
LogFile %LOGFILE%

Moduledir %ROOT%\modules
CacheDir %ROOT%\data
Pidfile %ROOT%\data\nxlog.pid
SpoolDir %ROOT%\data

<Extension json>
Module xm_json
</Extension>

<Extension _exec>
Module xm_exec
</Extension>

<Input in>
Module im_msvistalog
<QueryXML>
<QueryList>
<Query Id='1'>
<Select Path='Application'>*</Select>
<Select Path='Security'>*</Select>
</Query>
</QueryList>
</QueryXML>
<Exec>

#$attributes = $raw_event;
$log_type = $EventType;
$token = 'token goes here';
$raw_event = $raw_event + $log_type + $token;
$attributes = to_json();
rename_field("EventTime", "timestamp");
$body = $message;
delete($log_type);
delete($token);
delete($AccountName);
delete($AccountType);
delete($ActivityID);
delete($Category);
delete($Channel);
delete($Domain);
delete($EventID);
delete($EventTime);
delete($EventType);
delete($HandleId);
delete($Hostname);
delete($Keywords);
delete($MandatoryLabel);
delete($Message);
delete($NewProcessId);
delete($NewProcessName);
delete($ObjectServer);
delete($Opcode);
delete($OpcodeValue);
delete($ParentProcessName);
delete($PrivilegeList);
delete($ProcessName);
delete($ProcessID);
delete($ProviderGuid);
delete($RecordNumber);
delete($RelatedActivityID);
delete($Service);
delete($Severity);
delete($SeverityValue);
delete($SourceName);
delete($SubjectUserSid);
delete($SubjectUserName);
delete($SubjectDomainName);
delete($SubjectLogonId);
delete($Task);
delete($ThreadID);
delete($TargetUserSid);
delete($TargetUserSid);
delete($TargetUserName);
delete($TargetDomainName);
delete($TargetLogonId);
delete($TokenElevationType);
delete($TransactionId);
delete($UserID);
delete($Version);
delete($EventReceivedTime);
delete($SourceModuleName);
delete($SourceModuleType);
to_json();
</Exec>
</Input>

<Output file>
Module om_file
file "c:\\temp\\logdata.log"
</Output>

<Route 2>
Path in => file
</Route>

My results end up looking like this:

{
"timestamp": "2019-08-27 15:45:39",
"attributes": "{\"EventTime\":\"2019-08-27 15:45:39\",\"Hostname\":\"fakehost\",\"Keywords\":-9214364837600034816,\"EventType\":\"AUDIT_SUCCESS\",\"SeverityValue\":2,\"Severity\":\"INFO\",\"EventID\":4688,\"SourceName\":\"Microsoft-Windows-Security-Auditing\",\"ProviderGuid\":\"{guid}\",\"Version\":2,\"Task\":13312,\"OpcodeValue\":0,\"RecordNumber\":30506980,\"ProcessID\":4,\"ThreadID\":19308,\"Channel\":\"Security\",\"Message\":\"A new process has been created.\\r\\n\\r\\nCreator Subject:\\r\\n\\tSecurity ID:\\t\\tS-1-5-18\\r\\n\\tAccount Name:\\t\\fake$\\r\\n\\tAccount Domain:\\t\\tFake\\r\\n\\tLogon ID:\\t\\FakeID\\r\\n\\r\\nTarget Subject:\\r\\n\\tSecurity ID:\\t\\tS-1-0-0\\r\\n\\tAccount Name:\\t\\t-\\r\\n\\tAccount Domain:\\t\\t-\\r\\n\\tLogon ID:\\t\\t0x0\\r\\n\\r\\nProcess Information:\\r\\n\\tNew Process ID:\\t\\t0xc0c\\r\\n\\tNew Process Name:\\tC:\\\\Windows\\\\SysWOW64\\\\cmd.exe\\r\\n\\tToken Elevation Type:\\t%%1936\\r\\n\\tMandatory Label:\\t\\tS-1-16-16384\\r\\n\\tCreator Process ID:\\t0x30f8\\r\\n\\tCreator Process Name:\\tC:\\\\Program Files (x86)\\\\Stackdriver\\\\LoggingAgent\\\\Main\\\\bin\\\\ruby.exe\\r\\n\\tProcess Command Line:\\t\\r\\n\\r\\nToken Elevation Type indicates the type of token that was assigned to the new process in accordance with User Account Control policy.\\r\\n\\r\\nType 1 is a full token with no privileges removed or groups disabled. A full token is only used if User Account Control is disabled or if the user is the built-in Administrator account or a service account.\\r\\n\\r\\nType 2 is an elevated token with no privileges removed or groups disabled. An elevated token is used when User Account Control is enabled and the user chooses to start the program using Run as administrator. An elevated token is also used when an application is configured to always require administrative privilege or to always require maximum privilege, and the user is a member of the Administrators group.\\r\\n\\r\\nType 3 is a limited token with administrative privileges removed and administrative groups disabled. The limited token is used when User Account Control is enabled, the application does not require administrative privilege, and the user does not choose to start the program using Run as administrator.\",\"Category\":\"Process Creation\",\"Opcode\":\"Info\",\"SubjectUserSid\":\"S-1-5-18\",\"SubjectUserName\":\"FakeUser$\",\"SubjectDomainName\":\"FakeDomain\",\"SubjectLogonId\":\"0x3e7\",\"NewProcessId\":\"0xc0c\",\"NewProcessName\":\"C:\\\\Windows\\\\SysWOW64\\\\cmd.exe\",\"TokenElevationType\":\"%%1936\",\"TargetUserSid\":\"S-1-0-0\",\"TargetUserName\":\"-\",\"TargetDomainName\":\"-\",\"TargetLogonId\":\"0x0\",\"ParentProcessName\":\"C:\\\\Program Files (x86)\\\\Stackdriver\\\\LoggingAgent\\\\Main\\\\bin\\\\ruby.exe\",\"MandatoryLabel\":\"S-1-16-16384\",\"EventReceivedTime\":\"2019-08-27 15:45:41\",\"SourceModuleName\":\"in\",\"SourceModuleType\":\"im_msvistalog\",\"log_type\":\"AUDIT_SUCCESS\",\"token\":\"token goes here\"}",
"body": "A new process has been created.\r\n\r\nCreator Subject:\r\n\tSecurity ID:\t\tS-1-5-18\r\n\tAccount Name:\t\Fake$\r\n\tAccount Domain:\t\tFake\r\n\tLogon ID:\t\t0x3E7\r\n\r\nTarget Subject:\r\n\tSecurity ID:\t\tS-1-0-0\r\n\tAccount Name:\t\t-\r\n\tAccount Domain:\t\t-\r\n\tLogon ID:\t\t0x0\r\n\r\nProcess Information:\r\n\tNew Process ID:\t\t0xc0c\r\n\tNew Process Name:\tC:\\Windows\\SysWOW64\\cmd.exe\r\n\tToken Elevation Type:\t%%1936\r\n\tMandatory Label:\t\tS-1-16-16384\r\n\tCreator Process ID:\t0x30f8\r\n\tCreator Process Name:\tC:\\Program Files (x86)\\Stackdriver\\LoggingAgent\\Main\\bin\\ruby.exe\r\n\tProcess Command Line:\t\r\n\r\nToken Elevation Type indicates the type of token that was assigned to the new process in accordance with User Account Control policy.\r\n\r\nType 1 is a full token with no privileges removed or groups disabled. A full token is only used if User Account Control is disabled or if the user is the built-in Administrator account or a service account.\r\n\r\nType 2 is an elevated token with no privileges removed or groups disabled. An elevated token is used when User Account Control is enabled and the user chooses to start the program using Run as administrator. An elevated token is also used when an application is configured to always require administrative privilege or to always require maximum privilege, and the user is a member of the Administrators group.\r\n\r\nType 3 is a limited token with administrative privileges removed and administrative groups disabled. The limited token is used when User Account Control is enabled, the application does not require administrative privilege, and the user does not choose to start the program using Run as administrator."
}

How can I get "attributes" to be a regular JSON object?

Thanks!

AskedAugust 27, 2019 - 10:02pm

Answer (1)

You are probably wanting to use Nested JSON.

Try setting fields with the following style:

$attributes.token = "Value"
$attributes.log_type = "error"

https://nxlog.co/documentation/nxlog-user-guide/xm_json.html

Comments (1)

  • jonwalz's picture

    Unfortunately, I'm currently stuck with CE which doesn't seem to have DetectNestedJSON as an option. I tried this:

    #$attributes = $raw_event;
    rename_field("EventTime", "timestamp");
    $body = $message;
    $attributes.log_type = $EventType;
    $attributes.token = 'token goes here';
    $attributes.AccountName = $AccountName;
    $attributes.AccountType = $AccountType;
    $attributes.EventID = $EventID;

    And the JSON came out like this:

    {
    "timestamp": "2019-08-28 09:53:33",
    "body": "body text",
    "attributes.log_type": "AUDIT_SUCCESS",
    "attributes.token": "token goes here",
    "attributes.AccountName": null,
    "attributes.AccountType": null,
    "attributes.EventID": 4688
    }