Chapter 2. Reinventing Metasploit
After recalling the basics of Metasploit, we can now move further into the basic coding part of Metasploit. We will start with the basics of Ruby programming and understand the various syntaxes and semantics of it. This chapter will make it easy for you to write Metasploit modules. In this chapter, we will see how we can design and fabricate various custom Metasploit modules. We will also see how we can create custom post-exploitation modules, which will help us gain better control of the exploited machine.
Consider a scenario where the systems under the scope of the penetration test are very large in number, and we need to perform a post-exploitation function such as downloading a particular file from all the systems after exploiting them. Downloading a particular file from each system manually will consume a lot of time and will be tiring as well. Therefore, in a scenario like this, we can create a custom post-exploitation script that will automatically download a file from all the systems that are compromised.
This chapter focuses on building programming skill sets for Metasploit modules. This chapter kicks off with the basics of Ruby programming and ends with developing various Metasploit modules. In this chapter, we will cover the following points:
- Understanding the basics of Ruby programming
- Writing programs in Ruby programming
- Exploring modules in Metasploit
- Writing your own modules and post-exploitation modules
- Coding meterpreter scripts
- Understanding the syntaxes and semantics of Metasploit modules
- Performing the impossible with RailGun
- Writing your own RailGun scripts
Let's now understand the basics of Ruby programming and gather the required essentials we need to code Metasploit modules.
Before we delve deeper into coding Metasploit modules, we must know the core features of Ruby programming that are required in order to design these modules. However, why do we require Ruby for Metasploit? The following key points will help us understand the answer to this question:
- Constructing an automated class for reusable code is a feature of the Ruby language that matches the needs of Metasploit
- Ruby is an object-oriented style of programming
- Ruby is an interpreter-based language that is fast and consumes less development time
- Earlier, Perl used to not support code reuse