Modlishka Documentation

repository·master·Indexed 26 days ago

https://github.com/drk1wi/modlishka

An open-source man-in-the-middle (MitM) proxy designed for penetration testing and security research. Modlishka transparently proxies multi-domain HTTP/HTTPS traffic over a single domain to bypass 2FA implementations. It features a comprehensive CLI for targeting, credential management, and JS injection, and can be integrated into Go applications via the EmbeddedServer type.

Tokens
2.1K
Snippets
2
Records
11
Agent score
89%

What's inside Modlishka

  1. Install Modlishka

    master

    You can install Modlishka using go install or by building it manually from the source code.

    Using go install:

    go install github.com/drk1wi/Modlishka@latest

    Manual build:

    git clone https://github.com/drk1wi/Modlishka.git
    cd Modlishka
    make
    go install github.com/drk1wi/Modlishka@latest
  2. Run the Modlishka reverse proxy

    master

    Modlishka is a reverse proxy designed for specific use cases. The main entrypoint initializes configuration, logging, plugins, and the core runtime before starting the server. The execution flow follows these steps:

    1. Parse configuration via config.ParseConfiguration().
    2. Initialize logging based on Debug and LogPostOnly flags.
    3. Configure and enable plugins via plugin.SetPluginRuntimeConfig and plugin.Enable.
    4. Verify configuration requirements via conf.VerifyConfiguration().
    5. Set up core and server runtime configurations.
    6. Prepare regexes via runtime.MakeRegexes().
    7. Start the server using core.RunServer().
    // The main entrypoint executes the following sequence:
    package main
    
    func main() {
    	conf := Configuration{
    		config.ParseConfiguration(),
    	}
    
    	conf.initLogging()
    	plugin.SetPluginRuntimeConfig(conf.Options)
    	plugin.Enable(conf.Options)
    	conf.VerifyConfiguration()
    	runtime.SetCoreRuntimeConfig(conf.Options)
    	core.SetServerRuntimeConfig(conf.Options)
    	runtime.MakeRegexes()
    	core.RunServer()
    }
  3. Embed Modlishka as a server

    master
    To integrate Modlishka into your own Go application, use the EmbeddedServer type and the SetServerRuntimeConfig function. You can configure the proxy behavior by passing config.Options to SetServerRuntimeConfig. The EmbeddedServer allows you to serve the proxy over TLS with custom certificates and a certificate authority pool.
  4. Configure Modlishka logging

    master

    Logging behavior is controlled through the Configuration struct. The following settings determine the log output:

    • Log Level: If the Debug flag is set to true, the minimum log level is set to log.DEBUG. Otherwise, it defaults to log.INFO.
    • HTTP Method Logging:
      • log.Options.GET: Enabled by default unless LogPostOnly is set.
      • log.Options.POST: Controlled by the LogPostOnly flag.
    • Request Path Logging: The LogRequestPath option is set using the value from LogRequestFile.
  5. Reference: Modlishka CLI Flags

    master

    The following command-line options are available for the ./dist/proxy binary:

      -cert string
          base64 encoded TLS certificate
      -certKey string
          base64 encoded TLS certificate key
      -certPool string
          base64 encoded Certification Authority certificate
      -config string
          JSON configuration file. Convenient instead of using command line switches.
      -controlCreds string
          Username and password to protect the credentials page. user:pass format
      -controlURL string
          URL to view captured credentials and settings. (default "SayHello2Modlishka")
      -credParams string
          Credential regexp with matching groups. e.g.: base64(username_regex),base64(password_regex)
      -debug
          Print debug information
      -disableSecurity
          Disable proxy security features like anti-SSRF. Disable at your own risk.
      -disableDynamicSubdomains
          Translate URL domain names to be the proxy domain
      -dynamicMode
          Enable dynamic mode for 'Client Domain Hooking'
      -forceHTTP
          Strip all TLS from the traffic and proxy through HTTP only
      -forceHTTPS
          Strip all clear-text from the traffic and proxy through HTTPS only
      -allowSecureCookies
          Allow secure cookies to be set. Useful when using HTTPS and cookies have SameSite=None
      -ignoreTranslateDomains string
          Comma separated list of domains to never translate and proxy
      -jsRules string
          Comma separated list of URL patterns and JS base64 encoded payloads that will be injected
          e.g.: target.tld:base64(alert(1))
      -listeningAddress string
          Listening address (default "127.0.0.1")
      -listeningPortHTTP int
          Listening port for HTTP requests (default 80)
      -listeningPortHTTPS int
          Listening port for HTTPS requests (default 443)
      -log string
          Local file to which fetched requests will be written (appended)
      -pathHostRules string
          Comma separated list of URL path patterns and target domains
          e.g.: /path/:example.com,/path2:www.example.com
      -plugins string
          Comma separated list of enabled plugin names (default "all")
      -postOnly
          Log only HTTP POST requests
      -proxyAddress string
          Proxy that should be used (socks/https/http) e.g.: http://127.0.0.1:8080
      -proxyDomain string
          Proxy domain name that will be used e.g.: proxy.tld
      -rules string
          Comma separated list of string patterns and their replacements
          e.g.: base64(old):base64(new),base64(older):base64(newer)
      -staticLocations string
          Comma separated list of FQDNs in location headers that should be preserved
      -target string
          Target domain name e.g.: target.tld
      -targetRes string
          Comma separated list of domains that were not translated automatically
          e.g.: static.target.tld
      -terminateTriggers string
          Comma separated list of URLs from target's origin which will trigger session termination
      -terminateUrl string
          URL to which a client will be redirected after session termination
      -trackingCookie string
          Name of the HTTP cookie used to track the client (default "id")
      -trackingParam string
          Name of the HTTP parameter used to track the client (default "id")
  6. Configure Modlishka via CLI flags

    master

    Modlishka is a man-in-the-middle proxy that can be configured using various command-line flags. Key configuration areas include:

    • Targeting: Use -target to specify the target domain (e.g., target.tld).
    • Proxy Domain: Use -proxyDomain to set the domain name that will be used for the proxy (e.g., proxy.tld).
    • Listening: Set -listeningAddress (default 127.0.0.1), -listeningPortHTTP (default 80), and -listeningPortHTTPS (default 443).
    • Credentials Management: Use -controlURL to set the URL to view captured credentials (default SayHello2Modlishka) and -controlCreds to protect the credentials page using user:pass format.
    • TLS/SSL: Provide -cert, -certKey, and -certPool as base64 encoded strings.
    • Rules & Injection: Use -jsRules for pattern-based JavaScript injection (format target.tld:base64(payload)) and -rules for string pattern replacements.
  7. Configure TLS via EmbeddedServer.ListenAndServeTLS

    master
    The ListenAndServeTLS(addr string) method on EmbeddedServer starts a TLS listener. It automatically configures MinVersion to tls.VersionTLS10 and sets NextProtos to ["http/1.1"]. If WebServerCertificatePool is provided, it configures ClientCAs to validate client certificates.
  8. Run the standalone Modlishka server with RunServer

    master

    The RunServer() function starts the Modlishka proxy using the settings defined in the global ServerRuntimeConfig. It handles different modes based on the configuration:

    • ForceHTTP: Starts only an HTTP listener.
    • ForceHTTPS: Starts only a TLS listener using EmbeddedServer.
    • Default Mode: Starts both an HTTP listener and a TLS listener concurrently.
  9. Initialize the proxy runtime with SetServerRuntimeConfig

    master
    Call SetServerRuntimeConfig(conf config.Options) to initialize the global ServerRuntimeConfig. This function creates a new ServerConfig and initializes a new http.ServeMux for the proxy handler.
  10. Use EmbeddedServer for TLS hosting

    master

    The EmbeddedServer type extends http.Server to provide specialized TLS capabilities for the Modlishka proxy. It includes fields for managing the web server's identity and trust chain:

    • WebServerCertificate: The PEM-encoded certificate.
    • WebServerKey: The PEM-encoded private key.
    • WebServerCertificatePool: A PEM-encoded certificate authority (CA) pool for client certificate validation.
  11. Use ServerConfig for proxy configuration

    master
    The ServerConfig struct holds the proxy's operational state. It embeds config.Options and provides a MainHandler which is the primary entry point for processing proxied requests. It also includes a Port field and an http.ServeMux named Handler.