Use traffic mirror to audit VPC traffic

Updated at:

The VPC traffic mirror feature lets you detect and analyze cloud network traffic in real time for security auditing without disrupting your workloads.

Example scenario

A company deploys its core business workloads to the cloud and needs an efficient, non-intrusive way to monitor network traffic from its Alibaba Cloud ECS instances to identify and record potential security threats.

In this scenario, traffic mirror copies network traffic from one ECS instance to another that hosts a network threat detection system, enabling real-time inspection with security rules.

image
  • Traffic mirror: Copies network traffic from the elastic network interface (ENI) of a source ECS instance and forwards the traffic to a specified ENI. This feature is ideal for content inspection, threat monitoring, and troubleshooting.

  • Traffic audit: Uses Suricata as the core component for packet ingestion and anomaly detection. Suricata supports VXLAN decapsulation and provides Intrusion Detection System (IDS), Intrusion Prevention System (IPS), and network security monitoring capabilities. It identifies malicious traffic patterns and integrates with visualization and analytics systems such as Elasticsearch. You can also choose other analysis tools from security vendors on Alibaba Cloud Marketplace.

  • Log processing and storage: Uses Filebeat to collect Suricata logs, Elasticsearch to index and store the logs, and Kibana to query, visualize, and analyze the data.

  • Data Backup: Configures Elasticsearch to back up its indexes to Alibaba Cloud OSS for secure, long-term storage.

Prerequisites

  • You have created two VPCs, each containing one ECS instance.

    • You can associate an EIP with ECS1 to provide public-facing services.

    • ECS2 serves as the traffic mirror destination. Associate an EIP with ECS2 to access the internet for Suricata deployment.

    • In this example, both servers run the Alibaba Cloud Linux 3.2104 LTS 64-bit operating system.

    • Ensure the security group for ECS2 has an inbound rule allowing UDP traffic on port 4789. This port receives the encapsulated mirrored traffic.

  • If you are using the traffic mirror feature for the first time, enable it as prompted.

  • If the traffic mirror source and destination are not in the same VPC, make sure the VPCs can communicate with each other. In this example, a VPC peering connection is used to connect the two VPCs.

  • You have created an Alibaba Cloud Elasticsearch instance, enabled Public Network Access, and added your local machine's public IP address to the whitelist.

Procedure

Step 1: Configure Suricata

Deploy Suricata on the ECS2 server to receive network traffic and perform a security audit.

  1. Log on to ECS2 and run the following commands to install Suricata.

    # Install dependencies
    sudo dnf install -y gcc libpcap-devel pcre-devel libyaml-devel file-devel \
                         zlib-devel jansson-devel nss-devel libcap-ng-devel libnet-devel
    # Install Suricata
    sudo dnf install suricata -y
    # Ensure that Suricata starts automatically on boot
    sudo systemctl enable suricata
    sudo systemctl start suricata
  2. Configure Suricata.

    The Suricata configuration is stored in /etc/suricata/suricata.yaml. You can use the default configuration.

  3. Update the security rules.

    Run suricata-update to update the rule files. By default, they are saved in /var/lib/suricata/rules/suricata.rules.

  4. Run sudo service suricata restart to restart Suricata.

Step 2: Configure traffic mirroring

  1. Create a filter.

    1. Log on to the VPC console. In the left-side navigation pane, choose O&M and Monitoring > Traffic Mirror > Filter.

    2. On the Filter page, click Create Filter. In the Rule Configuration section, on the Outbound Rules tab, click Create Rule and use the default configuration to collect all traffic.

  2. Create and start a traffic mirror session.

    1. In the left-side navigation pane, choose O&M and Monitoring > Traffic Mirror > Traffic Mirror Session.

    2. On the Traffic Mirror Session page, click Create Traffic Mirror Session. Keep the default Basic Settings, select the filter you created in the previous step for Associate Filter, select the ENI of ECS1 as the Traffic Mirror Source, and select the ENI of ECS2 as the Traffic Mirror Destination.

    3. On the Traffic Mirror Session page, find the target traffic mirror session, and in the Actions column, click Start.

  3. After you configure traffic mirroring and Suricata is running correctly, it generates a series of log files in the /var/log/suricata/ directory.

    /var/log/suricata/
    ├── certs
    ├── core
    ├── eve.json		    ## Contains all captured logs for flows, alerts, stats, and application-layer protocols such as HTTP, in JSON format.
    ├── fast.log		    ## Contains alert logs generated by detection and analysis.
    ├── files
    ├── stats.log		    ## Contains detailed statistics on the number of captured and processed packets.
    ├── suricata.log	    ## Contains detailed logs about the service runtime.
    └── suricata-start.log	    ## Contains detailed logs about the service startup.

Step 3: Collect and store Suricata logs

Use Filebeat to send Suricata log data to your Alibaba Cloud Elasticsearch instance for indexing and storage, and then use Kibana for visualization and analysis.

  1. Log on to ECS2 and run the following commands to install Filebeat.

    curl -L -O https://artifacts.elastic.co/downloads/beats/filebeat/filebeat-7.10.0-x86_64.rpm
    sudo rpm -vi filebeat-7.10.0-x86_64.rpm
  2. Modify the Suricata module configuration to specify the Suricata traffic log files to collect.

    1. Run the sudo filebeat modules enable suricata command to enable the Suricata module.

    2. Run the sudo vim /etc/filebeat/modules.d/suricata.yml command and modify the Suricata module configuration as follows.

      - module: suricata
        # Specify the traffic log files to collect.
        eve:
          enabled: true
          var.paths: ["/var/log/suricata/eve.json"]
    3. Press the Esc key, enter :wq, and press the Enter key to save the file and exit.

  3. Run the sudo vim /etc/filebeat/filebeat.yml command to configure the filebeat.yml file and set the connection information.

    1. Modify the Filebeat modules configuration.

      filebeat.config.modules:
        # Load the module configuration globally.
        path: /etc/filebeat/modules.d/suricata.yml
        # Allow the configuration to be dynamically reloaded.
        reload.enabled: true
        # The interval at which the system checks for file changes in the specified path.
        reload.period: 1s
    2. Modify the Kibana configuration.

      setup.kibana:
        host: "https://es-cn-8l**********2r7ln-kibana.cn-hangzhou.elasticsearch.aliyuncs.com:5601"

      host: The access address of Kibana. You can obtain it from the Kibana configuration page. The format is <Kibana public endpoint>:5601.

    3. Modify the Elasticsearch output configuration.

      output.elasticsearch:
        # Configure the Elasticsearch instance for log storage.
        hosts: ["http://es-cn-8ly**********r7ln.elasticsearch.aliyuncs.com:9200"]
        username: "elastic"
        password: "<your_password>"

      hosts: The access address of your Elasticsearch instance. You can obtain it from the Basic Information page of your instance. The format is <Instance private or public endpoint>:9200.

      username: The username for accessing the Elasticsearch instance. The default value is elastic.

      password: The password that you specified when you created the instance. If you forget the password, you can reset the instance access password.

    4. Press the Esc key, enter :wq, and press the Enter key to save the file and exit.

    5. Run the following commands to upload assets such as dashboards to Elasticsearch and Kibana, and then start the Filebeat service.

      sudo filebeat setup
      sudo service filebeat start

Step 4: Visualize and analyze VPC traffic

  1. Log on to the Kibana console of your Elasticsearch instance. In the left-side navigation pane, click Kibana > Discover, and change the index pattern to filebeat-*.

  2. You can add an alert filter and select a time range in the upper-right corner to view potentially threatening VPC traffic from that time range.

    For example, in the query bar, enter alert and 192.168.0.201 and ensure the index pattern is set to filebeat-* to view alert logs from the source IP address 192.168.0.201. The search returns 409 Suricata alert records. The alert signature is SURICATA TCPv4 invalid checksum, the category is Generic Protocol Command Decode, and the severity level is 3.

Step 5: Verify alerts

  1. Log on to ECS1 and run the curl http://testmynids.org/uid/index.html command. This simulates the output of the id command to trigger an alert.

    curl http://testmynids.org/uid/index.html
    uid=0(root) gid=0(root) groups=0(root)

    The Suricata rule set includes the following rule. When a packet contains the string value uid=0|28|root|29| and the traffic is classified as unknown, Suricata drops the packet and generates an alert.

    alert ip any any -> any any (msg:"GPL ATTACK_RESPONSE id check returned root"; content:"uid=0|28|root|29|"; classtype:bad-unknown; sid:2100498; rev:7; metadata:created_at 2010_09_23, updated_at 2010_09_23;)
  2. On the Kibana page, add the GPL filter to view the alert event that matches the Suricata IDS signature rule "GPL ATTACK_RESPONSE id check returned root". A search for the keyword GPL in the Kibana log search interface shows one record of a Suricata IDS alert. Expand the log details. The event_type is alert, the source IP is 18.155.192.120, the destination IP is 192.168.0.201, the protocol is TCP (source port 80 and destination port 57978), the signature is GPL ATTACK_RESPONSE id check returned root, the category is Potentially Bad Traffic, and the severity is 2, which indicates that the alert was successfully triggered.

Data backup

Back up your Alibaba Cloud Elasticsearch indexes to ensure data security and long-term accessibility. Elasticsearch enables automatic backup by default. You can save automatic backup snapshots to an Alibaba Cloud OSS repository.

FAQ

  1. Applying Filebeat configuration changes

    To apply configuration changes, you must restart the service. Run the following command to restart Filebeat.

     sudo systemctl restart filebeat
  2. Verify that mirrored traffic reaches the destination

    Log on to ECS2, the traffic mirror destination, and run the following command to check if it is receiving packets.

    tcpdump -i eth0 udp port 4789 -nne

    The vni 1 field is the identifier for the traffic mirror session. Its presence confirms that the destination is receiving packets from the session.

    [root@ixxxZ ~]# tcpdump -i eth0 udp port 4789 -nne
    dropped privs to tcpdump
    tcpdump: verbose output suppressed, use -v or -vv for full protocol decode
    listening on eth0, link-type EN10MB (Ethernet), capture size 262144 bytes
    16:21:48.673510 ee:ff:ff:ff:ff:ff > 00:16:3e:13:51:9b, ethertype IPv4 (0x0800), length 110: 192.168.0.201.27551 > 172.16.0.105.4789: VXLAN, flags [I] (0x08), vni 1
    ee:ff:ff:ff:ff:ff > 00:16:3e:13:51:9b, ethertype IPv4 (0x0800), length 60: 45.200.149.95.57388 > 192.168.0.201.7432: Flags [R], seq 950507569, win 1200, options [mss 1460], length 0
    16:21:48.673706 ee:ff:ff:ff:ff:ff > 00:16:3e:13:51:9b, ethertype IPv4 (0x0800), length 188: 192.168.0.201.41566 > 172.16.0.105.4789: VXLAN, flags [I] (0x08), vni 1
    ee:ff:ff:ff:ff:ff > 00:16:3e:13:51:9b, ethertype IPv4 (0x0800), length 138: 172.16.0.105 > 192.168.0.201: ICMP 172.16.0.105 udp port 4789 unreachable, length 104