PageRenderTime 105ms CodeModel.GetById 17ms RepoModel.GetById 0ms app.codeStats 0ms

/includes/ctracker/engines/ct_security.php

http://github.com/MightyGorgon/icy_phoenix
PHP | 523 lines | 387 code | 40 blank | 96 comment | 29 complexity | 21dd28909f18c74c0595a4dd0562b062 MD5 | raw file
Possible License(s): AGPL-1.0
  1. <?php
  2. /**
  3. *
  4. * @package Icy Phoenix
  5. * @version $Id$
  6. * @copyright (c) 2008 Icy Phoenix
  7. * @license http://opensource.org/licenses/gpl-license.php GNU Public License
  8. *
  9. */
  10. /**
  11. *
  12. * @Extra credits for this file
  13. * Christian Knerr (cback) - (www.cback.de)
  14. *
  15. */
  16. /**
  17. * <b>CrackerTracker File: ct_security.php</b><br /><br />
  18. *
  19. * This file is responsible for the worm protection Unit of the CrackerTracker
  20. * Security System. The File includes a definition Array wich is used to
  21. * heuristically scan URL requests for attacks.
  22. *
  23. * We included some virtual Troopers for you. ;-)
  24. *
  25. * @author Christian Knerr (cback) and Tekin Birdüzen (cYbercOsmOnauT)
  26. * @package ctracker
  27. * @version 5.0.6
  28. * @since 15.07.2006 - 21:36:24
  29. * @copyright (c) 2006 www.cback.de
  30. *
  31. */
  32. if(!defined('IN_ICYPHOENIX'))
  33. {
  34. die('Hacking attempt!');
  35. }
  36. $disable_ct_warning = false;
  37. if(defined('CTRACKER_DISABLE_OUTPUT'))
  38. {
  39. $disable_ct_warning = true;
  40. }
  41. /*
  42. * Change the following to define('CT_DEBUG_MODE', true);
  43. * if you want to activate the debug mode of CrackerTracker
  44. * but don't forget to deactivate it again as soon as possible
  45. */
  46. define('CT_DEBUG_MODE', false);
  47. //define('CT_DEBUG_MODE', true);
  48. /*
  49. * DO NOT CHANGE ANYTHING BELOW!
  50. * CHANGING STUFF BELOW CAN DRAMATICALLY DECREASE
  51. * THE SECURITY OF YOUR BOARD SO PLEASE
  52. * DO NOT CHANGE ANYTHING BELOW THIS LINE!
  53. */
  54. /*
  55. /*
  56. * The first thing we do now is checking the integrity of the IP_ROOT_PATH
  57. * because CrackerTracker will need it later. With this step we prevent that
  58. * scripts without the IP_ROOT_PATH or without a validated IP_ROOT_PATH
  59. * can be executed.
  60. */
  61. if (!defined('IP_ROOT_PATH'))
  62. {
  63. /*
  64. * Create a HTML error Message output
  65. */
  66. $htmloutput = <<<EOM
  67. <html>
  68. <head><title>CBACK CrackerTracker :: Security Alert</title></head>
  69. <body>
  70. <br />
  71. <div align="center">
  72. <table style="border:2px solid #000000" border="0" width="600" cellpadding="10" cellspacing="0">
  73. <tr>
  74. <td align="left" bgcolor="#000000"><font face="Tahoma, Arial, Helvetica" size="4" color="#ffffff"><b>SECURITY ALERT &raquo; &raquo; &raquo; &raquo;</b></font></td>
  75. </tr>
  76. <tr>
  77. <td bgcolor="#fff4bf" align="left">
  78. <font face="Tahoma, Arial, Helvetica" size="2" color="#000000">
  79. CBACK CrackerTracker stopped your script because the engine detected
  80. that the script you want to execute has not initialized the constant
  81. <b>IP_ROOT_PATH</b> correctly.
  82. <br /><br />
  83. This could be a potential security risk for this board.
  84. <br /><br />
  85. If you are not the admin of this Board please contact him and tell him from
  86. this warning message and what you have done that he has the possibility to
  87. fix that problem.
  88. </font>
  89. </td>
  90. </tr>
  91. </table>
  92. </div>
  93. </body>
  94. </html>
  95. EOM;
  96. // Lets stop the script
  97. die($htmloutput);
  98. }
  99. /*
  100. * Now we define an array where all definition data is saved in.
  101. * After that we check URL committals for potential worm acitivities
  102. */
  103. $ct_rules = array(
  104. 'http_', '_server', 'delete%20', 'delete ', 'delete-', 'delete(', '(delete', 'drop%20',
  105. 'drop ', 'create%20', 'update-', 'update(', '(update', 'insert-', 'insert(', '(insert',
  106. 'create ', 'create(', 'create-', '(create', 'update%20', 'update ', 'insert%20', 'insert ',
  107. 'select%20', 'select ', 'bulk%20', 'bulk ', 'union%20', 'union ', 'select-', 'select(',
  108. '(select', 'union-', '(union', 'union(',
  109. 'or%20', 'or ', 'and%20', 'and ', 'exec', '@@', '%22', '"', 'openquery',
  110. 'openrowset', 'msdasql', 'sqloledb', 'sysobjects', 'syscolums',
  111. 'syslogins', 'sysxlogins', 'char%20', 'char ', 'into%20', 'into ',
  112. 'load%20', 'load ', 'msys', 'alert%20', 'alert ', 'eval%20', 'eval ',
  113. 'onkeyup', 'x5cx', 'fromcharcode', 'javascript:', 'javascript.', 'vbscript:',
  114. 'vbscript.', 'http-equiv', '->', 'expression%20', 'expression ',
  115. 'url%20', 'url ', 'innerhtml', 'document.', 'dynsrc', 'jsessionid',
  116. 'style%20', 'style ', 'phpsessid', '<applet', '<div', '<emded', '<iframe', '<img',
  117. '<meta', '<object', '<script', '<textarea', 'onabort', 'onblur',
  118. 'onchange', 'onclick', 'ondblclick', 'ondragdrop', 'onerror',
  119. 'onfocus', 'onkeydown', 'onkeypress', 'onload', 'onmouse',
  120. 'onmove', 'onreset', 'onresize', 'onselect', 'onsubmit',
  121. 'onunload', 'onreadystatechange', 'xmlhttp', 'uname%20', 'uname ',
  122. '%2C', 'union+', 'select+', 'delete+', 'create+', 'bulk+', 'or+', 'and+',
  123. 'into+', 'kill+', '+echr', '+chr', 'cmd+', '+1', 'user_password',
  124. 'id%20', 'id ', 'ls%20', 'ls ', 'cat%20', 'cat ', 'rm%20', 'rm ',
  125. 'kill%20', 'kill ', 'mail%20', 'mail ', 'wget%20', 'wget ', 'wget(',
  126. 'pwd%20', 'pwd ', 'objectclass', 'objectcategory', '<!-%20', '<!- ',
  127. 'total%20', 'total ', 'http%20request', 'http request', 'phpb8b4f2a0',
  128. 'phpinfo', 'php:', 'globals', '%2527', '%27', '\'', 'chr(',
  129. 'chr=', 'chr%20', 'chr ', '%20chr', ' chr', 'cmd=', 'cmd%20', 'cmd',
  130. '%20cmd', ' cmd', 'rush=', '%20rush', ' rush', 'rush%20', 'rush ',
  131. 'union%20', 'union ', '%20union', ' union', 'union(', 'union=',
  132. '%20echr', ' echr', 'esystem', 'cp%20', 'cp ', 'cp(', '%20cp', ' cp',
  133. 'mdir%20', 'mdir ', '%20mdir', ' mdir', 'mdir(', 'mcd%20', 'mcd ',
  134. 'mrd%20', 'mrd ', 'rm%20', 'rm ', '%20mcd', ' mcd', '%20mrd', ' mrd',
  135. '%20rm', ' rm', 'mcd(', 'mrd(', 'rm(', 'mcd=', 'mrd=', 'mv%20', 'mv ',
  136. 'rmdir%20', 'rmdir ', 'mv(', 'rmdir(', 'chmod(', 'chmod%20', 'chmod ',
  137. 'cc%20', 'cc ', '%20chmod', ' chmod', 'chmod(', 'chmod=', 'chown%20', 'chown ',
  138. 'chgrp%20', 'chgrp ', 'chown(', 'chgrp(', 'locate%20', 'locate ', 'grep%20', 'grep ',
  139. 'locate(', 'grep(', 'diff%20', 'diff ', 'kill%20', 'kill ', 'kill(', 'killall',
  140. 'passwd%20', 'passwd ', '%20passwd', ' passwd', 'passwd(', 'telnet%20', 'telnet ',
  141. 'vi(', 'vi%20', 'vi ', 'nigga(', '%20nigga', ' nigga', 'nigga%20', 'nigga ',
  142. 'fopen', 'fwrite', '%20like', ' like', 'like%20', 'like ', '$_',
  143. '$get', '.system', 'http_php', '%20getenv', ' getenv', 'getenv%20', 'getenv ',
  144. 'new_password', '/password', 'etc/', '/groups', '/gshadow',
  145. 'http_user_agent', 'http_host', 'bin/', 'wget%20', 'wget ', 'uname%5c',
  146. 'uname', 'usr', '/chgrp', '=chown', 'usr/bin', 'g%5c',
  147. 'g\\', 'bin/python', 'bin/tclsh', 'bin/nasm', 'perl%20', 'perl ', '.pl',
  148. 'traceroute%20', 'traceroute ', 'tracert%20', 'tracert ', 'ping%20', 'ping ',
  149. '/usr/x11r6/bin/xterm', 'lsof%20', 'lsof ', '/mail', '.conf', 'motd%20', 'motd ',
  150. 'http/1.', '.inc.php', 'config.php', 'cgi-', '.eml', 'file%5c://',
  151. 'file\:', 'file://', 'window.open', 'img src', 'img%20src', 'img src',
  152. '.jsp', 'ftp.', 'xp_enumdsn', 'xp_availablemedia',
  153. 'xp_filelist', 'nc.exe', '.htpasswd', 'servlet', '/etc/passwd', '/etc/shadow',
  154. 'wwwacl', '~root', '~ftp', '.js', '.jsp', '.history',
  155. 'bash_history', '~nobody', 'server-info', 'server-status',
  156. '%20reboot', ' reboot', '%20halt', ' halt', '%20powerdown', ' powerdown',
  157. '/home/ftp', '=reboot', 'www/', 'init%20', 'init ','=halt', '=powerdown',
  158. 'ereg(', 'secure_site', 'chunked', 'org.apache', '/servlet/con',
  159. '/robot', 'mod_gzip_status', '.inc', '.system', 'getenv',
  160. 'http_', '_php', 'php_', 'phpinfo()', '<?php', '?>', '%3C%3Fphp',
  161. '%3F>', 'sql=', '_global', 'global_', 'global[', '_server',
  162. 'server_', 'server[', '/modules', 'modules/', 'phpadmin',
  163. 'root_path', '_globals', 'globals_', 'globals[', 'iso-8859-1',
  164. '?hl=', '%3fhl=', '.exe', '.sh', '%00', rawurldecode('%00'), '_env', '/*', '\\*'
  165. );
  166. // Some fields in $_POST don't get checked to prevent wrong detection
  167. $unchecked_post_fields = array(
  168. 'username', 'password', 'subject', 'message',
  169. 'poll_title', 'poll_option', 'poll_delete',
  170. 'email', 'confirm_code', 'aim', 'msn', 'yim',
  171. 'interests', 'occupation', 'signature', 'website',
  172. 'location', 'search', 'sitename', 'word',
  173. 'replacement', 'help', 'last_msg', 'quote', 'dl',
  174. 'preview', 'post', 'mode', 'content', 'server_name',
  175. 'script_path', 'sitename', 'site_desc', 'disable_reg_msg',
  176. 'disable_msg', 'cookie', 'avatar', 'file', 'picture',
  177. 'filter', 'xs', 'edit', 'content', 'fileupload', 'filecomment',
  178. 'comment', 'rate', 'pic', 'search_author', 'add_poll_option_text',
  179. 'long_desc', 'submit',
  180. // Added by MG
  181. 'f', 't', 'p', 'u', 's', 'l',
  182. 'skype', 'selfdes', 'gender', 'user_flag', 'phone', 'topic_desc',
  183. 'title', 'position', 'active', 'type', 'cache', 'cachetime',
  184. 'blockfile', 'view', 'border', 'titlebar', 'local', 'background',
  185. 'edit', 'lid', 'id', 'save', 'post_time', 'usersubmit', 'notes',
  186. 'topictype', 'news_category', 'smiles_button', 'topic_show_portal',
  187. 'disable_html', 'disable_acro_auto', 'disable_bbcode', 'disable_smilies',
  188. 'attach_sig', 'setbm', 'notify', 'mark_edit', 'delete', 'lock', 'unlock',
  189. 'topic_calendar_hour', 'topic_calendar_min', 'topic_calendar_duration_day',
  190. 'topic_calendar_duration_hour', 'topic_calendar_duration_min', 'add_attachment_box',
  191. 'posted_attachments_box', 'attachment_list', 'filename_list', 'extension_list',
  192. 'mimetype_list', 'filesize_list', 'filetime_list', 'attach_id_list',
  193. 'attach_thumbnail_list', 'comment_list', 'lock_subject', 'helpbox', 'link_desc',
  194. 'addcategory', 'chatbarText', 'name', 'act', 'nm', 'co', 'sh', 'su', 'search_keywords',
  195. 'submitavatar', 'del_attachment', 'update_attachment', 'edit_comment',
  196. 'add_poll_option', 'edit_poll_option', 'del_poll_option', 'poll_option_text',
  197. 'pic_title', 'pic_desc', 'article_desc', 'email_confirm', 'article_name', 'article_desc',
  198. 'menu_name', 'menu_desc', 'menu_name_lang', 'remove', 'add', 'add_cat', 'add_item',
  199. 'autologin', 'current_email', 'download', 'menu_link', 'new_password', 'password_confirm',
  200. 'deleteall', 'cat_title', 'cat_desc', 'news_category_edit', 'pm_delete_attach',
  201. 'topic_title', 'topic_id', 'friendname', 'friendemail', 'drafts_list', 'agreed',
  202. // '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '', '',
  203. );
  204. // Some fields in $_GET don't get checked to prevent wrong detection
  205. $unchecked_get_fields = array(
  206. 'submit', 'search_author',
  207. // Added by MG
  208. 'mode', 'cachefile', 'avatarfile',
  209. 'text_content', 'text_size', 'text_font', 'text_color', 'text_position',
  210. 'topic_title',
  211. );
  212. /*
  213. * Let's check if a security level is set
  214. * and prepare our variables
  215. */
  216. if (!defined('CT_SECLEVEL') || (CT_SECLEVEL == 'HIGH'))
  217. {
  218. // Empty the variables for security reasons
  219. $ct_addheuristic = $ct_delheuristic = array();
  220. $ct_ignoregvar = $ct_ignorepvar = array();
  221. $ct_regex_ignorep = $ct_regex_ignoreg = array();
  222. }
  223. elseif ((CT_SECLEVEL == 'MEDIUM') || (CT_SECLEVEL == 'LOW'))
  224. {
  225. // Delete all duplicate heuristics and then merge with the standard rules
  226. $ct_addheuristic = array_diff((array) $ct_addheuristic, $ct_rules);
  227. $ct_rules = array_merge($ct_rules, $ct_addheuristic);
  228. // Now let's check if there are heuristics we want to ignore for this time
  229. $ct_rules = array_diff($ct_rules, (array) $ct_delheuristic);
  230. // Maybe also some new $_POST fields to ignore?
  231. $ct_ignorepvar = array_diff((array) $ct_ignorepvar, $unchecked_post_fields);
  232. $unchecked_post_fields = array_merge($unchecked_post_fields, $ct_ignorepvar);
  233. // Last but not least the same with $_GET
  234. $ct_ignoregvar = array_diff((array) $ct_ignoregvar, $unchecked_get_fields);
  235. $unchecked_get_fields = array_merge($unchecked_get_fields, $ct_ignoregvar);
  236. // Oh look, a new regex ignore method for smart admins and mod coders
  237. if (isset($ct_regex_ignorep))
  238. {
  239. $ct_regex_ignorep = implode('|', $ct_regex_ignorep);
  240. }
  241. if (isset($ct_regex_ignoreg))
  242. {
  243. $ct_regex_ignoreg = implode('|', $ct_regex_ignoreg);
  244. }
  245. }
  246. // Initialize detector var
  247. $ct_attack_detection = false;
  248. // Write query String in the var $cracktrack and make it lowercase
  249. $cracktrack = strtolower($_SERVER['QUERY_STRING']);
  250. // Filter out the unchecked fields
  251. $unchecked_get_fields = implode('|', $unchecked_get_fields);
  252. $cracktrack = preg_replace('#((' . $unchecked_get_fields . ')=([^&]|&amp;)*)#', '', $cracktrack);
  253. // Prevent Slash Tricks (SQL Tricks with /* are now stopped directly! So we don't replace this now!)
  254. $cracktrack = str_replace('\\', '/', $cracktrack);
  255. // Save copies for the debug mode check
  256. $crackcheck = $cracktrack;
  257. // Now we do a very simple method to mark potential Worm activities
  258. $checkworm = str_replace($ct_rules, '*', $cracktrack);
  259. if ($cracktrack != $checkworm)
  260. {
  261. $ct_attack_detection = true;
  262. ct_debugger($crackcheck, 'GET');
  263. }
  264. else
  265. {
  266. // We also check for rawurldecode-tricks
  267. $checkworm = str_replace($ct_rules, '*', strtolower(rawurldecode($cracktrack)));
  268. if (strtolower(rawurldecode($cracktrack)) != $checkworm)
  269. {
  270. $ct_attack_detection = true;
  271. ct_debugger($crackcheck, 'RAWGET');
  272. }
  273. elseif (CT_SECLEVEL != 'LOW' || !defined('CT_SECLEVEL'))
  274. {
  275. // We create a copy of the $_POST for checking
  276. $checkpost = (is_array($_POST)) ? $_POST : array();
  277. // Now we have a look to $_POST
  278. foreach ($checkpost as $post_var_fieldname => $post_var_field_value)
  279. {
  280. if (!in_array($post_var_fieldname, $unchecked_post_fields))
  281. {
  282. // We do a preg_replace if a smart admin used the regex ignore
  283. $post_var_check = (isset($ct_regex_ignorep)) ? preg_replace("#^($ct_regex_ignorep)$#", '*', $post_var_fieldname) : $post_var_fieldname;
  284. if ($post_var_check == $post_var_fieldname)
  285. {
  286. if (is_array($post_var_field_value))
  287. {
  288. // We proudly present AT-AT our new imperial array walker
  289. $post_var_field_value = atatwalk($post_var_field_value);
  290. }
  291. // Prevent tricks wich comment out SQL command
  292. $post_var_field_value = strtolower(str_replace('\\', '/', $post_var_field_value));
  293. // Now we do a very simple method to mark potential Worm activities
  294. $check_var = str_replace($ct_rules, '*', strtolower($post_var_field_value));
  295. if ($post_var_field_value != $check_var)
  296. {
  297. ct_debugger($checkpost, 'POST');
  298. $ct_attack_detection = true;
  299. // Attack found so we can leave the foreach loop
  300. break;
  301. }
  302. else
  303. {
  304. // We again check for rawurldecode tricks
  305. $check_var = str_replace($ct_rules, '*', strtolower(rawurldecode($post_var_field_value)));
  306. if (strtolower(rawurldecode($post_var_field_value)) != $check_var)
  307. {
  308. ct_debugger($checkpost, 'RAWPOST');
  309. $ct_attack_detection = true;
  310. // Attack found so we can leave the foreach loop
  311. break;
  312. }
  313. }
  314. }
  315. }
  316. }
  317. }
  318. }
  319. if ($ct_attack_detection)
  320. {
  321. if (CT_DEBUG_MODE !== true)
  322. {
  323. // include class for Logfile Management
  324. include_once(IP_ROOT_PATH . 'includes/ctracker/classes/class_log_manager.' . PHP_EXT);
  325. // write data into logfile
  326. $logfile = new log_manager();
  327. $logfile->write_worm();
  328. unset($logfile);
  329. }
  330. if ($disable_ct_warning == false)
  331. {
  332. // generate HTML Message
  333. $htmloutput = <<<EOM
  334. <html>
  335. <head><title>CBACK CrackerTracker :: Security Alert</title></head>
  336. <body>
  337. <br />
  338. <div align="center">
  339. <table style="border:2px solid #000000" border="0" width="600" cellpadding="10" cellspacing="0">
  340. <tr>
  341. <td align="left" bgcolor="#000000"><font face="Tahoma, Arial, Helvetica" size="4" color="#FFFFFF"><b>SECURITY ALERT&nbsp;&raquo;&nbsp;&raquo;&nbsp;&raquo;&nbsp;&raquo;</b></font></td>
  342. </tr>
  343. <tr>
  344. <td bgcolor="#FFDFDF" align="left">
  345. <font face="Tahoma, Arial, Helvetica" size="2" color="#000000">
  346. <b>CBACK CrackerTracker</b> has detected a potential attack on this site with a worm
  347. or exploit script so the Security System stopped the script.
  348. <br /><br /><br />
  349. If you can see this page after including a new MOD into your board or after clicking
  350. on a link please contact the Board Administrator with this error message and a description
  351. what you have done before you could see this page, that the Admin has the possibility to
  352. fix the problem.
  353. </font>
  354. </td>
  355. </tr>
  356. </table>
  357. </div>
  358. </body>
  359. </html>
  360. EOM;
  361. // stop the script
  362. die($htmloutput);
  363. }
  364. }
  365. // Tell the self test that this script was included correctly
  366. define('protection_unit_one', true);
  367. // Unfortunately we cannot unset $ct_rules because they are used in other files
  368. //unset($ct_rules);
  369. unset($unchecked_post_fields);
  370. unset($unchecked_get_fields);
  371. function ct_debugger($checkstring, $checkmode)
  372. {
  373. if (CT_DEBUG_MODE === false)
  374. {
  375. return;
  376. }
  377. global $ct_rules, $unchecked_post_fields;
  378. $dbgunchecked_post_fields = implode('|', $unchecked_post_fields);
  379. if (in_array($checkmode, array('POST', 'RAWPOST')))
  380. {
  381. $temp = '&';
  382. foreach($checkstring as $key=>$val)
  383. {
  384. $val = (is_array($val)) ? atatwalk($val) : $val;
  385. $temp .= "$key=$val&";
  386. }
  387. $checkstring = $temp;
  388. // Cut out the keys we already ignore
  389. $checkstring = preg_replace('#((' . $dbgunchecked_post_fields . ')=([^&]|&amp;)*)#', '', $checkstring);
  390. }
  391. if (in_array($checkmode, array('RAWGET', 'RAWPOST')))
  392. {
  393. $checkstring = rawurldecode($checkstring);
  394. }
  395. // Now we start debugging
  396. $matching_vars = array();
  397. $found_matches = '';
  398. foreach($ct_rules as $rule)
  399. {
  400. $preg_rule = preg_quote($rule, "#");
  401. if (preg_match_all('#(^|&)([^&]*?)=[^&]*?' . $preg_rule . '[^&]*($|&)#is', $checkstring, $dbgmatch, PREG_PATTERN_ORDER))
  402. {
  403. $found_matches .= "Matching rule: $rule\n";
  404. foreach($dbgmatch[2] as $matchline)
  405. {
  406. $found_matches .= "In variable: $matchline\n";
  407. $matching_vars[] = $matchline;
  408. }
  409. $found_matches .= "\n";
  410. }
  411. }
  412. $matching_vars = array_unique($matching_vars);
  413. $matching_vars = implode("','", $matching_vars);
  414. $matching_vars = "'" . $matching_vars . "'";
  415. if (sizeof($matching_vars))
  416. {
  417. // let's open the debug file and write in some stuff ;)
  418. $debugstream = @fopen(IP_ROOT_PATH . 'ctracker/logfiles/logfile_debug_mode.txt', 'ab');
  419. $scriptname = str_replace($_SERVER['DOCUMENT_ROOT'], '', $_SERVER['SCRIPT_FILENAME']);
  420. $scriptname = ((substr($scriptname, 0, 1) == '/') ? '' : '/') . $scriptname;
  421. $scriptname = str_replace('//', '/', $scriptname);
  422. @fwrite($debugstream, "++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++\n");
  423. @fwrite($debugstream, 'Script-Filename: ' . $scriptname . "\n----------------\n\n");
  424. @fwrite($debugstream, 'Attack-Time: ' . gmdate('d.m.Y G:i a') . "\n------------\n\n");
  425. @fwrite($debugstream, 'Request-Method: ' . (strpos($checkmode, 'POST') !== false ? 'POST' : 'GET') . "\n\n");
  426. @fwrite($debugstream, $found_matches);
  427. @fwrite($debugstream, 'Possible solution:' . "\n------------------\n\n");
  428. modcommand($debugstream, 'OPEN');
  429. @fwrite($debugstream, "$scriptname\n\n");
  430. modcommand($debugstream, 'FIND');
  431. if (preg_match('#^/admin/(admin_|index\.php)#', $scriptname))
  432. {
  433. @fwrite($debugstream, "require('pagestart.' . " . PHP_EXT . ");\n\n");
  434. }
  435. else
  436. {
  437. @fwrite($debugstream, "include(IP_ROOT_PATH . 'common.' . " . PHP_EXT . ");\n\n");
  438. }
  439. modcommand($debugstream, 'BEFORE, ADD');
  440. @fwrite($debugstream, "define('CT_SECLEVEL', 'MEDIUM');\n");
  441. if (strpos($checkmode, 'POST') !== false)
  442. {
  443. @fwrite($debugstream, "\$ct_ignorepvar = array($matching_vars);\n\n");
  444. }
  445. else
  446. {
  447. @fwrite($debugstream, "\$ct_ignoregvar = array($matching_vars);\n\n");
  448. }
  449. modcommand($debugstream, 'SAVE/CLOSE ALL FILES');
  450. @fwrite($debugstream, "# EoM\n\n");
  451. @fclose($debugstream);
  452. }
  453. }
  454. function modcommand($handle, $command)
  455. {
  456. @fwrite($handle,"#\n");
  457. @fwrite($handle,"#-----[ " . strtoupper($command) . " ]------------------------------------------\n");
  458. @fwrite($handle,"#\n");
  459. }
  460. // Function to walk through arrays
  461. // and find those nasty rebell value hideouts
  462. function atatwalk($var_array)
  463. {
  464. $complete_post = '';
  465. foreach($var_array as $var=>$key)
  466. {
  467. if (!is_array($key))
  468. {
  469. // If we don't need to dive deeper anymore
  470. // we can use php functions to fastly paste all values together
  471. return implode('!', $var_array);
  472. }
  473. // Deeper into the dungeon my dear
  474. $complete_post .= atatwalk($key) . '!';
  475. }
  476. return $complete_post;
  477. }
  478. ?>