#!/usr/bin/python
import requests, json
import time

now = int(round(time.time() * 1000))
now_time = time.strftime('%Y-%m-%d %H:%M:%S', time.localtime(now / 1000))


def check_version(url):
    headers = {
        'User-Agent': 'Mozilla/5.0',
        'D-Pisos': '8=D',
        'Ebut': 'mamku tvoyu'
    }
    r = requests.get(url, headers=headers)
    response_str = json.dumps(r.headers.__dict__['_store'])
    if r.status_code == 200 and 'PHP' in response_str and 'nginx' in response_str:

        check_vuln(url)
    else:
        return False


def check_vuln(url):
    for i in range(1500, 2000):
        url_dir = '/PHP%0Ais_the_shittiest_lang.php?' + 'Q' * i
        vuln_url = url + url_dir
        headers = {
            'User-Agent': 'Mozilla/5.0',
            'D-Pisos': '8=D',
            'Ebut': 'mamku tvoyu'
        }
        r = requests.get(vuln_url, headers=headers)
        if r.status_code == 502:
            return True


def initialization():

    return "thinkphp_code_exec_1", {
        "callback": check_version,
        "language": "php",
        "what_cms": "all"
    }
