rapid7/metasploit-framework — pull request #3467 by jvazquez-r7 (2014-06-20 19:14:32+00:00)
Title: [SeeRM #8815] struts_code_exec_parameters: Dont try to exploit when generate_payload_exe fails

Solves https://dev.metasploit.com/redmine/issues/8815, originally reported via #3462

When using the ```Linux``` target the ```generic/shell_reverse_tcp``` payload is selected automatically if you don't set up a payload manually. Unfortunately generate_payload_exe doesn't work with this payload, returning a nil, which is used later. This patch just fixes the module by failing if ```generate_payload_exe``` turns ```nil```.

Verification
--------

- [ ] use exploit/multi/http/struts_code_exec_parameters
- [ ] set target 1
- [ ] set rhost domain-name.com
- [ ] set rport 80
- [ ] set targeturi /xy/X.action
- [ ] exploit

You shouldn't see the unhandled exception anymore:

```
[*] Reloading module...

[*] Started reverse handler on 10.6.0.82:4444
[*] 172.0.0.1:8181 - Uploading exploit to /tmp/IK9sa
[-] Exploit failed: NoMethodError undefined method `length' for nil:NilClass
```

But a more informative message:

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

[*] Started reverse handler on 10.6.0.82:4444
[-] Exploit failed [bad-config]: 172.0.0.1:8181 - Failed to generate an EXE payload, please select a correct payload
```