Skip to content

Commit 6f92066

Browse files
Create attack flow (#118)
* implement content-check for muchdogesec/obstracts#131 * --- * version bump * initial --create_attack_flow impl #111 * add boolean to return value * add `incident_classification` to content-check #131 * renaming content check * bump stix2extension version * bumping requirements * Update cases-standard-tests.md * adding better demos * changing flag name * updating tests * add flow objects to main bundle #120 * tuning some extractions --------- Co-authored-by: David G <[email protected]>
1 parent 747ef1e commit 6f92066

File tree

15 files changed

+416
-153
lines changed

15 files changed

+416
-153
lines changed

README.md

+4-2
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ The following arguments are available:
9090

9191
How the extractions are performed
9292

93-
* `--use_extractions` (REQUIRED): if you only want to use certain extraction types, you can pass their slug found in either `includes/ai/config.yaml`, `includes/lookup/config.yaml` `includes/pattern/config.yaml` (e.g. `pattern_ipv4_address_only`). Default if not passed, no extractions applied. You can also pass a catch all wildcard `*` which will match all extraction paths (e.g. `pattern_*` would run all extractions starting with `pattern_`)
93+
* `--use_extractions` (REQUIRED): if you only want to use certain extraction types, you can pass their slug found in either `includes/ai/config.yaml`, `includes/lookup/config.yaml` `includes/pattern/config.yaml` (e.g. `pattern_ipv4_address_only`). Default if not passed, no extractions applied. You can also pass a catch all wildcard `*` which will match all extraction paths (e.g. `'pattern_*'` would run all extractions starting with `pattern_` -- make sure to use quotes when using a wildcard)
9494
* Important: if using any AI extractions (`ai_*`), you must set an AI API key in your `.env` file
9595
* Important: if you are using any MITRE ATT&CK, CAPEC, CWE, ATLAS or Location extractions you must set `CTIBUTLER` or NVD CPE or CVE extractions you must set `VULMATCH` settings in your `.env` file
9696
* `--relationship_mode` (REQUIRED): either.
@@ -110,11 +110,13 @@ If any AI extractions, or AI relationship mode is set, you must set the followin
110110
* Provider (env var required `OPENAI_API_KEY`): `openai:`, models e.g.: `gpt-4o`, `gpt-4o-mini`, `gpt-4-turbo`, `gpt-4` ([More here](https://platform.openai.com/docs/models))
111111
* Provider (env var required `ANTHROPIC_API_KEY`): `anthropic:`, models e.g.: `claude-3-5-sonnet-latest`, `claude-3-5-haiku-latest`, `claude-3-opus-latest` ([More here](https://docs.anthropic.com/en/docs/about-claude/models))
112112
* Provider (env var required `GOOGLE_API_KEY`): `gemini:models/`, models: `gemini-1.5-pro-latest`, `gemini-1.5-flash-latest` ([More here](https://ai.google.dev/gemini-api/docs/models/gemini))
113-
* Provider (env var required `DEEPSEEK_API_KEY`): `deepseek:`, models `deepseek-chat` ([More here](https://api-docs.deepseek.com/quick_start/pricing))
113+
* Provider (env var required `DEEPSEEK_API_KEY`): `deepseek:`, models `deepseek-chat` ([More here](https://api-docs.deepseek.com/quick_start/pricing))
114114
* See `tests/manual-tests/cases-ai-extraction-type.md` for some examples
115115
* `--ai_settings_relationships`:
116116
* similar to `ai_settings_extractions` but defines the model used to generate relationships. Only one model can be provided. Passed in same format as `ai_settings_extractions`
117117
* See `tests/manual-tests/cases-ai-relationships.md` for some examples
118+
* `--ai_check_content`: Passing this flag will get the AI to try and classify the text in the input to 1) determine if it is talking about threat intelligence, and 2) what type of threat intelligence it is talking about. For context, we use this to filter out non-threat intel posts in Obstracts and Stixify. You pass `provider:model` with this flag to determine the AI model you wish to use to perform the check.
119+
* `--ai_create_attack_flow`: passing this flag will also prompt the AI model (the same entered for `--ai_settings_relationships`) to generate an [Attack Flow](https://center-for-threat-informed-defense.github.io/attack-flow/) for the MITRE ATT&CK extractions to define the logical order in which they are being described. You must pass `--ai_settings_relationships` for this to work.
118120

119121
## Adding new extractions
120122

includes/extractions/ai/config.yaml

+5-5
Original file line numberDiff line numberDiff line change
@@ -725,7 +725,7 @@ ai_mitre_attack_enterprise:
725725
version: 1.0.0
726726
prompt_base: 'Extract all references to MITRE ATT&CK Enterprise tactics, techniques, groups, data sources, mitigations, software, and campaigns described in the text. These references may not be explicit in the text so you should be careful to account for the natural language of the text your analysis. Do not include MITRE ATT&CK ICS or MITRE ATT&CK Mobile in the results.'
727727
prompt_helper: 'If you are unsure, you can learn more about MITRE ATT&CK Enterprise here: https://attack.mitre.org/matrices/enterprise/'
728-
prompt_conversion: 'Convert all extractions into the corresponding ATT&CK ID.'
728+
prompt_conversion: 'You should respond with only the ATT&CK ID.'
729729
test_cases: ai_mitre_attack_enterprise
730730
stix_mapping: ctibutler-mitre-attack-enterprise-id
731731

@@ -740,7 +740,7 @@ ai_mitre_attack_mobile:
740740
version: 1.0.0
741741
prompt_base: 'Extract all references to MITRE ATT&CK Mobile tactics, techniques, groups, data sources, mitigations, software, and campaigns described in the text. These references may not be explicit in the text so you should be careful to account for the natural language of the text your analysis. Do not include MITRE ATT&CK ICS or MITRE ATT&CK Enterprise in the results.'
742742
prompt_helper: 'If you are unsure, you can learn more about MITRE ATT&CK Enterprise here: https://attack.mitre.org/matrices/mobile/'
743-
prompt_conversion: 'Convert all extractions into the corresponding ATT&CK ID.'
743+
prompt_conversion: 'You should respond with only the ATT&CK ID.'
744744
test_cases: ai_mitre_attack_mobile
745745
stix_mapping: ctibutler-mitre-attack-mobile-id
746746

@@ -755,7 +755,7 @@ ai_mitre_attack_ics:
755755
version: 1.0.0
756756
prompt_base: 'Extract all references to MITRE ATT&CK ICS tactics, techniques, groups, data sources, mitigations, software, and campaigns described in the text. These references may not be explicit in the text so you should be careful to account for the natural language of the text your analysis. Do not include MITRE ATT&CK Mobile or MITRE ATT&CK Enterprise in the results.'
757757
prompt_helper: 'If you are unsure, you can learn more about MITRE ATT&CK Enterprise here: https://attack.mitre.org/matrices/ics/'
758-
prompt_conversion: 'Convert all extractions into the corresponding ATT&CK ID.'
758+
prompt_conversion: 'You should respond with only the ATT&CK ID.'
759759
test_cases: ai_mitre_attack_ics
760760
stix_mapping: ctibutler-mitre-attack-ics-id
761761

@@ -772,7 +772,7 @@ ai_mitre_capec:
772772
version: 1.0.0
773773
prompt_base: 'Extract all references to a MITRE CAPEC object from the text.'
774774
prompt_helper: 'If you are unsure, you can learn more about MITRE CAPEC here: https://capec.mitre.org/'
775-
prompt_conversion: 'Convert all extractions into the corresponding CAPEC ID in the format `CAPEC-ID`'
775+
prompt_conversion: 'You should respond with only the CAPEC ID.'
776776
test_cases: ai_mitre_capec
777777
stix_mapping: ctibutler-mitre-capec-id
778778

@@ -789,7 +789,7 @@ ai_mitre_cwe:
789789
version: 1.0.0
790790
prompt_base: 'Extract all references to a MITRE CWE object from the text.'
791791
prompt_helper: 'If you are unsure, you can learn more about MITRE CAPEC here: https://cwe.mitre.org/'
792-
prompt_conversion: 'Convert all extractions into the corresponding CWE ID in the format `CWE-ID`'
792+
prompt_conversion: 'You should respond with only the CWE ID.'
793793
test_cases: ai_mitre_cwe
794794
stix_mapping: ctibutler-mitre-cwe-id
795795

includes/tests/test_cases.yaml

+10-10
Original file line numberDiff line numberDiff line change
@@ -492,8 +492,8 @@ ai_mitre_attack_enterprise:
492492
- 'T1053.005' # attack-pattern--005a06c6-14bf-4118-afa0-ebcd8aebb0c9
493493
- 'T1040' # attack-pattern--3257eb21-f9a7-4430-8de1-d8b6e288f529 , course-of-action--46b7ef91-4e1d-43c5-a2eb-00fa9444f6f4
494494
- 'TA0003' # x-mitre-tactic--5bc1d813-693e-4823-9961-abf9af4b0e92
495-
- 'Rundll32' # attack-pattern--045d0922-2310-4e60-b5e4-3302302cb3c5
496-
- 'OS Credential Dumping' # attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22
495+
# hidden as causes ai to get confused - 'Rundll32' # attack-pattern--045d0922-2310-4e60-b5e4-3302302cb3c5
496+
# hidden as causes ai to get confused - 'OS Credential Dumping' # attack-pattern--0a3ead4e-6d47-4ccb-854c-a6a4f9d96b22
497497
test_negative_examples:
498498
-
499499

@@ -520,8 +520,8 @@ ai_mitre_attack_mobile:
520520
- 'S0505' # malware--3271c107-92c4-442e-9506-e76d62230ee8
521521
- 'T1630.001' # attack-pattern--0cdd66ad-26ac-4338-a764-4972a1e17ee3
522522
- 'TA0029' # x-mitre-tactic--3e962de5-3280-43b7-bc10-334fbc1d6fa8
523-
- 'Impair Defenses' # attack-pattern--20b0931a-8952-42ca-975f-775bad295f1a
524-
- 'Call Log' # attack-pattern--1d1b1558-c833-482e-aabb-d07ef6eae63d
523+
# hidden as causes ai to get confused - 'Impair Defenses' # attack-pattern--20b0931a-8952-42ca-975f-775bad295f1a
524+
# hidden as causes ai to get confused - 'Call Log' # attack-pattern--1d1b1558-c833-482e-aabb-d07ef6eae63d
525525
test_negative_examples:
526526
-
527527

@@ -541,8 +541,8 @@ generic_mitre_attack_ics_name:
541541
ai_mitre_attack_ics:
542542
test_positive_examples:
543543
- 'TA0111' # x-mitre-tactic--33752ae7-f875-4f43-bdb6-d8d02d341046
544-
- 'Scripting' # attack-pattern--2dc2b567-8821-49f9-9045-8740f3d0b958
545-
- 'Program Upload' # attack-pattern--3067b85e-271e-4bc5-81ad-ab1a81d411e3
544+
# hidden as causes ai to get confused - 'Scripting' # attack-pattern--2dc2b567-8821-49f9-9045-8740f3d0b958
545+
# hidden as causes ai to get confused - 'Program Upload' # attack-pattern--3067b85e-271e-4bc5-81ad-ab1a81d411e3
546546
test_negative_examples:
547547

548548
####### MITRE CAPEC #######
@@ -567,8 +567,8 @@ generic_mitre_capec_name:
567567
ai_mitre_capec:
568568
test_positive_examples:
569569
- 'CAPEC-110' # attack-pattern--7c90bef7-530c-427b-8fb7-f9d3eda9c26a
570-
- 'Clickjacking' # attack-pattern--ec41b2b3-a3b6-4af0-be65-69e82907dfef
571-
- 'Overflow Buffers' # attack-pattern--77e51461-7843-411c-a90e-852498957f76
570+
# hidden as causes ai to get confused - 'Clickjacking' # attack-pattern--ec41b2b3-a3b6-4af0-be65-69e82907dfef
571+
# hidden as causes ai to get confused - 'Overflow Buffers' # attack-pattern--77e51461-7843-411c-a90e-852498957f76
572572
test_negative_examples:
573573
-
574574

@@ -596,8 +596,8 @@ ai_mitre_cwe:
596596
test_positive_examples:
597597
- 'CWE-1023' # weakness--c122031a-5735-54f2-a80b-194da3a2c0e6
598598
- 'CWE-102' # weakness--ad5b3e38-fdf2-5c97-90da-30dad0f1f016
599-
- 'Use of Redundant Code' # weakness--6dfb4e56-706d-5243-a3eb-6d4e49b16389
600-
- 'Insufficient Encapsulation' # weakness--b0a3b7a9-fefa-5435-8336-4d2e019597f8
599+
# hidden as causes ai to get confused - 'Use of Redundant Code' # weakness--6dfb4e56-706d-5243-a3eb-6d4e49b16389
600+
# hidden as causes ai to get confused - 'Insufficient Encapsulation' # weakness--b0a3b7a9-fefa-5435-8336-4d2e019597f8
601601
test_negative_examples:
602602

603603
####### MITRE ATLAS #######

pyproject.toml

+2-2
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ build-backend = "hatchling.build"
44

55
[project]
66
name = "txt2stix"
7-
version = "0.0.1b5"
7+
version = "0.0.2"
88
authors = [{ name = "DOGESEC", email = "[email protected]" }]
99
description = "txt2stix is a Python script that is designed to identify and extract IoCs and TTPs from text files, identify the relationships between them, convert them to STIX 2.1 objects, and output as a STIX 2.1 bundle."
1010
readme = "README.md"
@@ -23,7 +23,7 @@ dependencies = [
2323
"requests==2.32.3",
2424
"python-dotenv>=1.0.1",
2525
"schwifty>=2024.6.1",
26-
"stix2extensions @ https://github.com/muchdogesec/stix2extensions/archive/main.zip",
26+
"stix2extensions @ https://github.com/muchdogesec/stix2extensions/releases/download/main-2025-02-12-06-23-37/stix2extensions-0.0.3-py3-none-any.whl",
2727
"tld>=0.13",
2828
"tldextract>=5.1.2",
2929
"validators>=0.28.3",

requirements.txt

+2-2
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,6 @@ sniffio==1.3.1; python_version >= '3.7'
5151
sqlalchemy==2.0.30; python_version >= '3.7'
5252
stix2==3.0.1; python_version >= '3.6'
5353
stix2-patterns==2.0.0; python_version >= '3.6'
54-
https://github.com/muchdogesec/stix2extensions/archive/main.zip
5554
tenacity==8.3.0; python_version >= '3.8'
5655
tiktoken==0.7.0; python_version >= '3.8'
5756
tld==0.13; python_version >= '3.7' and python_version < '4'
@@ -63,4 +62,5 @@ validators==0.28.3; python_version >= '3.8'
6362
yarl==1.9.4; python_version >= '3.7'
6463
zipp==3.19.1; python_version >= '3.8'
6564
llama-index==0.10.51; python_version >= '3.8'
66-
base58>=2.1.1; python_version >= '3.8'
65+
base58>=2.1.1; python_version >= '3.8'
66+
stix2extensions @ https://github.com/muchdogesec/stix2extensions/releases/download/main-2025-02-12-06-23-37/stix2extensions-0.0.3-py3-none-any.whl
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
Victims receive spear phishing emails with from [email protected] malicious zip files attached named badfile.zip
2+
3+
Due to password protection, the zip files are able to bypass some AV detections.
4+
5+
The zip files are extracted and usually contain a malicious document, such as a .doc, .pdf, or .xls. Some examples are malware.pdf and bad.com
6+
7+
The extracted files contain malicious macros that connect to a C2 server 1.1.1.1

tests/manual-tests/cases-standard-tests.md

+46
Original file line numberDiff line numberDiff line change
@@ -362,4 +362,50 @@ python3 txt2stix.py \
362362
--confidence 100 \
363363
--use_extractions lookup_disarm_name \
364364
--report_id 8cb2dbf0-136f-4ecb-995c-095496e22abc
365+
```
366+
367+
### ai check content
368+
369+
```shell
370+
python3 txt2stix.py \
371+
--relationship_mode standard \
372+
--input_file tests/data/extraction_types/all_cases.txt \
373+
--name 'Test AI Content check' \
374+
--tlp_level clear \
375+
--confidence 100 \
376+
--use_extractions 'pattern_*' \
377+
--ai_content_check openai:gpt-4o \
378+
--report_id 4fa18f2d-278b-4fd4-8470-62a8807d35ad
379+
```
380+
381+
### attack flow demo
382+
383+
no indicators
384+
385+
```shell
386+
python3 txt2stix.py \
387+
--relationship_mode standard \
388+
--ai_settings_relationships openai:gpt-4o \
389+
--input_file tests/data/manually_generated_reports/attack_flow_demo.txt \
390+
--name 'Test MITRE ATT&CK Flow demo' \
391+
--tlp_level clear \
392+
--confidence 100 \
393+
--use_extractions 'ai_mitre_attack_enterprise' \
394+
--ai_create_attack_flow \
395+
--report_id c0fef67c-720b-4184-a62e-ea465b4d89b5
396+
```
397+
398+
with indicators
399+
400+
```shell
401+
python3 txt2stix.py \
402+
--relationship_mode standard \
403+
--ai_settings_relationships openai:gpt-4o \
404+
--input_file tests/data/manually_generated_reports/attack_flow_demo.txt \
405+
--name 'Test MITRE ATT&CK Flow demo with iocs' \
406+
--tlp_level clear \
407+
--confidence 100 \
408+
--use_extractions ai_mitre_attack_enterprise,'pattern_*' \
409+
--ai_create_attack_flow \
410+
--report_id 3b160a8d-12dd-4e7c-aee8-5af6e371b425
365411
```

0 commit comments

Comments
 (0)