Add #3463 commits from @ghost

Initial commit from changes made by @ghost
This may conflict with recent upstream changes 

https://github.com/rapid7/metasploit-framework/pull/3497