Help Center/ Web Application Firewall/ Best Practices/ Using LTS to Analyze WAF Logs/ Using LTS to Query and Analyze WAF Access Logs
Updated on 2024-12-20 GMT+08:00

Using LTS to Query and Analyze WAF Access Logs

Application Scenarios

After you authorize WAF to access Log Tank Service (LTS), you can use the WAF logs recorded by LTS for quick and efficient real-time analysis, device O&M management, and analysis of service trends.

This practice uses the access log stream lts-waf-access of log group lts-waf as an example to describe how to use LTS to quickly query and analyze logs.

Resource and Cost Planning

Table 1 Resources and costs

Resource

Description

Monthly Fee

Log Tank Service (LTS)

  • Billing mode: Pay-per-use
  • New log volume: 10 GB/day
  • Log retention period: 7 days

For details about billing rules, see Billing Description.

Web Application Firewall

Cloud - Standard edition

  • Billing mode: Yearly/Monthly
  • Number of domain names that can be protected: 10
  • QPS quota: 2,000 QPS
  • Peak bandwidth: 100 Mbit/s inside the cloud and 30 Mbit/s outside the cloud

For details about pricing rules, see Billing Description.

Step 1: Buy the Standard Edition Cloud WAF

The following describes how to buy the standard edition cloud WAF.

  1. Log in to Huawei Cloud management console.
  2. On the management console page, choose Security & Compliance > Web Application Firewall.
  3. In the upper right corner of the page, click Buy WAF. On the purchase page displayed, select Cloud Mode for WAF Mode.

    • Region: Select the region nearest to your services WAF will protect.
    • Edition: Select Standard.
    • Expansion Package and Required Duration: Set them based on site requirements.

  4. Confirm the product details and click Buy Now in the lower right corner of the page.
  5. Check the order details and read the WAF Disclaimer. Then, select the box and click Pay Now.
  6. On the payment page, select a payment method and pay for your order.

Step 2: Add Website Information to WAF

The following example shows how to add a website information to WAF in cloud CNAME access mode.

  1. In the navigation pane on the left, choose Website Settings.
  2. In the upper left corner of the website list, click Add Website.
  3. Select Cloud - CNAME and click Configure Now.
  4. Configure website information as prompted.

    Figure 1 Configuring basic information
    Table 2 Key parameters

    Parameter

    Description

    Example Value

    Domain Name

    Domain name you want to add to WAF for protection.

    • The domain name has an ICP license.
    • You can enter a single domain name (for example, top-level domain name example.com or level-2 domain name www.example.com) or a wildcard domain name (*.example.com).

    www.example.com

    Protected Port

    The port over which the website traffic goes

    Standard ports

    Server Configuration

    Web server address settings. You need to configure the client protocol, server protocol, server weights, server address, and server port.

    • Client Protocol: protocol used by a client to access a server. The options are HTTP and HTTPS.
    • Server Protocol: protocol used by WAF to forward client requests. The options are HTTP and HTTPS.
    • Server Address: public IP address (generally corresponding to the A record of the domain name configured on the DNS) or domain name (generally corresponding to the CNAME record of the domain name configured on the DNS) of the web server that a client accesses.
    • Server Port: service port over which the WAF instance forwards client requests to the origin server.
    • Weight: Requests are distributed across backend origin servers based on the load balancing algorithm you select and the weight you assign to each server.

    Client Protocol: Select HTTP.

    Server Protocol: HTTP

    Server Address: IPv4 XXX.XXX.1.1

    Server Port: 80

    Use Layer-7 Proxy

    You need to configure whether you deploy layer-7 proxies in front of WAF.

    Set this parameter based on your website deployment.

    Yes

  5. Click Next. Then, whitelist WAF back-to-source IP address, test WAF, and modify DNS records as prompted.

    Figure 2 Domain name added to WAF

Step 3: Enable LTS for Protection Logs

  1. Log in to the management console.
  2. Click in the upper left corner of the management console and select a region or project.
  3. Click in the upper left corner and choose Web Application Firewall under Security & Compliance.
  4. In the navigation pane on the left, choose Events.
  5. Click the Log Settings tab, enable LTS (), and select a log group and log stream. Table 3 describes the parameters.

    Figure 3 Log settings
    Table 3 Log configuration

    Parameter

    Description

    Example Value

    Log Group

    Select a log group or click View Log Group to go to the LTS console and create a log group.

    lts-group-waf

    Attack Log

    Select a log stream or click View Log Stream to go to the LTS console and create a log stream.

    An attack log includes information about event type, protective action, and attack source IP address of each attack.

    lts-topic-waf-attack

    Access Log

    Select a log stream or click View Log Stream to go to the LTS console and create a log stream.

    An access log includes key information about access time, client IP address, and resource URL of each HTTP access requests.

    lts-topic-waf-access

  6. Click OK.

    You can view WAF protection event logs on the LTS console.

Step 4: Query and Analyze WAF Access Logs in LTS

  1. Click in the upper left corner of the page and choose Management & Governance > Log Tank Service.
  2. In the Log Group Name column, click the name of the target log group (for example, lts-waf) to go the log stream page.
  3. In the Log Stream Name column, click the name of the log stream used for WAF access logs (for example, lts-waf-access). Then, select the Log Stream tab.

    Figure 4 Accessing the log stream page

  4. On the log stream details page, click in the upper right corner. On the page displayed, click the Cloud Structured Parsing tab.
  5. Select JSON as the log structure, as shown in Figure 5.

    Figure 5 JSON

  6. In the Step 1 Select a sample log event. area, click Select from existing log events. In the displayed Select Log Event dialog box, select a log and click OK.

    Figure 6 Select Log Event

  7. In the Step 2 Extract fields area, click Intelligent Extraction and enable quick analysis for the log field you want to analyze (for example, remote_ip).

    remote_ip: IP address of a client from which the request originates.

    Figure 7 Selecting log fields for quick analysis

  8. Click Save. Then, LTS will start a quick analysis and do statistics for logs collected in a certain period.

    Figure 8 Quickly analysis of access logs

  9. In the navigation pane, choose Visualization. On the right pane, select a log query time range, enter an SQL statement in the search box, and click Query to query the specified log.

    You can enter either of the following SQL statements in the search box to query logs of a specified IP address:

    select * where remote_ip = 'xx.xx.xx.xx' or select * where remote_ip like 'xx.xx.xx%'