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/wdscp/packet.rb
Views: 11766
# -*- coding: binary -*-1module Rex2module Proto3module DCERPC4module WDSCP5class Packet67WDS_CONST = Rex::Proto::DCERPC::WDSCP::Constants89def initialize(packet_type, opcode)10if opcode.nil? || packet_type.nil?11raise(ArgumentError, "Packet arguments cannot be nil")12end1314@variables = []15@packet_type = WDS_CONST::PACKET_TYPE[packet_type]16@opcode = WDS_CONST::OPCODE[opcode]17end1819def add_var(name, type_mod=0, value_length=nil, array_size=0, value)20padding = 021vt = WDS_CONST::VAR_TYPE_LOOKUP[name]22value_type = WDS_CONST::BASE_TYPE[vt]23name = Rex::Text.to_unicode(name).unpack('H*')[0]2425# Terminate strings with null char26if vt == :STRING27value << "\x00"28elsif vt == :WSTRING29value = Rex::Text.to_unicode(value)30value << "\x00\x00"31end3233value_length ||= value.length34# Variable block total size should be evenly divisible by 16.35len = 16 * (1 + (value_length/16))36@variables <<37[ name,38padding,39value_type,40type_mod,41value_length,42array_size,43value44].pack('H132vvvVVa%i' % len)45end4647def create48packet = []49var_count = @variables.count5051packet_size = 052@variables.each do |var|53packet_size += var.length54end5556# variables + operation57packet_size += 165859# These bytes are not part of the spec but are not part of DCERPC according to Wireshark60# Perhaps something from MSRPC specific? Basically length of the WDSCP packet twice...61packet << [(packet_size+40)].pack('V') * 262packet << create_endpoint_header(packet_size)63packet << create_operation_header(packet_size, var_count, @packet_type, @opcode)64packet.concat(@variables)6566return packet.join67end6869def create_operation_header(packet_size, var_count, packet_type=:REQUEST, opcode)70return [71packet_size, # PacketSize72256, # Version73packet_type, # Packet_Type740, # Padding75opcode, # Opcode76var_count, # Variable Count77].pack('VvCCVV')78end7980def create_endpoint_header(packet_size)81return [8240, # Header_Size83256, # Version84packet_size, # Packet_Size - This doesn't differ from operation header despite the spec...85WDS_CONST::OS_DEPLOYMENT_GUID, # GUID86"\x00"*16, # Reserved87].pack('vvVa16a16')88end89end90end91end92end93end949596