Cyask system background Getshell vulnerability prevention

Source: Internet
Author: User

Cyask writes the parameter settings to the cache. When writing the cache, it extracts unfiltered data from the database and writes the data directly to the file. As a result, webshell can be used.

Analysis:
Admin/setting_manage.php file: <? Php admin_footer (); exit ();} elseif ($ admin_action = setting_edit) {if (isset ($ _ POST [edit_submit]) {$ query = $ dblink-> query ("SELECT * FROM {$ tablepre} set where t in (str, num )"); while ($ row = $ dblink-> fetch_array ($ query) {$ dblink-> query ("UPDATE {$ tablepre} set set v = ". $ _ POST [$ row [K]. "where k = ". $ row [K]. ""); // write the settings to the database, not filtered by unknownman} create_cache (variable); // write cache by unknownman header ("location: ad Min. php? Admin_action = var_setting ");} else {$ query = $ dblink-> query (" SELECT * FROM {$ tablepre} set where t in (str, num) order by T "); admin_header ();?> The create_cache function is located in include/global. func. php: function create_cache ($ cachename) {global $ dblink, $ tablepre; $ prefix = cache _; $ cachedata =; if ($ cachename = variable) {$ query = $ dblink-> query ("SELECT * FROM {$ tablepre} set where t in (str, num )"); // retrieve the settings from the database by unknownman $ cachedata. = ""; while ($ row = $ dblink-> fetch_array ($ query) {if ($ row [T] = str) {$ cachedata. = "$ ". $ row [K]. "= ". $ row [V]. ";"; // the string is not filtered by un Knownman} elseif ($ row [T] = num) {$ cachedata. = "$ ". $ row [K]. "= ". intval ($ row [V]). ";"; // simple numeric parameter filtering by unknownman }}elseif ($ cachename = style) {$ query = $ dblink-> query ("SELECT templateid, name, tpldir, styledir FROM {$ tablepre} tpl order by templateid "); $ num = $ dblink-> num_rows ($ query); $ cachedata. = "$ _ DCACHE [style] = array (". ""; $ I = 1; while ($ row = $ dblink-> fetch_array ($ query) {$ cachedata. = $ row [templa Teid]. "=> array (". ""; foreach ($ row as $ key => $ val) {// $ val = addslashes ($ val); if ($ key = styledir) $ cachedata. = "$ key => $ val ". ""; else $ cachedata. = "$ key => $ val ,". "";} if ($ I = $ num) $ cachedata. = ")"; else $ cachedata. = "),"; $ I ++;} $ cachedata. = ");" ;}else {exit (cachename error !);} $ Dir = CYASK_ROOT ../askdata/cache/; if (! Is_dir ($ dir) {@ mkdir ($ dir, 0777);} if (@ $ fp = fopen ("$ dir $ prefix $ cachename. php ", w) // write the php file by unknownman {fwrite ($ fp," <? Php // Cyask cache file // Created on ". date (" Y-m-d H: I: s ")." $ cachedata?> "); // The php file itself is not set securely. Anyone Can access by unknownman fclose ($ fp);} else {exit (Can not write to cache files, please check directory. /askdata/and. /askdata/cache /.);}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.