Security Verification and Offensive-Defensive Practice

Blue Team Bible ⑨ [Traffic Analysis Edition] Network Traffic Analysis Practical Methodology: From Theory to Practice


Network traffic analysis plays a crucial role in today's complex and volatile cybersecurity environment. It is not only a passive monitoring method but also the foundation of proactive defence, threat hunting, and security operations. The strategic significance of network traffic analysis lies in its ability to provide security teams with a panoramic view of network activities, identify potential security threats and anomalous patterns, help organizations meet various industry standards and regulatory requirements, provide crucial evidence for security incident investigations, and assist IT infrastructure teams in identifying and resolving network performance issues. When building a strategic framework for network traffic analysis, it is first necessary to define the goals and scope, which includes aligning business objectives, conducting comprehensive risk assessments, sorting out compliance requirements, and defining the monitoring scope. Next, organizations should assess the maturity of their network traffic analysis capabilities, from the initial level to the optimizing level, with each level having its own characteristics, capabilities, and challenges. Finally, formulate resource allocation strategies, considering human resources, technical resources, and budget allocation, to ensure the effective implementation of network traffic analysis.

Dimension/Level

Initial

Repeatable

Defined

Managed

Optimizing

Data Collection

〇

〇

〇

〇

〇

Analysis Capability

〇

〇

〇

〇

〇

Response Mechanism

〇

〇

〇

〇

〇

Tool Integration

〇

〇

〇

〇

〇

Personnel Skills

〇

〇

〇

〇

〇

Network Traffic Analysis Capability Maturity Assessment Matrix

▌Tactical Implementation of Network Traffic Analysis

At the tactical level, the implementation of network traffic analysis involves data collection strategies, analysis workflow design, layered design of detection mechanisms, and response mechanism design.

Data Collection Strategy

Effective data collection is the foundation of network traffic analysis. Collection strategies should consider collection location selection, collection technologies, data filtering and sampling, storage and management, as well as performance considerations. For example, data collection can be performed at network boundaries, key internal network nodes, security devices, and endpoints. Collection technologies include full traffic mirroring, NetFlow/IPFIX, log collection, and probe deployment. Data filtering and sampling technologies include real-time filtering, intelligent sampling, and key retention. In terms of storage and management, tiered storage, data compression, and encryption protection should be adopted, while formulating data retention and destruction policies.

Example of Data Collection Architecture

Analysis Workflow Design

The analysis workflow design for network traffic analysis includes data preprocessing, feature extraction, behaviour analysis, threat detection, alert generation and prioritization, response and investigation, and reporting and feedback. Data preprocessing involves data cleaning, format standardization, and data enrichment. Feature extraction includes basic network features, statistical features, time-series features, and application-layer features. Steps such as behaviour analysis, threat detection, and alert generation are built on the basis of feature extraction and are carried out through rule-based detection, anomaly detection, and heuristic detection methods.

Layered Design of Detection Mechanisms

To improve detection accuracy and coverage, a layered detection mechanism should be adopted, including a rule-based layer, statistical analysis layer, machine learning layer, behaviour analysis layer, and threat intelligence integration layer. Each layer has its unique detection method and focus, ranging from rule matching to complex machine learning models, and further to behaviour analysis and threat intelligence integration. Below is a Python code example showing how to implement a multi-layered detection mechanism:

<span>import numpy as np</span>
<span>import numpy as np</span>
<span>import numpy as np</span>

Response Mechanism Design

An effective response mechanism is a key component of a network traffic analysis system. Response mechanism design includes response level division, automated response workflows, manual analysis workflows, collaboration and escalation mechanisms, as well as documentation and reporting. Response levels can range from low to high, covering log monitoring, automated response, and manual intervention. Automated response workflows should define trigger conditions, design response actions, and implement feedback loops. Manual analysis workflows involve alert classification, context enrichment, root cause analysis, and incident response. Collaboration and escalation mechanisms ensure cross-team collaboration and information sharing, while documentation and reporting record the incident handling process and lessons learned. Below is a simplified response mechanism workflow diagram:

▌Traffic Analysis Foundational Technologies

Foundational traffic analysis technologies are core components of cybersecurity and network management. These technologies provide the basis for more advanced analysis methods and are crucial for understanding network behaviour, detecting anomalies, and optimizing performance.

Packet Capture Technology

Packet capture is the foundation of traffic analysis, allowing the capture and inspection of raw packets transmitted in the network. Main packet capture technologies include NIC promiscuous mode, port mirroring, and Network Test Access Point (TAP).

<span><span>from</span> scapy.all <span>import</span> *</span>
<span><span>from</span> scapy.all <span>import</span> *</span>
<span><span>from</span> scapy.all <span>import</span> *</span>

Protocol Analysis

Protocol analysis involves parsing various protocol layers of network packets, which is essential for understanding the content and behaviour of network communications. It mainly includes link-layer protocols, network-layer protocols, transport-layer protocols, and application-layer protocols.

Traffic Statistics and Visualization

Traffic statistics and visualization are key to understanding network behaviour. They help network administrators quickly identify anomalous patterns and potential issues. Common statistical metrics include traffic throughput, packet count, protocol distribution, source/destination IP address distribution, and port usage.

Traffic Classification Technology

Traffic classification is the process of identifying and categorizing network traffic. It is essential for network management, security analysis, and Quality of Service (QoS) management. Main traffic classification methods include port-based classification, payload-based classification, behaviour-based classification, statistical-based classification, and machine learning-based classification.

Traffic Sampling Technology

In high-speed network environments, processing all traffic data can cause performance bottlenecks. Traffic sampling technology allows us to reduce the volume of data that needs to be processed while maintaining data representativeness. Main traffic sampling technologies include systematic sampling, random sampling, and stratified sampling.

Stream Reassembly Technology

Stream reassembly is the process of recombining packets belonging to the same session into a complete data stream. This is crucial for deep analysis of application-layer protocols and detecting attack patterns that span multiple packets. Key steps include session identification, packet ordering, handling retransmissions and overlaps, and reassembling data.

Protocol Parsing and Content Extraction

Protocol parsing is a key step in traffic analysis, involving a deep understanding of the structure and semantics of various network protocols. Content extraction is the retrieval of valuable information from parsed protocol data. This is very important for security analysis, performance optimization, and understanding application behaviour.

<span><span>import</span> re</span>
<span><span>import</span> re</span>
<span><span>import</span> re</span>

Anomaly Detection Technology

Anomaly detection is an important part of traffic analysis, helping to identify anomalous behaviour and potential threats in the network. Common anomaly detection methods include statistical-based methods, machine learning-based methods, and rule-based methods.

▌Advanced Traffic Analysis Technologies

Modern traffic analysis has gone far beyond simple statistics and rule matching, introducing a variety of advanced analysis technologies.

Deep Packet Inspection (DPI)

Deep Packet Inspection (DPI) is an advanced network packet analysis technology that can inspect the full content of packets, including application-layer data. The implementation of DPI involves various complex technologies, such as regular expression matching, decision trees, finite state machines, and deep learning models.

Machine Learning Models

The application of machine learning in traffic analysis is increasingly widespread, including supervised learning, unsupervised learning, and deep learning. These models can be used for the classification and detection of known threats, anomaly detection, network behaviour clustering, and complex pattern recognition.

Graph Analysis

Graph analysis technology plays an important role in cybersecurity, particularly in analysing network topology and communication patterns. Application scenarios include detecting botnets, identifying Advanced Persistent Threats (APTs), and visualizing network traffic.

<span><span>import</span> networkx <span>as</span> nx</span>
<span><span>import</span> networkx <span>as</span> nx</span>
<span><span>import</span> networkx <span>as</span> nx</span>

Time-Series Analysis

Time-series analysis is widely used in network traffic analysis, especially in identifying traffic patterns and predicting future trends. Application scenarios include identifying periodic traffic patterns, predicting network loads, and detecting anomalous traffic fluctuations.

Natural Language Processing (NLP)

Although not a traditional traffic analysis technology, NLP plays an important role in analysing textual information in log files and packet payloads. Application scenarios include analysing anomalous patterns in log files, detecting malicious commands in packets, and identifying covert channels in network communications.

<span><span>import</span> nltk</span>
<span><span>import</span> nltk</span>
<span><span>import</span> nltk</span>

▌Traffic Analysis Challenges and Mitigation Strategies

Despite the continuous development of traffic analysis technology, it still faces some challenges. Understanding these challenges and formulating corresponding mitigation strategies is crucial for the effective implementation of traffic analysis.

Explosive Growth in Data Volume

Challenge: With the expansion of network scale and the popularization of IoT devices, the volume of data that needs to be processed is growing exponentially. Mitigation Strategies:

  1. Distributed Processing: Utilize big data technologies such as Hadoop and Spark for distributed data processing.

  2. Data Sampling: Adopt intelligent sampling technologies to reduce data volume while ensuring analytical accuracy.

  3. Edge Computing: Perform preliminary data processing and filtering at the network edge to relieve pressure on central nodes.

Encrypted Traffic Analysis

Challenge: With the popularization of HTTPS, most network traffic is encrypted, rendering traditional content-based analysis methods ineffective. Mitigation Strategies:

  1. TLS Fingerprinting: Analyse features in the TLS handshake process, such as cipher suites, certificate information, etc.

  2. Traffic Feature Analysis: Analyse based on statistical features of traffic (such as packet size, time intervals).

  3. Machine Learning Models: Use machine learning algorithms to identify patterns in encrypted traffic.

Real-Time Requirements

Challenge: Network attacks occur faster and faster, requiring analysis systems to respond in real time. Mitigation Strategies:

  1. Stream Processing Technology: Use stream processing frameworks such as Apache Flink and Kafka Streams.

  2. In-Memory Computing: Utilize in-memory databases like Redis for high-speed data processing.

  3. GPU Acceleration: Use GPUs for parallel computing to accelerate complex analysis tasks.

False Positives and False Negatives

Challenge: Traffic analysis systems often face high rates of false positives or miss important events (false negatives). Mitigation Strategies:

  1. Multi-source Data Fusion: Combine multiple data sources such as network traffic, logs, and threat intelligence.

  2. Context-Aware Analysis: Consider contextual information such as network environment and user behaviour.

  3. Continuous Rule Optimization: Adjust and optimize detection rules continuously based on feedback.

  4. Introduce Artificial Intelligence: Use machine learning models to improve detection accuracy.

▌Traffic Analysis Application and Practical Case Studies

APT Attack Detection and Response Case Study

A large financial institution detected suspicious network activities during its daily security operations. The security team suspected they might be facing an Advanced Persistent Threat (APT) attack and needed to use traffic analysis technologies for in-depth investigation and response. The security team adopted a multi-layered traffic analysis approach to detect and respond to the APT attack, including anomalous traffic pattern identification, DNS traffic analysis, encrypted traffic analysis, and lateral movement detection.

Supply Chain Attack Detection Case Study

In early 2021, the security team of a large manufacturing enterprise received a notification from the national CERT warning that the enterprise might have fallen victim to an advanced supply chain attack. This attack was associated with a well-known APT group that infiltrated the network of a software vendor to plant a backdoor in a legitimate software update. The Blue Team response workflow included emergency assessment, preliminary traffic analysis, deep traffic inspection, custom detection rules, and behaviour analysis. Through these steps, the security team was able to confirm the attack and take countermeasures.

▌Conclusion

Network traffic analysis is a continuously evolving field. As technology advances and the threat landscape changes, security experts need to constantly update their knowledge and skills to effectively protect organizations from cyber threats. By combining foundational technologies and advanced analytical methods, security teams can improve detection accuracy, reduce false positives and false negatives, and thereby better protect critical assets and data.

▶▶▶ For more detailed content, please download the Blue Team Handbook ⑨ [Traffic Analysis Edition] Network Traffic Analysis Practical Methodology: From Theory to Practice to get the full report.