rapid7/metasploit-framework — pull request #4294 by limhoff-r7 (2014-12-02 17:45:33+00:00)
Title: Remove double call to init_module_paths from msfconsole boot

MSP-11672

`Msf::Simple::Framework#create` calls `framework.modules.init_module_paths` if `'DeferModuleLoads' => true` is not passed. `msfconsole` calls `Msf::Ui::Console::Driver#initialize`, which calls `Msf::Simple::Create#create`, which caused the first `framework/modules.init_module_paths`. Further in `Msf::Ui::Console::Driver#initialize`, it calls `framework.modules.init_modules_paths`. Calling `init_module_paths` twice does no cause modules to be loaded twice: the mtime check in `load_module` prevents that, but just having to enumerate all the files under `modules` and get their mtime takes ~6 seconds on my machine. Therefore, I removed the first call by passing `'DeferModuleLoads' => true` when `Driver#initialize` calls `Msf::Simple::Framework#create`. I also added a flag to `fail` if `init_module_paths` is called multiple times in the future. Real time for `msfconsole -q -x exit` dropped from 13.31 seconds to 6.98 seconds (-47.53%). Times will differ on other machines where the balance of CPU to process the module code and disk speed to enumerate files and retrieve mtime for each file differs from my setup (I have an SSD for example). Raw data is [available](https://docs.google.com/spreadsheets/d/1dmNo5M_vED1gO7wfnMtPC9KVJ17Y6ypQEFzqpZhT6MM/edit?usp=sharing)
![screen shot 2014-12-02 at 11 32 53 am](https://cloud.githubusercontent.com/assets/2230482/5267480/fc550244-7a16-11e4-8bf5-2104d4dd7a6b.png)

# Verification Steps

## Old time
- [ ] `git checkout 394d132d33d1b87fd54bd1b73b21d7a8822e7095`
- [ ] Use a `time` that will report realtime (zsh's builtin won't) and disable banners as printing them adds noise: `/usr/bin/time msfconsole -q -x`
- [ ] Record real time

## New time
- [ ] `git checkout 90c6764426d9341c260f6d86408e0b7fcf08c5ca`
- [ ] Use a `time` that will report realtime (zsh's builtin won't) and disable banners as printing them adds noise: `/usr/bin/time msfconsole -q -x`
- [ ] Record real time
- [ ] Verify new time is faster.

## msfconsole boots with modules
- [ ] `msfconsole`
- [ ] VERIFY banner shows non-zero module counts
- [ ] `use exploit/windows/smb/ms08_067_netapi`
- [ ] VERIFY module was loaded without error