CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutSign UpSign In
rapid7

Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.

GitHub Repository: rapid7/metasploit-framework
Path: blob/master/lib/rex/proto/dcerpc/uuid.rb
Views: 11704
1
# -*- coding: binary -*-
2
module Rex
3
module Proto
4
module DCERPC
5
class UUID
6
7
8
@@known_uuids =
9
{
10
'MGMT' => [ 'afa8bd80-7d8a-11c9-bef4-08002b102989', '2.0' ],
11
'REMACT' => [ '4d9f4ab8-7d1c-11cf-861e-0020af6e7c57', '0.0' ],
12
'SYSACT' => [ '000001a0-0000-0000-c000-000000000046', '0.0' ],
13
'LSA_DS' => [ '3919286a-b10c-11d0-9ba8-00c04fd92ef5', '0.0' ],
14
'SAMR' => [ '12345778-1234-abcd-ef00-0123456789ac', '1.0' ],
15
'MSMQ' => [ 'fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0' ],
16
'EVENTLOG' => [ '82273fdc-e32a-18c3-3f78-827929dc23ea', '0.0' ],
17
'SVCCTL' => [ '367abb81-9844-35f1-ad32-98f038001003', '2.0' ],
18
'SRVSVC' => [ '4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0' ],
19
'PNP' => [ '8d9f4e40-a03d-11ce-8f69-08003e30051b', '1.0' ]
20
}
21
22
# Convert a UUID in binary format to the string representation
23
def self.uuid_unpack(uuid_bin)
24
raise ArgumentError if uuid_bin.length != 16
25
sprintf("%.8x-%.4x-%.4x-%.4x-%s",
26
uuid_bin[ 0, 4].unpack('V')[0],
27
uuid_bin[ 4, 2].unpack('v')[0],
28
uuid_bin[ 6, 2].unpack('v')[0],
29
uuid_bin[ 8, 2].unpack('n')[0],
30
uuid_bin[10, 6].unpack('H*')[0]
31
)
32
end
33
34
# Validate a text based UUID
35
def self.is? (uuid_str)
36
raise ArgumentError if !uuid_str
37
if uuid_str.match(/^[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{4}-[a-fA-F0-9]{12}$/)
38
return true
39
else
40
return false
41
end
42
end
43
44
# Convert a UUID in string format to the binary representation
45
def self.uuid_pack (uuid_str)
46
raise ArgumentError if !self.is?(uuid_str)
47
parts = uuid_str.split('-')
48
[ parts[0].hex, parts[1].hex, parts[2].hex, parts[3].hex ].pack('Vvvn') + [ parts[4] ].pack('H*')
49
end
50
51
# Provide the common TransferSyntax UUID in packed format
52
def self.xfer_syntax_uuid ()
53
self.uuid_pack('8a885d04-1ceb-11c9-9fe8-08002b104860')
54
end
55
56
# Provide the common TransferSyntax version number
57
def self.xfer_syntax_vers ()
58
'2.0'
59
end
60
61
# Determine the UUID string for the DCERPC service with this name
62
def self.uuid_by_name (name)
63
if @@known_uuids.key?(name)
64
@@known_uuids[name][0]
65
end
66
end
67
68
# Determine the common version number for the DCERPC service with this name
69
def self.vers_by_name (name)
70
if @@known_uuids.key?(name)
71
@@known_uuids[name][1]
72
end
73
end
74
75
# Convert a string or number in float format to two unique numbers 2.0 => [2, 0]
76
def self.vers_to_nums (vers)
77
vers_maj = vers.to_i
78
vers_min = ((vers.to_f - vers.to_i) * 10).to_i
79
return vers_maj, vers_min
80
end
81
82
end
83
end
84
end
85
end
86
87