txt2detection 0.0.2rc12__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of txt2detection might be problematic. Click here for more details.

Files changed (54) hide show
  1. txt2detection-0.0.2rc12/.env.example +14 -0
  2. txt2detection-0.0.2rc12/.env.markdown +46 -0
  3. txt2detection-0.0.2rc12/.github/workflows/create-release.yml +71 -0
  4. txt2detection-0.0.2rc12/.github/workflows/run-tests.yml +51 -0
  5. txt2detection-0.0.2rc12/.gitignore +7 -0
  6. txt2detection-0.0.2rc12/LICENSE +202 -0
  7. txt2detection-0.0.2rc12/PKG-INFO +199 -0
  8. txt2detection-0.0.2rc12/README.md +168 -0
  9. txt2detection-0.0.2rc12/config/detection_languages.yaml +14 -0
  10. txt2detection-0.0.2rc12/docs/README.md +527 -0
  11. txt2detection-0.0.2rc12/docs/txt2detection.png +0 -0
  12. txt2detection-0.0.2rc12/pyproject.toml +51 -0
  13. txt2detection-0.0.2rc12/requirements.txt +358 -0
  14. txt2detection-0.0.2rc12/tests/files/CVE-2024-56520.txt +5 -0
  15. txt2detection-0.0.2rc12/tests/files/EC2-exfil.txt +1 -0
  16. txt2detection-0.0.2rc12/tests/files/observables.txt +23 -0
  17. txt2detection-0.0.2rc12/tests/files/sigma-rule-custom-tags.yml +31 -0
  18. txt2detection-0.0.2rc12/tests/files/sigma-rule-existing-related.yml +33 -0
  19. txt2detection-0.0.2rc12/tests/files/sigma-rule-master.yml +30 -0
  20. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-author.yml +29 -0
  21. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-date.yml +28 -0
  22. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-description.yml +29 -0
  23. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-level.yml +29 -0
  24. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-license.yml +29 -0
  25. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-status.yml +29 -0
  26. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-tags.yml +25 -0
  27. txt2detection-0.0.2rc12/tests/files/sigma-rule-no-title.yml +29 -0
  28. txt2detection-0.0.2rc12/tests/files/sigma-rule-observables.yml +30 -0
  29. txt2detection-0.0.2rc12/tests/files/sigma-rule-one-date.yml +29 -0
  30. txt2detection-0.0.2rc12/tests/manual-tests/README.md +448 -0
  31. txt2detection-0.0.2rc12/tests/src/__init__.py +0 -0
  32. txt2detection-0.0.2rc12/tests/src/requirements.txt +5 -0
  33. txt2detection-0.0.2rc12/tests/src/test_bundler.py +240 -0
  34. txt2detection-0.0.2rc12/tests/src/test_main.py +137 -0
  35. txt2detection-0.0.2rc12/tests/src/test_main_run_txt2detction.py +61 -0
  36. txt2detection-0.0.2rc12/tests/src/test_models.py +238 -0
  37. txt2detection-0.0.2rc12/tests/src/test_observables.py +96 -0
  38. txt2detection-0.0.2rc12/tests/src/test_utils.py +31 -0
  39. txt2detection-0.0.2rc12/txt2detection/__init__.py +2 -0
  40. txt2detection-0.0.2rc12/txt2detection/__main__.py +189 -0
  41. txt2detection-0.0.2rc12/txt2detection/ai_extractor/__init__.py +16 -0
  42. txt2detection-0.0.2rc12/txt2detection/ai_extractor/anthropic.py +12 -0
  43. txt2detection-0.0.2rc12/txt2detection/ai_extractor/base.py +57 -0
  44. txt2detection-0.0.2rc12/txt2detection/ai_extractor/deepseek.py +19 -0
  45. txt2detection-0.0.2rc12/txt2detection/ai_extractor/gemini.py +18 -0
  46. txt2detection-0.0.2rc12/txt2detection/ai_extractor/openai.py +20 -0
  47. txt2detection-0.0.2rc12/txt2detection/ai_extractor/openrouter.py +20 -0
  48. txt2detection-0.0.2rc12/txt2detection/ai_extractor/prompts.py +116 -0
  49. txt2detection-0.0.2rc12/txt2detection/ai_extractor/utils.py +19 -0
  50. txt2detection-0.0.2rc12/txt2detection/bundler.py +283 -0
  51. txt2detection-0.0.2rc12/txt2detection/models.py +391 -0
  52. txt2detection-0.0.2rc12/txt2detection/observables.py +186 -0
  53. txt2detection-0.0.2rc12/txt2detection/utils.py +81 -0
  54. txt2detection-0.0.2rc12/txt2detection.py +19 -0
@@ -0,0 +1,14 @@
1
+ ## AI Settings
2
+ INPUT_TOKEN_LIMIT=
3
+ OPENAI_API_KEY=
4
+ ANTHROPIC_API_KEY=
5
+ GOOGLE_API_KEY=
6
+ OPENROUTER_API_KEY=
7
+ DEEPSEEK_API_KEY=
8
+ TEMPERATURE=
9
+ ## CTIBUTLER
10
+ CTIBUTLER_BASE_URL=
11
+ CTIBUTLER_API_KEY=
12
+ ## VULMATCH
13
+ VULMATCH_BASE_URL=
14
+ VULMATCH_API_KEY=
@@ -0,0 +1,46 @@
1
+ # Environment file info
2
+
3
+ If you're running in production, you should set these securely.
4
+
5
+ However, if you just want to experiment, set the following values
6
+
7
+ ## AI Settings
8
+
9
+ * `INPUT_TOKEN_LIMIT`: `15000`
10
+ * (REQUIRED IF USING AI MODES) Ensure the input/output token count meets requirements and is supported by the model selected. Will not allow files with more than tokens specified to be processed
11
+ * `TEMPERATURE`: `0.0`
12
+ * The temperature value ranges from 0 to 2, with lower values indicating greater determinism and higher values indicating more randomness in responses.
13
+
14
+ **A small note on selecting a provider**
15
+
16
+ Below are the models you can use. We highly recommend using [OpenRouter](https://openrouter.ai/) (`OPENROUTER_API_KEY`) which gives you access to a wide range of models / providers. There is no benefit in function to using one provider over another (the txt2detection logic is the same for all). We provide the option to use provider supplied API keys (e.g. `OPENAI_API_KEY`) for those who cannot / do not want to use OpenRouter.
17
+
18
+ * `OPENROUTER_API_KEY`=
19
+ * (REQUIRED IF USING MODELS PROVIDED BY OPENROUTER IN AI MODES) get it from: https://openrouter.ai/settings/keys
20
+ * `DEEPSEEK_API_KEY`=
21
+ * (REQUIRED IF USING DEEPSEEK MODELS DIRECTLY IN AI MODES) get it from: https://platform.deepseek.com/api-key
22
+ * `OPENAI_API_KEY`: YOUR_API_KEY
23
+ * (REQUIRED IF USING OPENAI MODELS DIRECTLY IN AI MODES) get it from: https://platform.openai.com/api-keys
24
+ * `ANTHROPIC_API_KEY`: YOUR_API_KEY
25
+ * (REQUIRED IF USING ANTHROPIC MODELS DIRECTLY IN AI MODES) get it from" https://console.anthropic.com/settings/keys
26
+ * `GOOGLE_API_KEY`:
27
+ * (REQUIRED IF USING GOOGLE GEMINI MODELS DIRECTLY IN AI MODES) get it from the Google Cloud Platform (making sure the Gemini API is enabled for the project)
28
+
29
+ ## CTIBUTLER
30
+
31
+ txt2detection requires [ctibutler](https://github.com/muchdogesec/ctibutler) to lookup ATT&CK
32
+
33
+ * `CTIBUTLER_BASE_URL`: `'http://api.ctibutler.com'` (recommended)
34
+ * If you are running CTI Butler locally, be sure to set `'http://host.docker.internal:8006/api/'` in the `.env` file otherwise you will run into networking errors.
35
+ * `CTIBUTLER_BASE_URL`:
36
+ * If using `'http://api.ctibutler.com'`, [get your API key here](http://app.ctibutler.com). Can be left blank if running locally.
37
+
38
+
39
+ ## VULMATCH
40
+
41
+ txt2detection requires [vulmatch](https://github.com/muchdogesec/vulmatch) to lookup CVE IDs
42
+
43
+ * `VULMATCH_BASE_URL`: `'http://api.vulmatch.com'` (recommended)
44
+ * If you are running CTI Butler locally, be sure to set `'http://host.docker.internal:8005/api/'` in the `.env` file otherwise you will run into networking errors.
45
+ * `VULMATCH_BASE_URL`:
46
+ * If using `'http://api.vulmatch.com'`, [get your API key here](http://app.vulmatch.com). Can be left blank if running locally.
@@ -0,0 +1,71 @@
1
+ name: Create Release
2
+ run-name: Creating release
3
+
4
+ on:
5
+ workflow_dispatch:
6
+ push:
7
+ branches:
8
+ - 'main'
9
+
10
+ jobs:
11
+ create-release:
12
+ runs-on: ubuntu-latest
13
+ permissions:
14
+ contents: write
15
+ id-token: write
16
+
17
+ steps:
18
+ - uses: actions/checkout@v4
19
+
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.11"
24
+
25
+ - name: Install build dependencies
26
+ run: python3 -m pip install build hatchling
27
+
28
+ - name: Extract version from pyproject.toml
29
+ id: get-version
30
+ run: |
31
+ VERSION=$(python -m hatchling version)
32
+ echo "version=$VERSION" >> $GITHUB_OUTPUT
33
+
34
+ - name: Build package
35
+ run: python3 -m build
36
+
37
+ - name: Determine release tag
38
+ id: release-tag
39
+ run: |
40
+ if [[ "${{ github.ref_name }}" == "main" ]]; then
41
+ echo "tag=${{ steps.get-version.outputs.version }}" >> $GITHUB_OUTPUT
42
+ else
43
+ echo "tag=${{ steps.get-version.outputs.version }}-beta-$(date +"%Y-%m-%d-%H-%M-%S")" >> $GITHUB_OUTPUT
44
+ fi
45
+
46
+ - name: Create GitHub Release
47
+ env:
48
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
49
+ run: |
50
+ TAG="${{ steps.release-tag.outputs.tag }}"
51
+ gh release create "$TAG" --repo "${{ github.repository }}" --notes ""
52
+ gh release upload "$TAG" dist/** --repo "${{ github.repository }}"
53
+
54
+ - name: Clean up old beta releases (keep latest 10)
55
+ if: github.ref_name != 'main'
56
+ env:
57
+ GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }}
58
+ run: |
59
+ gh release list --limit 100 --repo "${{ github.repository }}" --json tagName,createdAt \
60
+ | jq -r '.[] | select(.tagName | test("-beta-")) | [.tagName, .createdAt] | @tsv' \
61
+ | sort -k2 -r \
62
+ | tail -n +11 \
63
+ | cut -f1 \
64
+ | while read old_tag; do
65
+ echo "Deleting old beta release: $old_tag"
66
+ gh release delete "$old_tag" --repo "${{ github.repository }}" --cleanup-tag --yes
67
+ done
68
+
69
+ - name: Publish package distributions to PyPI
70
+ if: github.ref_name == 'main'
71
+ uses: pypa/gh-action-pypi-publish@release/v1
@@ -0,0 +1,51 @@
1
+ name: Run Tests
2
+
3
+ on:
4
+ push:
5
+ branches:
6
+ - main
7
+ pull_request:
8
+
9
+ jobs:
10
+ run-tests:
11
+ runs-on: ubuntu-latest
12
+ environment: test_pipeline
13
+
14
+ steps:
15
+ - name: Checkout repository
16
+ uses: actions/checkout@v4
17
+ with:
18
+ fetch-depth: 1
19
+
20
+ - name: Set up Python
21
+ uses: actions/setup-python@v5
22
+ with:
23
+ python-version: "3.11"
24
+
25
+
26
+ - name: Set .env testing purpose
27
+ run: |
28
+ echo > .env
29
+ echo "INPUT_TOKEN_LIMIT=1000" >> .env
30
+ - name: test all
31
+ id: test-endpoints
32
+ run: |
33
+ set -a;
34
+ source .env;
35
+ set +a;
36
+ pip install -r tests/src/requirements.txt
37
+ pip install -e .[llms]
38
+
39
+ pytest --cov --cov-branch --cov-report=xml --junitxml=junit.xml -o junit_family=legacy
40
+
41
+ - name: Upload coverage reports to Codecov
42
+ if: ${{ !cancelled() }}
43
+ uses: codecov/codecov-action@v5
44
+ with:
45
+ token: ${{ secrets.CODECOV_TOKEN }}
46
+
47
+ - name: Upload test results to Codecov
48
+ if: ${{ !cancelled() }}
49
+ uses: codecov/test-results-action@v1
50
+ with:
51
+ token: ${{ secrets.CODECOV_TOKEN }}
@@ -0,0 +1,7 @@
1
+ .DS_Store
2
+
3
+ __pycache__/
4
+ .env
5
+ txt2detection-venv/
6
+ logs/
7
+ output/
@@ -0,0 +1,202 @@
1
+
2
+ Apache License
3
+ Version 2.0, January 2004
4
+ http://www.apache.org/licenses/
5
+
6
+ TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7
+
8
+ 1. Definitions.
9
+
10
+ "License" shall mean the terms and conditions for use, reproduction,
11
+ and distribution as defined by Sections 1 through 9 of this document.
12
+
13
+ "Licensor" shall mean the copyright owner or entity authorized by
14
+ the copyright owner that is granting the License.
15
+
16
+ "Legal Entity" shall mean the union of the acting entity and all
17
+ other entities that control, are controlled by, or are under common
18
+ control with that entity. For the purposes of this definition,
19
+ "control" means (i) the power, direct or indirect, to cause the
20
+ direction or management of such entity, whether by contract or
21
+ otherwise, or (ii) ownership of fifty percent (50%) or more of the
22
+ outstanding shares, or (iii) beneficial ownership of such entity.
23
+
24
+ "You" (or "Your") shall mean an individual or Legal Entity
25
+ exercising permissions granted by this License.
26
+
27
+ "Source" form shall mean the preferred form for making modifications,
28
+ including but not limited to software source code, documentation
29
+ source, and configuration files.
30
+
31
+ "Object" form shall mean any form resulting from mechanical
32
+ transformation or translation of a Source form, including but
33
+ not limited to compiled object code, generated documentation,
34
+ and conversions to other media types.
35
+
36
+ "Work" shall mean the work of authorship, whether in Source or
37
+ Object form, made available under the License, as indicated by a
38
+ copyright notice that is included in or attached to the work
39
+ (an example is provided in the Appendix below).
40
+
41
+ "Derivative Works" shall mean any work, whether in Source or Object
42
+ form, that is based on (or derived from) the Work and for which the
43
+ editorial revisions, annotations, elaborations, or other modifications
44
+ represent, as a whole, an original work of authorship. For the purposes
45
+ of this License, Derivative Works shall not include works that remain
46
+ separable from, or merely link (or bind by name) to the interfaces of,
47
+ the Work and Derivative Works thereof.
48
+
49
+ "Contribution" shall mean any work of authorship, including
50
+ the original version of the Work and any modifications or additions
51
+ to that Work or Derivative Works thereof, that is intentionally
52
+ submitted to Licensor for inclusion in the Work by the copyright owner
53
+ or by an individual or Legal Entity authorized to submit on behalf of
54
+ the copyright owner. For the purposes of this definition, "submitted"
55
+ means any form of electronic, verbal, or written communication sent
56
+ to the Licensor or its representatives, including but not limited to
57
+ communication on electronic mailing lists, source code control systems,
58
+ and issue tracking systems that are managed by, or on behalf of, the
59
+ Licensor for the purpose of discussing and improving the Work, but
60
+ excluding communication that is conspicuously marked or otherwise
61
+ designated in writing by the copyright owner as "Not a Contribution."
62
+
63
+ "Contributor" shall mean Licensor and any individual or Legal Entity
64
+ on behalf of whom a Contribution has been received by Licensor and
65
+ subsequently incorporated within the Work.
66
+
67
+ 2. Grant of Copyright License. Subject to the terms and conditions of
68
+ this License, each Contributor hereby grants to You a perpetual,
69
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70
+ copyright license to reproduce, prepare Derivative Works of,
71
+ publicly display, publicly perform, sublicense, and distribute the
72
+ Work and such Derivative Works in Source or Object form.
73
+
74
+ 3. Grant of Patent License. Subject to the terms and conditions of
75
+ this License, each Contributor hereby grants to You a perpetual,
76
+ worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77
+ (except as stated in this section) patent license to make, have made,
78
+ use, offer to sell, sell, import, and otherwise transfer the Work,
79
+ where such license applies only to those patent claims licensable
80
+ by such Contributor that are necessarily infringed by their
81
+ Contribution(s) alone or by combination of their Contribution(s)
82
+ with the Work to which such Contribution(s) was submitted. If You
83
+ institute patent litigation against any entity (including a
84
+ cross-claim or counterclaim in a lawsuit) alleging that the Work
85
+ or a Contribution incorporated within the Work constitutes direct
86
+ or contributory patent infringement, then any patent licenses
87
+ granted to You under this License for that Work shall terminate
88
+ as of the date such litigation is filed.
89
+
90
+ 4. Redistribution. You may reproduce and distribute copies of the
91
+ Work or Derivative Works thereof in any medium, with or without
92
+ modifications, and in Source or Object form, provided that You
93
+ meet the following conditions:
94
+
95
+ (a) You must give any other recipients of the Work or
96
+ Derivative Works a copy of this License; and
97
+
98
+ (b) You must cause any modified files to carry prominent notices
99
+ stating that You changed the files; and
100
+
101
+ (c) You must retain, in the Source form of any Derivative Works
102
+ that You distribute, all copyright, patent, trademark, and
103
+ attribution notices from the Source form of the Work,
104
+ excluding those notices that do not pertain to any part of
105
+ the Derivative Works; and
106
+
107
+ (d) If the Work includes a "NOTICE" text file as part of its
108
+ distribution, then any Derivative Works that You distribute must
109
+ include a readable copy of the attribution notices contained
110
+ within such NOTICE file, excluding those notices that do not
111
+ pertain to any part of the Derivative Works, in at least one
112
+ of the following places: within a NOTICE text file distributed
113
+ as part of the Derivative Works; within the Source form or
114
+ documentation, if provided along with the Derivative Works; or,
115
+ within a display generated by the Derivative Works, if and
116
+ wherever such third-party notices normally appear. The contents
117
+ of the NOTICE file are for informational purposes only and
118
+ do not modify the License. You may add Your own attribution
119
+ notices within Derivative Works that You distribute, alongside
120
+ or as an addendum to the NOTICE text from the Work, provided
121
+ that such additional attribution notices cannot be construed
122
+ as modifying the License.
123
+
124
+ You may add Your own copyright statement to Your modifications and
125
+ may provide additional or different license terms and conditions
126
+ for use, reproduction, or distribution of Your modifications, or
127
+ for any such Derivative Works as a whole, provided Your use,
128
+ reproduction, and distribution of the Work otherwise complies with
129
+ the conditions stated in this License.
130
+
131
+ 5. Submission of Contributions. Unless You explicitly state otherwise,
132
+ any Contribution intentionally submitted for inclusion in the Work
133
+ by You to the Licensor shall be under the terms and conditions of
134
+ this License, without any additional terms or conditions.
135
+ Notwithstanding the above, nothing herein shall supersede or modify
136
+ the terms of any separate license agreement you may have executed
137
+ with Licensor regarding such Contributions.
138
+
139
+ 6. Trademarks. This License does not grant permission to use the trade
140
+ names, trademarks, service marks, or product names of the Licensor,
141
+ except as required for reasonable and customary use in describing the
142
+ origin of the Work and reproducing the content of the NOTICE file.
143
+
144
+ 7. Disclaimer of Warranty. Unless required by applicable law or
145
+ agreed to in writing, Licensor provides the Work (and each
146
+ Contributor provides its Contributions) on an "AS IS" BASIS,
147
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148
+ implied, including, without limitation, any warranties or conditions
149
+ of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150
+ PARTICULAR PURPOSE. You are solely responsible for determining the
151
+ appropriateness of using or redistributing the Work and assume any
152
+ risks associated with Your exercise of permissions under this License.
153
+
154
+ 8. Limitation of Liability. In no event and under no legal theory,
155
+ whether in tort (including negligence), contract, or otherwise,
156
+ unless required by applicable law (such as deliberate and grossly
157
+ negligent acts) or agreed to in writing, shall any Contributor be
158
+ liable to You for damages, including any direct, indirect, special,
159
+ incidental, or consequential damages of any character arising as a
160
+ result of this License or out of the use or inability to use the
161
+ Work (including but not limited to damages for loss of goodwill,
162
+ work stoppage, computer failure or malfunction, or any and all
163
+ other commercial damages or losses), even if such Contributor
164
+ has been advised of the possibility of such damages.
165
+
166
+ 9. Accepting Warranty or Additional Liability. While redistributing
167
+ the Work or Derivative Works thereof, You may choose to offer,
168
+ and charge a fee for, acceptance of support, warranty, indemnity,
169
+ or other liability obligations and/or rights consistent with this
170
+ License. However, in accepting such obligations, You may act only
171
+ on Your own behalf and on Your sole responsibility, not on behalf
172
+ of any other Contributor, and only if You agree to indemnify,
173
+ defend, and hold each Contributor harmless for any liability
174
+ incurred by, or claims asserted against, such Contributor by reason
175
+ of your accepting any such warranty or additional liability.
176
+
177
+ END OF TERMS AND CONDITIONS
178
+
179
+ APPENDIX: How to apply the Apache License to your work.
180
+
181
+ To apply the Apache License to your work, attach the following
182
+ boilerplate notice, with the fields enclosed by brackets "[]"
183
+ replaced with your own identifying information. (Don't include
184
+ the brackets!) The text should be enclosed in the appropriate
185
+ comment syntax for the file format. We also recommend that a
186
+ file or class name and description of purpose be included on the
187
+ same "printed page" as the copyright notice for easier
188
+ identification within third-party archives.
189
+
190
+ Copyright 2020 DOGESEC (https://www.dogesec.com/)
191
+
192
+ Licensed under the Apache License, Version 2.0 (the "License");
193
+ you may not use this file except in compliance with the License.
194
+ You may obtain a copy of the License at
195
+
196
+ http://www.apache.org/licenses/LICENSE-2.0
197
+
198
+ Unless required by applicable law or agreed to in writing, software
199
+ distributed under the License is distributed on an "AS IS" BASIS,
200
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201
+ See the License for the specific language governing permissions and
202
+ limitations under the License.
@@ -0,0 +1,199 @@
1
+ Metadata-Version: 2.4
2
+ Name: txt2detection
3
+ Version: 0.0.2rc12
4
+ Summary: txt2detection is a tool
5
+ Project-URL: Homepage, https://github.com/muchdogesec/txt2detection
6
+ Project-URL: Issues, https://github.com/muchdogesec/txt2detection/issues
7
+ Author-email: DOGESEC <support@dogesec.com>
8
+ License-File: LICENSE
9
+ Classifier: License :: OSI Approved :: Apache Software License
10
+ Classifier: Operating System :: OS Independent
11
+ Classifier: Programming Language :: Python :: 3
12
+ Requires-Python: >=3.11
13
+ Requires-Dist: jsonschema>=4.22.0; python_version >= '3.8'
14
+ Requires-Dist: python-arango>=8.1.3; python_version >= '3.8'
15
+ Requires-Dist: python-dotenv>=1.0.1
16
+ Requires-Dist: python-slugify
17
+ Requires-Dist: pyyaml
18
+ Requires-Dist: requests>=2.31.0; python_version >= '3.7'
19
+ Requires-Dist: stix2
20
+ Requires-Dist: tqdm>=4.66.4; python_version >= '3.7'
21
+ Requires-Dist: validators>=0.34.0
22
+ Provides-Extra: llms
23
+ Requires-Dist: llama-index-core==0.12.7; extra == 'llms'
24
+ Requires-Dist: llama-index-llms-anthropic==0.6.3; extra == 'llms'
25
+ Requires-Dist: llama-index-llms-deepseek==0.1.1; extra == 'llms'
26
+ Requires-Dist: llama-index-llms-gemini==0.4.2; extra == 'llms'
27
+ Requires-Dist: llama-index-llms-openai-like==0.3.3; extra == 'llms'
28
+ Requires-Dist: llama-index-llms-openai==0.3.11; extra == 'llms'
29
+ Requires-Dist: llama-index-llms-openrouter==0.3.1; extra == 'llms'
30
+ Description-Content-Type: text/markdown
31
+
32
+ # txt2detection
33
+
34
+ [![codecov](https://codecov.io/gh/muchdogesec/txt2detection/graph/badge.svg?token=S0U7OC216R)](https://codecov.io/gh/muchdogesec/txt2detection)
35
+
36
+ ## Overview
37
+
38
+ ![txt2detection](docs/txt2detection.png)
39
+
40
+ A command line tool that takes a txt file containing threat intelligence and turns it into a detection rule.
41
+
42
+ ## The problems
43
+
44
+ To illustrate the problem, lets walk through the current status quo process a human goes through when going from idea (threat TTP) to detection rule:
45
+
46
+ 1. read and understand threat using their own research, aided by external sources (blogs, intel feed, etc.)
47
+ * problems: lots of reports, threats described in a range of ways, reports contain differing data
48
+ 2. understand what logs or security data can be used to detect this threat
49
+ * problems: log schemas are unknown to analyst, TTPs often span many logs making it hard to ensure your detection rule has full coverage
50
+ 3. convert the logic created in step 1 into a Sigma detection rule to search logs identified at step 2
51
+ * problems: hard to convert what has been understood into a logical detection rule (in a detection language an analyst might not be familiar with)
52
+ 4. modify the detection rule based on new intelligence as it is discovered
53
+ * problems: this is typically overlooked as people create and forget about rules in their detection tools
54
+
55
+ ## The solution
56
+
57
+ Use AI to process threat intelligence, create and keep them updated.
58
+
59
+ txt2detection allows a user to enter some threat intelligence as a file to considered be turned into a detection.
60
+
61
+ 1. User uploads intel report
62
+ 2. Based on the user input, AI prompts structured and sent to produce an intelligence rule
63
+ 3. Rules converted into STIX objects
64
+
65
+ ## tl;dr
66
+
67
+ [![txt2detection](https://img.youtube.com/vi/uJWXYKyu3Xg/0.jpg)](https://www.youtube.com/watch?v=uJWXYKyu3Xg)
68
+
69
+ [Watch the demo](https://www.youtube.com/watch?v=uJWXYKyu3Xg).
70
+
71
+ ## Usage
72
+
73
+ ### Setup
74
+
75
+ Install the required dependencies using:
76
+
77
+ ```shell
78
+ # clone the latest code
79
+ git clone https://github.com/muchdogesec/txt2detection
80
+ cd txt2detection
81
+ # create a venv
82
+ python3 -m venv txt2detection-venv
83
+ source txt2detection-venv/bin/activate
84
+ # install requirements
85
+ pip3 install -r requirements.txt
86
+ pip3 install .
87
+ ```
88
+
89
+ ### Set variables
90
+
91
+ txt2detection has various settings that are defined in an `.env` file.
92
+
93
+ To create a template for the file:
94
+
95
+ ```shell
96
+ cp .env.example .env
97
+ ```
98
+
99
+ To see more information about how to set the variables, and what they do, read the `.env.markdown` file.
100
+
101
+ ### Run
102
+
103
+ ```shell
104
+ python3 txt2detection.py MODE \
105
+ ARGUEMENTS
106
+ ```
107
+
108
+ There are 3 modes in which you can use txt2detection:
109
+
110
+ * `file`: A text file, usually a threat report you want to create rules from the intel held within
111
+ * `text`: A text prompt that describes the rule you want to create
112
+ * `sigma`: An existing Sigma Rule you want to convert into a STIX bundle
113
+
114
+ #### File (`file`) / Text Input (`text`)
115
+
116
+ Use this mode to generate a set of rules from an input text file;
117
+
118
+ * `--input_file` (required, if not using `--input_text`, file path): the file to be converted. Must be `.txt`
119
+ * `--input_text` (required, if not using `--input_file`, string): a text string that will be analysed to create a rule by the AI if you don't want to use a file.
120
+ * `--name` (required): name of file, max 72 chars. Will be used in the STIX Report Object created. Note, the Indicator object names/titles are generated by AI
121
+ * `--report_id` (optional, default random uuidv4): Sometimes it is required to control the id of the `report` object generated. You can therefore pass a valid UUIDv4 in this field to be assigned to the report. e.g. passing `2611965-930e-43db-8b95-30a1e119d7e2` would create a STIX object id `report--2611965-930e-43db-8b95-30a1e119d7e2`. If this argument is not passed, the UUID will be randomly generated.
122
+ * `--tlp_level` (optional, default `clear`): Options are `clear`, `green`, `amber`, `amber_strict`, `red`.
123
+ * `--labels` (optional): whitspace separated list of labels. Case-insensitive (will all be converted to lower-case). Allowed `a-z`, `0-9`. Must use a namespaces (`NAMESPACE.TAG_VALUE`). e.g.`"namespace.label1" "namespace.label_2"` would create 2 labels. Added to both report and indicator objects created and the rule `tags`.
124
+ * note: you can use reserved namespaces `cve.` and `attack.` when creating labels to perform external enrichment using Vulmatch and CTI Butler. All Indicators will be linked to these objects (AI enrichments link individual rules). Created tags will be appended to the list of AI generated tags.
125
+ * note: you cannot use the namespace `tlp.` Use the `--tlp_level` flag instead.
126
+ * `--created` (optional, `YYYY-MM-DDTHH:MM:SS`): by default all object `created` times will take the time the script was run. If you want to explicitly set these times you can do so using this flag. Pass the value in the format `YYYY-MM-DDTHH:MM:SS` e.g. `2020-01-01T00:00:00`
127
+ * `--use_identity` (optional, default txt2detection identity): can pass a full STIX 2.1 identity object (make sure to properly escape). Will be validated by the STIX2 library. The ID is used to create the Indicator and Report STIX objects, and is used as the `author` property in the Sigma Rule.
128
+ * `--license` (optional): [License of the rule according the SPDX ID specification](https://spdx.org/licenses/). Will be added to the rule.
129
+ * `--reference_urls` (optional): A list of URLs to be added as `references` in the Sigma Rule property and in the `external_references` property of the Indicator and Report STIX object created. e.g `"https://www.google.com/" "https://www.facebook.com/"`
130
+ * `--external_refs` (optional): txt2detection will automatically populate the `external_references` of the report object it creates for the input. You can use this value to add additional objects to `external_references`. Note, you can only add `source_name` and `external_id` values currently. Pass as `source_name=external_id`. e.g. `--external_refs txt2stix=demo1 source=id` would create the following objects under the `external_references` property: `{"source_name":"txt2stix","external_id":"demo1"},{"source_name":"source","external_id":"id"}`
131
+ * `ai_provider` (required): defines the `provider:model` to be used to generate the rule. Select one option. Currently supports:
132
+ * Provider (env var required `OPENROUTER_API_KEY`): `openrouter:`, providers/models `openai/gpt-4o`, `deepseek/deepseek-chat` ([More here](https://openrouter.ai/models))
133
+ * 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))
134
+ * 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))
135
+ * 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))
136
+ * Provider (env var required `DEEPSEEK_API_KEY`): `deepseek:`, models `deepseek-chat` ([More here](https://api-docs.deepseek.com/quick_start/pricing))
137
+
138
+ Note, in this mode, the following values will be automatically assigned to the rule
139
+
140
+ * `level`: the AI will be prompted to assign, either `informational`, `low`, `medium`, `high`, `critical`
141
+ * `status`: will always be `experimental` in this mode
142
+
143
+ #### Sigma rule input (`sigma`)
144
+
145
+ Use this mode to turn a Sigma Rule into a STIX bundle and get it enriched with ATT&CK and Vulmatch.
146
+
147
+ Note, in this mode you should be aware of a few things;
148
+
149
+ * `--sigma_file` (required, file path): the sigma rule .yml you want to be processed. Must be a `.yml` or `.yaml` file. Does not currently support correlation rules.
150
+ * `--report_id`: will overwrite any `id` value found in the rule, also used for both Indicator and Report
151
+ * `--name`: will be assigned as `title` of the rule. Will overwrite existing title
152
+ * `--tlp_level` (optional): the `tlp.` tag in the report will be turned into a TLP level. If not TLP tag in rule, default is that is will be assigned TLP `clear` and tag added. You can pass `clear`, `green`, `amber`, `amber_strict`, `red` using this property to overwrite default behaviour. If TLP exist in rule, setting a value for this property will overwrite the existing value
153
+ * `--labels` (optional): whitespace separated list of labels. Case-insensitive (will all be converted to lower-case). Allowed `a-z`, `0-9`. e.g.`"namespace.label1" "namespace.label2"` would create 2 labels. Added to both report and indicator objects created and the rule `tags`. Note, if any existing `tags` in the rule, these values will be appended to the list.
154
+ * note: you can use reserved namespaces `cve.` and `attack.` when creating labels to perform external enrichment using Vulmatch and CTI Butler. Created tags will be appended to the list of existing tags.
155
+ * note: you cannot use the namespace `tlp.` Use the `--tlp_level` flag instead.
156
+ * `--created` (optional, `YYYY-MM-DDTHH:MM:SS`): by default the `data` and `modified` values in the rule will be used. If no values exist for these, the default behaviour is to use script run time. You can pass `created` time here which will overwrite `date` and `modified` date in the rule
157
+ * `--use_identity` (optional): can pass a full STIX 2.1 identity object (make sure to properly escape). Will be validated by the STIX2 library. The ID is used to create the Indicator and Report STIX objects, and is used as the `author` property in the Sigma Rule. Will overwrite any existing `author` value. If `author` value in rule, will be converted into a STIX Identity
158
+ * `--license` (optional): [License of the rule according the SPDX ID specification](https://spdx.org/licenses/). Will be added to the rule as `license`. Will overwrite any existing `license` value in rule.
159
+ * `--reference_urls` (optional): A list of URLs to be added as `references` in the Sigma Rule property and in the `external_references` property of the Indicator and Report STIX object created. e.g `"https://www.google.com/" "https://www.facebook.com/"`. Will appended to any existing `references` in the rule.
160
+ * `--external_refs` (optional): txt2detection will automatically populate the `external_references` of the report object it creates for the input. You can use this value to add additional objects to `external_references`. Note, you can only add `source_name` and `external_id` values currently. Pass as `source_name=external_id`. e.g. `--external_refs txt2stix=demo1 source=id` would create the following objects under the `external_references` property: `{"source_name":"txt2stix","external_id":"demo1"},{"source_name":"source","external_id":"id"}`
161
+ * `status` (optional): either `stable`, `test`, `experimental`, `deprecated`, `unsupported`. If passed, will overwrite any existing `status` recorded in the rule
162
+ * `level` (optional): either `informational`, `low`, `medium`, `high`, `critical`. If passed, will overwrite any existing `level` recorded in the rule
163
+
164
+ ### A note on observable extraction
165
+
166
+ txt2detection will automatically attempt to extract any observables (aka indicators of compromise) that are found in the created or imported rules to turn them into STIX objects joined to the STIX Indicator object of the Rule.
167
+
168
+ In `txt2detection/observables.py` you will find the observable types (and regexs used detection) currently supported.
169
+
170
+ ### Output
171
+
172
+ The output of each run is structured as follows;
173
+
174
+ ```txt
175
+ .
176
+ ├── logs
177
+ │ ├── log-<REPORT UUID>.log
178
+ │ ├── log-<REPORT UUID>.log
179
+ │ └── log-<REPORT UUID>.log
180
+ └── output
181
+ └── bundle--<REPORT UUID>
182
+ ├── rules
183
+ │ ├── rule--<UUID>.yml
184
+ │ └── rule--<UUID>.yml
185
+ ├── data.json # AI output, useful for debugging
186
+ └── bundle.json # final STIX bundle with all objects
187
+ ```
188
+
189
+ ## Examples
190
+
191
+ See `tests/manual-tests/README.md` for some example commands.
192
+
193
+ ## Support
194
+
195
+ [Minimal support provided via the DOGESEC community](https://community.dogesec.com/).
196
+
197
+ ## License
198
+
199
+ [Apache 2.0](/LICENSE).