EchoHelper.cs 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. /* Copyright (C) 2014-2017 Tal Aloni <tal.aloni.il@gmail.com>. All rights reserved.
  2. *
  3. * You can redistribute this program and/or modify it under the terms of
  4. * the GNU Lesser Public License as published by the Free Software Foundation,
  5. * either version 3 of the License, or (at your option) any later version.
  6. */
  7. using System;
  8. using System.Collections.Generic;
  9. using SMBLibrary.SMB1;
  10. namespace SMBLibrary.Server.SMB1
  11. {
  12. internal class EchoHelper
  13. {
  14. internal static List<SMB1Command> GetEchoResponse(EchoRequest request)
  15. {
  16. List<SMB1Command> response = new List<SMB1Command>();
  17. for (int index = 0; index < request.EchoCount; index++)
  18. {
  19. EchoResponse echo = new EchoResponse();
  20. echo.SequenceNumber = (ushort)index;
  21. echo.Data = request.Data;
  22. response.Add(echo);
  23. }
  24. return response;
  25. }
  26. internal static SMB1Message GetUnsolicitedEchoReply()
  27. {
  28. // [MS-CIFS] 3.2.5.1 - If the PID and MID values of the received message are not found in the
  29. // Client.Connection.PIDMIDList, the message MUST be discarded.
  30. SMB1Header header = new SMB1Header();
  31. header.Command = CommandName.SMB_COM_ECHO;
  32. header.Status = NTStatus.STATUS_SUCCESS;
  33. header.Flags = HeaderFlags.CaseInsensitive | HeaderFlags.CanonicalizedPaths | HeaderFlags.Reply;
  34. // [MS-CIFS] SMB_FLAGS2_LONG_NAMES SHOULD be set to 1 when the negotiated dialect is NT LANMAN.
  35. // [MS-CIFS] SMB_FLAGS2_UNICODE SHOULD be set to 1 when the negotiated dialect is NT LANMAN.
  36. header.Flags2 = HeaderFlags2.LongNamesAllowed | HeaderFlags2.NTStatusCode | HeaderFlags2.Unicode;
  37. header.UID = 0xFFFF;
  38. header.TID = 0xFFFF;
  39. header.PID = 0xFFFFFFFF;
  40. header.MID = 0xFFFF;
  41. EchoResponse response = new EchoResponse();
  42. SMB1Message reply = new SMB1Message();
  43. reply.Header = header;
  44. reply.Commands.Add(response);
  45. return reply;
  46. }
  47. }
  48. }