If you have trouble with enabling audit logging in Office 365, complete the following steps.
-
Login to https://protection.office.com/.
-
Verify that the Search > Audit log search context is active. If it is not, execute the following commands from PowerShell:
$ $UserCredential = Get-Credential
# use your Azure account
$ $Session = New-PSSession -ConfigurationName Microsoft.Exchange -ConnectionUri https://outlook.office365.com/powershell-liveid/ -Credential $UserCredential -Authentication Basic -AllowRedirection
$ Import-PSSession $Session -DisableNameChecking
$ Enable-OrganizationCustomization
# Wait 4 hours
$ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
# Wait 1 hour
$ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $false
# Wait 1 hour
$ Set-AdminAuditLogConfig -UnifiedAuditLogIngestionEnabled $true
# Wait 1 hour
-
Login to https://protection.office.com/ and check if there are audit logs under Search > Audit log search. Note that in some cases, the logs will appear only after 24-48 hours.
The osquery application allows you to ask questions about your machine using an SQL-like language. For example, you can query running processes, logged in users, installed packages and syslog messages as well. You can make queries on demand, and also schedule them to run regularly.
The osquery() source of syslog-ng PE allows you read the results of periodical osquery queries (from the /var/log/osquery/osqueryd.results.log file) and automatically parse the messages (if you want to use syslog-ng PE to send log messages to osquery, read this blogpost). For example, you can:
-
Create filters from the fields of the messages.
-
Limit which fields to store, or create additional fields (combine multiple fields into one filed, and so on).
-
Send the messages to a central location, for example, to Elasticsearch, directly from syslog-ng PE.
The syslog-ng PE application automatically adds the .osquery. prefix to the name of the fields the extracted from the message.
The osquery() source is available in syslog-ng PE version 3.107.0.4 and later.
Prerequisites
-
To use the osquery() driver, the scl.conf file must be included in your syslog-ng PE configuration:
@include "scl.conf"
-
syslog-ng PE must be compiled with JSON-support enabled.
The osquery() driver is actually a reusable configuration snippet configured to read the osquery log file using the file() driver, and process its JSON contents. For details on using or writing such configuration snippets, see Reusing configuration blocks. You can find the source of this configuration snippet on GitHub.
Example: Using the osquery() driver with the default settings
The following syslog-ng PE configuration sample uses the default settings of the driver, reading osquery result logs from the /var/log/osquery/osqueryd.results.log file, and writes the log messages generated from the traps into a file.
@version: 7.0
@include "scl.conf"
source s_osquery {
osquery();
};
log {
source(s_osquery);
destination {
file("/var/log/example.log");
};
};
Filter for messages related to loading Linux kernel modules:
@version: 7.0
@include "scl.conf"
source s_osquery {
osquery();
};
log {
source(s_osquery);
filter f_modules {
"${.osquery.name}" eq "pack_incident-response_kernel_modules"
};
destination {
file("/var/log/example.log");
};
};
Example: Using the osquery() driver with custom configuration
The following syslog-ng PE configuration sample reads osquery result logs from the /tmp/osquery_input.log file, and writes the log messages generated from the traps into a file. Using the format-json template, the outgoing message will be a well-formed JSON message.
Input message
{"name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost","calendarTime":"Fri Jul 21 10:04:41 2017 UTC","unixTime":"1500631481","decorations":{"host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332","username":"myuser"},"columns":{"build_distro":"xenial","build_platform":"ubuntu","config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee","config_valid":"1","counter":"4","extensions":"active","instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d","pid":"19764","resident_size":"26416000","start_time":"1500629552","system_time":"223","user_time":"476","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332","version":"2.5.0","watcher":"19762"},"action":"added"}
syslog-ng PE configuration
@version: 7.0
@include "scl.conf"
source s_osquery {
osquery(
file(/tmp/osquery_input.log)
prefix(.osquery.)
);
};
destination d_file {
file("/tmp/output.txt"
template("$(format_json --key .osquery.*)\n")
);
};
log {
source(s_osquery);
destination(d_file);
flags(flow-control);
};
Outgoing message
Outgoing message; message='{"_osquery":{"unixTime":"1500631481","name":"pack_osquery-monitoring_osquery_info","hostIdentifier":"testhost","decorations":{"username":"myuser","host_uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332"},"columns":{"watcher":"19762","version":"2.5.0","uuid":"4C4C4544-004D-3610-8043-C2C04F4D3332","user_time":"476","system_time":"223","start_time":"1500629552","resident_size":"26416000","pid":"19764","instance_id":"d0c3eb0d-f8e0-4bea-868b-18a2c61b438d","extensions":"active","counter":"4","config_valid":"1","config_hash":"43cd1c6a7d0c283e21e026a53e619b2e582e94ee","build_platform":"ubuntu","build_distro":"xenial"},"calendarTime":"Fri Jul 21 10:04:41 2017 UTC","action":"added"}}\x0a'
To configure a destination to send the log messages to Elasticsearch, see elasticsearch2: Sending messages directly to Elasticsearch version 2.0 or higher (DEPRECATED). For other destinations, see Sending and storing log messages — destinations and destination drivers.
The osquery() driver has the following options.
file()
Type: |
path |
Default: |
/var/log/osquery/osqueryd.results.log |
Description: The log file of osquery that stores the results of periodic queries. The syslog-ng PE application reads the messages from this file.
prefix()
Description: Insert a prefix before the name part of the parsed name-value pairs to help further processing. For example:
-
To insert the my-parsed-data. prefix, use the prefix(my-parsed-data.) option.
-
To refer to a particular data that has a prefix, use the prefix in the name of the macro, for example, ${my-parsed-data.name} .
-
If you forward the parsed messages using the IETF-syslog protocol, you can insert all the parsed data into the SDATA part of the message using the prefix(.SDATA.my-parsed-data.) option.
Names starting with a dot (for example,
.example) are reserved for use by syslog-ng PE. If you use such a macro name as the name of a parsed value, it will attempt to replace the original value of the macro (note that only soft macros can be overwritten, see
Hard versus soft macros for details). To avoid such problems, use a prefix when naming the parsed values, for example,
prefix(my-parsed-data.)
Default value
.osquery. option.
The pipe driver opens a named pipe with the specified name and listens for messages. It is used as the native message delivery protocol on HP-UX.
The pipe driver has a single required parameter, specifying the filename of the pipe to open. For the list of available optional parameters, see pipe() source options.
Declaration
pipe(filename);
NOTE: As of syslog-ng Open Source Edition 3.0.2, pipes are created automatically. In earlier versions, you had to create the pipe using the mkfifo(1) command.
Pipe is very similar to the file() driver, but there are a few differences, for example, pipe() opens its argument in read-write mode, therefore it is not recommended to be used on special files like /proc/kmsg.
|
Caution:
-
It is not recommended to use pipe() on anything else than real pipes.
-
By default, syslog-ng PE uses the flags(no-hostname) option for pipes, meaning that syslog-ng PE assumes that the log messages received from the pipe do not contain the hostname field. If your messages do contain the hostname field, use flags(expect-hostname). For details, see flags(). |
Example: Using the pipe() driver
source s_pipe {
pipe("/dev/pipe"
pad-size(2048)
);
};