dementor 1.0.0.dev4__tar.gz → 1.0.0.dev5__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Potentially problematic release.
This version of dementor might be problematic. Click here for more details.
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/PKG-INFO +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/__init__.py +1 -1
- dementor-1.0.0.dev5/dementor/config/__init__.py +53 -0
- dementor-1.0.0.dev5/dementor/config/attr.py +44 -0
- dementor-1.0.0.dev5/dementor/config/session.py +99 -0
- dementor-1.0.0.dev4/dementor/config.py → dementor-1.0.0.dev5/dementor/config/toml.py +2 -116
- dementor-1.0.0.dev5/dementor/config/util.py +44 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/database.py +1 -2
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/filters.py +23 -27
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/loader.py +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/logger.py +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/paths.py +2 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/ftp.py +2 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/http.py +16 -31
- dementor-1.0.0.dev5/dementor/protocols/imap.py +412 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/kerberos.py +2 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/ldap.py +9 -26
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/llmnr.py +12 -9
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/mdns.py +6 -5
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/msrpc/rpc.py +12 -21
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/msrpc.py +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/mssql.py +20 -34
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/netbios.py +7 -4
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/ntlm.py +67 -1
- dementor-1.0.0.dev5/dementor/protocols/pop3.py +389 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/quic.py +2 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/smb.py +18 -75
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/smtp.py +23 -48
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/servers.py +26 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/standalone.py +4 -3
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor.egg-info/PKG-INFO +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor.egg-info/SOURCES.txt +7 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/pyproject.toml +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/test/test_dcerpc.py +1 -1
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/LICENSE +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/README.md +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/__main__.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/__init__.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/msrpc/__init__.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/msrpc/dcom.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/msrpc/epm.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor/protocols/spnego.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor.egg-info/dependency_links.txt +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor.egg-info/entry_points.txt +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/dementor.egg-info/top_level.txt +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/docs/README.pypi.md +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/setup.cfg +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/test/test_dcom.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/test/test_epm.py +0 -0
- {dementor-1.0.0.dev4 → dementor-1.0.0.dev5}/test/test_mssql_auth.py +0 -0
|
@@ -0,0 +1,53 @@
|
|
|
1
|
+
# Copyright (c) 2025-Present MatrixEditor
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
import sys
|
|
21
|
+
import pathlib
|
|
22
|
+
import tomllib
|
|
23
|
+
|
|
24
|
+
from dementor.paths import CONFIG_PATH, DEFAULT_CONFIG_PATH
|
|
25
|
+
|
|
26
|
+
# global configuration values
|
|
27
|
+
dm_config: dict
|
|
28
|
+
|
|
29
|
+
def _get_global_config() -> dict:
|
|
30
|
+
return getattr(sys.modules[__name__], "dm_config", {})
|
|
31
|
+
|
|
32
|
+
|
|
33
|
+
def _set_global_config(config: dict) -> None:
|
|
34
|
+
setattr(sys.modules[__name__], "dm_config", config)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def init_from_file(path: str) -> None:
|
|
38
|
+
target = pathlib.Path(path)
|
|
39
|
+
if not target.exists() or not target.is_file():
|
|
40
|
+
return
|
|
41
|
+
|
|
42
|
+
# by default, we just replace the global config
|
|
43
|
+
with target.open("rb") as f:
|
|
44
|
+
new_config = tomllib.load(f)
|
|
45
|
+
_set_global_config(new_config)
|
|
46
|
+
|
|
47
|
+
|
|
48
|
+
# Default initialization procedure is:
|
|
49
|
+
# 1. use default config
|
|
50
|
+
# 2. use config file if it exists
|
|
51
|
+
# 3. use custom config if specified via CLI
|
|
52
|
+
init_from_file(DEFAULT_CONFIG_PATH)
|
|
53
|
+
init_from_file(CONFIG_PATH)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2025-Present MatrixEditor
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
#
|
|
21
|
+
# Shared attributes for all configuration classes
|
|
22
|
+
from dementor.config.toml import Attribute
|
|
23
|
+
from dementor.config.util import is_true
|
|
24
|
+
|
|
25
|
+
ATTR_CERT = Attribute(
|
|
26
|
+
attr_name="certfile",
|
|
27
|
+
qname="Cert",
|
|
28
|
+
default_val=None,
|
|
29
|
+
section_local=False,
|
|
30
|
+
)
|
|
31
|
+
|
|
32
|
+
ATTR_KEY = Attribute(
|
|
33
|
+
attr_name="keyfile",
|
|
34
|
+
qname="Key",
|
|
35
|
+
default_val=None,
|
|
36
|
+
section_local=False,
|
|
37
|
+
)
|
|
38
|
+
|
|
39
|
+
ATTR_TLS = Attribute(
|
|
40
|
+
attr_name="use_ssl",
|
|
41
|
+
qname="TLS",
|
|
42
|
+
default_val=False,
|
|
43
|
+
factory=is_true,
|
|
44
|
+
)
|
|
@@ -0,0 +1,99 @@
|
|
|
1
|
+
# Copyright (c) 2025-Present MatrixEditor
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
import asyncio
|
|
21
|
+
|
|
22
|
+
from typing import Any, List
|
|
23
|
+
|
|
24
|
+
from dementor.config.toml import TomlConfig, Attribute
|
|
25
|
+
from dementor.config.util import is_true
|
|
26
|
+
from dementor.paths import DEMENTOR_PATH
|
|
27
|
+
from dementor import config
|
|
28
|
+
|
|
29
|
+
|
|
30
|
+
class SessionConfig(TomlConfig):
|
|
31
|
+
_section_ = "Dementor"
|
|
32
|
+
_fields_ = [
|
|
33
|
+
Attribute("extra_modules", "ExtraModules", list),
|
|
34
|
+
Attribute("workspace_path", "Workspace", DEMENTOR_PATH),
|
|
35
|
+
] + [
|
|
36
|
+
# TODO: place this somewhere else
|
|
37
|
+
Attribute(f"{name.lower()}_enabled", name, True, factory=is_true)
|
|
38
|
+
for name in (
|
|
39
|
+
"LLMNR",
|
|
40
|
+
"NBTNS",
|
|
41
|
+
"NBTDS",
|
|
42
|
+
"SMTP",
|
|
43
|
+
"SMB",
|
|
44
|
+
"FTP",
|
|
45
|
+
"KDC",
|
|
46
|
+
"LDAP",
|
|
47
|
+
"QUIC",
|
|
48
|
+
"mDNS",
|
|
49
|
+
"HTTP",
|
|
50
|
+
"RPC",
|
|
51
|
+
"WinRM",
|
|
52
|
+
"MSSQL",
|
|
53
|
+
"SSRP",
|
|
54
|
+
"IMAP",
|
|
55
|
+
"POP3",
|
|
56
|
+
)
|
|
57
|
+
]
|
|
58
|
+
|
|
59
|
+
# TODO: move into .pyi
|
|
60
|
+
db: Any
|
|
61
|
+
db_config: Any
|
|
62
|
+
krb5_config: Any
|
|
63
|
+
mdns_config: Any
|
|
64
|
+
llmnr_config: Any
|
|
65
|
+
quic_config: Any
|
|
66
|
+
netbiosns_config: Any
|
|
67
|
+
ldap_config: List[Any]
|
|
68
|
+
|
|
69
|
+
def __init__(self) -> None:
|
|
70
|
+
super().__init__(config.dm_config.get("Dementor", {}))
|
|
71
|
+
# global options that are not loaded from configuration
|
|
72
|
+
self.ipv6 = None
|
|
73
|
+
self.ipv4 = None
|
|
74
|
+
self.interface = None
|
|
75
|
+
self.analysis = False
|
|
76
|
+
self.loop = asyncio.get_event_loop()
|
|
77
|
+
self.protocols = {}
|
|
78
|
+
|
|
79
|
+
# SMTP configuration
|
|
80
|
+
self.smtp_servers = []
|
|
81
|
+
|
|
82
|
+
# NTLM configuration
|
|
83
|
+
self.ntlm_challange = b"1337LEET"
|
|
84
|
+
self.ntlm_ess = True
|
|
85
|
+
|
|
86
|
+
# SMB configuration
|
|
87
|
+
self.smb_server_config = []
|
|
88
|
+
|
|
89
|
+
def is_bound_to_all(self) -> bool:
|
|
90
|
+
# REVISIT: this should raise an exception
|
|
91
|
+
return self.interface == "ALL"
|
|
92
|
+
|
|
93
|
+
@property
|
|
94
|
+
def bind_address(self) -> str:
|
|
95
|
+
return "::" if self.ipv6 else str(self.ipv4)
|
|
96
|
+
|
|
97
|
+
@property
|
|
98
|
+
def ipv6_support(self) -> bool:
|
|
99
|
+
return bool(self.ipv6) and not getattr(self, "ipv4_only", False)
|
|
@@ -17,14 +17,9 @@
|
|
|
17
17
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
19
|
# SOFTWARE.
|
|
20
|
-
import
|
|
21
|
-
import os
|
|
22
|
-
import asyncio
|
|
23
|
-
|
|
24
|
-
from typing import Any, List, Optional, NamedTuple, Callable
|
|
25
|
-
|
|
26
|
-
from dementor.paths import ASSETS_PATH, CONFIG_PATH, DEMENTOR_PATH
|
|
20
|
+
from typing import NamedTuple, Callable, Any
|
|
27
21
|
|
|
22
|
+
from dementor.config.util import get_value
|
|
28
23
|
|
|
29
24
|
_LOCAL = object()
|
|
30
25
|
|
|
@@ -131,112 +126,3 @@ class TomlConfig:
|
|
|
131
126
|
func(value)
|
|
132
127
|
else:
|
|
133
128
|
setattr(self, field_name, value)
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
def is_true(value) -> bool:
|
|
137
|
-
return str(value).lower() in ("true", "1", "yes", "on")
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
class SessionConfig(TomlConfig):
|
|
141
|
-
_section_ = "Dementor"
|
|
142
|
-
_fields_ = [
|
|
143
|
-
Attribute("llmnr_enabled", "LLMNR", True, factory=is_true),
|
|
144
|
-
Attribute("nbtns_enabled", "NBTNS", True, factory=is_true),
|
|
145
|
-
Attribute("nbtds_enabled", "NBTDS", True, factory=is_true),
|
|
146
|
-
Attribute("smtp_enabled", "SMTP", True, factory=is_true),
|
|
147
|
-
Attribute("smb_enabled", "SMB", True, factory=is_true),
|
|
148
|
-
Attribute("ftp_enabled", "FTP", True, factory=is_true),
|
|
149
|
-
Attribute("kdc_enabled", "KDC", True, factory=is_true),
|
|
150
|
-
Attribute("ldap_enabled", "LDAP", True, factory=is_true),
|
|
151
|
-
Attribute("quic_enabled", "QUIC", True, factory=is_true),
|
|
152
|
-
Attribute("mdns_enabled", "mDNS", True, factory=is_true),
|
|
153
|
-
Attribute("http_enabled", "HTTP", True, factory=is_true),
|
|
154
|
-
Attribute("msrpc_enabled", "RPC", True, factory=is_true),
|
|
155
|
-
Attribute("winrm_enabled", "WinRM", True, factory=is_true),
|
|
156
|
-
Attribute("mssql_enabled", "MSSQL", True, factory=is_true),
|
|
157
|
-
Attribute("ssrp_enabled", "SSRP", True, factory=is_true),
|
|
158
|
-
Attribute("extra_modules", "ExtraModules", list),
|
|
159
|
-
Attribute("workspace_path", "Workspace", DEMENTOR_PATH),
|
|
160
|
-
]
|
|
161
|
-
|
|
162
|
-
# TODO: move into .pyi
|
|
163
|
-
db: Any
|
|
164
|
-
db_config: Any
|
|
165
|
-
krb5_config: Any
|
|
166
|
-
mdns_config: Any
|
|
167
|
-
llmnr_config: Any
|
|
168
|
-
quic_config: Any
|
|
169
|
-
netbiosns_config: Any
|
|
170
|
-
ldap_config: List[Any]
|
|
171
|
-
|
|
172
|
-
def __init__(self) -> None:
|
|
173
|
-
super().__init__(dm_config.get("Dementor", {}))
|
|
174
|
-
# global options that are not loaded from configuration
|
|
175
|
-
self.ipv6 = None
|
|
176
|
-
self.ipv4 = None
|
|
177
|
-
self.interface = None
|
|
178
|
-
self.analysis = False
|
|
179
|
-
self.loop = asyncio.get_event_loop()
|
|
180
|
-
self.protocols = {}
|
|
181
|
-
|
|
182
|
-
# SMTP configuration
|
|
183
|
-
self.smtp_servers = []
|
|
184
|
-
|
|
185
|
-
# NTLM configuration
|
|
186
|
-
self.ntlm_challange = b"1337LEET"
|
|
187
|
-
self.ntlm_ess = True
|
|
188
|
-
|
|
189
|
-
# SMB configuration
|
|
190
|
-
self.smb_server_config = []
|
|
191
|
-
|
|
192
|
-
def is_bound_to_all(self) -> bool:
|
|
193
|
-
# REVISIT: this should raise an exception
|
|
194
|
-
return self.interface == "ALL"
|
|
195
|
-
|
|
196
|
-
@property
|
|
197
|
-
def bind_address(self) -> str:
|
|
198
|
-
return "::" if self.ipv6 else str(self.ipv4)
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
def _read(path: str):
|
|
202
|
-
with open(path, "rb") as f:
|
|
203
|
-
return tomllib.load(f)
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
dm_default_config = _read(os.path.join(ASSETS_PATH, "Dementor.toml"))
|
|
207
|
-
|
|
208
|
-
if os.path.exists(CONFIG_PATH):
|
|
209
|
-
dm_config = _read(CONFIG_PATH)
|
|
210
|
-
else:
|
|
211
|
-
dm_config = {}
|
|
212
|
-
|
|
213
|
-
if not dm_config or "Dementor" not in dm_config:
|
|
214
|
-
# TODO: do first run
|
|
215
|
-
dm_config = dm_default_config
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
def get_bool(section: str, key: str, default=False) -> bool:
|
|
219
|
-
value = str(get_value(section, key=key, default=str(default)))
|
|
220
|
-
return is_true(value)
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
def get_value(section: str, key: str | None, default=None) -> Any:
|
|
224
|
-
sections = section.split(".")
|
|
225
|
-
if len(sections) == 1:
|
|
226
|
-
target = dm_config.get(sections[0], {})
|
|
227
|
-
else:
|
|
228
|
-
target = dm_config
|
|
229
|
-
for section in sections:
|
|
230
|
-
target = target[section]
|
|
231
|
-
|
|
232
|
-
if key is None:
|
|
233
|
-
return target
|
|
234
|
-
|
|
235
|
-
return target.get(key, default)
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
def init_from_file(path: str):
|
|
239
|
-
global dm_config
|
|
240
|
-
|
|
241
|
-
if os.path.exists(path):
|
|
242
|
-
dm_config = _read(path)
|
|
@@ -0,0 +1,44 @@
|
|
|
1
|
+
# Copyright (c) 2025-Present MatrixEditor
|
|
2
|
+
#
|
|
3
|
+
# Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
4
|
+
# of this software and associated documentation files (the "Software"), to deal
|
|
5
|
+
# in the Software without restriction, including without limitation the rights
|
|
6
|
+
# to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
7
|
+
# copies of the Software, and to permit persons to whom the Software is
|
|
8
|
+
# furnished to do so, subject to the following conditions:
|
|
9
|
+
#
|
|
10
|
+
# The above copyright notice and this permission notice shall be included in all
|
|
11
|
+
# copies or substantial portions of the Software.
|
|
12
|
+
#
|
|
13
|
+
# THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
14
|
+
# IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
15
|
+
# FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
16
|
+
# AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
17
|
+
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
|
+
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
|
+
# SOFTWARE.
|
|
20
|
+
from typing import Any
|
|
21
|
+
|
|
22
|
+
from dementor.config import _get_global_config
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def get_value(section: str, key: str | None, default=None) -> Any:
|
|
26
|
+
sections = section.split(".")
|
|
27
|
+
config = _get_global_config()
|
|
28
|
+
if len(sections) == 1:
|
|
29
|
+
target = config.get(sections[0], {})
|
|
30
|
+
else:
|
|
31
|
+
target = config
|
|
32
|
+
for section in sections:
|
|
33
|
+
target = target[section]
|
|
34
|
+
|
|
35
|
+
if key is None:
|
|
36
|
+
return target
|
|
37
|
+
|
|
38
|
+
return target.get(key, default)
|
|
39
|
+
|
|
40
|
+
|
|
41
|
+
# --- factory methods for attributes ---
|
|
42
|
+
def is_true(value: str) -> bool:
|
|
43
|
+
return str(value).lower() in ("true", "1", "on", "yes")
|
|
44
|
+
|
|
@@ -33,7 +33,7 @@ from sqlalchemy.exc import NoSuchTableError, NoInspectionAvailable
|
|
|
33
33
|
|
|
34
34
|
|
|
35
35
|
from dementor.logger import dm_logger, dm_console_lock
|
|
36
|
-
from dementor.config import TomlConfig, Attribute as A
|
|
36
|
+
from dementor.config.toml import TomlConfig, Attribute as A
|
|
37
37
|
|
|
38
38
|
|
|
39
39
|
class DatabaseConfig(TomlConfig):
|
|
@@ -52,7 +52,6 @@ def init_dementor_db(session) -> str:
|
|
|
52
52
|
|
|
53
53
|
name = session.db_config.db_name
|
|
54
54
|
db_path = pathlib.Path(workspace_path) / name
|
|
55
|
-
|
|
56
55
|
if not db_path.exists():
|
|
57
56
|
dm_logger.info("Initializing Dementor database")
|
|
58
57
|
# TODO: check for parent dirs
|
|
@@ -24,7 +24,7 @@ import pathlib
|
|
|
24
24
|
import warnings
|
|
25
25
|
|
|
26
26
|
from typing import Any, List
|
|
27
|
-
from dementor.config import Attribute
|
|
27
|
+
from dementor.config.toml import Attribute
|
|
28
28
|
|
|
29
29
|
|
|
30
30
|
class FilterObj:
|
|
@@ -76,39 +76,35 @@ class FilterObj:
|
|
|
76
76
|
return filters
|
|
77
77
|
|
|
78
78
|
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
A("ignored", "Ignore", None, section_local=False),
|
|
82
|
-
]
|
|
79
|
+
def _optional_filter(value):
|
|
80
|
+
return None if value is None else Filters(value)
|
|
83
81
|
|
|
84
|
-
def set_ignored(self, value):
|
|
85
|
-
self.ignored = value if value is None else Filters(value)
|
|
86
82
|
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
A("targets", "Target", None, section_local=False),
|
|
95
|
-
]
|
|
96
|
-
|
|
97
|
-
def set_targets(self, value):
|
|
98
|
-
self.targets = value if value is None else Filters(value)
|
|
99
|
-
|
|
100
|
-
def is_target(self, host: str):
|
|
101
|
-
# will always be a target if no list has been configured
|
|
102
|
-
return host in self.targets if self.targets else True
|
|
83
|
+
ATTR_BLACKLIST = Attribute(
|
|
84
|
+
"ignored",
|
|
85
|
+
"Ignore",
|
|
86
|
+
default_val=None,
|
|
87
|
+
section_local=False,
|
|
88
|
+
factory=_optional_filter,
|
|
89
|
+
)
|
|
103
90
|
|
|
91
|
+
ATTR_WHITELIST = Attribute(
|
|
92
|
+
"targets",
|
|
93
|
+
"Target",
|
|
94
|
+
default_val=None,
|
|
95
|
+
section_local=False,
|
|
96
|
+
factory=_optional_filter,
|
|
97
|
+
)
|
|
104
98
|
|
|
105
99
|
def in_scope(value: str, config: Any) -> bool:
|
|
106
|
-
if
|
|
107
|
-
|
|
100
|
+
if hasattr(config, "targets"):
|
|
101
|
+
is_target = value in config.targets if config.targets else True
|
|
102
|
+
if not is_target:
|
|
108
103
|
return False
|
|
109
104
|
|
|
110
|
-
if
|
|
111
|
-
if config.
|
|
105
|
+
if hasattr(config, "ignored"):
|
|
106
|
+
is_ignored = value in config.ignored if config.ignored else False
|
|
107
|
+
if is_ignored:
|
|
112
108
|
return False
|
|
113
109
|
|
|
114
110
|
return True
|
|
@@ -32,7 +32,7 @@ from rich.console import Console
|
|
|
32
32
|
from rich.logging import RichHandler
|
|
33
33
|
from rich.markup import render
|
|
34
34
|
|
|
35
|
-
from dementor.config import TomlConfig, Attribute as A
|
|
35
|
+
from dementor.config.toml import TomlConfig, Attribute as A
|
|
36
36
|
|
|
37
37
|
dm_console = Console(
|
|
38
38
|
soft_wrap=True,
|
|
@@ -21,7 +21,8 @@ import os
|
|
|
21
21
|
import dementor
|
|
22
22
|
|
|
23
23
|
DEMENTOR_PATH = os.path.expanduser("~/.dementor")
|
|
24
|
-
CONFIG_PATH = os.path.join(DEMENTOR_PATH, "Dementor.conf")
|
|
25
24
|
ASSETS_PATH = os.path.join(os.path.dirname(dementor.__file__), "assets")
|
|
25
|
+
CONFIG_PATH = os.path.join(DEMENTOR_PATH, "Dementor.toml")
|
|
26
|
+
DEFAULT_CONFIG_PATH = os.path.join(ASSETS_PATH, "Dementor.toml")
|
|
26
27
|
BANNER_PATH = os.path.join(ASSETS_PATH, "banner.txt")
|
|
27
28
|
HTTP_TEMPLATES_PATH = os.path.join(ASSETS_PATH, "www")
|
|
@@ -17,7 +17,8 @@
|
|
|
17
17
|
# LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
18
18
|
# OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
19
19
|
# SOFTWARE.
|
|
20
|
-
from dementor.config import Attribute as A
|
|
20
|
+
from dementor.config.toml import TomlConfig, Attribute as A
|
|
21
|
+
from dementor.config.util import get_value
|
|
21
22
|
from dementor.logger import ProtocolLogger
|
|
22
23
|
from dementor.servers import BaseProtoHandler, ThreadingTCPServer, ServerThread
|
|
23
24
|
from dementor.database import _CLEARTEXT
|
|
@@ -33,15 +33,17 @@ from jinja2 import select_autoescape
|
|
|
33
33
|
from rich import markup
|
|
34
34
|
from impacket import ntlm
|
|
35
35
|
|
|
36
|
-
from dementor.config import Attribute as A
|
|
36
|
+
from dementor.config.toml import TomlConfig, Attribute as A
|
|
37
|
+
from dementor.config.util import get_value, is_true
|
|
37
38
|
from dementor.logger import ProtocolLogger, dm_logger
|
|
38
39
|
from dementor.servers import ServerThread, bind_server
|
|
39
40
|
from dementor.database import _CLEARTEXT, normalize_client_address, _NO_USER
|
|
40
41
|
from dementor.paths import HTTP_TEMPLATES_PATH
|
|
41
42
|
from dementor.protocols.ntlm import (
|
|
42
43
|
NTLM_AUTH_CreateChallenge,
|
|
43
|
-
|
|
44
|
-
|
|
44
|
+
ATTR_NTLM_CHALLENGE,
|
|
45
|
+
ATTR_NTLM_ESS,
|
|
46
|
+
NTLM_report_auth,
|
|
45
47
|
NTLM_split_fqdn,
|
|
46
48
|
)
|
|
47
49
|
|
|
@@ -161,8 +163,6 @@ class HTTPServerConfig(TomlConfig):
|
|
|
161
163
|
A("http_port", "Port"),
|
|
162
164
|
A("http_server_type", "ServerType", "Microsoft-IIS/10.0"),
|
|
163
165
|
A("http_auth_schemes", "AuthSchemes", ["Negotiate", "NTLM", "Basic", "Bearer"]),
|
|
164
|
-
A("http_ntlm_challenge", "NTLM.Challenge", b"A" * 8),
|
|
165
|
-
A("http_ess", "NTLM.ExtendedSessionSecurity", True, factory=is_true),
|
|
166
166
|
A("http_fqdn", "FQDN", "DEMENTOR", section_local=False),
|
|
167
167
|
A("http_extra_headers", "ExtraHeaders", list),
|
|
168
168
|
A("http_wpad_enabled", "WPAD", True, factory=is_true),
|
|
@@ -173,6 +173,8 @@ class HTTPServerConfig(TomlConfig):
|
|
|
173
173
|
A("http_cert", "Cert", None, section_local=False),
|
|
174
174
|
A("http_cert_key", "Key", None, section_local=False),
|
|
175
175
|
A("http_use_ssl", "TLS", False, factory=is_true),
|
|
176
|
+
ATTR_NTLM_CHALLENGE,
|
|
177
|
+
ATTR_NTLM_ESS,
|
|
176
178
|
]
|
|
177
179
|
|
|
178
180
|
def set_http_ntlm_challenge(self, challenge):
|
|
@@ -206,7 +208,7 @@ class HTTPHeaders:
|
|
|
206
208
|
|
|
207
209
|
class HTTPHandler(BaseHTTPRequestHandler):
|
|
208
210
|
def __init__(self, session, config, request, client_address, server) -> None:
|
|
209
|
-
self.config = config
|
|
211
|
+
self.config = config # REVISIT: this is confusing
|
|
210
212
|
self.session = session
|
|
211
213
|
self.client_address = client_address
|
|
212
214
|
self.challenge = None
|
|
@@ -262,7 +264,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
|
|
|
262
264
|
# let us log mssages
|
|
263
265
|
text = format % args
|
|
264
266
|
msg = text.translate(self._control_char_table)
|
|
265
|
-
self.logger.debug(f"
|
|
267
|
+
self.logger.debug(f"(http) {msg}")
|
|
266
268
|
|
|
267
269
|
def send_response(self, code: int, message: str | None = None) -> None:
|
|
268
270
|
if not hasattr(self, "_headers_buffer"):
|
|
@@ -389,8 +391,8 @@ class HTTPHandler(BaseHTTPRequestHandler):
|
|
|
389
391
|
challenge = NTLM_AUTH_CreateChallenge(
|
|
390
392
|
message,
|
|
391
393
|
*NTLM_split_fqdn(self.config.http_fqdn),
|
|
392
|
-
challenge=self.config.
|
|
393
|
-
disable_ess=not self.config.
|
|
394
|
+
challenge=self.config.ntlm_challenge,
|
|
395
|
+
disable_ess=not self.config.ntlm_ess,
|
|
394
396
|
)
|
|
395
397
|
self.send_response(HTTPStatus.UNAUTHORIZED, "Unauthorized")
|
|
396
398
|
data = base64.b64encode(challenge.getData()).decode()
|
|
@@ -401,29 +403,12 @@ class HTTPHandler(BaseHTTPRequestHandler):
|
|
|
401
403
|
|
|
402
404
|
case ntlm.NTLM_HTTP_AuthChallengeResponse():
|
|
403
405
|
self.display_request("NTLMSSP_AUTH", logger)
|
|
404
|
-
|
|
405
|
-
|
|
406
|
-
|
|
407
|
-
self.
|
|
408
|
-
|
|
409
|
-
auth_message["domain_name"],
|
|
410
|
-
auth_message["lanman"],
|
|
411
|
-
auth_message["ntlm"],
|
|
412
|
-
auth_message["flags"],
|
|
413
|
-
)
|
|
414
|
-
domain = NTLM_AUTH_decode_string(
|
|
415
|
-
auth_message["domain_name"], auth_message["flags"]
|
|
416
|
-
)
|
|
417
|
-
username = NTLM_AUTH_decode_string(
|
|
418
|
-
auth_message["user_name"], auth_message["flags"]
|
|
419
|
-
)
|
|
420
|
-
self.session.db.add_auth(
|
|
421
|
-
self.client_address,
|
|
422
|
-
credtype=hashversion,
|
|
423
|
-
username=username,
|
|
424
|
-
password=hashvalue,
|
|
406
|
+
NTLM_report_auth(
|
|
407
|
+
message,
|
|
408
|
+
challenge=self.config.ntlm_challenge,
|
|
409
|
+
client=self.client_address,
|
|
410
|
+
session=self.session,
|
|
425
411
|
logger=logger,
|
|
426
|
-
domain=domain,
|
|
427
412
|
extras=self.get_extras(),
|
|
428
413
|
)
|
|
429
414
|
self.finish_request(logger)
|