dementor 1.0.0.dev2__tar.gz → 1.0.0.dev3__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.

Files changed (42) hide show
  1. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/PKG-INFO +1 -1
  2. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/__init__.py +1 -1
  3. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/config.py +9 -4
  4. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/database.py +12 -4
  5. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/http.py +100 -17
  6. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/quic.py +1 -2
  7. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/smb.py +1 -5
  8. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/smtp.py +1 -1
  9. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/servers.py +2 -2
  10. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/standalone.py +1 -1
  11. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor.egg-info/PKG-INFO +1 -1
  12. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/pyproject.toml +1 -1
  13. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/LICENSE +0 -0
  14. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/README.md +0 -0
  15. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/__main__.py +0 -0
  16. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/filters.py +0 -0
  17. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/loader.py +0 -0
  18. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/logger.py +0 -0
  19. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/paths.py +0 -0
  20. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/__init__.py +0 -0
  21. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/ftp.py +0 -0
  22. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/kerberos.py +0 -0
  23. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/ldap.py +0 -0
  24. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/llmnr.py +0 -0
  25. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/mdns.py +0 -0
  26. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/msrpc/__init__.py +0 -0
  27. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/msrpc/dcom.py +0 -0
  28. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/msrpc/epm.py +0 -0
  29. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/msrpc/rpc.py +0 -0
  30. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/msrpc.py +0 -0
  31. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/netbios.py +0 -0
  32. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/ntlm.py +0 -0
  33. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor/protocols/spnego.py +0 -0
  34. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor.egg-info/SOURCES.txt +0 -0
  35. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor.egg-info/dependency_links.txt +0 -0
  36. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor.egg-info/entry_points.txt +0 -0
  37. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/dementor.egg-info/top_level.txt +0 -0
  38. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/docs/README.pypi.md +0 -0
  39. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/setup.cfg +0 -0
  40. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/test/test_dcerpc.py +0 -0
  41. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/test/test_dcom.py +0 -0
  42. {dementor-1.0.0.dev2 → dementor-1.0.0.dev3}/test/test_epm.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev2
3
+ Version: 1.0.0.dev3
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.dev2"
21
+ __version__ = "1.0.0.dev3"
22
22
  __author__ = "MatrixEditor"
@@ -41,10 +41,10 @@ class TomlConfig:
41
41
  _section_: str | None
42
42
  _fields_: list[Attribute]
43
43
 
44
- def __init__(self, config: dict) -> None:
44
+ def __init__(self, config: dict | None = None) -> None:
45
45
  for field in self._fields_:
46
46
  self._set_field(
47
- config,
47
+ config or {},
48
48
  field.attr_name,
49
49
  field.qname,
50
50
  field.default_val,
@@ -152,6 +152,7 @@ class SessionConfig(TomlConfig):
152
152
  Attribute("mdns_enabled", "mDNS", True, factory=is_true),
153
153
  Attribute("http_enabled", "HTTP", True, factory=is_true),
154
154
  Attribute("msrpc_enabled", "RPC", True, factory=is_true),
155
+ Attribute("winrm_enabled", "WinRM", True, factory=is_true),
155
156
  Attribute("extra_modules", "ExtraModules", list),
156
157
  Attribute("workspace_path", "Workspace", DEMENTOR_PATH),
157
158
  ]
@@ -169,8 +170,8 @@ class SessionConfig(TomlConfig):
169
170
  def __init__(self) -> None:
170
171
  super().__init__(dm_config.get("Dementor", {}))
171
172
  # global options that are not loaded from configuration
172
- self.ipv6: Optional[str] = None
173
- self.ipv4: Optional[str] = None
173
+ self.ipv6 = None
174
+ self.ipv4 = None
174
175
  self.interface = None
175
176
  self.analysis = False
176
177
  self.loop = asyncio.get_event_loop()
@@ -190,6 +191,10 @@ class SessionConfig(TomlConfig):
190
191
  # REVISIT: this should raise an exception
191
192
  return self.interface == "ALL"
192
193
 
194
+ @property
195
+ def bind_address(self) -> str:
196
+ return "::" if self.ipv6 else str(self.ipv4)
197
+
193
198
 
194
199
  def _read(path: str):
195
200
  with open(path, "rb") as f:
@@ -197,11 +197,19 @@ class DementorDB:
197
197
  )
198
198
  results = self.db_exec(q).all()
199
199
  text = "Password" if credtype == _CLEARTEXT else "Hash"
200
+ username_text = markup.escape(username)
201
+ is_blank = len(str(username).strip()) == 0
202
+ if is_blank:
203
+ username_text = "(blank)"
204
+
200
205
  full_name = (
201
- f"[b]{markup.escape(username)}[/]/[b]{markup.escape(domain)}[/]"
206
+ f" for [b]{username_text}[/]/[b]{markup.escape(domain)}[/]"
202
207
  if domain
203
- else f"[b]{markup.escape(username)}[/]"
208
+ else f" for [b]{username_text}[/]"
204
209
  )
210
+ if is_blank:
211
+ full_name = ""
212
+
205
213
  if not results or self.config.db_config.db_duplicate_creds:
206
214
  # just insert a new row
207
215
  q = sql.insert(self.CredentialsTable).values(
@@ -219,13 +227,13 @@ class DementorDB:
219
227
  self.db_exec(q)
220
228
  with dm_console_lock:
221
229
  target_logger.success(
222
- f"Captured {credtype} {text} for {full_name} from {client_address}:",
230
+ f"Captured {credtype} {text}{full_name} from {client_address}:",
223
231
  host=hostname or client_address,
224
232
  locked=True,
225
233
  )
226
234
  if username != _NO_USER:
227
235
  target_logger.highlight(
228
- f"{credtype} Username: {markup.escape(username)}",
236
+ f"{credtype} Username: {username_text}",
229
237
  host=hostname or client_address,
230
238
  locked=True,
231
239
  )
@@ -20,7 +20,7 @@
20
20
  import socket
21
21
  import base64
22
22
  import pathlib
23
-
23
+ import ssl
24
24
 
25
25
  from http import HTTPStatus
26
26
  from http.server import ThreadingHTTPServer, BaseHTTPRequestHandler
@@ -54,12 +54,31 @@ def apply_config(session):
54
54
  servers.append(HTTPServerConfig(server_config))
55
55
  session.http_config = servers
56
56
 
57
+ winrm_config = []
58
+ config = HTTPServerConfig({"Port": 5985})
59
+ config.http_wpad_enabled = False
60
+ config.http_webdav_enabled = False
61
+
62
+ ssl_enabled = bool(config.http_cert)
63
+ config.http_cert = None
64
+ config.http_cert_key = None
65
+ winrm_config.append(config)
66
+ if ssl_enabled:
67
+ ssl_config = HTTPServerConfig({"Port": 5986})
68
+ ssl_config.http_wpad_enabled = False
69
+ ssl_config.http_webdav_enabled = False
70
+ ssl_config.http_use_ssl = True
71
+ winrm_config.append(ssl_config)
72
+
73
+ if session.winrm_enabled:
74
+ session.winrm_config = winrm_config
75
+
57
76
 
58
77
  def create_server_threads(session):
59
78
  servers = []
60
79
  for server_config in session.http_config if session.http_enabled else []:
61
80
  address = (
62
- "::" if session.ipv6 else session.ipv4 or "",
81
+ session.bind_address,
63
82
  server_config.http_port,
64
83
  )
65
84
  servers.append(
@@ -72,6 +91,19 @@ def create_server_threads(session):
72
91
  )
73
92
  )
74
93
 
94
+ if session.winrm_enabled:
95
+ for winrm_config in session.winrm_config:
96
+ servers.append(
97
+ ServerThread(
98
+ session,
99
+ HTTPServer,
100
+ winrm_config,
101
+ RequestHandlerClass=WinRMHandler,
102
+ server_address=(session.bind_address, winrm_config.http_port),
103
+ ipv6=bool(session.ipv6),
104
+ )
105
+ )
106
+
75
107
  return servers
76
108
 
77
109
 
@@ -138,6 +170,9 @@ class HTTPServerConfig(TomlConfig):
138
170
  A("http_templates", "TemplatesPath", [HTTP_TEMPLATES_PATH]),
139
171
  A("http_webdav_enabled", "WebDAV", True, factory=is_true),
140
172
  A("http_methods", "Methods", ["GET", "POST"]),
173
+ A("http_cert", "Cert", None, section_local=False),
174
+ A("http_cert_key", "Key", None, section_local=False),
175
+ A("http_use_ssl", "TLS", False, factory=is_true),
141
176
  ]
142
177
 
143
178
  def set_http_ntlm_challenge(self, challenge):
@@ -173,31 +208,35 @@ class HTTPHandler(BaseHTTPRequestHandler):
173
208
  def __init__(self, session, config, request, client_address, server) -> None:
174
209
  self.config = config
175
210
  self.session = session
211
+ self.client_address = client_address
212
+ self.challenge = None
213
+ self.setup_proto_logger()
214
+ for http_method in config.http_methods:
215
+ if http_method in ("OPTIONS", "PROPFIND"):
216
+ # reserved options
217
+ continue
218
+
219
+ setattr(self, f"do_{http_method}", lambda: self.handle_request(self.logger))
220
+
221
+ super().__init__(request, client_address, server)
222
+
223
+ def setup_proto_logger(self):
176
224
  self.logger = ProtocolLogger(
177
225
  extra={
178
226
  "protocol": "HTTP",
179
227
  "protocol_color": "chartreuse3",
180
- "host": normalize_client_address(client_address[0]),
181
- "port": config.http_port,
228
+ "host": normalize_client_address(self.client_address[0]),
229
+ "port": self.config.http_port,
182
230
  }
183
231
  )
184
232
  self.webdav_logger = ProtocolLogger(
185
233
  extra={
186
234
  "protocol": "WebDAV",
187
235
  "protocol_color": "sea_green3",
188
- "host": normalize_client_address(client_address[0]),
189
- "port": config.http_port,
236
+ "host": normalize_client_address(self.client_address[0]),
237
+ "port": self.config.http_port,
190
238
  }
191
239
  )
192
- self.challenge = None
193
- for http_method in config.http_methods:
194
- if http_method in ("OPTIONS", "PROPFIND"):
195
- # reserved options
196
- continue
197
-
198
- setattr(self, f"do_{http_method}", lambda: self.handle_request(self.logger))
199
-
200
- super().__init__(request, client_address, server)
201
240
 
202
241
  def do_PROPFIND(self):
203
242
  if self.config.http_webdav_enabled:
@@ -226,6 +265,9 @@ class HTTPHandler(BaseHTTPRequestHandler):
226
265
  self.logger.debug(f"- - {msg}")
227
266
 
228
267
  def send_response(self, code: int, message: str | None = None) -> None:
268
+ if not hasattr(self, "_headers_buffer"):
269
+ self._headers_buffer = []
270
+
229
271
  super().send_response(code, message)
230
272
  for header in self.config.http_extra_headers:
231
273
  self._headers_buffer.append(f"{header}\r\n".encode("latin-1", "strict"))
@@ -267,6 +309,12 @@ class HTTPHandler(BaseHTTPRequestHandler):
267
309
  path = pathlib.Path(self.path)
268
310
  return path.suffix == ".pac" or path.stem == "wpad"
269
311
 
312
+ def display_request(self, req_type: str | None = None, logger=None):
313
+ line = f"{self.command} request for {markup.escape(self.path)}"
314
+ if req_type:
315
+ line = f"{line} ({req_type})"
316
+ (logger or self.logger).display(line)
317
+
270
318
  def send_wpad_script(self):
271
319
  if self.config.proxy_config.proxy_script:
272
320
  # try to render the custom script
@@ -291,7 +339,6 @@ class HTTPHandler(BaseHTTPRequestHandler):
291
339
  self.wfile.write(body)
292
340
 
293
341
  def handle_request(self, logger):
294
- logger.display(f"{self.command} request for {markup.escape(self.path)}")
295
342
  if HTTPHeaders.AUTHORIZATION not in self.headers:
296
343
  # make sure the client authenticates to us
297
344
  if (
@@ -301,6 +348,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
301
348
  ):
302
349
  return self.send_wpad_script()
303
350
 
351
+ self.display_request("Unauthorized", logger)
304
352
  self.send_error(
305
353
  HTTPStatus.UNAUTHORIZED,
306
354
  "Unauthorized",
@@ -315,6 +363,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
315
363
  if method:
316
364
  method(token, logger)
317
365
  else:
366
+ logger.debug(f"Unknown authentication scheme: {name}")
318
367
  self.send_error(HTTPStatus.NOT_FOUND, "Not Found")
319
368
 
320
369
  def auth_negotiate(self, token, logger):
@@ -336,6 +385,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
336
385
 
337
386
  match message:
338
387
  case ntlm.NTLM_HTTP_AuthNegotiate():
388
+ self.display_request("NTLMSSP_NEGOTIATE", logger)
339
389
  challenge = NTLM_AUTH_CreateChallenge(
340
390
  message,
341
391
  *NTLM_split_fqdn(self.config.http_fqdn),
@@ -350,6 +400,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
350
400
  self.end_headers()
351
401
 
352
402
  case ntlm.NTLM_HTTP_AuthChallengeResponse():
403
+ self.display_request("NTLMSSP_AUTH", logger)
353
404
  # try to decode auth message
354
405
  auth_message = message
355
406
  hashversion, hashvalue = NTLM_AUTH_to_hashcat_format(
@@ -384,6 +435,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
384
435
  )
385
436
 
386
437
  def auth_bearer(self, token, logger):
438
+ self.display_request("Bearer", logger)
387
439
  self.session.db.add_auth(
388
440
  client=self.client_address,
389
441
  credtype="BearerToken",
@@ -395,6 +447,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
395
447
  self.finish_request(logger)
396
448
 
397
449
  def auth_basic(self, token, logger):
450
+ self.display_request("Basic", logger)
398
451
  try:
399
452
  username, password = base64.b64decode(token).decode().split(":", 1)
400
453
  except ValueError:
@@ -435,6 +488,18 @@ class HTTPHandler(BaseHTTPRequestHandler):
435
488
  return extras
436
489
 
437
490
 
491
+ class WinRMHandler(HTTPHandler):
492
+ def setup_proto_logger(self):
493
+ self.logger = ProtocolLogger(
494
+ extra={
495
+ "protocol": "WinRM",
496
+ "protocol_color": "spring_green1",
497
+ "host": normalize_client_address(self.client_address[0]),
498
+ "port": self.config.http_port,
499
+ }
500
+ )
501
+
502
+
438
503
  class HTTPServer(ThreadingHTTPServer):
439
504
  service_name = "HTTP"
440
505
 
@@ -458,9 +523,23 @@ class HTTPServer(ThreadingHTTPServer):
458
523
  )
459
524
 
460
525
  super().__init__(
461
- server_address or ("", 80),
526
+ server_address or (self.config.bind_address, 80),
462
527
  RequestHandlerClass or HTTPHandler,
463
528
  )
529
+ if self.server_config.http_use_ssl:
530
+ # if defined use ssl
531
+ cert_path = pathlib.Path(str(self.server_config.http_cert))
532
+ key_path = pathlib.Path(str(self.server_config.http_cert_key))
533
+ if not cert_path.exists() or not key_path.exists():
534
+ dm_logger.error(
535
+ f"({self.service_name}, {self.server_address[:2]}) Certificate or key file not found: "
536
+ f"Cert={self.server_config.http_cert} "
537
+ f"Key={self.server_config.http_cert_key}"
538
+ )
539
+ return
540
+ self.ssl_context = ssl.SSLContext(ssl.PROTOCOL_TLS_SERVER)
541
+ self.ssl_context.load_cert_chain(certfile=cert_path, keyfile=key_path)
542
+ self.socket = self.ssl_context.wrap_socket(self.socket, server_side=True)
464
543
 
465
544
  def server_bind(self):
466
545
  bind_server(self, self.config)
@@ -492,3 +571,7 @@ class HTTPServer(ThreadingHTTPServer):
492
571
  print(e)
493
572
  dm_logger.error("Error rendering page: Could not find template")
494
573
  return
574
+
575
+
576
+ class WinRMServer(HTTPServer):
577
+ service_name = "WinRM"
@@ -57,8 +57,7 @@ def apply_config(session):
57
57
  def create_server_threads(session):
58
58
  servers = []
59
59
  if session.quic_enabled:
60
- address = "::" if session.ipv6 else session.ipv4 or ""
61
- servers.append(QuicServerThread(session, address, ipv6=bool(session.ipv6)))
60
+ servers.append(QuicServerThread(session, session.bind_address, ipv6=bool(session.ipv6)))
62
61
 
63
62
  return servers
64
63
 
@@ -148,13 +148,9 @@ class SMBServerThread(threading.Thread):
148
148
  # always disconnect
149
149
 
150
150
  # Change address_family to IPv6 if this is configured
151
- address = self.config.ipv4
151
+ address = self.config.bind_address
152
152
  if self.config.ipv6:
153
153
  SMBSERVER.address_family = socket.AF_INET6
154
- # empty string means all interfaces even though IPv6 can be bound to a specific
155
- # interface. Unfortunately, impacket's SMBSERVER does not support binding to
156
- # specific IPv6 addresses.
157
- address = ""
158
154
 
159
155
  self.server = SMBSERVER(
160
156
  (address, self.server_config.smb_port),
@@ -334,7 +334,7 @@ class SMTPServerThread(threading.Thread):
334
334
 
335
335
  # NOTE: hostname on the controller points to the local address that will be
336
336
  # bound and the SMTP hostname is just a string that will be sent to the client,
337
- controller.hostname = "::" if self.config.ipv6 else self.config.ipv4
337
+ controller.hostname = config.bind_address
338
338
 
339
339
  # alter the server hostname
340
340
  controller.SMTP_kwargs["hostname"] = smtp_config.smtp_fqdn.split(".", 1)[0]
@@ -136,7 +136,7 @@ class ThreadingUDPServer(socketserver.ThreadingMixIn, socketserver.UDPServer):
136
136
  self.address_family = socket.AF_INET6
137
137
 
138
138
  super().__init__(
139
- server_address or ("", self.default_port),
139
+ server_address or (self.config.bind_address, self.default_port),
140
140
  RequestHandlerClass or self.default_handler_class,
141
141
  )
142
142
 
@@ -173,7 +173,7 @@ class ThreadingTCPServer(socketserver.ThreadingMixIn, socketserver.TCPServer):
173
173
  if config.ipv6 and not self.ipv4_only:
174
174
  self.address_family = socket.AF_INET6
175
175
  super().__init__(
176
- server_address or ("", self.default_port),
176
+ server_address or (self.config.bind_address, self.default_port),
177
177
  RequestHandlerClass or self.default_handler_class,
178
178
  )
179
179
 
@@ -259,7 +259,7 @@ def main_print_options(session: SessionConfig, interface):
259
259
  poisoners_lines.append(main_format_config("Interface", interface))
260
260
 
261
261
  protocols_lines = ["", "[bold]Servers:[/bold]"]
262
- additional_protocols = ["KDC", "NBTDS"]
262
+ additional_protocols = ["KDC", "NBTDS", "WinRM"]
263
263
  for name in (list(session.protocols) or []) + additional_protocols:
264
264
  attr_name = f"{name.lower()}_enabled"
265
265
  value = getattr(session, attr_name, None)
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev2
3
+ Version: 1.0.0.dev3
4
4
  Summary: LLMNR/NBT-NS/mDNS Poisoner and rogue service provider
5
5
  Author: MatrixEditor
6
6
  Maintainer: MatrixEditor
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dementor"
3
- version = "1.0.0.dev2"
3
+ version = "1.0.0.dev3"
4
4
  license = { file = "LICENSE" }
5
5
 
6
6
  description = "LLMNR/NBT-NS/mDNS Poisoner and rogue service provider"
File without changes
File without changes
File without changes