rapid7/metasploit-framework — pull request #2180 by jvennix-r7 (2013-07-31 13:55:02+00:00)
Title: Rewrite osx x64 cmd payload to accept args.

### RM #8260: bug/osx-x64-payload-doesnt-accept-args

#### Check for regressions

- [ ] Checkout master. Generate an OSX x64 cmd exec payload:

$ git checkout master
$ ./msfpayload osx/x64/exec CMD="/bin/ls" X > ~/Desktop/exec64.bin

- [ ] Ensure that running the payload binary results in your root dir being listed:

$ chmod +x ~/Desktop/exec64.bin
$ arch -x86_64 ~/Desktop/exec64.bin
Shared blankslate joe
...

- [ ] Checkout this branch (`bug/osx-x64-payload-doesnt-accept-args`) and generate the same payload:

$ git checkout bug/osx-x64-payload-doesnt-accept-args
$ ./msfpayload osx/x64/exec CMD="/bin/ls" X > ~/Desktop/exec64_fix.bin

- [ ] Ensure that running the cmd results in your root dir being listed:

$ chmod +x ~/Desktop/exec64_fix.bin
$ arch -x86_64 ~/Desktop/exec64_fix.bin
Shared blankslate joe
...

- [ ] Disassemble and compare the two payloads:

![64diff](https://f.cloud.github.com/assets/1184013/886377/76faaf7c-f9e8-11e2-9a1f-c98ab54244d7.png)

#### Verify new behavior

- [ ] Compile the following C program:

#include

int main(int argc, char *argv[]) {
int x;
for (x = 0; x < argc; x++) {
printf("%s\n", argv[x]);
}
return 0;
}

$ gcc print_args.c -O ~/Desktop/print_args

- [ ] Generate a payload that calls this file:

$ ./msfpayload osx/x64/exec CMD="/Users/joe/Desktop/print_args a bb ccc dddd eeeee ffffff ggggggg hhhhhhhh" X > ~/Desktop/exec64_print_args.bin
$ chmod +x ~/Desktop/exec64_print_args.bin

- [ ] Run the payload, verify that you see the following output:

$ arch -x86_64 ~/Desktop/exec64_print_args.bin
a
bb
ccc
dddd
eeeee
ffffff
ggggggg
hhhhhhhh