Skip to content

Commit c9b6c05

Browse files
author
HD Moore
committed
Fix improper use of host-endian or signed pack/unpack
Note that there are some cases of host-endian left, these are intentional because they operate on host-local memory or services. When in doubt, please use: ``` ri pack ```
1 parent 255e792 commit c9b6c05

File tree

26 files changed

+65
-65
lines changed

26 files changed

+65
-65
lines changed

lib/bit-struct/octet-field.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ def add_accessors_to(cl, attr = name) # :nodoc:
3737
old_writer = "#{attr_chars}="
3838

3939
define_method "#{attr}=" do |val|
40-
data = val.split(sep).map{|s|s.to_i(base)}.pack("c*")
40+
data = val.split(sep).map{|s|s.to_i(base)}.pack("C*")
4141
send(old_writer, data)
4242
end
4343
end

lib/msf/core/exploit/afp.rb

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -246,8 +246,7 @@ def parse_info_response(response)
246246
end
247247

248248
def parse_header(packet)
249-
header = packet.unpack('CCnNNN') #ruby 1.8.7 don't support unpacking signed integers in big-endian order
250-
header[3] = packet[4..7].reverse.unpack("l").first
249+
header = packet.unpack('CCnNNN')
251250
return header
252251
end
253252

lib/msf/core/post/windows/accounts.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -270,7 +270,7 @@ def check_dir_perms(dir, token)
270270

271271
#define generic mapping structure
272272
gen_map = [0,0,0,0]
273-
gen_map = gen_map.pack("L")
273+
gen_map = gen_map.pack("V")
274274
buffer_size = 500
275275

276276
#get Security Descriptor for the directory

lib/msf/core/post/windows/ldap.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -248,15 +248,15 @@ def query_ldap(session_handle, base, scope, filter, fields)
248248
# @param pEntry [Fixnum] Pointer to the Entry
249249
# @return [Array] Entry data structure
250250
def get_entry(pEntry)
251-
return client.railgun.memread(pEntry,41).unpack('LLLLLLLLLSCCC')
251+
return client.railgun.memread(pEntry,41).unpack('VVVVVVVVVvCCC')
252252
end
253253

254254
# Get BER Element data structure from LDAPMessage
255255
#
256256
# @param msg [String] The LDAP Message from the server
257257
# @return [String] The BER data structure
258258
def get_ber(msg)
259-
ber = client.railgun.memread(msg[2],60).unpack('L*')
259+
ber = client.railgun.memread(msg[2],60).unpack('V*')
260260

261261
# BER Pointer is different between x86 and x64
262262
if client.platform =~ /x64/

lib/msf/core/post/windows/services.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -334,7 +334,7 @@ def service_status(name, server=nil)
334334
raise RuntimeError.new("Could not query service. QueryServiceStatus error: #{handle["GetLastError"]}")
335335
end
336336

337-
vals = status['lpServiceStatus'].unpack('L*')
337+
vals = status['lpServiceStatus'].unpack('V*')
338338
adv.CloseServiceHandle(handle["return"])
339339

340340
ret = {

lib/msf/util/exe.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ def self.replace_msi_buffer(pe, opts)
654654
msi = fd.read(fd.stat.size)
655655
}
656656

657-
section_size = 2**(msi[30..31].unpack('s<')[0])
658-
sector_allocation_table = msi[section_size..section_size*2].unpack('l<*')
657+
section_size = 2**(msi[30..31].unpack('v')[0])
658+
sector_allocation_table = msi[section_size..section_size*2].unpack('V*')
659659

660660
buffer_chain = []
661661
current_secid = 5 # This is closely coupled with the template provided and ideally

lib/rex/encoder/ndr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def NDR.short(string)
2828
# use to encode:
2929
# byte element_1;
3030
def NDR.byte(string)
31-
return [string].pack('c')
31+
return [string].pack('C')
3232
end
3333

3434
# Encode a byte array

lib/rex/ole/util.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -124,15 +124,15 @@ def self.pack8(value)
124124

125125

126126
def self.getUnicodeString(buf)
127-
buf = buf.unpack('S*').pack('C*')
127+
buf = buf.unpack('v*').pack('C*')
128128
if (idx = buf.index(0x00.chr))
129129
buf.slice!(idx, buf.length)
130130
end
131131
buf
132132
end
133133

134134
def self.putUnicodeString(buf)
135-
buf = buf.unpack('C*').pack('S*')
135+
buf = buf.unpack('C*').pack('v*')
136136
if (buf.length < 0x40)
137137
buf << "\x00" * (0x40 - buf.length)
138138
end

lib/rex/post/meterpreter/extensions/stdapi/railgun/util.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -452,9 +452,9 @@ def read_data(type, position, buffer = nil)
452452
# Both on x86 and x64, DWORD is 32 bits
453453
return raw.unpack('V').first
454454
when :BOOL
455-
return raw.unpack('l').first == 1
455+
return raw.unpack('V').first == 1
456456
when :LONG
457-
return raw.unpack('l').first
457+
return raw.unpack('V').first
458458
end
459459

460460
#If nothing worked thus far, return it raw

lib/rex/proto/dcerpc/ndr.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ def self.short(string)
3434
# byte element_1;
3535
def self.byte(string)
3636
warn 'should be using Rex::Encoder::NDR'
37-
return [string].pack('c')
37+
return [string].pack('C')
3838
end
3939

4040
# Encode a byte array

0 commit comments

Comments
 (0)