dementor 1.0.0.dev0__py3-none-any.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.
dementor/standalone.py ADDED
@@ -0,0 +1,371 @@
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
+ import tomllib
22
+ import json
23
+ import typer
24
+ import pathlib
25
+
26
+ from typing import List
27
+ from typing_extensions import Annotated
28
+
29
+ from impacket.version import version as ImpacketVersion
30
+ from aiosmtpd import __version__ as AiosmtpdVersion
31
+ from aioquic import __version__ as AioquicVersion
32
+ from scapy import VERSION as ScapyVersion
33
+ from scapy.arch import get_if_addr, in6_getifaddr
34
+
35
+ from rich import print
36
+ from rich.console import Console
37
+ from rich.columns import Columns
38
+
39
+ from dementor import __version__ as DementorVersion
40
+ from dementor import logger, database, config
41
+ from dementor.config import SessionConfig, TomlConfig
42
+ from dementor.logger import dm_logger
43
+ from dementor.loader import ProtocolLoader
44
+ from dementor.paths import BANNER_PATH
45
+
46
+
47
+ def serve(
48
+ interface: str,
49
+ analyze_only: bool = False,
50
+ config_path: str | None = None,
51
+ session: SessionConfig | None = None,
52
+ supress_output: bool = False,
53
+ loop: asyncio.AbstractEventLoop | None = None,
54
+ run_forever: bool = True,
55
+ éxtra_options: dict | None = None,
56
+ ) -> tuple | None:
57
+ if config_path:
58
+ try:
59
+ config.init_from_file(config_path)
60
+ except tomllib.TOMLDecodeError as e:
61
+ dm_logger.error(f"Failed to load configuration file: {e}")
62
+ return
63
+
64
+ if session is None:
65
+ session = SessionConfig()
66
+
67
+ logger.init()
68
+ logger.ProtocolLogger.init_logfile(session)
69
+
70
+ if éxtra_options:
71
+ for section, options in éxtra_options.items():
72
+ if section not in config.dm_config:
73
+ config.dm_config[section] = {}
74
+
75
+ for key, value in options.items():
76
+ config.dm_config[section][key] = value
77
+
78
+ if interface and not session.interface:
79
+ session.interface = interface
80
+ try:
81
+ session.ipv4 = get_if_addr(session.interface)
82
+ except ValueError:
83
+ # interface does not exist
84
+ dm_logger.error(
85
+ f"Interface {session.interface} does not exist or is not up, check your configuration"
86
+ )
87
+ return
88
+
89
+ session.ipv6 = next(
90
+ (ip[0] for ip in in6_getifaddr() if ip[2] == session.interface), None
91
+ )
92
+ if session.ipv4 == "0.0.0.0" and not session.ipv6:
93
+ # current interface is not available
94
+ dm_logger.error(
95
+ f"Interface {session.interface} is not available, check your configuration"
96
+ )
97
+ return
98
+
99
+ session.analysis = analyze_only
100
+
101
+ # Setup database for current session
102
+ if not getattr(session, "db", None):
103
+ session.db_config = TomlConfig.build_config(database.DatabaseConfig)
104
+ db_path = database.init_dementor_db(session)
105
+ session.db = database.DementorDB(database.init_engine(db_path), session)
106
+
107
+ # Load protocols
108
+ loader = ProtocolLoader()
109
+ protocols = {}
110
+ if not session.protocols:
111
+ session.protocols = loader.get_protocols(session)
112
+
113
+ for name, path in session.protocols.items():
114
+ protocol = loader.load_protocol(path)
115
+ protocols[name] = protocol
116
+ loader.apply_config(protocol, session)
117
+
118
+ if not supress_output:
119
+ pass
120
+
121
+ if not getattr(session, "loop", None):
122
+ session.loop = loop or asyncio.get_event_loop()
123
+
124
+ asyncio.set_event_loop(session.loop)
125
+ threads = []
126
+ for name, protocol in protocols.items():
127
+ try:
128
+ servers = loader.create_servers(protocol, session)
129
+ threads.extend(servers)
130
+ except Exception as e:
131
+ dm_logger.exception(f"Failed to create server for protocol {name}: {e}")
132
+
133
+ # Start threads
134
+ for thread in threads:
135
+ thread.daemon = True
136
+ thread.start()
137
+
138
+ if run_forever:
139
+ try:
140
+ session.loop.run_forever()
141
+ except KeyboardInterrupt:
142
+ pass
143
+ finally:
144
+ stop_session(session, threads)
145
+
146
+ return (session, threads)
147
+
148
+
149
+ def stop_session(session: SessionConfig, threads=None) -> None:
150
+ # 1. stop event loop
151
+ session.loop.stop()
152
+
153
+ # 2. close threads
154
+ for thread in threads or []:
155
+ del thread
156
+
157
+ # 3. close database
158
+ session.db.close()
159
+
160
+
161
+ _SkippedOption = typer.Option(parser=lambda _: _, hidden=True, expose_value=False)
162
+
163
+
164
+ def parse_options(options: List[str]) -> dict:
165
+ result = {}
166
+ for option in options:
167
+ key, raw_value = option.split("=", 1)
168
+ # Each definition is a key=value pair with an optional section prefix
169
+ if key.count(".") > 1:
170
+ dm_logger.warning(f"Invalid option definition: {option}")
171
+ raise typer.Exit(1)
172
+
173
+ if "." in key:
174
+ section, key = key.rsplit(".", 1)
175
+ else:
176
+ section = "Dementor"
177
+
178
+ match raw_value.strip().lower():
179
+ case "true" | "on" | "yes":
180
+ value = True
181
+ case "false" | "off" | "no":
182
+ value = False
183
+ case _:
184
+ raw_value = raw_value.strip()
185
+ value = None
186
+ if raw_value[0] == "[":
187
+ value = json.loads(raw_value)
188
+ elif raw_value[0] not in ('"', "'"):
189
+ try:
190
+ value = int(raw_value)
191
+ except ValueError:
192
+ pass
193
+
194
+ if value is None:
195
+ value = raw_value.removeprefix('"').removesuffix('"')
196
+
197
+ if section not in result:
198
+ result[section] = {}
199
+
200
+ result[section][key] = value
201
+ return result
202
+
203
+
204
+ # --- main
205
+ def main_print_banner(quiet_mode: bool) -> None:
206
+ banner_file = pathlib.Path(BANNER_PATH)
207
+
208
+ if not quiet_mode and not banner_file.exists():
209
+ # fall back to small banner
210
+ quiet_mode = True
211
+
212
+ if quiet_mode:
213
+ # only print out scapy and impacket versions
214
+ print(
215
+ f"[bold]Dementor[/bold] - [white]Running with Scapy v{ScapyVersion} "
216
+ f"and Impacket v{ImpacketVersion}[/white]\n",
217
+ )
218
+ return
219
+
220
+ text = banner_file.read_text().format(
221
+ dementor_version=DementorVersion,
222
+ scapy_version=ScapyVersion,
223
+ impacket_version=ImpacketVersion,
224
+ aiosmtpd_version=AiosmtpdVersion,
225
+ aioquic_version=AioquicVersion,
226
+ )
227
+ print(text)
228
+
229
+
230
+ def main_format_config(name: str, value: str) -> str:
231
+ line = f"{name} [white]".ljust(45, ".")
232
+ return f"{line}[/white] {value}"
233
+
234
+
235
+ # TODO: refactor this
236
+ def main_print_options(session: SessionConfig, interface):
237
+ console = Console()
238
+ console.rule(style="white", title="Dementor Configuration")
239
+ analyze_only = r"[bold grey]\[Analyze Only][/bold grey]"
240
+ on = r"[bold green]\[ON][/bold green]"
241
+ off = r"[bold red]\[OFF][/bold red]"
242
+
243
+ poisoners_lines = ["", "[bold]Poisoners:[/bold]"]
244
+ for name in ("LLMNR", "mDNS", "NBTNS"):
245
+ attr_name = f"{name.lower()}_enabled"
246
+ status = on if getattr(session, attr_name, False) else off
247
+ if session.analysis:
248
+ status = analyze_only
249
+
250
+ poisoners_lines.append(main_format_config(name, status))
251
+
252
+ poisoners_lines.append("\n[bold]Config:[/bold]")
253
+ mode = (
254
+ r"[bold red]\[Attack][/bold red]"
255
+ if not session.analysis
256
+ else r"[bold blue]\[Analysis][/bold blue]"
257
+ )
258
+ poisoners_lines.append(main_format_config("Mode", mode))
259
+ poisoners_lines.append(main_format_config("Interface", interface))
260
+
261
+ protocols_lines = ["", "[bold]Servers:[/bold]"]
262
+ additional_protocols = ["KDC", "NBTDS"]
263
+ for name in (list(session.protocols) or []) + additional_protocols:
264
+ attr_name = f"{name.lower()}_enabled"
265
+ value = getattr(session, attr_name, None)
266
+ if value is None:
267
+ continue
268
+
269
+ protocols_lines.append(main_format_config(name.upper(), on if value else off))
270
+
271
+ columns = Columns(
272
+ [
273
+ "\n".join(protocols_lines),
274
+ "\n".join(poisoners_lines),
275
+ ],
276
+ expand=True,
277
+ align="left",
278
+ )
279
+ console.print(columns)
280
+ console.print()
281
+ console.rule(style="white", title="Log")
282
+ console.print()
283
+
284
+
285
+ def main(
286
+ interface: Annotated[
287
+ str,
288
+ typer.Option(
289
+ "--interface",
290
+ "-I",
291
+ show_default=False,
292
+ metavar="NAME",
293
+ help="Network interface to use (required for poisoning)",
294
+ ),
295
+ ],
296
+ analyze: Annotated[
297
+ bool,
298
+ typer.Option(
299
+ "--analyze",
300
+ "-A",
301
+ help="Only analyze traffic, don't respond to requests",
302
+ ),
303
+ ] = False,
304
+ config_path: Annotated[
305
+ str,
306
+ typer.Option(
307
+ "--config",
308
+ "-c",
309
+ metavar="PATH",
310
+ show_default=False,
311
+ help="Path to a configuration file (otherwise standard path is used)",
312
+ ),
313
+ ] = None,
314
+ options: Annotated[
315
+ List[str],
316
+ typer.Option(
317
+ "--option",
318
+ "-O",
319
+ metavar="KEY=VALUE",
320
+ show_default=False,
321
+ help="Add an extra option to the global configuration file.",
322
+ ),
323
+ ] = None,
324
+ verbose: Annotated[bool, _SkippedOption] = False,
325
+ debug: Annotated[bool, _SkippedOption] = False,
326
+ quiet: Annotated[
327
+ bool,
328
+ typer.Option(
329
+ "--quiet", "-q", help="Don't print banner at startup", show_default=False
330
+ ),
331
+ ] = False,
332
+ ) -> None:
333
+ main_print_banner(quiet)
334
+
335
+ # prepare options
336
+ extras = parse_options(options or [])
337
+ if config_path:
338
+ try:
339
+ config.init_from_file(config_path)
340
+ except tomllib.TOMLDecodeError as e:
341
+ dm_logger.error(f"Failed to load configuration file: {e}")
342
+ return
343
+
344
+ session = SessionConfig()
345
+ session.analysis = analyze
346
+ logger.init()
347
+
348
+ if extras:
349
+ for section, options in extras.items():
350
+ if section not in config.dm_config:
351
+ config.dm_config[section] = {}
352
+
353
+ for key, value in options.items():
354
+ config.dm_config[section][key] = value
355
+
356
+ loader = ProtocolLoader()
357
+ session.protocols = loader.get_protocols(session)
358
+
359
+ if not quiet:
360
+ main_print_options(session, interface)
361
+
362
+ logger.ProtocolLogger.init_logfile(session)
363
+ serve(interface=interface, session=session)
364
+
365
+
366
+ def run_from_cli() -> None:
367
+ typer.run(main)
368
+
369
+
370
+ if __name__ == "__main__":
371
+ run_from_cli()
@@ -0,0 +1,89 @@
1
+ Metadata-Version: 2.4
2
+ Name: dementor
3
+ Version: 1.0.0.dev0
4
+ Summary: LLMNR/NBT-NS/mDNS Poisoner and rogue service provider
5
+ Author: MatrixEditor
6
+ Maintainer: MatrixEditor
7
+ License: The MIT License (MIT)
8
+
9
+ Copyright (c) 2025-present MatrixEditor
10
+
11
+ Permission is hereby granted, free of charge, to any person obtaining a copy
12
+ of this software and associated documentation files (the "Software"), to deal
13
+ in the Software without restriction, including without limitation the rights
14
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
15
+ copies of the Software, and to permit persons to whom the Software is
16
+ furnished to do so, subject to the following conditions:
17
+
18
+ The above copyright notice and this permission notice shall be included in all
19
+ copies or substantial portions of the Software.
20
+
21
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
22
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
23
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
24
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
25
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
26
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
27
+ SOFTWARE.
28
+ Project-URL: homepage, https://matrixeditor.github.io/dementor
29
+ Project-URL: documentation, https://matrixeditor.github.io/dementor
30
+ Project-URL: source, https://github.com/MatrixEditor/dementor
31
+ Classifier: Development Status :: 4 - Beta
32
+ Classifier: Intended Audience :: Developers
33
+ Classifier: Intended Audience :: Science/Research
34
+ Classifier: License :: OSI Approved :: MIT License
35
+ Classifier: Programming Language :: Python :: 3
36
+ Classifier: Programming Language :: Python :: 3.13
37
+ Classifier: Programming Language :: Python :: 3 :: Only
38
+ Classifier: Programming Language :: Python :: Implementation :: CPython
39
+ Classifier: Topic :: Security
40
+ Classifier: Topic :: System :: Networking
41
+ Classifier: Typing :: Typed
42
+ Classifier: Operating System :: POSIX
43
+ Classifier: Operating System :: Unix
44
+ Description-Content-Type: text/markdown
45
+ License-File: LICENSE
46
+ Dynamic: license-file
47
+
48
+ # Dementor
49
+
50
+ IPv6/IPv4 LLMNR/NBT-NS/mDNS Poisoner and rogue service provider - you can think if it as Responder 2.0. Get more information
51
+ on the [Documentation](https://matrixeditor.github.io/dementor/) page.
52
+
53
+ ### Offers
54
+
55
+ - No reliance on hardcoded or precomputed packets
56
+ - Fine-grained, per-protocol configuration using a modular system (see [Docs - Configuration](https://matrixeditor.github.io/dementor/config/index.html))
57
+ - Near-complete protocol parity with Responder (see [Docs - Compatibility](https://matrixeditor.github.io/dementor/compat.html))
58
+ - Easy integration of new protocols via the extension system
59
+
60
+ ## Installation
61
+
62
+ Installation via `pip` from GitHub or PyPI:
63
+
64
+ ```bash
65
+ pip install dementor
66
+ ```
67
+
68
+ ## Usage
69
+
70
+ Just type in _Dementor_, specify the target interface and you are good to go! It is recommended
71
+ to run _Dementor_ with `sudo` as most protocol servers use privileged ports.
72
+
73
+ ```bash
74
+ sudo Dementor -I "$INTERFACE_NAME"
75
+ ```
76
+
77
+ Let's take a look.
78
+
79
+ ![index_video](https://raw.githubusercontent.com/MatrixEditor/dementor/refs/heads/master/docs/source/_static/images/index-video.gif)
80
+
81
+
82
+ ## You need more?
83
+
84
+ Take a look at the [Documentation on GitHub-Pages](https://matrixeditor.github.io/dementor/)
85
+
86
+
87
+ ## License
88
+
89
+ Distributed under the MIT License. See LICENSE for more information.
@@ -0,0 +1,28 @@
1
+ dementor/__init__.py,sha256=p0womkXlDMiuorQHeubhVFDT4RgOr1gqZU_JyCmXFEY,1155
2
+ dementor/__main__.py,sha256=xcoO05yCYxwp3nEK7ezfXrA-4VM4gm6HC_PaDq5Irg4,60
3
+ dementor/config.py,sha256=-XBxri-8EGHOmGCzzCRXFXcXSIYzGIJskCLBx_ZKbAk,7467
4
+ dementor/database.py,sha256=eEUbYCmpcbeRBmmwyrPuv-PiTeWTevtLqUm8Rb8rLIo,8344
5
+ dementor/filters.py,sha256=Y3dlyvu_5qG1bmeqgplEpX90bZ0CdKJcd32pvCcVhI0,5333
6
+ dementor/loader.py,sha256=3DGRjWgz4rvaspZBHfF8IX6TFLNIaeHvzfowTX3osGE,3279
7
+ dementor/logger.py,sha256=TtdgmsaPCXDSLT2FASIi4j8PB1aok4gOMzOan55nPuY,7751
8
+ dementor/paths.py,sha256=nsPpnaEvVfHhB3OzvixdCeuxBVahOEoxTGpWL5sq06o,1362
9
+ dementor/servers.py,sha256=2-b-Ceo8DXyJKKUMwpM08RiXZ_9TDFW73eeS2m-VQaw,6540
10
+ dementor/standalone.py,sha256=W8B8ao3vNt9w9I5fPIWwsKTUVXIbzOCEOckhivFL8ps,11435
11
+ dementor/protocols/__init__.py,sha256=7PFcfslQgMJIFi2I15_WDNOii-EFdb2NuufrCOz4hbg,1098
12
+ dementor/protocols/ftp.py,sha256=KjMrluB-PdRlQgMi6CrZzb3JzIzLlABX3n6FzhORR5E,3709
13
+ dementor/protocols/kerberos.py,sha256=qdhXW3D3UOfoOdFeUSrOaZftj-39Uk5OoOXzwAc3HuY,10279
14
+ dementor/protocols/ldap.py,sha256=3IebO8snPIrfBLf2p47DobuLHxiIGWR0eX9NvCKb1o0,14617
15
+ dementor/protocols/llmnr.py,sha256=Fi0XxTC3zSR5B9zyOeqC_wDvQm13C7fuYG7mgnWbVw0,5615
16
+ dementor/protocols/mdns.py,sha256=H1rKJR0mDLJIlsBoURCl7zNKYaHD2qWwYGQ4qfV-udE,7464
17
+ dementor/protocols/netbios.py,sha256=6WCW0A1xapelGPcsdXPct9MmoQ85JmVOpnpxIQxn1-0,9531
18
+ dementor/protocols/ntlm.py,sha256=2dAanVYdhfUaCXkIs1XhZBtnhBhnVHzpvqyZHRNZXb0,7422
19
+ dementor/protocols/quic.py,sha256=4btJNRUcifPZec1xl3pNFEtfp7Rp_DhzU6ozPyA_uKM,7199
20
+ dementor/protocols/smb.py,sha256=7fmrZ_dwgvROznmT-0CvwPxqjcMtgwJ0ZY_QMHpCO10,22903
21
+ dementor/protocols/smtp.py,sha256=nutPnTk-b8ftEoGnvrRm7rn_O_Q3BU6EMeYpFcuFVEg,13724
22
+ dementor/protocols/spnego.py,sha256=BGj0a0bnRo2wrONuqNAkqnKZPNi5kWdLO5NJbOg2BEk,1557
23
+ dementor-1.0.0.dev0.dist-info/licenses/LICENSE,sha256=ofH7HY5xgFJjcGSnVj_nbYPWWQlKAFVXoXj6tT3PtSA,1086
24
+ dementor-1.0.0.dev0.dist-info/METADATA,sha256=c1E2SzUAIC3fNsbnCtzHZn8QxgZ_d9IoZyvaYvTfPvo,3584
25
+ dementor-1.0.0.dev0.dist-info/WHEEL,sha256=CmyFI0kx5cdEMTLiONQRbGQwjIoR1aIYB7eCAQ4KPJ0,91
26
+ dementor-1.0.0.dev0.dist-info/entry_points.txt,sha256=51vt5TmkE0Po_8lLRu98wFMY81Lm2ICdIdlxRfipZjM,62
27
+ dementor-1.0.0.dev0.dist-info/top_level.txt,sha256=AP1NySEoQnHZnpQG5y3_T0wf5Cwx0NC27_m-a_I6zVo,9
28
+ dementor-1.0.0.dev0.dist-info/RECORD,,
@@ -0,0 +1,5 @@
1
+ Wheel-Version: 1.0
2
+ Generator: setuptools (78.1.0)
3
+ Root-Is-Purelib: true
4
+ Tag: py3-none-any
5
+
@@ -0,0 +1,2 @@
1
+ [console_scripts]
2
+ Dementor = dementor.standalone:run_from_cli
@@ -0,0 +1,21 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2025-present MatrixEditor
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
+ dementor