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/handle.rb
Views: 11704
1
# -*- coding: binary -*-
2
module Rex
3
module Proto
4
module DCERPC
5
class Handle
6
7
8
@@protocols = ['ncacn_ip_tcp', 'ncacn_ip_udp', 'ncacn_np', 'ncacn_http']
9
attr_accessor :uuid, :protocol, :address, :options
10
11
# instantiate a handle object, akin to Microsoft's string binding handle by values
12
def initialize(uuid, protocol, address, options)
13
raise ArgumentError if !Rex::Proto
14
raise ArgumentError if !Rex::Proto::DCERPC::UUID.is?(uuid[0])
15
raise ArgumentError if !@@protocols.include?(protocol)
16
self.uuid = uuid
17
self.protocol = protocol
18
self.address = address
19
self.options = options
20
end
21
22
# instantiate a handle object, by parsing a string binding handle
23
def self.parse (handle)
24
uuid_re = '[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}'
25
rev_re = '\d+.\d+'
26
proto_re = '(?:' + @@protocols.join('|') + ')'
27
re = Regexp.new("(#{uuid_re}):(#{rev_re})\@(#{proto_re}):(.*?)\\[(.*)\\]$", Regexp::IGNORECASE | Regexp::NOENCODING)
28
match = re.match(handle)
29
raise ArgumentError if !match
30
31
uuid = [match[1], match[2]]
32
protocol = match[3]
33
address = match[4]
34
options = match[5].split(',')
35
i = Rex::Proto::DCERPC::Handle.new(uuid, protocol, address, options)
36
return i
37
end
38
39
# stringify a handle
40
def to_s
41
self.uuid.join(':') + '@' + self.protocol + ':' + self.address + '[' + self.options.join(', ') + ']'
42
end
43
44
end
45
end
46
end
47
end
48
49