Class: Rex::Proto::MsDtyp::MsDtypAccessMask

Inherits:
BinData::Record
  • Object
show all
Defined in:
lib/rex/proto/ms_dtyp.rb

Overview

Constant Summary collapse

ALL =
MsDtypAccessMask.new({ gr: 1, gw: 1, gx: 1, ga: 1, ma: 1, as: 1, sy: 1, wo: 1, wd: 1, rc: 1, de: 1, protocol: 0xffff })
NONE =
MsDtypAccessMask.new({ gr: 0, gw: 0, gx: 0, ga: 0, ma: 0, as: 0, sy: 0, wo: 0, wd: 0, rc: 0, de: 0, protocol: 0 })

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.from_sddl_text(sddl_text) ⇒ Object



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
# File 'lib/rex/proto/ms_dtyp.rb', line 90

def self.from_sddl_text(sddl_text)
  if sddl_text =~ /\A0x[0-9a-fA-F]{1,8}\Z/
    return self.read([sddl_text.delete_prefix('0x').to_i(16)].pack('L<'))
  end

  access_mask = self.new
  sddl_text.split(/(G[ARWX]|RC|SD|WD|WO|RP|WP|CC|DC|LC|SW|LO|DT|CR|F[ARWX]|K[ARWX]|N[RWX])/).each do |right|
    case right
    # generic access rights
    when 'GA', 'GR', 'GW', 'GX'
      access_mask.send("#{right.downcase}=", true)
    # standard access rights
    when 'RC'
      access_mask.rc = true
    when 'SD'
      access_mask.de = true
    when 'WD', 'WO'
      access_mask.send("#{right.downcase}=", true)
    # directory service object access rights
    when 'RP'
      access_mask.protocol |= 16
    when 'WP'
      access_mask.protocol |= 32
    when 'CC'
      access_mask.protocol |= 1
    when 'DC'
      access_mask.protocol |= 2
    when 'LC'
      access_mask.protocol |= 4
    when 'SW'
      access_mask.protocol |= 8
    when 'LO'
      access_mask.protocol |= 128
    when 'DT'
      access_mask.protocol |= 64
    when 'CR'
      access_mask.protocol |= 256
    # file access rights
    when 'FA'
      access_mask.protocol |= 0x1ff
      access_mask.de = true
      access_mask.rc = true
      access_mask.wd = true
      access_mask.wo = true
      access_mask.sy = true
    when 'FR'
      access_mask.protocol |= 0x89
    when 'FW'
      access_mask.protocol |= 0x116
    when 'FX'
      access_mask.protocol |= 0xa0
    # registry key access rights
    when 'KA'
      access_mask.protocol |= 0x3f
      access_mask.de = true
      access_mask.rc = true
      access_mask.wd = true
      access_mask.wo = true
    when 'KR'
      access_mask.protocol |= 0x19
    when 'KW'
      access_mask.protocol |= 0x06
    when 'KX'
      access_mask.protocol |= 0x19
    when 'NR', 'NW', 'NX'
      raise SDDLParseError.new('unsupported ACE access right: ' + right)
    when ''
    else
      raise SDDLParseError.new('unknown ACE access right: ' + right)
    end
  end

  access_mask
end

Instance Method Details

#permissionsObject

Obtain an array of the abbreviated names of permissions that the access mask specifies.

Returns:

  • Returns nil if the permissions can't be represented as an array of abbreviations.



41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
# File 'lib/rex/proto/ms_dtyp.rb', line 41

def permissions
  if (protocol & 0b1111111000000000) != 0 || ma == 1 || as == 1
    return nil
  end

  permissions = []
  permissions << :GA if ga == 1
  permissions << :GR if gr == 1
  permissions << :GW if gw == 1
  permissions << :GX if gx == 1

  file_access_mask = protocol & 0b000111111111
  permissions << :FA if file_access_mask == 0b000111111111 && de == 1 && rc == 1 && wd == 1 && wo == 1 && sy == 1
  permissions << :FR if file_access_mask == 0b000010001001
  permissions << :FW if file_access_mask == 0b000100010110
  permissions << :FX if file_access_mask == 0b000010100000

  # windows does not reduce registry access flags (i.e. KA, KR, KW) so ignore them here to match it

  permissions << :CC if (protocol & 0b000000000001) != 0 && !permissions.include?(:FA) && !permissions.include?(:FR)
  permissions << :DC if (protocol & 0b000000000010) != 0 && !permissions.include?(:FA) && !permissions.include?(:FW)
  permissions << :LC if (protocol & 0b000000000100) != 0 && !permissions.include?(:FA) && !permissions.include?(:FW)
  permissions << :SW if (protocol & 0b000000001000) != 0 && !permissions.include?(:FA) && !permissions.include?(:FR)
  permissions << :RP if (protocol & 0b000000010000) != 0 && !permissions.include?(:FA) && !permissions.include?(:FW)
  permissions << :WP if (protocol & 0b000000100000) != 0 && !permissions.include?(:FA) && !permissions.include?(:FX)
  permissions << :DT if (protocol & 0b000001000000) != 0 && !permissions.include?(:FA)
  permissions << :LO if (protocol & 0b000010000000) != 0 && !permissions.include?(:FA)
  permissions << :CR if (protocol & 0b000100000000) != 0 && !permissions.include?(:FA)

  permissions << :SD if de == 1 && !permissions.include?(:FA)
  permissions << :RC if rc == 1 && !permissions.include?(:FA)
  permissions << :WD if wd == 1 && !permissions.include?(:FA)
  permissions << :WO if wo == 1 && !permissions.include?(:FA)

  permissions
end

#to_sddl_textObject



78
79
80
81
82
83
84
85
86
87
88
# File 'lib/rex/proto/ms_dtyp.rb', line 78

def to_sddl_text
  perms = permissions

  if perms.nil?
    # if one of these conditions are true, we can't reduce this to a set of flags so dump it as hex
    return "0x#{to_binary_s.unpack1('L<').to_s(16).rjust(8, '0')}"
  end


  permissions.map(&:to_s).join
end