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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
|
# File 'lib/ruby_smb/dcerpc/srvsvc/net_share_enum_all.rb', line 44
def self.parse_response(response)
shares = []
res = response.dup
win_error = res.slice!(-4, 4).unpack("V")[0]
if win_error != 0
raise RuntimeError, "Invalid DCERPC response: win_error = #{win_error}"
end
res.slice!(0, 12) share_count = res.slice!(0, 4).unpack("V")[0]
res.slice!(0, 4) share_max_count = res.slice!(0, 4).unpack("V")[0]
if share_max_count != share_count
raise RuntimeError, "Invalid DCERPC response: count != count max (#{share_count}/#{share_max_count})"
end
types = res.slice!(0, share_count * 12).scan(/.{12}/n).map { |a| a[4, 2].unpack("v")[0] }
share_count.times do |t|
length, offset, max_length = res.slice!(0, 12).unpack("VVV")
if offset != 0
raise RuntimeError, "Invalid DCERPC response: offset != 0 (#{offset})"
end
if length != max_length
raise RuntimeError, "Invalid DCERPC response: length !=max_length (#{length}/#{max_length})"
end
name = res.slice!(0, 2 * length).gsub('\x00', '')
res.slice!(0, 2) if length % 2 == 1
, , = res.slice!(0, 12).unpack("VVV")
if != 0
raise RuntimeError, "Invalid DCERPC response: comment_offset != 0 (#{})"
end
if !=
raise RuntimeError, "Invalid DCERPC response: comment_length != comment_max_length (#{}/#{})"
end
= res.slice!(0, 2 * )
res.slice!(0, 2) if % 2 == 1
name = name.gsub("\x00", "")
s_type = ['DISK', 'PRINTER', 'DEVICE', 'IPC', 'SPECIAL', 'TEMPORARY'][types[t]].gsub("\x00", "")
= .gsub("\x00", "")
shares << [name, s_type, ]
end
shares
end
|