rapid7/metasploit-framework — pull request #2912 by wchen-r7 (2014-01-24 04:54:22+00:00)
Title: [FixRM #8749] - Make spawn_meterpreter respect lport/lhost options

[FixRM #8749] Basically the spawn_meterpreter script doesn't actually allow the user to set their own LHOST/LPORT datastore options, because they come from the session object, not from the active module or the framework object.

Issue originally found by Dennis Distler.

The fix is to allow the user to config them from framework. But if they forget to do this (because naturally people probably assume that active module datastore options are the same as the ones set in framework), then for LHOST, we default whatever we get from Rex::Socket.source_address. As for LPORT, we'll pick a one that's not used by any of the sessions.

Bug ticket: http://dev.metasploit.com/redmine/issues/8749

### To reproduce the issue:

- [ ] Create a windows/shell_reverse_tcp executable
- [ ] Configure a handler for windows/shell_reverse_tcp, with option: ```exitonsession false```.
- [ ] ```run -j```, and make sure you have a session. Assuming this is session 1 for you.
- [ ] Run ```sessions -u 1```
- [ ] Confirm that you end up getting another shell session, and not a meterpreter session (this is because the same lhost and lport are reused)

### To verify the patch:

- [ ] Setup the payload/handler exactly the same as above
- [ ] Confirm that instead of getting another shell session, you should get a meterpreter session.