10 Metasploit
10 Metasploit
Introduction
Before seeing how to write the module, we will show you the
exploitation process of the Els Echo Server using a custom
Metasploit module.
Metasploit is a very huge framework and we will not cover all of its
features and functions. Rather, we will give you a starting point to
learn how to use and develop modules in Metasploit.
https://github.com/rapid7/metasploit-framework/wiki#metasploit-development
MSF CORE
CLI
MODULES
Payloads Exploits Encoders Post-Modules Auxiliary
We will mainly explain how to use the Metasploit API and how to
find all the information that you need for you custom module. This
is because it is not good to write a lot of library structure concepts
when the best way to learn to develop modules is to explore them
and reuse the code you find.
We will briefly see the major points of each in the following slides.
You have already used it during the entire PTP course therefore we
will not explain its basic concepts. The only thing we want you to
notice is that msfconsole is a complex interface and a shell
command too.
With msfcli, you have to know a bit about the framework. For
example, you have to know an exploit to launch it. It is the best
choice if you already know what you have to do and you do not
want to use the msfconsole.
Once registered, you can create a user and password to login and
use the interface.
https://github.com/rapid7/metasploit-framework/blob/master/documentation/developers_guide.pdf
You can explore its modules, classes, utilities etc. You can also use
its libraries in your scripts without using any Metasploit interface
(as reported in the Metasploit Developer’s Guide Appendix).
https://github.com/rapid7/metasploit-framework/wiki#metasploit-development
https://rapid7.github.io/metasploit-framework/api/
It contains some examples that show you how to use its features in
your external scripts and tools by loading the Rex library (or some
parts of it).
http://rapid7.github.io/metasploit-framework/api/
TOOLS Rex
MSF CORE
MSF BASE
The instance contains the entire framework state and you can
create it using the Msf::Framework class framework =
Msf::Framework.new
For our purposes, we will not directly use the Framework Core.
https://github.com/rapid7/metasploit-framework/wiki#metasploit-development
MSF CORE
Rex
You can use the API documentation
under the Msf namespace as we MSF CORE
have seen for Core.
MSF BASE
We will see them briefly but we will study them deeply when we
will explore the echoserv custom module.
MODULES
Payloads Exploits Encoders Post-Modules Auxiliary
We will analyze both the exploit and the local directory structure in
deep when we will explore the echoserv module.
The stager is used to setup the connection between the target and
the attacker machine.
We suggest you take a look at the Ruby code of one of your mainly
used payloads in order to realize what they are.
We suggest you do that after you study all of this chapter (after
exploring the echoserv module) because it will be all more clear
for you.
These are advanced concepts that are not strictly required for our
purposes but it is good to know that you can use these type of
modules.
As usual, we will not deeply cover encoders and nops but you can
read about them in the Metasploit Developer’s Guide (here).
From their name, you can assume they are used to perform post
exploitation tasks and therefore they may require an active
meterpreter session to interact with as an option.
LIBRARIES
If you want to use some Rex
TOOLS Rex
classes or features, you are
writing what is called a Metasploit MSF CORE
dependent tool and you have
MSF BASE
to include it the Rex library.
Note that you can download the module in the members area too.
To test it, you can download and start the Els Echo server on your
local machine or use the Hera Laboratory designed for that
(Exploitation with ruby and Metasploit).
Once tested, we suggest you erase it and write it again from the
contents in following the next slides; we will explore it thoroughly.
Module type
Module
Requirements
Module information
Module Operations
http://www.rubydoc.info/github/rapid7/metasploit-framework/Msf/Exploit/Remote
http://www.rubydoc.info/github/rapid7/metasploit-framework/Msf/Exploit/Remote
We suggest to keep close the full module code while you read the
following slides in order to have a global view of the module since
we will show the entire module by screen sections.
http://www.rubydoc.info/github/rapid7/metasploit-framework/Msf/Module/Target
http://www.rubydoc.info/github/rapid7/metasploit-framework/Msf/Payload
Penetration Testing Professional 5.0 – Caendra Inc. © 2018
The first part of the payload simply set 44 nops at the very
beginning. Please refer to the previous chapter to check how we
calculated them.
http://www.rubydoc.info/github/rapid7/metasploit-framework/Msf/EncodedPayload
Note: if you test the module with an XP machine, all should work
well while if you test the module with a different target OS (such as
Windows 7), it will certainly fail.
From the system module, you should know what ASLR is and how
it works. Please refer to it if you do not recall.
We have already seen some of its features during the PTP course.
You can write your own scripts using Meterpreter APIs and you can
use them in your penetration testing activities with the run
command.
Then you can test the APIs using the irb interpreter available in
each meterpreter session.
Meterpreter scripting