File size: 3,861 Bytes
27f6252
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
# CVE-to-TTP Mapper Module

This module implements CVE-to-TTP (Tactics, Techniques, and Procedures) mapping and inference using two complementary approaches:

1. **CWE-based Mapping**: Uses the existing CWE→CAPEC→TTP mappings generated by the data collection pipeline
2. **TIE Inference**: Uses the [Technique Inference Engine](https://github.com/center-for-threat-informed-defense/technique-inference-engine)  to infer TTPs from CVE descriptions

## Prerequisites

1. **Run the data collection pipeline first** to generate CWE-CAPEC-MITRE mappings:
   ```bash

   python -m src.collectors.main_collector --download

   python -m src.collectors.main_collector --convert

   ```

2. **Install NumPy** (optional, for TIE inference):
   ```bash

   pip install numpy

   ```

3. **Download MITRE ATT&CK data** (required for TIE inference):
   ```bash

   # Run the setup script to download missing data

   python src/mapper/setup_mapper.py

   

   # Or download manually:

   wget https://raw.githubusercontent.com/mitre-attack/attack-stix-data/master/enterprise-attack/enterprise-attack.json -O src/mapper/tie_models/enterprise-attack.json

   ```

## Usage

### 1. As a Python Module

```python

from src.mapper.cve_ttp_mapper import CVEtoTTPMapper

from src.mapper.mapper_config import MapperConfig



# Initialize mapper

config = MapperConfig()

mapper = CVEtoTTPMapper(config)



# Map a single CVE

cve_data = {

    "id": "CVE-2021-44228",

    "description": "Apache Log4j2 JNDI injection vulnerability...",

    "cwe_ids": ["CWE-502", "CWE-20"]

}



result = mapper.map_cve_to_ttps(cve_data)

print(f"Found TTPs: {result['ttps']}")

```

### 2. Command-Line Interface

```bash

# Map a single CVE

python -m src.mapper.mapper_cli single CVE-2021-44228 \

    --description "Remote code execution vulnerability" \

    --cwe CWE-502 --cwe CWE-20



# Process a CVE file

python -m src.mapper.mapper_cli file path/to/cve_data.json \

    --output path/to/mappings.json



# Batch process multiple files

python -m src.mapper.mapper_cli batch path/to/cve_directory \

    --pattern "*.json" \

    --output path/to/output_dir

```

### 3. Test the Module

```bash

# Run the test suite

python src/mapper/test_simple_mapper.py

```

### 4. Batch Processing

```bash

# Process CVE data and generate mappings

python src/mapper/run_cve_ttp_mapping.py

```

## How It Works

### CWE-based Mapping (Direct)
1. Extracts CWE IDs from CVE data
2. Uses pre-computed CWE→CAPEC→TTP mappings
3. Returns all TTPs associated with the CVE's weaknesses

### TIE Inference (ML-based)
1. Extracts keywords from CVE description that indicate techniques
2. Uses pre-trained TIE model to infer related techniques
3. Returns predicted TTPs with confidence scores

### Combined Approach
The mapper combines both methods:
- First applies CWE-based mapping for direct associations
- Then uses TIE to infer additional TTPs from the description
- Deduplicates and returns comprehensive results

## Output Format

```json

{

  "cve_id": "CVE-2021-44228",

  "ttps": ["T1190", "T1059", "T1203"],

  "methods_used": ["CWE-to-CAPEC-to-TTP", "TIE-inference"],

  "total_ttps_found": 3,

  "details": {

    "cwe_mapping": {

      "method": "CWE-to-CAPEC-to-TTP",

      "mappings": [

        {

          "cwe": "CWE-502",

          "capecs": ["CAPEC-586"],

          "ttps": ["T1203"]

        }

      ]

    },

    "tie_inference": {

      "method": "tie_inference",

      "keyword_ttps": ["T1190"],

      "inferred_ttps": ["T1059"],

      "confidence_scores": {

        "T1059": 0.85

      }

    }

  },

  "mapping_timestamp": "2024-01-01T12:00:00"

}

```

## Configuration

Edit `mapper_config.py` to customize:
- TIE confidence threshold
- Maximum predictions per CVE
- Input/output paths