dementor 1.0.0.dev17__tar.gz → 1.0.0.dev18__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (64) hide show
  1. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/PKG-INFO +1 -1
  2. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/__init__.py +1 -1
  3. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/smb.py +67 -27
  4. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor.egg-info/PKG-INFO +1 -1
  5. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/pyproject.toml +1 -1
  6. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/LICENSE +0 -0
  7. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/README.md +0 -0
  8. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/__main__.py +0 -0
  9. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/Dementor.toml +0 -0
  10. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/banner.txt +0 -0
  11. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/www/error_page.html +0 -0
  12. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/www/upnp-default/dd.xml +0 -0
  13. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/www/upnp-default/present.html +0 -0
  14. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/www/upnp-default/scpd.xml +0 -0
  15. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/assets/www/wpad.dat +0 -0
  16. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/config/__init__.py +0 -0
  17. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/config/attr.py +0 -0
  18. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/config/session.py +0 -0
  19. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/config/toml.py +0 -0
  20. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/config/util.py +0 -0
  21. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/db/__init__.py +0 -0
  22. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/db/connector.py +0 -0
  23. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/db/model.py +0 -0
  24. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/filters.py +0 -0
  25. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/loader.py +0 -0
  26. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/log/__init__.py +0 -0
  27. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/log/hexdump.py +0 -0
  28. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/log/logger.py +0 -0
  29. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/log/stream.py +0 -0
  30. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/paths.py +0 -0
  31. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/__init__.py +0 -0
  32. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/ftp.py +0 -0
  33. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/http.py +0 -0
  34. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/imap.py +0 -0
  35. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/ipp.py +0 -0
  36. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/kerberos.py +0 -0
  37. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/ldap.py +0 -0
  38. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/llmnr.py +0 -0
  39. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/mdns.py +0 -0
  40. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/msrpc/__init__.py +0 -0
  41. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/msrpc/dcom.py +0 -0
  42. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/msrpc/epm.py +0 -0
  43. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/msrpc/rpc.py +0 -0
  44. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/msrpc.py +0 -0
  45. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/mssql.py +0 -0
  46. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/mysql.py +0 -0
  47. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/netbios.py +0 -0
  48. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/ntlm.py +0 -0
  49. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/pop3.py +0 -0
  50. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/quic.py +0 -0
  51. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/smtp.py +0 -0
  52. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/spnego.py +0 -0
  53. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/ssdp.py +0 -0
  54. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/upnp.py +0 -0
  55. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/protocols/x11.py +0 -0
  56. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/servers.py +0 -0
  57. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor/standalone.py +0 -0
  58. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor.egg-info/SOURCES.txt +0 -0
  59. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor.egg-info/dependency_links.txt +0 -0
  60. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor.egg-info/entry_points.txt +0 -0
  61. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor.egg-info/requires.txt +0 -0
  62. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/dementor.egg-info/top_level.txt +0 -0
  63. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/docs/README.pypi.md +0 -0
  64. {dementor-1.0.0.dev17 → dementor-1.0.0.dev18}/setup.cfg +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev17
3
+ Version: 1.0.0.dev18
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.dev17"
21
+ __version__ = "1.0.0.dev18"
22
22
  __author__ = "MatrixEditor"
@@ -68,13 +68,14 @@ from dementor.servers import BaseProtoHandler, ThreadingTCPServer, ServerThread
68
68
  SMB2_DIALECTS = {
69
69
  smb2.SMB2_DIALECT_002: "SMB 2.002",
70
70
  smb2.SMB2_DIALECT_21: "SMB 2.1",
71
+ smb2.SMB2_DIALECT_WILDCARD: "SMB 2.???",
71
72
  smb2.SMB2_DIALECT_30: "SMB 3.0",
72
73
  smb2.SMB2_DIALECT_302: "SMB 3.0.2",
73
74
  smb2.SMB2_DIALECT_311: "SMB 3.1.1",
74
- # used in SMB1 requests
75
- 0x0000: "SMB 2.???",
76
75
  }
77
76
 
77
+ SMB2_NEGOTIABLE_DIALECTS = set(SMB2_DIALECTS) - {smb2.SMB2_DIALECT_WILDCARD}
78
+
78
79
  SMB2_DIALECT_REV = {v: k for k, v in SMB2_DIALECTS.items()}
79
80
 
80
81
  SMB2_INTEGRITY_SHA512 = uint16.to_bytes(0x0001, order=LittleEndian)
@@ -196,10 +197,12 @@ def SMB3_get_target_capabilities(
196
197
  target_sign = 0x001 # SMB2_SIGNING_AES_CMAC
197
198
  try:
198
199
  context_data = smb3.SMB311ContextData(request["ClientStartTime"])
199
- raw_context_list = request.rawData[context_data["NegotiateContextOffset"] :]
200
+ # remove header size from offset
201
+ context_list_offset = context_data["NegotiateContextOffset"] - 64
202
+ raw_context_list = request.rawData[context_list_offset:]
200
203
  offset = 0
201
204
  for _ in range(context_data["NegotiateContextCount"]):
202
- context = smb3.SMB2NegotiateContext(raw_context_list)
205
+ context = smb3.SMB2NegotiateContext(raw_context_list[offset:])
203
206
  match context["ContextType"]:
204
207
  case smb3.SMB2_ENCRYPTION_CAPABILITIES:
205
208
  req_enc_caps = smb3.SMB2EncryptionCapabilities(context["Data"])
@@ -278,9 +281,10 @@ def smb2_negotiate(
278
281
  ]
279
282
  )
280
283
 
281
- # print(len(command["Buffer"]))
282
- command["NegotiateContextOffset"] = 0x80 + command["SecurityBufferLength"] + 2
283
- command["NegotiateContextList"] = b"\xff\xff" + context_data
284
+ offset: int = 0x80 + command["SecurityBufferLength"]
285
+ sec_buf_pad = SMB3_get_neg_context_pad(0x80 + command["SecurityBufferLength"])
286
+ command["NegotiateContextOffset"] = offset + len(sec_buf_pad)
287
+ command["NegotiateContextList"] = sec_buf_pad + context_data
284
288
  command["NegotiateContextCount"] = 3
285
289
 
286
290
  return command
@@ -289,19 +293,32 @@ def smb2_negotiate(
289
293
  def smb2_negotiate_protocol(handler: "SMBHandler", packet: smb2.SMB2Packet) -> None:
290
294
  req = smb3.SMB2Negotiate(data=packet["Data"])
291
295
  # Let's take the first dialect the clients wan't us to use
292
- req_dialects = req["Dialects"][: req["DialectCount"]]
296
+ dialect_count: int = req["DialectCount"]
297
+ req_raw_dialects: list[int] = req["Dialects"]
298
+ if len(req_raw_dialects) < dialect_count:
299
+ # automatically adjust length
300
+ dialect_count = len(req_raw_dialects)
301
+
302
+ req_dialects: list[int] = req_raw_dialects[:dialect_count]
303
+ if len(req_dialects) == 0:
304
+ # 3.3.5.4 Receiving an SMB2 NEGOTIATE Request
305
+ # If the DialectCount of the SMB2 NEGOTIATE Request is 0, the server MUST fail the request with
306
+ # STATUS_INVALID_PARAMETER.
307
+ handler.log_client("Client sent no dialects", "SMB_COM_NEGOTIATE")
308
+ handler.logger.fail("SMB Negotiation: Client failed to provide any dialects.")
309
+ raise BaseProtoHandler.TerminateConnection
310
+
293
311
  str_req_dialects = ", ".join([SMB2_DIALECTS.get(d, hex(d)) for d in req_dialects])
294
312
  guid = uuid.UUID(bytes_le=req["ClientGuid"])
295
313
  handler.log_client(
296
314
  f"requested dialects: {str_req_dialects} (client: {guid})", "SMB2_NEGOTIATE"
297
315
  )
298
316
 
299
- # REVISIT
300
- dialect = req_dialects[-1]
301
- # for candidate in req_dialects:
302
- # if candidate < 0x300:
303
- # dialect = candidate
304
-
317
+ # select greatest common dialect
318
+ dialect = max(
319
+ (d for d in req_dialects if d in SMB2_NEGOTIABLE_DIALECTS),
320
+ default=None,
321
+ )
305
322
  if dialect is None:
306
323
  handler.logger.fail(
307
324
  f"Client requested unsupported dialects: {str_req_dialects}"
@@ -347,7 +364,7 @@ def smb2_logoff(handler: "SMBHandler", packet: smb2.SMB2Packet) -> None:
347
364
 
348
365
 
349
366
  # --- SMB1 --------------------------------------------------------------------
350
- def smb1_negotiate_protocol(handler, packet: smb.NewSMBPacket) -> None:
367
+ def smb1_negotiate_protocol(handler: "SMBHandler", packet: smb.NewSMBPacket) -> None:
351
368
  resp = smb.NewSMBPacket()
352
369
  resp["Flags1"] = smb.SMB.FLAGS1_REPLY
353
370
  resp["Pid"] = packet["Pid"]
@@ -355,19 +372,37 @@ def smb1_negotiate_protocol(handler, packet: smb.NewSMBPacket) -> None:
355
372
  resp["Mid"] = packet["Mid"]
356
373
 
357
374
  req = smb.SMBCommand(packet["Data"][0])
358
- dialects = [
375
+ req_data_dialects: list[bytes] = req["Data"].split(b"\x02")[1:]
376
+ if len(req_data_dialects) == 0:
377
+ # 3.3.5.4 Receiving an SMB2 NEGOTIATE Request
378
+ # If the DialectCount of the SMB2 NEGOTIATE Request is 0, the server MUST fail the request with
379
+ # STATUS_INVALID_PARAMETER.
380
+ handler.log_client("Client sent no dialects", "SMB_COM_NEGOTIATE")
381
+ handler.logger.fail("SMB Negotiation: Client failed to provide any dialects.")
382
+ raise BaseProtoHandler.TerminateConnection
383
+
384
+ dialects: list[str] = [
359
385
  dialect.rstrip(b"\x00").decode(errors="replace")
360
- for dialect in req["Data"].split(b"\x02")[1:]
386
+ for dialect in req_data_dialects
361
387
  ]
362
388
  handler.log_client(f"dialects: {', '.join(dialects)}", "SMB_COM_NEGOTIATE")
363
- # always select the first one present if SMB2 is not present
364
- index = 0
365
- for i, dialect in enumerate(dialects):
366
- if dialect in SMB2_DIALECT_REV and handler.smb_config.smb2_support:
367
- index = i
368
- break
369
-
370
- target_dialect = dialects[index]
389
+ smb2_entries: dict[str, int] = {
390
+ dialect: index
391
+ for index, dialect in enumerate(dialects)
392
+ if dialect in SMB2_DIALECT_REV and handler.smb_config.smb2_support
393
+ }
394
+ if smb2_entries:
395
+ # 3.3.5.3.1 SMB 2.1 or SMB 3.x Support
396
+ # Otherwise, the server MUST scan the dialects provided for the dialect string "SMB 2.???". If the string
397
+ # is not present, continue to section 3.3.5.3.2. If the string is present, the server MUST respond with an
398
+ # SMB2 NEGOTIATE Response as specified in 2.2.4.
399
+ index, target_dialect = smb2_entries.get("SMB 2.???"), "SMB 2.???"
400
+ if index is None:
401
+ target_dialect = list(smb2_entries)[-1]
402
+ index = smb2_entries[target_dialect]
403
+ else:
404
+ index, target_dialect = 0, dialects[0]
405
+
371
406
  if target_dialect in SMB2_DIALECT_REV:
372
407
  # Requested dialect is SMB2 -> respond with SMB2
373
408
  command = smb2_negotiate(handler, SMB2_DIALECT_REV[target_dialect])
@@ -418,7 +453,7 @@ def smb1_negotiate_protocol(handler, packet: smb.NewSMBPacket) -> None:
418
453
  handler.send_data(resp.getData())
419
454
 
420
455
 
421
- def smb1_session_setup(handler, packet: smb.NewSMBPacket) -> None:
456
+ def smb1_session_setup(handler: "SMBHandler", packet: smb.NewSMBPacket) -> None:
422
457
  command = smb.SMBCommand(packet["Data"][0])
423
458
  handler.log_client(f"session setup: {command.fields}", "SMB_COM_SESSION_SETUP_ANDX")
424
459
  # handler.send_data(packet.getData())
@@ -458,6 +493,11 @@ def smb1_session_setup(handler, packet: smb.NewSMBPacket) -> None:
458
493
  packet,
459
494
  error_code=error_code,
460
495
  )
496
+ else:
497
+ handler.logger.warning(
498
+ f"<SMB_COM_SESSION_SETUP_ANDX> Unsupported WordCount: {command['WordCount']}"
499
+ )
500
+ raise BaseProtoHandler.TerminateConnection
461
501
 
462
502
 
463
503
  # --- Handler ---
@@ -696,7 +736,7 @@ class SMBHandler(BaseProtoHandler):
696
736
  token = neg_token["ResponseToken"]
697
737
 
698
738
  # NTLM authentication below
699
- if len(token) < 8:
739
+ if len(token) <= 8:
700
740
  self.logger.fail(
701
741
  f"<{command_name}> Invalid NTLM token length: {len(token)}"
702
742
  )
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: dementor
3
- Version: 1.0.0.dev17
3
+ Version: 1.0.0.dev18
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.dev17"
3
+ version = "1.0.0.dev18"
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