☑️Additional Feature
Exploit-DB
ExploitDB is a great choice when searching for a custom exploit. We can use tags to search through the different exploitation scenarios for each available script. One of these tags is Metasploit Framework (MSF), which, if selected, will display only scripts that are also available in Metasploit module format. These can be directly downloaded from ExploitDB and installed in our local Metasploit Framework directory, from where they can be searched and called from within the msfconsole.
Lets say we are looking for a specific exploit nagios3, but we cant find it in msfconsole meaning that it was not in the official release or our metasploit database isnt updated. In that case we can use the tool searchsploit that's part of exploit-DB to search for it. The result will give us many scripts but we are only interested in the .rb scripts thats for metasploit:
searchsploit -t Nagios3 --exclude=".py"We have to download the .rb file and place it in the correct directory. The default directory where all the modules, scripts, plugins, and msfconsole proprietary files are stored is /usr/share/metasploit-framework. The critical folders are also symlinked in our home and root folders in the hidden ~/.msf4/ location.
Then we can also load the additional modules at runtime with msfconsole.
msfconsole -m /usr/share/metasploit-framework/modules/Or in msfconsole:
msf6> loadpath /usr/share/metasploit-framework/modules/Alternativly we can the the reload_all command in msfconsole.
Ruby - Writing our modules
To adapt a custom Python, PHP, or any type of exploit script to a Ruby module for Metasploit, we will need to learn the Ruby programming language. Note that Ruby modules for Metasploit are always written using hard tabs.
We will often face a custom-built network running proprietary code to serve its clients during specific assessments. Most of the modules we have at hand do not even make a dent in their perimeter, and we cannot seem to scan and document the target with anything we have correctly. This is where we might find it helpful to dust off our Ruby skills and start coding our modules.
All necessary information about Metasploit Ruby coding can be found on the Rubydoc.info Metasploit Framework related page. From scanners to other auxiliary tools, from custom-made exploits to ported ones, coding in Ruby for the Framework is an amazingly applicable skill.
Please look below at a similar module that we can use as boilerplate code for our exploit port-over. This is the Bludit Directory Traversal Image File Upload Vulnerability exploit, which has already been imported into msfconsole. Take a moment to acknowledge all the different fields included in the module before the exploit proof-of-concept (POC). Note that this code has not been changed in the snippet below to fit our current import but is a direct snapshot of the pre-existing module mentioned above. The information will need to be adjusted accordingly for the new port-over project.
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::PhpEXE
include Msf::Exploit::FileDropper
include Msf::Auxiliary::ReportFunction
Description
Msf::Exploit::Remote::HttpClient
This module provides methods for acting as an HTTP client when exploiting an HTTP server.
Msf::Exploit::PhpEXE
This is a method for generating a first-stage php payload.
Msf::Exploit::FileDropper
This method transfers files and handles file clean-up after a session with the target is established.
Msf::Auxiliary::Report
This module provides methods for reporting data to the MSF DB.
Here is the documentation: rubydoc rapid7 documentation
Looking at their purposes above, we conclude that we will not need the FileDropper method, and we can drop it from the final module code.
We see that there are different sections dedicated to the info page of the module, the options section. We fill them in appropriately, offering the credit due to the individuals who discovered the exploit, the CVE information, and other relevant details.
After the general identification information is filled in, we can move over to the options menu variables:
Looking back at our exploit, we see that a wordlist will be required instead of the BLUDITPASS variable for the module to brute-force the passwords for the same username. It would look something like the following snippet:
The rest of the exploit code needs to be adjusted according to the classes, methods, and variables used in the porting to the Metasploit Framework for the module to work in the end. The final version of the module would look like this:
If you would like to learn more about porting scripts into the Metasploit Framework, check out the Metasploit: A Penetration Tester's Guide book from No Starch Press. Rapid7 has also created blog posts on this topic, which can be found here.
Last updated