Skip to content

Base Classes and Mixins

Once you choose a type, select the class to inherit from and the mixins to include (or prepend). The base class defines the kind of module; mixins define how it communicates and runs.

class MetasploitModule < Msf::Exploit::Remote
# Or Msf::Exploit::Local / Msf::Auxiliary / Msf::Post
end
TaskBase class
Deliver a payload over the networkMsf::Exploit::Remote
Use local privilege escalation in an existing session to get a new sessionMsf::Exploit::Local
Operate or enumerate without opening a sessionMsf::Auxiliary
Collect or administer through an existing sessionMsf::Post

The current class name is MetasploitModule.

Mixins add methods and datastore options by include-ing Ruby modules. They let you use framework implementations instead of writing your own socket or HTTP client from scratch.

class MetasploitModule < Msf::Exploit::Remote
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::FileDropper
end

This example adds:

  • HttpClient → send_request_cgi, RHOST, RPORT, SSL, etc.
  • CmdStager → execute_cmdstager (requires execute_command)
  • FileDropper → register_file_for_cleanup
  1. Communication method (HTTP / TCP / SSH / SMB / existing session)
  2. Execution model (single run / multi-host scanner / authentication brute force)
  3. Delivery method (CmdStager, HttpServer, FileDropper)
  4. Storage (Report is often already included by HttpClient)
CommunicationMixinTypical API
HTTP(S) clientMsf::Exploit::Remote::HttpClientsend_request_cgi
Raw TCPMsf::Exploit::Remote::Tcpconnect / sock
SSHMsf::Exploit::Remote::SSHSSH connection helpers
SMBMsf::Exploit::Remote::SMB::Client and othersShares and pipes
Malicious HTTP serverMsf::Exploit::Remote::HttpServerDelivery to browsers
Existing session(Inherit from Msf::Post for Common/File and others)cmd_exec / read_file

Details: HttpClient / Tcp / SSH / SMB / HttpServer / Post mixins

ModelMixinEntry point
Single host(Optional)run / exploit
Parallel multi-hostMsf::Auxiliary::Scannerrun_host(ip)
Dictionary loginMsf::Auxiliary::AuthBruteAuthentication loop + LoginScanner
Run check automatically before exploitprepend Msf::Exploit::Remote::AutoCheckRequires check
class MetasploitModule < Msf::Exploit::Remote
Rank = ExcellentRanking
prepend Msf::Exploit::Remote::AutoCheck
include Msf::Exploit::Remote::HttpClient
include Msf::Exploit::CmdStager
include Msf::Exploit::FileDropper
end
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::HttpClient
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::Report
end
class MetasploitModule < Msf::Post
include Msf::Post::File
include Msf::Post::Unix
include Msf::Auxiliary::Report
end
class MetasploitModule < Msf::Auxiliary
include Msf::Exploit::Remote::SSH
include Msf::Auxiliary::Scanner
include Msf::Auxiliary::AuthBrute
include Msf::Auxiliary::Report
end
  • Writing only run and omitting run_host for a Scanner module.
  • Building HTTP manually using only Tcp when HttpClient is needed (hard to maintain).
  • Using include for AutoCheck (use prepend).
  • Registering RHOSTS / THREADS again when mixins already register them.

Next, write the metadata shown in msfconsole with update_info.