From 24aac8b5ae99495281458954e552c7bd46870b54 Mon Sep 17 00:00:00 2001 From: HD Moore Date: Mon, 16 Jul 2007 01:13:25 +0000 Subject: [PATCH] Fixes #127. Applying patch from Alex that solves ASN.1 encoding issues. git-svn-id: file:///home/svn/framework3/trunk@5049 4d416f70-5f16-0410-b530-b9f4589650da --- lib/rex/proto/smb/utils.rb | 31 +++++++++++++++++++++---------- 1 file changed, 21 insertions(+), 10 deletions(-) diff --git a/lib/rex/proto/smb/utils.rb b/lib/rex/proto/smb/utils.rb index 1ed695eed3..6979b9b1f2 100644 --- a/lib/rex/proto/smb/utils.rb +++ b/lib/rex/proto/smb/utils.rb @@ -94,18 +94,29 @@ CONST = Rex::Proto::SMB::Constants return decoded end + # + # Prepends an ASN1 formatted length field to a piece of data + # def self.asn1encode(str = '') res = '' - case str.length - when 0 .. 0x80 - res = [str.length].pack('C') + str - when 0x81 .. 0x100 - res = [0x81, str.length].pack('CC') + str - when 0x101 .. 0x100000 - res = [0x82, str.length].pack('Cn') + str - when 0x100001 .. 0xffffffff - res = [0x83, str.length].pack('CN') + str - end + + # If the high bit of the first byte is 1, it contains the number of + # length bytes that follow + + case data.length + when 0 .. 0x7F + res = [data.length].pack('C') + data + when 0x80 .. 0xFF + res = [0x81, data.length].pack('CC') + data + when 0x100 .. 0xFFFF + res = [0x82, data.length].pack('Cn') + data + when 0x10000 .. 0xffffff + res = [0x83, data.length >> 16, data.length & 0xFFFF].pack('CCn') + data + when 0x1000000 .. 0xffffffff + res = [0x84, data.length].pack('CN') + data + else + raise "ASN1 data too long" + end return res end