dementor 1.0.0.dev13__tar.gz → 1.0.0.dev15__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/PKG-INFO +1 -1
  2. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/__init__.py +1 -1
  3. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/Dementor.toml +6 -12
  4. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/config/session.py +88 -13
  5. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/config/toml.py +9 -4
  6. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/config/util.py +4 -4
  7. dementor-1.0.0.dev15/dementor/db/__init__.py +27 -0
  8. dementor-1.0.0.dev15/dementor/db/connector.py +100 -0
  9. dementor-1.0.0.dev13/dementor/database.py → dementor-1.0.0.dev15/dementor/db/model.py +141 -126
  10. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/filters.py +11 -10
  11. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/loader.py +36 -17
  12. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/log/logger.py +41 -11
  13. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/log/stream.py +21 -1
  14. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/ftp.py +10 -3
  15. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/http.py +47 -17
  16. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/imap.py +19 -3
  17. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/ipp.py +26 -6
  18. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/kerberos.py +11 -5
  19. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/ldap.py +28 -14
  20. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/llmnr.py +18 -8
  21. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/mdns.py +27 -17
  22. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/msrpc/rpc.py +33 -5
  23. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/msrpc.py +3 -2
  24. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/mssql.py +28 -3
  25. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/mysql.py +16 -4
  26. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/netbios.py +31 -19
  27. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/pop3.py +18 -4
  28. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/quic.py +16 -9
  29. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/smb.py +11 -0
  30. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/smtp.py +25 -12
  31. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/spnego.py +1 -1
  32. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/ssdp.py +13 -5
  33. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/upnp.py +30 -12
  34. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/x11.py +16 -9
  35. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/servers.py +22 -9
  36. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/standalone.py +67 -14
  37. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor.egg-info/PKG-INFO +1 -1
  38. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor.egg-info/SOURCES.txt +3 -1
  39. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/pyproject.toml +1 -1
  40. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/LICENSE +0 -0
  41. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/README.md +0 -0
  42. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/__main__.py +0 -0
  43. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/banner.txt +0 -0
  44. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/www/error_page.html +0 -0
  45. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/www/upnp-default/dd.xml +0 -0
  46. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/www/upnp-default/present.html +0 -0
  47. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/www/upnp-default/scpd.xml +0 -0
  48. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/assets/www/wpad.dat +0 -0
  49. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/config/__init__.py +0 -0
  50. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/config/attr.py +0 -0
  51. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/log/__init__.py +0 -0
  52. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/log/hexdump.py +0 -0
  53. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/paths.py +0 -0
  54. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/__init__.py +0 -0
  55. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/msrpc/__init__.py +0 -0
  56. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/msrpc/dcom.py +0 -0
  57. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/msrpc/epm.py +0 -0
  58. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor/protocols/ntlm.py +0 -0
  59. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor.egg-info/dependency_links.txt +0 -0
  60. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor.egg-info/entry_points.txt +0 -0
  61. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor.egg-info/requires.txt +0 -0
  62. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/dementor.egg-info/top_level.txt +0 -0
  63. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/docs/README.pypi.md +0 -0
  64. {dementor-1.0.0.dev13 → dementor-1.0.0.dev15}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev13
3
+ Version: 1.0.0.dev15
4
4
  Summary: LLMNR/NBT-NS/mDNS Poisoner and rogue service provider
5
5
  Author: MatrixEditor
6
6
  Maintainer: MatrixEditor
@@ -18,5 +18,5 @@
18
18
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
19
  # SOFTWARE.
20
20
 
21
- __version__ = "1.0.0.dev13"
21
+ __version__ = "1.0.0.dev15"
22
22
  __author__ = "MatrixEditor"
@@ -186,10 +186,10 @@ UPnP = true
186
186
  # These extra fields (e.g., `foo`, `bar`) will be passed to the final
187
187
  # FilterObj instance and may be used for protocol-specific handling.
188
188
 
189
- # AnswerTo = []
189
+ # Target = []
190
190
 
191
191
  # Describes a list of hosts to *exclude* from poisoning (blacklist approach).
192
- # Uses the same filter structure as `AnswerTo`.
192
+ # Uses the same filter structure as Target.
193
193
 
194
194
  # Ignore = []
195
195
 
@@ -205,16 +205,10 @@ UPnP = true
205
205
 
206
206
  DuplicateCreds = true
207
207
 
208
- # Custom database filename (overrides default "Dementor.db"). Do not put any
209
- # path information here.
210
-
211
- # Name = "database.db"
212
-
213
- # Custom path where the database file will be stored. If set, it overrides the
214
- # workspace directory.
215
-
216
- # Directory = "/path/to/directory/"
217
-
208
+ # Dialect = "sqlite"
209
+ # Driver = "pysqlite"
210
+ # Url = "sqlite:///:memory:"
211
+ # Path = "Dementor.db"
218
212
 
219
213
  # =============================================================================
220
214
  # mDNS
@@ -17,10 +17,11 @@
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
+ # pyright: reportUninitializedInstanceVariable=false
20
21
  import asyncio
22
+ import typing
21
23
 
22
- from typing import Any, List
23
-
24
+ from typing import Any
24
25
  from pathlib import Path
25
26
 
26
27
  from dementor.config.toml import TomlConfig, Attribute
@@ -28,6 +29,31 @@ from dementor.config.util import is_true
28
29
  from dementor.paths import DEMENTOR_PATH
29
30
  from dementor import config
30
31
 
32
+ if typing.TYPE_CHECKING:
33
+ from dementor.protocols import (
34
+ kerberos,
35
+ mdns,
36
+ netbios,
37
+ llmnr,
38
+ ldap,
39
+ smb,
40
+ smtp,
41
+ ftp,
42
+ http,
43
+ imap,
44
+ ipp,
45
+ mssql,
46
+ mysql,
47
+ pop3,
48
+ quic,
49
+ ssdp,
50
+ upnp,
51
+ x11,
52
+ )
53
+ from dementor.protocols.msrpc import rpc
54
+ from dementor.db.model import DementorDB
55
+ from dementor.db.connector import DatabaseConfig
56
+
31
57
 
32
58
  class SessionConfig(TomlConfig):
33
59
  _section_ = "Dementor"
@@ -64,14 +90,66 @@ class SessionConfig(TomlConfig):
64
90
  ]
65
91
 
66
92
  # TODO: move into .pyi
67
- db: Any
68
- db_config: Any
69
- krb5_config: Any
70
- mdns_config: Any
71
- llmnr_config: Any
72
- quic_config: Any
73
- netbiosns_config: Any
74
- ldap_config: List[Any]
93
+ if typing.TYPE_CHECKING:
94
+ workspace_path: str
95
+ extra_modules: list[str]
96
+ ipv6: str | None
97
+ ipv4: str | None
98
+ interface: str | None
99
+ protocols: dict[str, Any]
100
+
101
+ db: DementorDB
102
+ db_config: DatabaseConfig
103
+ krb5_config: kerberos.KerberosConfig
104
+ mdns_config: mdns.MDNSConfig
105
+ llmnr_config: llmnr.LLMNRConfig
106
+ netbiosns_config: netbios.NBTNSConfig
107
+ ldap_config: list[ldap.LDAPServerConfig]
108
+ smtp_servers: list[smtp.SMTPServerConfig]
109
+ smb_config: list[smb.SMBServerConfig]
110
+ ftp_config: list[ftp.FTPServerConfig]
111
+ proxy_config: http.ProxyAutoConfig
112
+ http_config: list[http.HTTPServerConfig]
113
+ winrm_config: list[http.HTTPServerConfig]
114
+ imap_config: list[imap.IMAPServerConfig]
115
+ ipp_config: ipp.IPPConfig
116
+ rpc_config: rpc.RPCConfig
117
+ mssql_config: mssql.MSSQLConfig
118
+ ssrp_config: mssql.SSRPConfig
119
+ mysql_config: mysql.MySQLConfig
120
+ pop3_config: list[pop3.POP3ServerConfig]
121
+ quic_config: quic.QuicServerConfig
122
+ ssdp_config: ssdp.SSDPConfig
123
+ upnp_config: upnp.UPNPConfig
124
+ x11_config: x11.X11Config
125
+
126
+ ntlm_challange: bytes
127
+ ntlm_ess: bool
128
+ analysis: bool
129
+ loop: asyncio.AbstractEventLoop
130
+
131
+ llmnr_enabled: bool
132
+ nbtns_enabled: bool
133
+ nbtds_enabled: bool
134
+ smtp_enabled: bool
135
+ smb_enabled: bool
136
+ ftp_enabled: bool
137
+ kdc_enabled: bool
138
+ ldap_enabled: bool
139
+ quic_enabled: bool
140
+ mdns_enabled: bool
141
+ http_enabled: bool
142
+ rpc_enabled: bool
143
+ winrm_enabled: bool
144
+ mssql_enabled: bool
145
+ ssrp_enabled: bool
146
+ imap_enabled: bool
147
+ pop3_enabled: bool
148
+ mysql_enabled: bool
149
+ x11_enabled: bool
150
+ ipp_enabled: bool
151
+ ssdp_enabled: bool
152
+ upnp_enabled: bool
75
153
 
76
154
  def __init__(self) -> None:
77
155
  super().__init__(config._get_global_config().get("Dementor", {}))
@@ -90,9 +168,6 @@ class SessionConfig(TomlConfig):
90
168
  self.ntlm_challange = b"1337LEET"
91
169
  self.ntlm_ess = True
92
170
 
93
- # SMB configuration
94
- self.smb_server_config = []
95
-
96
171
  def is_bound_to_all(self) -> bool:
97
172
  # REVISIT: this should raise an exception
98
173
  return self.interface == "ALL"
@@ -17,11 +17,12 @@
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 typing import NamedTuple, Callable, Any
20
+ from typing import NamedTuple, Callable, Any, TypeVar
21
21
 
22
22
  from dementor.config.util import get_value
23
23
 
24
24
  _LOCAL = object()
25
+ _T = TypeVar("_T", bound="TomlConfig")
25
26
 
26
27
 
27
28
  class Attribute(NamedTuple):
@@ -36,7 +37,7 @@ class TomlConfig:
36
37
  _section_: str | None
37
38
  _fields_: list[Attribute]
38
39
 
39
- def __init__(self, config: dict | None = None) -> None:
40
+ def __init__(self, config: dict[str, Any] | None = None) -> None:
40
41
  for field in self._fields_:
41
42
  self._set_field(
42
43
  config or {},
@@ -62,8 +63,12 @@ class TomlConfig:
62
63
  raise KeyError(f"Could not find config with key {key!r}")
63
64
 
64
65
  @staticmethod
65
- def build_config(cls_ty, section: str | None = None) -> Any:
66
- return cls_ty(get_value(section or cls_ty._section_, key=None, default={}))
66
+ def build_config(cls_ty: type[_T], section: str | None = None) -> _T:
67
+ section_name = section or cls_ty._section_
68
+ if section_name is None:
69
+ raise ValueError("section cannot be None")
70
+
71
+ return cls_ty(get_value(section_name, key=None, default={}))
67
72
 
68
73
  def _set_field(
69
74
  self,
@@ -53,10 +53,10 @@ def is_true(value: str) -> bool:
53
53
 
54
54
 
55
55
  class BytesValue:
56
- def __init__(self, length=None) -> None:
57
- self.length = length
56
+ def __init__(self, length: int | None = None) -> None:
57
+ self.length: int | None = length
58
58
 
59
- def __call__(self, value) -> Any:
59
+ def __call__(self, value: Any) -> bytes:
60
60
  match value:
61
61
  case None:
62
62
  return secrets.token_bytes(self.length or 1)
@@ -78,7 +78,7 @@ def random_value(size: int) -> str:
78
78
  return "".join(random.choice(string.ascii_letters) for _ in range(size))
79
79
 
80
80
 
81
- def format_string(value: str, locals: dict | None = None) -> str:
81
+ def format_string(value: str, locals: dict[str, Any] | None = None) -> str:
82
82
  config = _get_global_config()
83
83
  try:
84
84
  template = _SANDBOX.from_string(value)
@@ -0,0 +1,27 @@
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
+ _CLEARTEXT = "Cleartext"
22
+ _NO_USER = "<missing-user>"
23
+
24
+
25
+ def normalize_client_address(client: str) -> str:
26
+ return client.removeprefix("::ffff:")
27
+
@@ -0,0 +1,100 @@
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
+ # pyright: reportUninitializedInstanceVariable=false
21
+ import typing
22
+ from sqlalchemy import Engine, create_engine
23
+
24
+ from dementor.config.session import SessionConfig
25
+ from dementor.db.model import DementorDB, ModelBase
26
+ from dementor.log.logger import dm_logger
27
+ from dementor.config.toml import TomlConfig, Attribute as A
28
+
29
+
30
+ class DatabaseConfig(TomlConfig):
31
+ _section_ = "DB"
32
+ _fields_ = [
33
+ A("db_raw_path", "Url", None),
34
+ A("db_path", "Path", "Dementor.db"),
35
+ A("db_duplicate_creds", "DuplicateCreds", False),
36
+ A("db_dialect", "Dialect", None),
37
+ A("db_driver", "Driver", None),
38
+ ]
39
+
40
+ if typing.TYPE_CHECKING:
41
+ db_raw_path: str | None
42
+ db_path: str
43
+ db_duplicate_creds: bool
44
+ db_dialect: str | None
45
+ db_driver: str | None
46
+
47
+
48
+ def init_dementor_db(session: SessionConfig) -> Engine | None:
49
+ engine = init_engine(session)
50
+ if engine is not None:
51
+ ModelBase.metadata.create_all(engine)
52
+ return engine
53
+
54
+
55
+ def init_engine(session: SessionConfig) -> Engine | None:
56
+ # based on dialect and driver configuration
57
+ raw_path = session.db_config.db_raw_path
58
+ if raw_path is None:
59
+ # fall back to constructing the path manually
60
+ dialect = session.db_config.db_dialect or "sqlite"
61
+ driver = session.db_config.db_driver or "pysqlite"
62
+ path = session.db_config.db_path
63
+ if not path:
64
+ return dm_logger.error("Database path not specified!")
65
+
66
+ if dialect == "sqlite":
67
+ if path != ":memory:":
68
+ real_path = session.resolve_path(path)
69
+ if not real_path.parent.exists():
70
+ dm_logger.debug(f"Creating database directory {real_path.parent}")
71
+ real_path.parent.mkdir(parents=True, exist_ok=True)
72
+
73
+ path = f"/{real_path}"
74
+
75
+ # see https://docs.sqlalchemy.org/en/20/core/engines.html#database-urls
76
+ raw_path = f"{dialect}+{driver}://{path}"
77
+ else:
78
+ sql_type, path = raw_path.split("://")
79
+ if sql_type.count("+") > 0:
80
+ dialect, driver = sql_type.split("+")
81
+ else:
82
+ dialect = sql_type
83
+ driver = "<default>"
84
+
85
+ if dialect != "sqlite":
86
+ first_element, *parts = path.split("/")
87
+ if "@" in first_element:
88
+ first_element = first_element.split("@")[1]
89
+ path = "***:***@" + "/".join([first_element] + list(parts))
90
+
91
+ dm_logger.debug("Using database [%s:%s] at: %s", dialect, driver, path)
92
+ return create_engine(raw_path, isolation_level="AUTOCOMMIT", future=True)
93
+
94
+
95
+ def create_db(session: SessionConfig) -> DementorDB:
96
+ # TODO: add support for custom database implementations
97
+ engine = init_engine(session)
98
+ if not engine:
99
+ raise Exception("Failed to create database engine")
100
+ return DementorDB(engine, session)