The Wallarm user interface provides the ability to search for a number of different types of attack traffic within alert data. More information about the supported types of searches can be found in the
Wallarm documentation
.
However, the search functionality of the Wallarm UI does not provide full visibility into every type of potential attack or full details of a particular alert. If this level of visibility is necessary, then the access logs can be exported from Nginx into an ELK cluster where it is possible to perform full-text searches and other data analytics against them. This also enables this information to be fed into other systems that the organization may be using for threat detection or threat intelligence generation and analysis.
A couple of different options exist for exporting this data from Nginx. This article focuses on the approach of sending Nginx access logs to an ELK cluster. Alternatively, it is possible to use the Wallarm API to extract request information, as described in this blog.
How to Export Nginx Access Logs
Sending access logs from Nginx to an ELK cluster is a multi-stage process. In this article, we’ll focus on configuring Nginx to export the logs in the correct format and send them to a listening TCP/UDP port. The remaining steps of the process (configuring Logstash and Elasticsearch) are well-described on the Internet, and links are provided that contain more detail on how to accomplish these steps correctly.
Step 1: Configure JSON Access Log Output
The first step in setting up the export of Nginx access logs is configuring Nginx to send the data out in the desired format. For ease of use, we’ll be defining a JSON-based log format for the export.
The following shows the structure of a custom log format that combines some standard Nginx attributes, such as number of connection requests and response status, with some Wallarm-specific data, such as the Wallarm attack type. More information about the standard attributes available with Nginx is available in
their documentation
, and the
Wallarm documentation
describes the set of custom attributes that Wallarm defines.
One option is to use fluentd to perform the transfer. After saving the log file as a text file, a local copy of fluentd can be used to perform the transfer. For more information regarding this option, check out the
fluentd documentation
.
Alternatively, it is possible to use Nginx’s built-in syslog client to perform the log file export. However, this option requires the receiving Logstash instance to be configured to use
the syslog plugin
to receive input. If this is the case, use the following configuration to send the access logs via syslog: