packetgen-plugin-smb 0.6.1 → 0.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (55) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/specs.yml +28 -0
  3. data/.rubocop.yml +6 -0
  4. data/Gemfile +15 -0
  5. data/README.md +50 -12
  6. data/Rakefile +10 -4
  7. data/lib/packetgen-plugin-smb.rb +2 -2
  8. data/lib/packetgen/plugin/gssapi.rb +4 -2
  9. data/lib/packetgen/plugin/llmnr.rb +4 -4
  10. data/lib/packetgen/plugin/netbios.rb +2 -0
  11. data/lib/packetgen/plugin/netbios/datagram.rb +3 -3
  12. data/lib/packetgen/plugin/netbios/name.rb +4 -4
  13. data/lib/packetgen/plugin/netbios/session.rb +5 -5
  14. data/lib/packetgen/plugin/ntlm.rb +3 -3
  15. data/lib/packetgen/plugin/ntlm/authenticate.rb +2 -2
  16. data/lib/packetgen/plugin/ntlm/av_pair.rb +3 -5
  17. data/lib/packetgen/plugin/ntlm/challenge.rb +2 -2
  18. data/lib/packetgen/plugin/ntlm/negotiate.rb +2 -2
  19. data/lib/packetgen/plugin/ntlm/ntlmv2_response.rb +2 -2
  20. data/lib/packetgen/plugin/smb.rb +12 -12
  21. data/lib/packetgen/plugin/smb/blocks.rb +2 -2
  22. data/lib/packetgen/plugin/smb/browser.rb +2 -2
  23. data/lib/packetgen/plugin/smb/browser/domain_announcement.rb +2 -2
  24. data/lib/packetgen/plugin/smb/browser/host_announcement.rb +2 -2
  25. data/lib/packetgen/plugin/smb/browser/local_master_announcement.rb +2 -2
  26. data/lib/packetgen/plugin/smb/close.rb +2 -2
  27. data/lib/packetgen/plugin/smb/close/request.rb +2 -2
  28. data/lib/packetgen/plugin/smb/close/response.rb +2 -2
  29. data/lib/packetgen/plugin/smb/filetime.rb +4 -2
  30. data/lib/packetgen/plugin/smb/negotiate.rb +2 -2
  31. data/lib/packetgen/plugin/smb/negotiate/dialect.rb +7 -0
  32. data/lib/packetgen/plugin/smb/negotiate/request.rb +7 -0
  33. data/lib/packetgen/plugin/smb/negotiate/response.rb +8 -2
  34. data/lib/packetgen/plugin/smb/nt_create_and_x.rb +2 -2
  35. data/lib/packetgen/plugin/smb/ntcreateandx/request.rb +4 -4
  36. data/lib/packetgen/plugin/smb/ntcreateandx/response.rb +2 -2
  37. data/lib/packetgen/plugin/smb/string.rb +40 -28
  38. data/lib/packetgen/plugin/smb/trans.rb +2 -2
  39. data/lib/packetgen/plugin/smb/trans/request.rb +3 -3
  40. data/lib/packetgen/plugin/smb/trans/response.rb +2 -2
  41. data/lib/packetgen/plugin/smb2.rb +3 -3
  42. data/lib/packetgen/plugin/smb2/base.rb +3 -3
  43. data/lib/packetgen/plugin/smb2/error.rb +3 -4
  44. data/lib/packetgen/plugin/smb2/guid.rb +4 -3
  45. data/lib/packetgen/plugin/smb2/negotiate.rb +2 -2
  46. data/lib/packetgen/plugin/smb2/negotiate/context.rb +3 -3
  47. data/lib/packetgen/plugin/smb2/negotiate/request.rb +3 -5
  48. data/lib/packetgen/plugin/smb2/negotiate/response.rb +4 -6
  49. data/lib/packetgen/plugin/smb2/session_setup.rb +2 -2
  50. data/lib/packetgen/plugin/smb2/session_setup/request.rb +4 -4
  51. data/lib/packetgen/plugin/smb2/session_setup/response.rb +5 -5
  52. data/lib/packetgen/plugin/smb_version.rb +3 -1
  53. data/packetgen-plugin-smb.gemspec +4 -11
  54. metadata +6 -82
  55. data/.travis.yml +0 -12
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Common blocks used for unsupported SMB messages.
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Browser Trans sub-protocol.
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  class Browser
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  class Browser
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  class Browser
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Namespace for CLOSE related classes
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  module Close
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  module Close
@@ -1,15 +1,17 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # SMB FILETIME.
11
11
  # @author Sylvain Daubert
12
12
  class Filetime
13
+ include PacketGen::Types::Fieldable
14
+
13
15
  # Base time for SMB FILETIME.
14
16
  # This value also indicate no time.
15
17
  NO_TIME = Time.utc(1601).freeze
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Namespace for NEGOTIATE related classes
@@ -1,3 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of packetgen-plugin-smb.
4
+ # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
5
+ # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
6
+ # This program is published under MIT license.
7
+
1
8
  module PacketGen::Plugin
2
9
  class SMB
3
10
  module Negotiate
@@ -1,3 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of packetgen-plugin-smb.
4
+ # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
5
+ # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
6
+ # This program is published under MIT license.
7
+
1
8
  module PacketGen::Plugin
2
9
  class SMB
3
10
  module Negotiate
@@ -1,3 +1,10 @@
1
+ # frozen_string_literal: true
2
+
3
+ # This file is part of packetgen-plugin-smb.
4
+ # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
5
+ # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
6
+ # This program is published under MIT license.
7
+
1
8
  module PacketGen::Plugin
2
9
  class SMB
3
10
  module Negotiate
@@ -7,7 +14,6 @@ module PacketGen::Plugin
7
14
  # and {Blocks#bytes}.
8
15
  # @author Sylvain Daubert
9
16
  class Response < Blocks
10
-
11
17
  # Get index of the dialect selected by the server from the list presented in the request.
12
18
  # @return [Integer]
13
19
  def dialect_index
@@ -20,4 +26,4 @@ module PacketGen::Plugin
20
26
  end
21
27
  end
22
28
  end
23
- end
29
+ end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Namespace for NT_CREATE_ANDX related classes
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Namespace for NT_CREATE_ANDX related classes
@@ -128,7 +128,7 @@ module PacketGen::Plugin
128
128
  # Padding before {#filename} to align it on 16-bit boundary. Only present
129
129
  # if {SMB#flags2_unicode?} is +true+.
130
130
  # @return [Integer]
131
- define_field :pad1, PacketGen::Types::Int8, optional: ->(h) { h.packet && h.packet.smb.flags2_unicode? }
131
+ define_field :pad1, PacketGen::Types::Int8, optional: ->(h) { h&.packet&.smb&.flags2_unicode? }
132
132
  # @!attribute filename
133
133
  # A string that represents the fully qualified name of the file
134
134
  # relative to the supplied TID
@@ -154,6 +154,6 @@ module PacketGen::Plugin
154
154
  self.byte_count = bcount
155
155
  end
156
156
  end
157
- end
157
+ end
158
158
  end
159
159
  end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Namespace for NT_CREATE_ANDX related classes
@@ -1,34 +1,39 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
8
+ require 'forwardable'
7
9
 
8
10
  module PacketGen::Plugin
9
11
  class SMB
10
12
  # SMB strings (UTF-16 little-endian or OEM).
11
13
  # @author Sylvain Daubert
12
- class String < PacketGen::Types::CString
13
- # @param [Boolean] value
14
- # @return [Boolean]
15
- attr_writer :unicode
14
+ class String
15
+ extend Forwardable
16
+ include PacketGen::Types::Fieldable
17
+
18
+ def_delegators :@string, :[], :length, :size, :inspect, :==, :<<,
19
+ :unpack, :force_encoding, :encoding, :index, :empty?,
20
+ :encode
21
+
22
+ # @return [::String]
23
+ attr_reader :string
16
24
  # @param [Boolean] null_terminated
17
25
  # @return [Boolean]
18
26
  attr_writer :null_terminated
19
27
 
20
28
  # @param [Hash] options
21
- # @option options [Integer] :static_length set a static length for this string
22
29
  # @option options [Boolean] :unicode If +true+, string is encoded as a UTF-16
23
30
  # unicode string. If +false+, string is encode in ASCII. Defaults to +true+.
24
31
  # @option options [Boolean] :null_terminated If +true+, string is null-terminated.
25
32
  # If +false+, string is not null-terminated. Defaults to +true+.
26
33
  def initialize(options={})
27
- super
28
34
  @unicode = options.key?(:unicode) ? options[:unicode] : true
29
35
  @null_terminated = options.key?(:null_terminated) ? options[:null_terminated] : true
30
- encoding = unicode? ? 'UTF-16LE' : 'ASCII-8BIT'
31
- self.encode!(encoding)
36
+ @string = +''.encode(self_encoding)
32
37
  end
33
38
 
34
39
  # @return [Boolean]
@@ -36,6 +41,14 @@ module PacketGen::Plugin
36
41
  @unicode
37
42
  end
38
43
 
44
+ # @param [Boolean] bool
45
+ # @return [Boolean]
46
+ def unicode=(bool)
47
+ @unicode = bool
48
+ @string.force_encoding(self_encoding)
49
+ bool
50
+ end
51
+
39
52
  # @return [Boolean]
40
53
  def null_terminated?
41
54
  @null_terminated
@@ -48,48 +61,47 @@ module PacketGen::Plugin
48
61
 
49
62
  str2 = case str.encoding
50
63
  when Encoding::BINARY
51
- binidx = nil
52
- 0.step(to: str.size, by: 2) do |i|
53
- binidx = i if str[i, 2] == binary_terminator
54
- end
55
- s = if binidx.nil?
56
- str
57
- else
58
- str[0, binidx]
59
- end
60
- s.force_encoding(self_encoding)
64
+ str.dup.force_encoding(self_encoding)
61
65
  else
62
66
  str.encode(self_encoding)
63
67
  end
64
- str2 = str2[0, @static_length / 2] if @static_length.is_a? Integer
65
68
  idx = str2.index(+"\x00".encode(self_encoding))
66
69
  str2 = str2[0, idx] unless idx.nil?
67
- self.replace str2
70
+ @string = str2
68
71
  self
69
72
  end
70
73
 
71
74
  # @return [String]
72
75
  def to_s
73
- s = super
74
- s.encode(self_encoding)
75
- return s if null_terminated?
76
+ str = string.dup.force_encoding('BINARY')
77
+ return str unless null_terminated?
78
+
79
+ str << binary_terminator.force_encoding('BINARY')
80
+ end
76
81
 
77
- s[0...-binary_terminator.size]
82
+ # Populate String from a human readable (ie UTF-8) string
83
+ # @param [String] str
84
+ # @return [self]
85
+ def from_human(str)
86
+ return self if str.nil?
87
+
88
+ @string = str.encode(self_encoding)
89
+ self
78
90
  end
79
91
 
80
92
  # @return [String]
81
93
  def to_human
82
- super.encode('UTF-8')
94
+ string.encode('UTF-8')
83
95
  end
84
96
 
85
97
  private
86
98
 
87
99
  def self_encoding
88
- @unicode ? Encoding::UTF_16LE : Encoding:: ASCII_8BIT
100
+ @unicode ? Encoding::UTF_16LE : Encoding::ASCII_8BIT
89
101
  end
90
102
 
91
103
  def binary_terminator
92
- @unicode ? "\x00\x00" : "\x00"
104
+ [0].pack('C').encode(self_encoding)
93
105
  end
94
106
  end
95
107
  end
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  # Namespace for TRANS related classes
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  module Trans
@@ -96,7 +96,7 @@ module PacketGen::Plugin
96
96
  # 8-bit optional padding to align {#name} on a 2-byte boundary. Only present
97
97
  # if {SMB#flags2_unicode?} is +true+.
98
98
  # @return [Integer]
99
- define_field :padname, PacketGen::Types::Int8, optional: ->(h) { h.packet && h.packet.smb.flags2_unicode? }
99
+ define_field :padname, PacketGen::Types::Int8, optional: ->(h) { h&.packet&.smb&.flags2_unicode? }
100
100
  # @!attribute name
101
101
  # Pathname of the mailslot or named pipe.
102
102
  # @return [String]
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  class SMB
10
10
  module Trans
@@ -1,10 +1,10 @@
1
+ # frozen_string_literal: true
2
+
1
3
  # This file is part of packetgen-plugin-smb.
2
4
  # See https://github.com/sdaubert/packetgen-plugin-smb for more informations
3
5
  # Copyright (C) 2018 Sylvain Daubert <sylvain.daubert@laposte.net>
4
6
  # This program is published under MIT license.
5
7
 
6
- # frozen_string_literal: true
7
-
8
8
  module PacketGen::Plugin
9
9
  # Server Message Block version 2 and 3 (SMB2) header.
10
10
  # @author Sylvain Daubert
@@ -84,7 +84,7 @@ module PacketGen::Plugin
84
84
  # 64-bit unique ID that is created by the server to handle operations
85
85
  # asynchronously. Only present for asynchronous messages.
86
86
  # @return [Integer]
87
- define_field :async_id, PacketGen::Types::Int64le, optional: ->(h) { h.flags & 2 == 2}
87
+ define_field :async_id, PacketGen::Types::Int64le, optional: ->(h) { h.flags & 2 == 2 }
88
88
  # @!attribute reserved
89
89
  # 32-bit reserved field.
90
90
  # Only present for synchronous messages.