Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Real-time collaboration for Jupyter Notebooks, Linux Terminals, LaTeX, VS Code, R IDE, and more,
all in one place.
Path: blob/master/lib/rex/proto/dcerpc/handle.rb
Views: 11704
# -*- coding: binary -*-1module Rex2module Proto3module DCERPC4class Handle567@@protocols = ['ncacn_ip_tcp', 'ncacn_ip_udp', 'ncacn_np', 'ncacn_http']8attr_accessor :uuid, :protocol, :address, :options910# instantiate a handle object, akin to Microsoft's string binding handle by values11def initialize(uuid, protocol, address, options)12raise ArgumentError if !Rex::Proto13raise ArgumentError if !Rex::Proto::DCERPC::UUID.is?(uuid[0])14raise ArgumentError if !@@protocols.include?(protocol)15self.uuid = uuid16self.protocol = protocol17self.address = address18self.options = options19end2021# instantiate a handle object, by parsing a string binding handle22def self.parse (handle)23uuid_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}'24rev_re = '\d+.\d+'25proto_re = '(?:' + @@protocols.join('|') + ')'26re = Regexp.new("(#{uuid_re}):(#{rev_re})\@(#{proto_re}):(.*?)\\[(.*)\\]$", Regexp::IGNORECASE | Regexp::NOENCODING)27match = re.match(handle)28raise ArgumentError if !match2930uuid = [match[1], match[2]]31protocol = match[3]32address = match[4]33options = match[5].split(',')34i = Rex::Proto::DCERPC::Handle.new(uuid, protocol, address, options)35return i36end3738# stringify a handle39def to_s40self.uuid.join(':') + '@' + self.protocol + ':' + self.address + '[' + self.options.join(', ') + ']'41end4243end44end45end46end474849