#!/usr/bin/env python
# _*_ coding:utf-8 _*_


import logging
import sys
import requests
import time
import re

from ..platform import ManageProcessor,Color


logging.basicConfig(filename='Weblogic.log',
                    format='%(asctime)s %(message)s',
                    filemode="w", level=logging.INFO)
headers = {'user-agent': 'ceshi/0.0.1','content-type':'text/xml', 'host':'smtp-relay.gmail.com:25'}
VUL='CVE-2020-2766'
path='/consolehelp/console-help.portal'
payload='XXXX'

@ManageProcessor.plugin_register('CVE20202766')
class CVE20192725(object):
    def process(self,ip,port):
        self.run(ip,port)
    def run(self,ip,port):
        r=requests.post('http://'+ str(ip) + ':' + str(port) + path,headers=headers,data=payload,timeout=3)
        #print(r.status_code)
        if(r.status_code==200) and re.search('.*220 smtp-relay.gmail.com.*', r.text):
            logging.info('[+]The target weblogic has a SSRF vulnerability:{}'.format(VUL))
            print(Color.OKBLUE+'[+]The target weblogic has a SSRF vulnerability:{}'.format(VUL)+Color.ENDC)
            print(Color.OKGREEN+'[+]CVE-2020-2766 漏洞存在'+Color.ENDC)
        else:
            logging.info('[-]Target weblogic not detected {}'.format(VUL))
            print(Color.FAIL+'[-]Target weblogic not detected {}'.format(VUL)+Color.ENDC)
