https.proxy

A full featured HTTPS transparent proxy that can be scripted using javascript modules. If used together with a spoofer, all HTTPS traffic will be redirected to it and it will automatically handle port redirections as needed.

When a new TLS connection is being proxied, bettercap will fetch the original certificate from the target host and resign on the fly the full chain using its own CA.

Commands

https.proxy on

Start the HTTPS proxy.

https.proxy off

Stop the HTTPS proxy.

Parameters

parameterdefaultdescription
https.port443HTTPS port to redirect when the proxy is activated.
https.proxy.address<interface address>Address to bind the HTTPS proxy to.
https.proxy.port8083Port to bind the HTTPS proxy to.
https.proxy.certificate~/.bettercap-ca.cert.pemHTTPS proxy certification authority TLS certificate file.
https.proxy.key~/.bettercap-ca.key.pemHTTPS proxy certification authority TLS key file.
https.proxy.certificate.bits4096Number of bits of the RSA private key of the generated HTTPS certificate authority.
https.proxy.certificate.commonnameGo Daddy Secure Certificate Authority - G2Common Name field of the generated HTTPS certificate authority.
https.proxy.certificate.countryUSCountry field of the generated HTTPS certificate authority.
https.proxy.certificate.localityScottsdaleLocality field of the generated HTTPS certificate authority.
https.proxy.certificate.organizationGoDaddy.com, Inc.Organization field of the generated HTTPS certificate authority.
https.proxy.certificate.organizationalunithttps://certs.godaddy.com/repository/Organizational Unit field of the generated HTTPS certificate authority.
https.proxy.sslstripfalseEnable or disable SSL stripping.
https.proxy.scriptPath of a proxy module script.
https.proxy.injectjsURL, path or javascript code to inject into every HTML page.
https.proxy.blacklistComma separated list of hostnames to skip while proxying (wildcard expressions can be used).
https.proxy.whitelistComma separated list of hostnames to proxy if the blacklist is used (wildcard expressions can be used).

Modules

The http.proxy and https.proxy modules can be scripted using javascript files that must declare at least one of the following functions:

  1. // called when the script is loaded
  2. function onLoad() {
  3. }
  4. // called when the request is received by the proxy
  5. // and before it is sent to the real server.
  6. function onRequest(req, res) {
  7. }
  8. // called when the request is sent to the real server
  9. // and a response is received
  10. function onResponse(req, res) {
  11. }
  12. // called every time an unknown session command is typed,
  13. // proxy modules can optionally handle custom commands this way:
  14. function onCommand(cmd) {
  15. if( cmd == "test" ) {
  16. /*
  17. * Custom session command logic here.
  18. */
  19. // tell the session we handled this command
  20. return true
  21. }
  22. }

Modules can change the req request and res response objects, for instance the web-override.cap caplet is using the onRequest function in order to override every request before it is executed with a fake response:

  1. function onRequest(req, res) {
  2. res.Status = 200;
  3. res.ContentType = "text/html";
  4. res.Body = readFile("caplets/www/index.html");
  5. headers = res.Headers.split("\r\n")
  6. for (var i = 0; i < headers.length; i++) {
  7. header_name = headers[i].replace(/:.*/, "")
  8. res.RemoveHeader(header_name);
  9. }
  10. res.SetHeader("Connection", "close");
  11. }

The login-man-abuse.cap caplet instead will use the onResponse handler to inject its malicious javascript file in every html response:

  1. function onResponse(req, res) {
  2. if( res.ContentType.indexOf('text/html') == 0 ){
  3. var body = res.ReadBody();
  4. if( body.indexOf('</head>') != -1 ) {
  5. res.Body = body.replace(
  6. '</head>',
  7. '<script type="text/javascript">' + "\n" +
  8. AbuserJavascript +
  9. '</script>' +
  10. '</head>'
  11. );
  12. }
  13. }
  14. }

Builtin Functions

Modules can use the following builtin functions.

functiondescription
readDir(“/path/“)Return the contents of a directory as a string array.
readFile(“/path/to/file”)Return the contents of a file as a string.
writeFile(“/path/to/file”, “hello world”)Write the string hello world to a file, returns null or an error message.
log_debug(“message”)Log a message in the interactive session (its level will be DEBUG).
log_info(“message”)Log a message in the interactive session (its level will be INFO).
log_warn(“message”)Log a message in the interactive session (its level will be WARNING).
log_error(“message”)Log a message in the interactive session (its level will be ERROR).
log_fatal(“message”)Log a message in the interactive session (its level will be FATAL).
log(“message”)Shortcut for log_info(“message”).
btoa(“message”)Encode a message to base64.
atob(“bWVzc2FnZQ==”)Decode a message from base64.
gzipCompress(“plaintext data”)Compress a string using gzip encoding.
gzipDecompress(“)9�+�I��+I�(QHI,I����”)Decompress a gzip encoded string.
env(“iface.ipv4”)Read a variable.
env(“foo”, “bar”)Set a variable.