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/uuid.rb
Views: 11704
# -*- coding: binary -*-1module Rex2module Proto3module DCERPC4class UUID567@@known_uuids =8{9'MGMT' => [ 'afa8bd80-7d8a-11c9-bef4-08002b102989', '2.0' ],10'REMACT' => [ '4d9f4ab8-7d1c-11cf-861e-0020af6e7c57', '0.0' ],11'SYSACT' => [ '000001a0-0000-0000-c000-000000000046', '0.0' ],12'LSA_DS' => [ '3919286a-b10c-11d0-9ba8-00c04fd92ef5', '0.0' ],13'SAMR' => [ '12345778-1234-abcd-ef00-0123456789ac', '1.0' ],14'MSMQ' => [ 'fdb3a030-065f-11d1-bb9b-00a024ea5525', '1.0' ],15'EVENTLOG' => [ '82273fdc-e32a-18c3-3f78-827929dc23ea', '0.0' ],16'SVCCTL' => [ '367abb81-9844-35f1-ad32-98f038001003', '2.0' ],17'SRVSVC' => [ '4b324fc8-1670-01d3-1278-5a47bf6ee188', '3.0' ],18'PNP' => [ '8d9f4e40-a03d-11ce-8f69-08003e30051b', '1.0' ]19}2021# Convert a UUID in binary format to the string representation22def self.uuid_unpack(uuid_bin)23raise ArgumentError if uuid_bin.length != 1624sprintf("%.8x-%.4x-%.4x-%.4x-%s",25uuid_bin[ 0, 4].unpack('V')[0],26uuid_bin[ 4, 2].unpack('v')[0],27uuid_bin[ 6, 2].unpack('v')[0],28uuid_bin[ 8, 2].unpack('n')[0],29uuid_bin[10, 6].unpack('H*')[0]30)31end3233# Validate a text based UUID34def self.is? (uuid_str)35raise ArgumentError if !uuid_str36if 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}$/)37return true38else39return false40end41end4243# Convert a UUID in string format to the binary representation44def self.uuid_pack (uuid_str)45raise ArgumentError if !self.is?(uuid_str)46parts = uuid_str.split('-')47[ parts[0].hex, parts[1].hex, parts[2].hex, parts[3].hex ].pack('Vvvn') + [ parts[4] ].pack('H*')48end4950# Provide the common TransferSyntax UUID in packed format51def self.xfer_syntax_uuid ()52self.uuid_pack('8a885d04-1ceb-11c9-9fe8-08002b104860')53end5455# Provide the common TransferSyntax version number56def self.xfer_syntax_vers ()57'2.0'58end5960# Determine the UUID string for the DCERPC service with this name61def self.uuid_by_name (name)62if @@known_uuids.key?(name)63@@known_uuids[name][0]64end65end6667# Determine the common version number for the DCERPC service with this name68def self.vers_by_name (name)69if @@known_uuids.key?(name)70@@known_uuids[name][1]71end72end7374# Convert a string or number in float format to two unique numbers 2.0 => [2, 0]75def self.vers_to_nums (vers)76vers_maj = vers.to_i77vers_min = ((vers.to_f - vers.to_i) * 10).to_i78return vers_maj, vers_min79end8081end82end83end84end858687