karton-core 5.9.0__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.
Files changed (39) hide show
  1. karton_core-5.9.0/LICENSE +29 -0
  2. karton_core-5.9.0/PKG-INFO +165 -0
  3. karton_core-5.9.0/README.md +146 -0
  4. karton_core-5.9.0/karton/core/__init__.py +16 -0
  5. karton_core-5.9.0/karton/core/__version__.py +1 -0
  6. karton_core-5.9.0/karton/core/asyncio/__init__.py +21 -0
  7. karton_core-5.9.0/karton/core/asyncio/backend.py +379 -0
  8. karton_core-5.9.0/karton/core/asyncio/base.py +133 -0
  9. karton_core-5.9.0/karton/core/asyncio/karton.py +364 -0
  10. karton_core-5.9.0/karton/core/asyncio/logger.py +57 -0
  11. karton_core-5.9.0/karton/core/asyncio/resource.py +384 -0
  12. karton_core-5.9.0/karton/core/backend.py +1191 -0
  13. karton_core-5.9.0/karton/core/base.py +287 -0
  14. karton_core-5.9.0/karton/core/config.py +244 -0
  15. karton_core-5.9.0/karton/core/exceptions.py +10 -0
  16. karton_core-5.9.0/karton/core/inspect.py +186 -0
  17. karton_core-5.9.0/karton/core/karton.py +477 -0
  18. karton_core-5.9.0/karton/core/logger.py +85 -0
  19. karton_core-5.9.0/karton/core/main.py +291 -0
  20. karton_core-5.9.0/karton/core/py.typed +0 -0
  21. karton_core-5.9.0/karton/core/query.py +362 -0
  22. karton_core-5.9.0/karton/core/resource.py +639 -0
  23. karton_core-5.9.0/karton/core/task.py +577 -0
  24. karton_core-5.9.0/karton/core/test.py +269 -0
  25. karton_core-5.9.0/karton/core/utils.py +135 -0
  26. karton_core-5.9.0/karton/system/__init__.py +3 -0
  27. karton_core-5.9.0/karton/system/__main__.py +3 -0
  28. karton_core-5.9.0/karton/system/system.py +432 -0
  29. karton_core-5.9.0/karton_core.egg-info/PKG-INFO +165 -0
  30. karton_core-5.9.0/karton_core.egg-info/SOURCES.txt +38 -0
  31. karton_core-5.9.0/karton_core.egg-info/dependency_links.txt +1 -0
  32. karton_core-5.9.0/karton_core.egg-info/entry_points.txt +3 -0
  33. karton_core-5.9.0/karton_core.egg-info/requires.txt +4 -0
  34. karton_core-5.9.0/karton_core.egg-info/top_level.txt +1 -0
  35. karton_core-5.9.0/pyproject.toml +73 -0
  36. karton_core-5.9.0/requirements.txt +5 -0
  37. karton_core-5.9.0/setup.cfg +8 -0
  38. karton_core-5.9.0/tests/test_core.py +72 -0
  39. karton_core-5.9.0/tests/test_task_filters.py +557 -0
@@ -0,0 +1,29 @@
1
+ BSD 3-Clause License
2
+
3
+ Copyright (c) 2020, CERT Polska
4
+ All rights reserved.
5
+
6
+ Redistribution and use in source and binary forms, with or without
7
+ modification, are permitted provided that the following conditions are met:
8
+
9
+ 1. Redistributions of source code must retain the above copyright notice, this
10
+ list of conditions and the following disclaimer.
11
+
12
+ 2. Redistributions in binary form must reproduce the above copyright notice,
13
+ this list of conditions and the following disclaimer in the documentation
14
+ and/or other materials provided with the distribution.
15
+
16
+ 3. Neither the name of the copyright holder nor the names of its
17
+ contributors may be used to endorse or promote products derived from
18
+ this software without specific prior written permission.
19
+
20
+ THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
21
+ AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22
+ IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
23
+ DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE
24
+ FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25
+ DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
26
+ SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
27
+ CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
28
+ OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
29
+ OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
@@ -0,0 +1,165 @@
1
+ Metadata-Version: 2.4
2
+ Name: karton-core
3
+ Version: 5.9.0
4
+ Summary: Distributed malware analysis orchestration framework
5
+ License-Expression: BSD-3-Clause
6
+ Project-URL: Homepage, https://github.com/CERT-Polska/karton
7
+ Project-URL: Documentation, https://karton-core.readthedocs.io/
8
+ Project-URL: Repository, https://github.com/CERT-Polska/karton
9
+ Classifier: Programming Language :: Python :: 3
10
+ Classifier: Operating System :: OS Independent
11
+ Requires-Python: >=3.8
12
+ Description-Content-Type: text/markdown
13
+ License-File: LICENSE
14
+ Requires-Dist: redis
15
+ Requires-Dist: orjson
16
+ Requires-Dist: boto3<=1.35.81
17
+ Requires-Dist: aioboto3==13.3.0
18
+ Dynamic: license-file
19
+
20
+ # Karton <img src="img/logo.svg" width="64">
21
+
22
+ Distributed malware processing framework based on Python, Redis and S3.
23
+
24
+ ## The idea
25
+
26
+ Karton is a robust framework for creating **flexible** and **lightweight** malware analysis backends.
27
+ It can be used to connect malware* analysis systems into a robust pipeline with very little effort.
28
+
29
+ We've been in the automation business for a long time. We're dealing with more and more threats, and we have to automate everything to keep up with incidents. Because of this, we often end up with many scripts stuck together with ~~duck~~ duct tape and WD-40. These scripts are written by analysts in the heat of the moment, fragile and ugly - but they work, and produce intel that must be stored, processed further, sent to other systems or shared with other organisations.
30
+
31
+ We needed a way to take our PoC scripts and easily insert them into our analysis pipeline. We also wanted to monitor their execution, centralise logging, improve robustness, reduce development inertia... For this exact purpose, we created **Karton**.
32
+
33
+
34
+ *\* while Karton was designed with malware analysis in mind, it works nicely in every microservice-oriented project.*
35
+
36
+
37
+ ## Installation
38
+
39
+ Installation is as easy as a single `pip install` command:
40
+
41
+ ```
42
+ pip3 install karton-core
43
+ ```
44
+
45
+ In order to setup the whole backend environment you will also need S3-compatible storage and Redis, see the [docs](https://karton-core.readthedocs.io/en/latest/getting_started.html#installation) for details.
46
+
47
+ ## Example usage
48
+ To use karton you have to provide class that inherits from Karton.
49
+
50
+
51
+ ```python
52
+ from karton.core import Karton, Task, Resource
53
+
54
+ class GenericUnpacker(Karton):
55
+ """
56
+ Performs sample unpacking
57
+ """
58
+ identity = "karton.generic-unpacker"
59
+ filters = [
60
+ {
61
+ "type": "sample",
62
+ "kind": "runnable",
63
+ "platform": "win32"
64
+ }
65
+ ]
66
+
67
+ def process(self, task: Task) -> None:
68
+ # Get sample object
69
+ packed_sample = task.get_resource('sample')
70
+ # Log with self.log
71
+ self.log.info(f"Hi {packed_sample.name}, let me analyze you!")
72
+ ...
73
+ # Send our results for further processing or reporting
74
+ task = Task(
75
+ {
76
+ "type": "sample",
77
+ "kind": "raw"
78
+ }, payload = {
79
+ "parent": packed_sample,
80
+ "sample": Resource(filename, unpacked)
81
+ })
82
+ self.send_task(task)
83
+
84
+ if __name__ == "__main__":
85
+ GenericUnpacker.main()
86
+ ```
87
+
88
+ ## Command line
89
+
90
+ This package also provies a command-line utility called "karton". You can use it for simple management tasks (but it's not designed as a fully capable management tool).
91
+
92
+ ```
93
+ $ karton configure # create a new configuration file
94
+
95
+ $ karton list -s # list current binds
96
+ karton name version karton
97
+ ------------------------------------------------------------------------
98
+ karton.yaramatcher 1.2.0 5.3.0
99
+ karton.autoit-ripper 1.2.1 5.3.3
100
+ karton.mwdb-reporter 1.3.0 5.3.2
101
+
102
+ $ karton logs # start streaming all system logs
103
+
104
+ $ karton delete karton.something # remove unused bind (will be GCed by system during the next operation)
105
+ ```
106
+
107
+
108
+ ## Karton systems
109
+
110
+ Some Karton systems are universal and useful to everyone. We decided to share them with the community.
111
+
112
+ #### [karton](https://github.com/CERT-Polska/karton)
113
+ This repository. It contains the `karton.system` service - main service, responsible for dispatching tasks within the system. It also contains the `karton.core` module, that is used as a library by other systems.
114
+
115
+ #### [karton-dashboard](https://github.com/CERT-Polska/karton-dashboard)
116
+ A small Flask dashboard for task and queue management and monitoring.
117
+
118
+ #### [karton-classifier](https://github.com/CERT-Polska/karton-classifier)
119
+ The "router". It recognises samples/files and produces various task types depending on the file format. Thanks to this, other systems may only listen for tasks with a specific format (for example, only `zip` archives).
120
+
121
+ #### [karton-archive-extractor](https://github.com/CERT-Polska/karton-archive-extractor)
122
+ Generic archive unpacker. Archives uploaded into the system will be extracted, and every file will be processed individually.
123
+
124
+ #### [karton-config-extractor](https://github.com/CERT-Polska/karton-config-extractor)
125
+ Malware extractor. It uses Yara rules and Python modules to extract static configuration from malware samples and analyses. It's a fishing rod, not a fish - we don't share the modules themselves. But it's easy to write your own!
126
+
127
+ #### [karton-mwdb-reporter](https://github.com/CERT-Polska/karton-mwdb-reporter)
128
+ A very important part of the pipeline. Reporter submits all files, tags, comments and other intel produced during the analysis to [MWDB](https://github.com/CERT-Polska/mwdb-core). If you don't use MWDB yet or just prefer other backends, it's easy to write your own reporter.
129
+
130
+ #### [karton-yaramatcher](https://github.com/CERT-Polska/karton-yaramatcher)
131
+ Automatically runs Yara rules on all files in the pipeline, and tags samples appropriately. Rules not included ;).
132
+
133
+ #### [karton-asciimagic](https://github.com/CERT-Polska/karton-asciimagic)
134
+ Karton system that decodes files encoded with common methods, like `hex`, `base64`, etc. (You wouldn't believe how common it is).
135
+
136
+ #### [karton-autoit-ripper](https://github.com/CERT-Polska/karton-autoit-ripper)
137
+ A small wrapper around [AutoIt-Ripper](https://github.com/nazywam/AutoIt-Ripper) that extracts embedded AutoIt scripts and resources from compiled AutoIt executables.
138
+
139
+ #### [DRAKVUF Sandbox](https://github.com/CERT-Polska/drakvuf-sandbox)
140
+ Automated black-box malware analysis system with DRAKVUF engine under the hood, which does not require an agent on guest OS.
141
+
142
+ ---
143
+
144
+ This is how these systems can be used to form a basic malware analysis pipeline:
145
+ [![](img/karton-systems.svg)](img/karton-systems.svg?raw=true)
146
+
147
+
148
+ ## Community projects that incorporate the Karton framework
149
+
150
+ #### [c3rb3ru5d3d53c/karton-unpacker](https://github.com/c3rb3ru5d3d53c/karton-unpacker)
151
+ A modular Karton Framework service that unpacks common packers like UPX and others using the Qiling Framework.
152
+
153
+ #### [c3rb3ru5d3d53c/mwcfg](https://github.com/c3rb3ru5d3d53c/mwcfg) / [c3rb3ru5d3d53c/mwcfg-modules](https://github.com/c3rb3ru5d3d53c/mwcfg-modules)
154
+ A Feature Rich Modular Malware Configuration Extraction Utility for MalDuck
155
+
156
+ #### [raw-data/karton-die-classifier](https://github.com/raw-data/karton-die-classifier)
157
+ Detect-It-Easy classifier for the Karton framework
158
+
159
+ #### [raw-data/karton-retdec-unpacker](https://github.com/raw-data/karton-retdec-unpacker)
160
+ RetDec unpacker module for the Karton framework
161
+
162
+ #### [W3ndige/aurora](https://github.com/W3ndige/aurora) / [W3ndige/karton-similarity](https://github.com/W3ndige/karton-similarity)
163
+ Malware similarity platform with modularity in mind.
164
+
165
+ ![Co-financed by the Connecting Europe Facility by of the European Union](https://www.cert.pl/uploads/2019/02/en_horizontal_cef_logo-e1550495232540.png)
@@ -0,0 +1,146 @@
1
+ # Karton <img src="img/logo.svg" width="64">
2
+
3
+ Distributed malware processing framework based on Python, Redis and S3.
4
+
5
+ ## The idea
6
+
7
+ Karton is a robust framework for creating **flexible** and **lightweight** malware analysis backends.
8
+ It can be used to connect malware* analysis systems into a robust pipeline with very little effort.
9
+
10
+ We've been in the automation business for a long time. We're dealing with more and more threats, and we have to automate everything to keep up with incidents. Because of this, we often end up with many scripts stuck together with ~~duck~~ duct tape and WD-40. These scripts are written by analysts in the heat of the moment, fragile and ugly - but they work, and produce intel that must be stored, processed further, sent to other systems or shared with other organisations.
11
+
12
+ We needed a way to take our PoC scripts and easily insert them into our analysis pipeline. We also wanted to monitor their execution, centralise logging, improve robustness, reduce development inertia... For this exact purpose, we created **Karton**.
13
+
14
+
15
+ *\* while Karton was designed with malware analysis in mind, it works nicely in every microservice-oriented project.*
16
+
17
+
18
+ ## Installation
19
+
20
+ Installation is as easy as a single `pip install` command:
21
+
22
+ ```
23
+ pip3 install karton-core
24
+ ```
25
+
26
+ In order to setup the whole backend environment you will also need S3-compatible storage and Redis, see the [docs](https://karton-core.readthedocs.io/en/latest/getting_started.html#installation) for details.
27
+
28
+ ## Example usage
29
+ To use karton you have to provide class that inherits from Karton.
30
+
31
+
32
+ ```python
33
+ from karton.core import Karton, Task, Resource
34
+
35
+ class GenericUnpacker(Karton):
36
+ """
37
+ Performs sample unpacking
38
+ """
39
+ identity = "karton.generic-unpacker"
40
+ filters = [
41
+ {
42
+ "type": "sample",
43
+ "kind": "runnable",
44
+ "platform": "win32"
45
+ }
46
+ ]
47
+
48
+ def process(self, task: Task) -> None:
49
+ # Get sample object
50
+ packed_sample = task.get_resource('sample')
51
+ # Log with self.log
52
+ self.log.info(f"Hi {packed_sample.name}, let me analyze you!")
53
+ ...
54
+ # Send our results for further processing or reporting
55
+ task = Task(
56
+ {
57
+ "type": "sample",
58
+ "kind": "raw"
59
+ }, payload = {
60
+ "parent": packed_sample,
61
+ "sample": Resource(filename, unpacked)
62
+ })
63
+ self.send_task(task)
64
+
65
+ if __name__ == "__main__":
66
+ GenericUnpacker.main()
67
+ ```
68
+
69
+ ## Command line
70
+
71
+ This package also provies a command-line utility called "karton". You can use it for simple management tasks (but it's not designed as a fully capable management tool).
72
+
73
+ ```
74
+ $ karton configure # create a new configuration file
75
+
76
+ $ karton list -s # list current binds
77
+ karton name version karton
78
+ ------------------------------------------------------------------------
79
+ karton.yaramatcher 1.2.0 5.3.0
80
+ karton.autoit-ripper 1.2.1 5.3.3
81
+ karton.mwdb-reporter 1.3.0 5.3.2
82
+
83
+ $ karton logs # start streaming all system logs
84
+
85
+ $ karton delete karton.something # remove unused bind (will be GCed by system during the next operation)
86
+ ```
87
+
88
+
89
+ ## Karton systems
90
+
91
+ Some Karton systems are universal and useful to everyone. We decided to share them with the community.
92
+
93
+ #### [karton](https://github.com/CERT-Polska/karton)
94
+ This repository. It contains the `karton.system` service - main service, responsible for dispatching tasks within the system. It also contains the `karton.core` module, that is used as a library by other systems.
95
+
96
+ #### [karton-dashboard](https://github.com/CERT-Polska/karton-dashboard)
97
+ A small Flask dashboard for task and queue management and monitoring.
98
+
99
+ #### [karton-classifier](https://github.com/CERT-Polska/karton-classifier)
100
+ The "router". It recognises samples/files and produces various task types depending on the file format. Thanks to this, other systems may only listen for tasks with a specific format (for example, only `zip` archives).
101
+
102
+ #### [karton-archive-extractor](https://github.com/CERT-Polska/karton-archive-extractor)
103
+ Generic archive unpacker. Archives uploaded into the system will be extracted, and every file will be processed individually.
104
+
105
+ #### [karton-config-extractor](https://github.com/CERT-Polska/karton-config-extractor)
106
+ Malware extractor. It uses Yara rules and Python modules to extract static configuration from malware samples and analyses. It's a fishing rod, not a fish - we don't share the modules themselves. But it's easy to write your own!
107
+
108
+ #### [karton-mwdb-reporter](https://github.com/CERT-Polska/karton-mwdb-reporter)
109
+ A very important part of the pipeline. Reporter submits all files, tags, comments and other intel produced during the analysis to [MWDB](https://github.com/CERT-Polska/mwdb-core). If you don't use MWDB yet or just prefer other backends, it's easy to write your own reporter.
110
+
111
+ #### [karton-yaramatcher](https://github.com/CERT-Polska/karton-yaramatcher)
112
+ Automatically runs Yara rules on all files in the pipeline, and tags samples appropriately. Rules not included ;).
113
+
114
+ #### [karton-asciimagic](https://github.com/CERT-Polska/karton-asciimagic)
115
+ Karton system that decodes files encoded with common methods, like `hex`, `base64`, etc. (You wouldn't believe how common it is).
116
+
117
+ #### [karton-autoit-ripper](https://github.com/CERT-Polska/karton-autoit-ripper)
118
+ A small wrapper around [AutoIt-Ripper](https://github.com/nazywam/AutoIt-Ripper) that extracts embedded AutoIt scripts and resources from compiled AutoIt executables.
119
+
120
+ #### [DRAKVUF Sandbox](https://github.com/CERT-Polska/drakvuf-sandbox)
121
+ Automated black-box malware analysis system with DRAKVUF engine under the hood, which does not require an agent on guest OS.
122
+
123
+ ---
124
+
125
+ This is how these systems can be used to form a basic malware analysis pipeline:
126
+ [![](img/karton-systems.svg)](img/karton-systems.svg?raw=true)
127
+
128
+
129
+ ## Community projects that incorporate the Karton framework
130
+
131
+ #### [c3rb3ru5d3d53c/karton-unpacker](https://github.com/c3rb3ru5d3d53c/karton-unpacker)
132
+ A modular Karton Framework service that unpacks common packers like UPX and others using the Qiling Framework.
133
+
134
+ #### [c3rb3ru5d3d53c/mwcfg](https://github.com/c3rb3ru5d3d53c/mwcfg) / [c3rb3ru5d3d53c/mwcfg-modules](https://github.com/c3rb3ru5d3d53c/mwcfg-modules)
135
+ A Feature Rich Modular Malware Configuration Extraction Utility for MalDuck
136
+
137
+ #### [raw-data/karton-die-classifier](https://github.com/raw-data/karton-die-classifier)
138
+ Detect-It-Easy classifier for the Karton framework
139
+
140
+ #### [raw-data/karton-retdec-unpacker](https://github.com/raw-data/karton-retdec-unpacker)
141
+ RetDec unpacker module for the Karton framework
142
+
143
+ #### [W3ndige/aurora](https://github.com/W3ndige/aurora) / [W3ndige/karton-similarity](https://github.com/W3ndige/karton-similarity)
144
+ Malware similarity platform with modularity in mind.
145
+
146
+ ![Co-financed by the Connecting Europe Facility by of the European Union](https://www.cert.pl/uploads/2019/02/en_horizontal_cef_logo-e1550495232540.png)
@@ -0,0 +1,16 @@
1
+ from .config import Config
2
+ from .karton import Consumer, Karton, LogConsumer, Producer
3
+ from .resource import LocalResource, RemoteResource, Resource
4
+ from .task import Task
5
+
6
+ __all__ = [
7
+ "Karton",
8
+ "Producer",
9
+ "Consumer",
10
+ "Task",
11
+ "LogConsumer",
12
+ "Config",
13
+ "LocalResource",
14
+ "Resource",
15
+ "RemoteResource",
16
+ ]
@@ -0,0 +1 @@
1
+ __version__ = "5.9.0"
@@ -0,0 +1,21 @@
1
+ import sys
2
+
3
+ if sys.version_info < (3, 11, 0):
4
+ raise ImportError("karton.core.asyncio is only compatible with Python 3.11+")
5
+
6
+ from karton.core.config import Config
7
+ from karton.core.task import Task
8
+
9
+ from .karton import Consumer, Karton, Producer
10
+ from .resource import LocalResource, RemoteResource, Resource
11
+
12
+ __all__ = [
13
+ "Karton",
14
+ "Producer",
15
+ "Consumer",
16
+ "Task",
17
+ "Config",
18
+ "LocalResource",
19
+ "Resource",
20
+ "RemoteResource",
21
+ ]