Detect load module leaks with Metasploit::Framework::Spec::Constants

MSP-11130

# Suite Leaks

`Metasploit::Framework::Spec::Constants::Suite.configure!` sets up a `before(:suite)` callback that detects if modules are loaded outside any spec's `before(:all)` or `before(:each)` callback.

## Before Suite Leaks

These `before(:suite)` leaks are usually due to calling `Msf::Simple::Framework.create` in the body of a `context` or `describe` block.  They can be found by placing a break point at the beginning of [`Msf::Modules::Loader::Base#load_module`](https://github.com/rapid7/metasploit-framework/blob/b45cbfdf53a4fb1d7784475721d90f588627b546/lib/msf/core/modules/loader/base.rb#L119) and looking up the callstack when the debugger hits the break point to the point where the errant `Msf::Simple::Framework#create` call exists.  Replace it with either

```ruby
include_context 'Msf::Simple::Framework'
```

if you just need a `framework` to use.  If you need one or more modules loaded, those must be loaded explicitly.  You can do the following then:

```ruby
  include_context 'Msf::Simple::Framework#modules loading'
  
  let(:encoder_module) {
    load_and_create_module(
        module_type: 'encoder',
        reference_name: 'x86/shikata_ga_nai'
    )
  }
  
  let(:payload_module) {
    load_and_create_module(
        ancestor_reference_names: %w{
          stagers/windows/reverse_tcp
          stages/windows/meterpreter
        },
        module_type: 'payload',
        reference_name: 'windows/meterpreter/reverse_tcp'
    )
  }
```

ensure that the `load_and_create_module` is done before you expect your code needs to use the module.

## After Suite Leaks

If there are no leaks before the suite runs, but there are during the suite run, then the `after(:suite)` callback will detect the leaks and log them to `log/metasploit/framework/spec/constants/suite.log`.

## `rake spec`

If using `rake spec`, it will check for `log/metasploit/framework/spec/constants/suite.log` and exit with `1` instead of `0` after printing all the leaked constants.  The log will contain instructions to add `Metasploit::Framework::Spec::Constants::Each.configure!` to `spec/spec_helper.rb` to narrow down the examples where the leaks are occurring.  `Metasploit::Framework::Spec::Constants::Each` isn't always configured as it can lead to false positives if a `before(:all)` loads modules and they are cleaned up with `after(:all)`.

# Example Leaks

`Metasploit::Framework::Spec::Constants::Each.configure!` sets up a `before(:each)` that cleans any pre-existing leaks and an `after(:each)` that checks for any leaks from the current example.

## Before Example Leaks

If the `before(:each)` has to clean leaks it is recorded in `Metasploit::Framework::Spec::Constants.leaks_cleaned`, which can be checked with `Metasploit::Framework::Spec::Constants.leaks_cleaned?`.  A message will also be printed to $stderr with the full description of the example where the leaks were cleaned.  **NOTE: the cleaning happens in a `before(:each)`, so the actual leak had to occur in a `before(:all)` or a previous example.

## After Example Leaks

If leaks are detected in the `after(:each)`, then the example will fail with a `RuntimeError` so the developer knows which example to clean up.  The leak itself could be in a `let`, `before(:each)`, or `before(:all)` in any context wrapping the example which fails.  Part of the `RuntimeError` message is instructions to use `Metasploit::Framework::Spec::Constants cleaner` to clean up the leaked constants.  If you use `Metasploit::Framework::Simple#modules loading`, it will include the `Metasploit::Framework::Spec::Constants cleaner` for you.

## After Suite

If any leaks were cleaned in `before(:each)`, then `1` is written to `log/remove-cleaner`. If no leaks were cleaned in the `before(:each)` then `log/remove-cleaner` is deleted.

## `rake spec`

If using `rake spec`, it will check for `log/remove-cleaner` and exit with `1` instead of `0` after printing instructions to remove `Metasploit::Framework::Spec::Constants::Each.configure!` from `spec/spec_helper.rb` and removing `log/remove-cleaner`.

# Verification Steps

## `Metasploit::Framework
- [x] `git checkout 7e28972`
- [x] `SPEC=spec/lib/msf/base/simple/framework_spec.rb rake spec`
- [x] VERIFY 'Msf::Simple::Framework it should behave like Msf::Simple::Framework::ModulePaths#init_module_paths should refresh module cache from database' fails
- [x] VERIFY fail is due to `RuntimeError` with a list of leaked constants.

## `Metasploit::Framework::Spec::Constants::Suite.configure!` `before(:suite)`
- [x] `git checkout 78ea930`
- [x] `rake spec`
- [x] VERIFY `8 constants leaked under Msf::Modules. Modules are being loaded outside callbacks before suite starts. See log/metasploit/framework/spec/constants/suite/before.log for details.` is printed to stderr.
- [x] `echo $?`
- [x] VERIFY exit `1`
- [x] VERIFY leaked constants are printed: 
```
Leaked constants detected under Msf::Modules before suite:
  Mod6e6f702f7838362f73696e676c655f62797465 # nop/x86/single_byte
  Mod6e6f702f7838362f6f70747932 # nop/x86/opty2
  Mod6e6f702f7836342f73696d706c65 # nop/x64/simple
  Mod6e6f702f7474792f67656e65726963 # nop/tty/generic
  Mod6e6f702f73706172632f72616e646f6d # nop/sparc/random
  Mod6e6f702f7070632f73696d706c65 # nop/ppc/simple
  Mod6e6f702f7068702f67656e65726963 # nop/php/generic
  Mod6e6f702f61726d6c652f73696d706c65 # nop/armle/simple
```

## Remove `Metasploit::Framework::Spec::Constants::Each.configure!`
- [x] `git checkout 0c769e2`
- [x] `rake spec`
- [x] `echo $?`
- [x] VERIFY exit `1`
- [x] VERIFY instructions were printed to remove `Metasploit::Framework::Spec::Constants::Each.configure!` from `spec/spec_helper.rb`.

##  No leaks
- [x] `git checkout feature/MSP-11130/metasploit-framework-spec-constants`
- [x] `bundle install`
- [x] `rake spec`
- [x] VERIFY no failures