Using multiple networking mixins in a Metasploit module is always a tricky thing to do, because most likely you will run into issues like overlapping datastore options, variables, methods, the super call is only meant for one mixin, etc. This is considered as advanced module development, and sometimes can be rather painful to figure out on your own. To improve the Metasploit development experience, we have a few examples to demonstrate common scenarios that require you to use multiple mixins to achieve exploitation.
### Today's lesson: Send a HTTP request to attack the target machine, and use a HttpServer for payload delivery.
Say you want to exploit a web server or web application. You have code execution on the box, but you need to find a way to deliver the final payload (probably an executable), and a HTTP server happens to be your option.
Here's what happens when you run the above example:
1. The super call wrapped in the Timeout block will start the web server.
2. Before the web server is in the infinite loop state, the primer() method is called, which is where you send your malicious requests to get code execution.
3. Your HttpServer serves the final payload upon request.
4. After 10 seconds, the module raises a Timeout exception. The web server finally terminates.
In case you're wondering why the web server must terminate after a period of time, this is because if the module fails to gain code execution on the target machine, obviously it will never ask your web server for the malicious payload, therefore there is no point to keeping it alive forever. Typically it shouldn't take a very long time to get a payload request, either, so we keep the timeout short.
The output for the above example should look something like this: