PluginProbe ʕ •ᴥ•ʔ
Anti-Malware Security and Brute-Force Firewall / 4.21.89
Anti-Malware Security and Brute-Force Firewall v4.21.89
4.23.90 trunk 1.2.03.23 1.3.02.15 3.07.06 4.14.47 4.15.16 4.16.17 4.17.28 4.17.29 4.17.44 4.17.57 4.17.58 4.17.68 4.17.69 4.18.52 4.18.62 4.18.63 4.18.69 4.18.71 4.18.74 4.18.76 4.19.44 4.19.50 4.19.68 4.19.69 4.20.59 4.20.72 4.20.92 4.20.93 4.20.94 4.20.95 4.20.96 4.21.74 4.21.83 4.21.84 4.21.85 4.21.86 4.21.87 4.21.88 4.21.89 4.21.90 4.21.91 4.21.92 4.21.93 4.21.94 4.21.95 4.21.96 4.23.56 4.23.57 4.23.67 4.23.68 4.23.69 4.23.71 4.23.73 4.23.77 4.23.81 4.23.83 4.23.85 4.23.87 4.23.88 4.23.89
gotmls / images / index.php
gotmls / images Last commit date
.htaccess 11 years ago ELI-16x16.gif 14 years ago GOTMLS-16x16.gif 12 years ago blocked.gif 14 years ago btn_donateCC_WIDE.gif 13 years ago checked.gif 14 years ago index.php 3 years ago question.gif 13 years ago threat.gif 13 years ago wait.gif 14 years ago
index.php
2050 lines
1 <?php
2 /**
3 * GOTMLS Plugin Global Variables and Functions
4 * @package GOTMLS
5 */
6
7 function GOTMLS_define($DEF, $val) {
8 if (!defined($DEF))
9 define($DEF, $val);
10 }
11
12 $file = basename(__FILE__);
13 GOTMLS_define("GOTMLS_local_images_path", substr(__FILE__, 0, strlen(__FILE__) - strlen($file)));
14 GOTMLS_define("GOTMLS_plugin_path", substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen(basename(dirname(__FILE__)))));
15 GOTMLS_define("GOTMLS_Version", '4.21.89');
16 GOTMLS_define("GOTMLS_require_version", "3.3");
17
18 if (!function_exists("__")) {
19 function __($text, $domain = "gotmls") {
20 return $text;
21 }}
22
23 GOTMLS_define("GOTMLS_Failed_to_list_LANGUAGE", __("Failed to list files in directory!",'gotmls'));
24 GOTMLS_define("GOTMLS_Run_Quick_Scan_LANGUAGE", __("Quick Scan",'gotmls'));
25 GOTMLS_define("GOTMLS_View_Quarantine_LANGUAGE", __("View Quarantine",'gotmls'));
26 GOTMLS_define("GOTMLS_View_Scan_Log_LANGUAGE", __("View Scan History",'gotmls'));
27 GOTMLS_define("GOTMLS_require_version_LANGUAGE", sprintf(__("This Plugin requires WordPress version %s or higher",'gotmls'), GOTMLS_require_version));
28 GOTMLS_define("GOTMLS_Scan_Settings_LANGUAGE", __("Scan Settings",'gotmls'));
29 GOTMLS_define("GOTMLS_Loading_LANGUAGE", __("Loading, Please Wait ...",'gotmls'));
30 GOTMLS_define("GOTMLS_Automatically_Fix_LANGUAGE", __("Automatically Fix SELECTED Files Now",'gotmls'));
31
32 function GOTMLS_get_version($which = "") {
33 global $wp_version, $cp_version;
34 if (function_exists('classicpress_version'))
35 $match = array("GOTMLS_wp_version", "c", classicpress_version());
36 elseif (isset($cp_version) && ($cp_version))
37 $match = array("GOTMLS_wp_version", "c", $cp_version);
38 elseif (isset($wp_version) && ($wp_version))
39 $match = array("GOTMLS_wp_version", "w", "$wp_version");
40 elseif (!(is_file($file = ABSPATH."wp-includes/version.php") && ($contents = @file_get_contents($file)) && preg_match('/\n\$(c|w)p_version\s*=\s*[\'"]([0-9\.]+)/i', $contents, $match)))
41 $match = array("GOTMLS_wp_version", "w", "Unknown");
42 GOTMLS_define("GOTMLS_wp_version", $match[2]);
43 if ($which == "URL")
44 return 'ver='.GOTMLS_Version.'&'.$match[1].'p='.GOTMLS_wp_version;
45 else
46 return GOTMLS_wp_version;
47 }
48
49 function GOTMLS_load_contents($TXT, $default_encoding = "UTF-8") {
50 if (!(function_exists("mb_detect_encoding") && ($encoding = mb_detect_encoding($TXT, ['UTF-8', 'ISO-8859-1']))))
51 $encoding = $default_encoding;
52 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $TXT;
53 if (function_exists("mb_internal_encoding"))
54 mb_internal_encoding($encoding);
55 if (function_exists("mb_regex_encoding"))
56 mb_regex_encoding($encoding);
57 $GLOBALS["GOTMLS"]["tmp"]["encoding"] = $encoding;
58 return strlen(GOTMLS_convert_r($TXT));
59 }
60
61 function GOTMLS_htmlentities($TXT, $flags = ENT_COMPAT, $encoding = "ASCII") {
62 $prelen = strlen($TXT);
63 if ($prelen == 0)
64 return "";
65 if ($encoding == "ASCII")
66 $encoding = "UTF-8";
67 $encoded = htmlentities($TXT, $flags, $encoding);
68 if (strlen($encoded) == 0) {
69 $encoding = "ISO-8859-1";
70 $encoded = htmlentities($TXT, $flags, $encoding);
71 }
72 if (strlen($encoded) == 0)
73 $encoded = __("Failed to encode HTML entities!",'gotmls');
74 return $encoded;
75 }
76
77 function GOTMLS_htmlspecialchars($TXT, $flags = ENT_COMPAT, $encoding = "ASCII") {
78 $prelen = strlen($TXT);
79 if ($prelen == 0)
80 return "";
81 if ($encoding == "ASCII")
82 $encoding = "UTF-8";
83 $encoded = htmlspecialchars($TXT, $flags, $encoding);
84 if (strlen($encoded) == 0) {
85 $encoding = "ISO-8859-1";
86 $encoded = htmlspecialchars($TXT, $flags, $encoding);
87 }
88 if (strlen($encoded) == 0)
89 $encoded = __("Failed to encode HTML characters!",'gotmls');
90 return $encoded;
91 }
92
93 function GOTMLS_convert_r($r_str) {
94 if (function_exists("mb_ereg_replace"))
95 return mb_ereg_replace("\r", "", $r_str);
96 else
97 return preg_replace('/\r/', "", $r_str);
98 }
99
100 function GOTMLS_error_div($error_str, $class = "error") {
101 return GOTMLS_html_tags(array('div' => $error_str, array('div' => "class=\"$class\"")));
102 }
103
104 function GOTMLS_uckserialize($unsafe_serialized) {
105 if (!(is_array($unsafe_serialized)) && (is_array($safe_unserialized = @unserialize(preg_replace('/[oc]:\d+:".*?":(\d+):\{/is', 'a:\1:{', $unsafe_serialized)))))
106 return $safe_unserialized;
107 return $unsafe_serialized;
108 }
109
110 if (!defined("ABSPATH")) {
111 define("ABSPATH", dirname(dirname(__FILE__)).'/safe-load/');
112 $root_path = dirname(ABSPATH);
113 while (strlen($root_path) > 1 && !is_file($root_path."/wp-config.php"))
114 $root_path = dirname($root_path);
115 if (is_file($root_path."/wp-config.php"))
116 include_once($root_path."/wp-config.php");
117 else
118 die("No wp-config!");
119 }
120
121 $bad = array("eval", "preg_replace", "auth_pass");
122 $GLOBALS["GOTMLS"] = array(
123 "MT" => microtime(true),
124 "tmp"=>array("HeadersError"=>"", "onLoad"=>"", "file_contents"=>"", "new_contents"=>"", "threats_found"=>array(),
125 "base_page" => "GOTMLS-settings",
126 "pluginTitle" => "Anti-Malware",
127 "skip_dirs" => array(".", ".."), "scanfiles" => array(), "nonce"=>array(),
128 "mt" => ((isset($_REQUEST["mt"])&&is_numeric($_REQUEST["mt"]))?$_REQUEST["mt"]:microtime(true)),
129 "threat_files" => array("htaccess"=>".htaccess","timthumb"=>"thumb.php"),
130 "threat_levels" => array(__("Database Injections",'gotmls')=>"db_scan",__("htaccess Threats",'gotmls')=>"htaccess",__("TimThumb Exploits",'gotmls')=>"timthumb",__("Known Threats",'gotmls')=>"known",__("Core File Changes",'gotmls')=>"wp_core",__("Potential Threats",'gotmls')=>"potential"),
131 "apache" => array(),
132 "skip_ext"=>array("png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff", "psd", "svg", "webp", "doc", "docx", "ttf", "fla", "flv", "mov", "mp3", "pdf", "css", "pot", "po", "mo", "so", "exe", "zip", "7z", "gz", "rar"),
133 "execution_time" => 60,
134 "default" => array("msg_position" => array("80px", "40px", "400px", "600px")),
135 "Definition" => array("Default" => "CCIGG"),
136 "definitions_array" => array(
137 "potential" => array(
138 $bad[0] => array("CCIGG", "/[^a-z_\\/'\"]".$bad[0]."\\(.+\\)+\\s*;/i"),
139 $bad[1]." /e" => array("CCIGG", "/".$bad[1]."[\\s*\\(]+(['\"])([\\!\\/\\#\\|\\@\\%\\^\\*\\~]).+?\\2[imsx]*e[imsx]*\\1\\s*,[^,]+,[^\\)]+[\\);\\s]+/i"),
140 $bad[2] => array("CCIGG", "/\\\$".$bad[2]."\\s*=.+;/i"),
141 "function add_action wp_enqueue_script json2" => array("CCIGG", "/json2\\.min\\.js/i"),
142 "Tagged Code" => array("CCIGG", "/\\#(\\w+)\\#.+?\\#\\/\\1\\#/is"),
143 "protected by copyright" => array("CCIGG", "/\\/\\* This file is protected by copyright law and provided under license. Reverse engineering of this file is strictly prohibited. \\*\\//i")
144 )
145 )
146 )
147 );
148 if (isset($_SERVER["HTTP_HOST"]))
149 $SERVER_HTTP = 'HOST://'.GOTMLS_safe_domain($_SERVER["HTTP_HOST"]);
150 elseif (isset($_SERVER["SERVER_NAME"]))
151 $SERVER_HTTP = 'NAME://'.GOTMLS_safe_domain($_SERVER["SERVER_NAME"]);
152 elseif (isset($_SERVER["SERVER_ADDR"]))
153 $SERVER_HTTP = 'ADDR://'.GOTMLS_safe_ip($_SERVER["SERVER_ADDR"]);
154 else
155 $SERVER_HTTP = "NULL://not.anything.com";
156 if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"])
157 $SERVER_HTTP .= ":".GOTMLS_safe_ip($_SERVER["SERVER_PORT"]);
158 $SERVER_parts = explode(":", $SERVER_HTTP.":");
159 if ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1)) || (count($SERVER_parts) > 2 && $SERVER_parts[2] == "443"))
160 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "https:";
161 else
162 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "http:";
163 GOTMLS_define("GOTMLS_script_URI", preg_replace('/\&(last_)?mt=[0-9\.]+/i', '', str_replace('&amp;', '&', GOTMLS_htmlspecialchars($_SERVER["REQUEST_URI"], ENT_QUOTES))).'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"]);
164 GOTMLS_define("GOTMLS_plugin_home", "https://gotmls.net/");
165 if (function_exists("plugins_url"))
166 GOTMLS_define("GOTMLS_images_path", plugins_url('/', __FILE__));
167 elseif (function_exists("plugin_dir_url"))
168 GOTMLS_define("GOTMLS_images_path", plugin_dir_url(__FILE__));
169 elseif (isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && strlen($_SERVER["DOCUMENT_ROOT"]) < __FILE__ && substr(__FILE__, 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
170 GOTMLS_define("GOTMLS_images_path", substr(dirname(__FILE__), strlen($_SERVER["DOCUMENT_ROOT"])).'/');
171 elseif (isset($_SERVER["SCRIPT_FILENAME"]) && isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && strlen($_SERVER["DOCUMENT_ROOT"]) < strlen($_SERVER["SCRIPT_FILENAME"]) && substr($_SERVER["SCRIPT_FILENAME"], 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
172 GOTMLS_define("GOTMLS_images_path", substr(GOTMLS_safe_url(dirname($_SERVER["SCRIPT_FILENAME"])), strlen($_SERVER["DOCUMENT_ROOT"])).'/');
173 else
174 GOTMLS_define("GOTMLS_images_path", "/wp-content/plugins/gotmls/images/");
175
176 function GOTMLS_encode($unencoded_string) {
177 if (function_exists("base64_encode"))
178 $encoded_string = base64_encode($unencoded_string);
179 elseif (function_exists("mb_convert_encoding"))
180 $encoded_string = mb_convert_encoding($unencoded_string, "BASE64", "UTF-8");
181 else
182 $encoded_string = "Cannot encode: $unencoded_string function_exists: ";
183 $encoded_array = explode("=", $encoded_string."=");
184 return strtr($encoded_array[0], "+/0", "-_=").(count($encoded_array)-1);
185 }
186
187 function GOTMLS_decode($encoded_string) {
188 $tail = 0;
189 if (strlen($encoded_string) > 1 && is_numeric(substr($encoded_string, -1)) && substr($encoded_string, -1) > 0)
190 $tail = substr($encoded_string, -1) - 1;
191 else
192 $encoded_string .= "$tail";
193 $encoded_string = strtr(substr($encoded_string, 0, -1), "-_=", "+/0").str_repeat("=", $tail);
194 if (function_exists("base64_decode"))
195 return base64_decode($encoded_string);
196 elseif (function_exists("mb_convert_encoding"))
197 return mb_convert_encoding($encoded_string, "UTF-8", "BASE64");
198 else
199 return "Cannot decode: $encoded_string";
200 }
201
202 function GOTMLS_user_can() {
203 if (is_multisite())
204 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] = "manage_network";
205 elseif (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"]) || $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] == "manage_network")
206 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"] = "activate_plugins";
207 if (current_user_can($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["user_can"]))
208 return true;
209 else
210 return false;
211 }
212
213 function GOTMLS_update_option($index, $value = array()) {
214 return update_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($value)));
215 }
216
217 function GOTMLS_get_option($index, $value = array()) {
218 if (is_array($tmp = get_option('GOTMLS_'.$index.'_array', array())) && count($tmp)) {
219 GOTMLS_update_option($index, $tmp);
220 delete_option('GOTMLS_'.$index.'_array');
221 } else
222 $tmp = $value;
223 return GOTMLS_uckserialize(GOTMLS_decode(get_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($tmp)))));
224 }
225
226 $GOTMLS_chmod_file = (0644);
227 $GOTMLS_chmod_dir = (0755);
228 $GLOBALS["GOTMLS"]["tmp"]["nonce"] = GOTMLS_get_option('nonce', array());
229 $GLOBALS["GOTMLS"]["tmp"]["settings_array"] = get_option('GOTMLS_settings_array', array());
230 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"] = GOTMLS_get_option('definitions', $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]);
231 GOTMLS_define("GOTMLS_siteurl", get_option("siteurl", $GLOBALS["GOTMLS"]["tmp"]["protocol"].$SERVER_parts[1].((count($SERVER_parts) > 2 && ($SERVER_parts[2] == '80' || $SERVER_parts[2] == '443'))?"":":".$SERVER_parts[2])."/"));
232 $GLOBALS["GOTMLS"]["log"] = get_option('GOTMLS_scan_log/'.(isset($_SERVER["REMOTE_ADDR"])?GOTMLS_safe_ip($_SERVER["REMOTE_ADDR"]):"0.0.0.0").'/'.$GLOBALS["GOTMLS"]["tmp"]["mt"], array());
233 if (!(isset($GLOBALS["GOTMLS"]["log"]["settings"]) && is_array($GLOBALS["GOTMLS"]["log"]["settings"])))
234 $GLOBALS["GOTMLS"]["log"]["settings"] = $GLOBALS["GOTMLS"]["tmp"]["settings_array"];
235 GOTMLS_define("GOTMLS_installation_key", md5(GOTMLS_siteurl));
236 GOTMLS_define("GOTMLS_update_home", "//updates.gotmls.net/".GOTMLS_installation_key."/");
237
238 function GOTMLS_get_corefile_URL($path, $hash) {
239 if (strpos($URL = GOTMLS_get_version("URL"), '&cp='))
240 //$hash != md5($contents)."O".strlen($contents)
241 return 'http:'.GOTMLS_update_home.'cp_core.php?'.$URL.'&f='.GOTMLS_encode($path)."&h=$hash&ts=".gmdate("YmdHis").'&d='.rawurlencode(GOTMLS_siteurl);
242 else
243 return "http://core.svn.wordpress.org/tags/".GOTMLS_wp_version."$path";
244 }
245
246 function GOTMLS_Invalid_Nonce($pre = "//Error: ") {
247 return $pre.__("Invalid or expired Nonce Token!",'gotmls').(isset($_REQUEST["GOTMLS_mt"])?(" (".GOTMLS_htmlspecialchars($_REQUEST["GOTMLS_mt"]).((strlen($_REQUEST["GOTMLS_mt"]) == 32)?(isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]])?GOTMLS_htmlspecialchars($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]):" !found)"):" !len[".strlen($_REQUEST["GOTMLS_mt"])."])")):" (GOTMLS_mt !set)").__("Refresh and try again?",'gotmls');
248 }
249
250 function GOTMLS_set_nonce($context = "NULL") {
251 $hour = (int) round(round($GLOBALS["GOTMLS"]["tmp"]["mt"]/60)/60);
252 $transient_name = md5(substr(number_format(microtime(true), 9, '-', '/'), 6).GOTMLS_installation_key.GOTMLS_plugin_path);
253 if (isset($GLOBALS["GOTMLS"]["tmp"]["nonce"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["nonce"])) {
254 foreach ($GLOBALS["GOTMLS"]["tmp"]["nonce"] as $nonce_key => $nonce_value) {
255 if (($nonce_value > $hour) || (($nonce_value + 24) < $hour))
256 unset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$nonce_key]);
257 elseif ($nonce_value == $hour)
258 $transient_name = $nonce_key;
259 }
260 }
261 if (!isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name])) {
262 $GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name] = $hour;
263 if (!GOTMLS_update_option('nonce', $GLOBALS["GOTMLS"]["tmp"]["nonce"]))
264 return (GOTMLS_sanitize($context)."=DB-err:".rawurlencode(preg_replace('/[\r\n]+/', " ", print_r($GLOBALS["GOTMLS"]["tmp"]["nonce"],1).$wpdb->last_error)));
265 }
266 return 'GOTMLS_mt='.rawurlencode($transient_name);
267 }
268
269 function GOTMLS_get_nonce() {
270 if (isset($_REQUEST["GOTMLS_mt"])) {
271 if (is_array($_REQUEST["GOTMLS_mt"])) {
272 foreach ($_REQUEST["GOTMLS_mt"] as $_REQUEST_GOTMLS_mt)
273 if (strlen($_REQUEST_GOTMLS_mt) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST_GOTMLS_mt]))
274 return (INT) $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST_GOTMLS_mt];
275 return 0;
276 } elseif (strlen($_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]))
277 return (INT) $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]];
278 else
279 return "";
280 } else
281 return false;
282 }
283
284 function GOTMLS_fileperms($file) {
285 if ($prm = @fileperms($file)) {
286 if (($prm & 0xC000) == 0xC000)
287 $ret = "s";
288 elseif (($prm & 0xA000) == 0xA000)
289 $ret = "l";
290 elseif (($prm & 0x8000) == 0x8000)
291 $ret = "-";
292 elseif (($prm & 0x6000) == 0x6000)
293 $ret = "b";
294 elseif (($prm & 0x4000) == 0x4000)
295 $ret = "d";
296 elseif (($prm & 0x2000) == 0x2000)
297 $ret = "c";
298 elseif (($prm & 0x1000) == 0x1000)
299 $ret = "p";
300 else
301 $ret = "u";
302 $ret .= (($prm & 0x0100)?"r":"-").(($prm & 0x0080)?"w":"-");
303 $ret .= (($prm & 0x0040)?(($prm & 0x0800)?"s":"x" ):(($prm & 0x0800)?"S":"-"));
304 $ret .= (($prm & 0x0020)?"r":"-").(($prm & 0x0010)?"w":"-");
305 $ret .= (($prm & 0x0008)?(($prm & 0x0400)?"s":"x" ):(($prm & 0x0400)?"S":"-"));
306 $ret .= (($prm & 0x0004)?"r":"-").(($prm & 0x0002)?"w":"-");
307 $ret .= (($prm & 0x0001)?(($prm & 0x0200)?"t":"x" ):(($prm & 0x0200)?"T":"-"));
308 return $ret;
309 } else
310 return "stat failed!";
311 }
312
313 function GOTMLS_file_details($file) {
314 return '<div id="file_details_'.md5($file).'" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>File Details: '.GOTMLS_htmlspecialchars(basename($file)).'</b><br />in: '.dirname(realpath($file)).'<br />size: '.filesize(realpath($file)).' ( '.ceil(strlen(GOTMLS_htmlspecialchars($GLOBALS["GOTMLS"]["tmp"]["file_contents"]))/1024).' KB )<br />encoding: '.(isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])?$GLOBALS["GOTMLS"]["tmp"]["encoding"]:(function_exists("mb_detect_encoding")?mb_detect_encoding($GLOBALS["GOTMLS"]["tmp"]["file_contents"]):"Unknown")).'<br />permissions: '.GOTMLS_fileperms(realpath($file)).'<br />Owner/Group: '.fileowner(realpath($file)).'/'.filegroup(realpath($file)).' (you are: '.getmyuid().'/'.getmygid().')<br />modified:'.gmdate(" Y-m-d H:i:s ", filemtime(realpath($file))).'<br />changed:'.gmdate(" Y-m-d H:i:s ", filectime(realpath($file))).'</div>';
315 }
316
317 function GOTMLS_esc_url($url) {
318 if ("" === trim($url))
319 return "";
320 $original_url = $url;
321 $url = str_replace(' ', '%20', ltrim($url));
322 $url = preg_replace('|[^a-z0-9-~+_.?#=!&;,/:%@$\|*\'()\[\]\\x80-\\xff]|i', '', $url);
323 $url = wp_kses_normalize_entities($url);
324 $url = str_replace('&amp;', '&#038;', $url);
325 $url = str_replace("'", '&#039;', $url);
326 if ((false !== strpos($url, '[')) || (false !== strpos($url, ']'))) {
327 $end_dirty = preg_replace('/^([fhtps]+\:)?\/\/([^\@]+\@)*[^\/]++/i', '', $url);
328 $end_clean = str_replace(array('[', ']'), array('%5B', '%5D'), $end_dirty);
329 $url = str_replace($end_dirty, $end_clean, $url);
330 }
331 return $url;
332 }
333
334 function GOTMLS_admin_url($action, $url = '') {
335 $return = admin_url("admin-ajax.php?action=$action");
336 foreach (array('eli', 'GOTMLS_debug') as $pass_on)
337 if (isset($_GET["$pass_on"]))
338 $return .= "&$pass_on=".GOTMLS_esc_url($_GET["$pass_on"]);
339 return ("$return&$url");
340 }
341
342 function GOTMLS_close_button($box_id, $margin = '6px') {
343 return '<a href="javascript:void(0);" style="float: right; color: #F00; overflow: hidden; width: 20px; height: 20px; text-decoration: none; margin: '.$margin.'" onclick="showhide(\''.$box_id.'\');"><span class="dashicons dashicons-dismiss"></span>X</a>';
344 }
345
346 function GOTMLS_get_styles($pre_style = '<style>') {
347 $head_nonce = GOTMLS_set_nonce(__FUNCTION__."316");
348 return $pre_style.'
349 span.GOTMLS_date {float: right; width: 130px; white-space: nowrap;}
350 .GOTMLS_page {float: left; border-radius: 10px; padding: 0 5px;}
351 .GOTMLS_quarantine_item {margin: 4px 12px;}
352 .rounded-corners {margin: 10px; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000;}
353 .shadowed-box {box-shadow: -3px 3px 3px #666; -moz-box-shadow: -3px 3px 3px #666; -webkit-box-shadow: -3px 3px 3px #666;}
354 .sidebar-box {background-color: #CCC;}
355 iframe {border: 0;}
356 .GOTMLS-scanlog li a {display: none;}
357 .GOTMLS-scanlog li:hover a {display: block;}
358 .GOTMLS-sidebar-links {list-style: none;}
359 .GOTMLS-sidebar-links li img {margin: 3px; height: 16px; vertical-align: middle;}
360 .GOTMLS-sidebar-links li {margin-bottom: 0 !important;}
361 .popup-box {background-color: #FFC; display: none; position: absolute; left: 0px; z-index: 10;}
362 .shadowed-text {text-shadow: #00F -1px 1px 1px;}
363 .sub-option {float: left; margin: 3px 5px;}
364 .inside {margin: 10px; position: relative;}
365 .GOTMLS_li, .GOTMLS_plugin li {list-style: none;}
366 .GOTMLS_plugin {margin: 5px; background: #cfc; border: 1px solid #0C0; padding: 0 5px; border-radius: 3px;}
367 .GOTMLS_plugin.known, .GOTMLS_plugin.db_scan, .GOTMLS_plugin.htaccess, .GOTMLS_plugin.timthumb, .GOTMLS_plugin.errors {background: #f99; border: 1px solid #f00;}
368 .GOTMLS_plugin.potential, .GOTMLS_plugin.wp_core, .GOTMLS_plugin.skipdirs, .GOTMLS_plugin.skipped {background: #ffc; border: 1px solid #fc6;}
369 .GOTMLS ul li {margin-left: 12px;}
370 .GOTMLS h2 {margin: 0 0 10px;}
371 .postbox {margin-right: 10px; line-height: 1.4; font-size: 13px;}
372 #pastDonations li {list-style: none;}
373 #quarantine_buttons {margin: 0px; padding: 0px;}
374 #quarantine_buttons input.button-primary {margin-right: 20px;}
375 #reclean_buttons {
376 color: #a00;
377 min-height: 32px;
378 border-top: solid 2px black;
379 padding-top: 10px;
380 }
381 #reclean_buttons input.button-primary {float: right;}
382 #delete_button {
383 background-color: #C33;
384 color: #FFF;
385 background-image: linear-gradient(to bottom, #C22, #933);
386 border-color: #933 #933 #900;
387 box-shadow: 0 1px 0 rgba(230, 120, 120, 0.5) inset;
388 text-decoration: none; text-shadow: 0 1px 0 rgba(0, 0, 0, 0.1);
389 margin-top: 10px;
390 }
391 #main-page-title {
392 background: url("https://secure.gravatar.com/avatar/5feb789dd3a292d563fea3b885f786d6?s=64") no-repeat scroll 0 0 transparent;
393 height: 64px;
394 line-height: 58px;
395 margin: 10px 0 0 0;
396 max-width: 600px;
397 padding: 0 110px 0 84px;
398 }
399 #main-page-title h1 {
400 background: url("https://secure.gravatar.com/avatar/8151cac22b3fc543d099241fd573d176?s=64") no-repeat scroll top right transparent;
401 height: 64px;
402 line-height: 32px;
403 margin: 0;
404 padding: 0 84px 0 0;
405 display: table-cell;
406 text-align: center;
407 vertical-align: middle;
408 }
409 </style>
410 <div id="div_file" class="shadowed-box rounded-corners sidebar-box" style="padding: 0; display: none; position: fixed; top: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][1].'; left: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][0].'; width: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][3].'; height: '.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][2].'; border: solid #c00; z-index: 112358;"><table style="width: 100%; height: 100%;" cellspacing="0" cellpadding="0"><tr><td style="border-bottom: 1px solid #EEE; height: 32px;" colspan="2">'.GOTMLS_close_button("div_file").'<h3 onmousedown="grabDiv();" onmouseup="releaseDiv();" id="windowTitle" style="cursor: move; border-bottom: 0px none; z-index: 2345677; position: absolute; left: 0px; top: 0px; margin: 0px; padding: 6px; width: 90%; height: 20px;">'.GOTMLS_Loading_LANGUAGE.'</h3></td></tr><tr><td colspan="2" style="height: 100%"><div style="width: 100%; height: 100%; position: relative; padding: 0; margin: 0;" class="inside"><br /><br /><center><img src="'.GOTMLS_images_path.'wait.gif" height=16 width=16 alt="..."> '.GOTMLS_Loading_LANGUAGE.'<br /><br /><input type="button" onclick="showhide(\'GOTMLS_iFrame\', true);" value="'.__("If this is taking too long, click here.",'gotmls').'" class="button-primary" /></center><iframe id="GOTMLS_iFrame" name="GOTMLS_iFrame" style="top: 0px; left: 0px; position: absolute; width: 100%; height: 100%; background-color: #CCC;"></iframe></td></tr><tr><td style="height: 20px;"><iframe id="GOTMLS_statusFrame" name="GOTMLS_statusFrame" style="width: 100%; height: 20px; background-color: #CCC;"></iframe></div></td><td style="height: 20px; width: 20px;"><h3 id="cornerGrab" onmousedown="grabCorner();" onmouseup="releaseCorner();" style="cursor: move; height: 24px; width: 24px; margin: 0; padding: 0; z-index: 2345678; overflow: hidden; position: absolute; right: 0px; bottom: 0px;"><span class="dashicons dashicons-editor-expand"></span>&#8690;</h3></td></tr></table></div>
411 <script type="text/javascript">
412 function showhide(id) {
413 divx = document.getElementById(id);
414 if (divx) {
415 if (divx.style.display == "none" || arguments[1]) {
416 divx.style.display = "block";
417 divx.parentNode.className = (divx.parentNode.className+"close").replace(/close/gi,"");
418 return true;
419 } else {
420 divx.style.display = "none";
421 return false;
422 }
423 }
424 }
425 function checkAllFiles(check) {
426 var checkboxes = new Array();
427 checkboxes = document["GOTMLS_Form_clean"].getElementsByTagName("input");
428 for (var i=0; i<checkboxes.length; i++)
429 if (checkboxes[i].type == "checkbox" && (checkboxes[i].id.substring(0, 6) == "check_" || checkboxes[i].id.substring(0, 24) == "GOTMLS_quarantine_check_"))
430 checkboxes[i].checked = check;
431 }
432 function setvalAllFiles(val) {
433 var checkboxes = document.getElementById("GOTMLS_fixing");
434 if (checkboxes)
435 checkboxes.value = val;
436 }
437 function getWindowWidth(min) {
438 if (typeof window.innerWidth != "undefined" && window.innerWidth > min)
439 min = window.innerWidth;
440 else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientWidth != "undefined" && document.documentElement.clientWidth > min)
441 min = document.documentElement.clientWidth;
442 else if (typeof document.getElementsByTagName("body")[0].clientWidth != "undefined" && document.getElementsByTagName("body")[0].clientWidth > min)
443 min = document.getElementsByTagName("body")[0].clientWidth;
444 return min;
445 }
446 function getWindowHeight(min) {
447 if (typeof window.innerHeight != "undefined" && window.innerHeight > min)
448 min = window.innerHeight;
449 else if (typeof document.documentElement != "undefined" && typeof document.documentElement.clientHeight != "undefined" && document.documentElement.clientHeight > min)
450 min = document.documentElement.clientHeight;
451 else if (typeof document.getElementsByTagName("body")[0].clientHeight != "undefined" && document.getElementsByTagName("body")[0].clientHeight > min)
452 min = document.getElementsByTagName("body")[0].clientHeight;
453 return min;
454 }
455 function loadIframe(title) {
456 showhide("GOTMLS_iFrame", true);
457 showhide("GOTMLS_iFrame");
458 document.getElementById("windowTitle").innerHTML = title;
459 if (curDiv) {
460 windowW = getWindowWidth(200);
461 windowH = getWindowHeight(200);
462 if (windowW > 200)
463 windowW -= 30;
464 if (windowH > 200)
465 windowH -= 20;
466 if (px2num(curDiv.style.width) > windowW) {
467 curDiv.style.width = windowW + "px";
468 curDiv.style.left = "0px";
469 } else if ((px2num(curDiv.style.left) + px2num(curDiv.style.width)) > windowW) {
470 curDiv.style.left = (windowW - px2num(curDiv.style.width)) + "px";
471 }
472 if (px2num(curDiv.style.height) > windowH) {
473 curDiv.style.height = windowH + "px";
474 curDiv.style.top = "0px";
475 } else if ((px2num(curDiv.style.top) + px2num(curDiv.style.height)) > windowH) {
476 curDiv.style.top = (windowH - px2num(curDiv.style.height)) + "px";
477 }
478 if (px2num(curDiv.style.left) < 0)
479 curDiv.style.left = "0px";
480 if (px2num(curDiv.style.top)< 0)
481 curDiv.style.top = "0px";
482 }
483 showhide("div_file", true);
484 if (IE)
485 curDiv.scrollIntoView(true);
486 }
487 function cancelserver(divid) {
488 document.getElementById(divid).innerHTML = "<div class=\'error\'>'.GOTMLS_strip4java(__("No response from server!",'gotmls')).'</div>";
489 }
490 var stopCheckingDefinitions = 0;
491 function checkPrimaryUpdateServer() {
492 var updatescript = document.createElement("script");
493 updatescript.setAttribute("src", pri_addr);
494 if (divx = document.getElementById("Definition_Updates"))
495 divx.appendChild(updatescript);
496 return setTimeout(function() {stopCheckingDefinitions = checkAlternateUpdateServer();}, 15000);
497 }
498 function checkAlternateUpdateServer() {
499 var updatescript = document.createElement("script");
500 if (arguments[0])
501 updatescript.setAttribute("src", alt_addr+arguments[0]);
502 else
503 updatescript.setAttribute("src", alt_addr);
504 if (divx = document.getElementById("Definition_Updates"))
505 divx.appendChild(updatescript);
506 return setTimeout(function() {stopCheckingDefinitions = cancelserver("Definition_Updates");}, 15000);
507 }
508 function checkupdateserver(server) {
509 var updatescript = document.createElement("script");
510 updatescript.setAttribute("src", server);
511 if (divx = document.getElementById("GOTMLS_patch_searching"))
512 divx.appendChild(updatescript);
513 return setTimeout(function() {cancelserver("GOTMLS_patch_searching");}, '.(((INT) $GLOBALS["GOTMLS"]["tmp"]['execution_time'])+1).'000+3000);
514 }
515 var IE = document.all?true:false;
516 //if (!IE) document.addEventListener("mousemove", getMouseXY);
517 document.onmousemove = getMouseXY;
518 var offsetX = 0;
519 var offsetY = 0;
520 var offsetW = 0;
521 var offsetH = 0;
522 var curX = 0;
523 var curY = 0;
524 var curDiv;
525 function getMouseXY(e) {
526 if (IE) { // grab the mouse pos if browser is IE
527 curX = event.clientX + document.body.scrollLeft;
528 curY = event.clientY + document.body.scrollTop;
529 } else { // grab the mouse pos if browser is Not IE
530 curX = e.pageX - document.body.scrollLeft;
531 curY = e.pageY - document.body.scrollTop;
532 }
533 if (curX < 0) {curX = 0;}
534 if (curY < 0) {curY = 0;}
535 if (offsetX && curX > 10) {curDiv.style.left = (curX - offsetX)+"px";}
536 if (offsetY && (curY - offsetY) > 0) {curDiv.style.top = (curY - offsetY)+"px";}
537 if (offsetW && (curX - offsetW) > 360) {curDiv.style.width = (curX - offsetW)+"px";}
538 if (offsetH && (curY - offsetH) > 200) {curDiv.style.height = (curY - offsetH)+"px";}
539 return true;
540 }
541 function px2num(px) {
542 return parseInt(px.substring(0, px.length - 2), 10);
543 }
544 function setDiv(DivID) {
545 if (curDiv = document.getElementById(DivID)) {
546 if (IE)
547 curDiv.style.position = "absolute";
548 curDiv.style.left = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][0].'";
549 curDiv.style.top = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][1].'";
550 curDiv.style.height = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][2].'";
551 curDiv.style.width = "'.$GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"][3].'";
552 }
553 }
554 function grabDiv() {
555 corner = document.getElementById("windowTitle");
556 if (corner) {
557 corner.style.width="100%";
558 corner.style.height="100%";
559 }
560 offsetX=curX-px2num(curDiv.style.left);
561 offsetY=curY-px2num(curDiv.style.top);
562 }
563 function releaseDiv() {
564 corner = document.getElementById("windowTitle");
565 if (corner) {
566 corner.style.width="90%";
567 corner.style.height="20px";
568 }
569 document.getElementById("GOTMLS_statusFrame").src = "'.GOTMLS_admin_url('GOTMLS_position', $head_nonce.'&GOTMLS_x=').'"+curDiv.style.left+"&GOTMLS_y="+curDiv.style.top;
570 offsetX=0;
571 offsetY=0;
572 }
573 function grabCorner() {
574 corner = document.getElementById("cornerGrab");
575 if (corner) {
576 corner.style.width="100%";
577 corner.style.height="100%";
578 }
579 offsetW=curX-px2num(curDiv.style.width);
580 offsetH=curY-px2num(curDiv.style.height);
581 }
582 function releaseCorner() {
583 corner = document.getElementById("cornerGrab");
584 if (corner) {
585 corner.style.width="20px";
586 corner.style.height="20px";
587 }
588 document.getElementById("GOTMLS_statusFrame").src = "'.GOTMLS_admin_url('GOTMLS_position', $head_nonce.'&GOTMLS_w=').'"+curDiv.style.width+"&GOTMLS_h="+curDiv.style.height;
589 offsetW=0;
590 offsetH=0;
591 }
592 function check_for_donation(chk) {
593 if ((audl = document.getElementById("autoUpdateDownload")) && audl.src.replace(/^.+\?/,"")=="0")
594 if (chk.substr(0, 8) != "Changed " || chk.substr(8, 1) != "0")
595 chk += "\\n\\n'.__("Please make a donation for the use of this wonderful feature!",'gotmls').'";
596 alert(chk);
597 }
598 setDiv("div_file");
599 </script>';
600 }
601
602 function GOTMLS_get_header($optional_box = "") {
603 if (isset($_GET["check_site"]) && $_GET["check_site"])
604 $pre_style = '<div id="check_site" style="z-index: 1234567;"><img src="'.GOTMLS_images_path.'checked.gif" height=16 width=16 alt="&#x2714;"> '.__("Tested your site. It appears we didn't break anything",'gotmls').' ;-)</div><script type="text/javascript">if (csw = window.parent.document.getElementById("check_site_warning")) csw.style.backgroundColor=\'#0C0\';window.addEventListener(\'load\', (event) => {showhide(\'inside_ddd6dbd641b9a5909fe4d44da2017cc7\');});</script><li>Please <a target="_blank" href="https://wordpress.org/support/plugin/gotmls/reviews/#wporg-footer">write a "Five-Star" Review</a> on WordPress.org if you like this plugin.</li><style>#footer, #GOTMLS-metabox-container, #GOTMLS-right-sidebar, #admin-page-container, #wpadminbar, #adminmenuback, #adminmenuwrap, #adminmenu, .error, .updated, .notice, .update-nag {display: none !important;} #wpbody-content {padding-bottom: 0;} #wpbody, html.wp-toolbar {padding-top: 0 !important;} #wpcontent, #footer {margin-left: 5px !important;}';
605 else
606 $pre_style = '<style>#GOTMLS-right-sidebar {float: right; margin-right: 0px;}';
607 return GOTMLS_get_styles($pre_style).'<div id="main-page-title"><h1 style="vertical-align: middle;">Anti-Malware from&nbsp;GOTMLS.NET</h1></div>';
608 }
609
610 function GOTMLS_object_to_array($obj) {
611 if (is_object($obj))
612 $obj = (array) $obj;
613 $new = array();
614 if (is_array($obj)) {
615 foreach ($obj as $key => $val)
616 $new[$key] = GOTMLS_object_to_array($val);
617 } else
618 $new = $obj;
619 return $new;
620 }
621
622 function GOTMLS_get_pagination($count, $wrap = "") {
623 $Q_Paged = "";
624 if (isset($_REQUEST["paged"]) && is_numeric($_REQUEST["paged"])) {
625 if ((INT) $count < (INT) $_REQUEST["paged"])
626 $GLOBALS["GOTMLS"]["Quarantine"]["paged"] = (INT) $count;
627 else
628 $GLOBALS["GOTMLS"]["Quarantine"]["paged"] = (INT) $_REQUEST["paged"];
629 } else
630 $GLOBALS["GOTMLS"]["Quarantine"]["paged"] = 1;
631 for ($p = 1; $p <= $count; $p++) {
632 $Q_Paged .= '<input class="GOTMLS_page" type="submit" value="'.$p.'"'.((isset($GLOBALS["GOTMLS"]["Quarantine"]["paged"]) && $GLOBALS["GOTMLS"]["Quarantine"]["paged"] == $p) || (!isset($GLOBALS["GOTMLS"]["Quarantine"]["paged"]) && 1 == $p)?" DISABLED":"").' name="paged">';
633 }
634 if ($Q_Paged) {
635 foreach ($_GET as $name => $value) {
636 if (substr($name, 0, 10) != 'paged') {
637 if (is_array($value)) {
638 foreach ($value as $val)
639 $Q_Paged .= '<input type="hidden" name="'.GOTMLS_htmlspecialchars($name).'[]" value="'.GOTMLS_htmlspecialchars($val).'">';
640 } else
641 $Q_Paged .= '<input type="hidden" name="'.GOTMLS_htmlspecialchars($name).'" value="'.GOTMLS_htmlspecialchars($value).'">';
642 }
643 }
644 $Q_Paged = '<form method="GET" name="GOTMLS_Form_page"><div style="float: left;">Page:</div>'."$Q_Paged\n</form><br style=\"clear: left;\" />\n";
645 }
646 if ($wrap)
647 return "$Q_Paged<!-- p = $p , count = $count -->$wrap$Q_Paged";
648 else
649 return $Q_Paged;
650 }
651
652 function GOTMLS_get_quarantine($only = false) {
653 global $wpdb, $post;
654 if (is_numeric($only))
655 return get_post($only, ARRAY_A);
656 elseif ($only)
657 return $wpdb->get_var("SELECT COUNT(*) FROM `$wpdb->posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` != 'trash'");
658 else
659 $args = array("orderby" => 'date', "post_type" => 'GOTMLS_quarantine', "post_status" => array('pending', 'draft', 'private'));
660 if (isset($_REQUEST["post_status"]))
661 $args["post_status"] = $_REQUEST["post_status"];
662 if (isset($_REQUEST["paged"]) && is_numeric($_REQUEST["paged"]))
663 $args["paged"] = (INT) $_REQUEST["paged"];
664 if (isset($_REQUEST["posts_per_page"]) && is_numeric($_REQUEST["posts_per_page"]) && ($_REQUEST["posts_per_page"]))
665 $args["posts_per_page"] = (INT) $_REQUEST["posts_per_page"];
666 else
667 $args["posts_per_page"] = 200;
668 $my_query = new WP_Query($args);
669 if ($my_query->have_posts()) {
670 $Q_Page = '<form method="POST" action="'.admin_url('admin-ajax.php').'" target="GOTMLS_iFrame" name="GOTMLS_Form_clean"><input type="hidden" id="GOTMLS_fixing" name="GOTMLS_fixing" value="1"><input type="hidden" name="'.str_replace('=', '" value="', GOTMLS_set_nonce(__FUNCTION__."639")).'"><input type="hidden" name="action" value="GOTMLS_fix"><p id="quarantine_buttons" style="display: none;"><input id="repair_button" type="submit" value="'.__("Restore selected files from quarantine records",'gotmls').'" class="button-primary" onclick="if (confirm(\''.__("Are you sure you want to overwrite the previously cleaned files with the selected files in the Quarantine?",'gotmls').'\')) { setvalAllFiles(1); loadIframe(\'File Restoration Results\'); } else return false;" /><input id="delete_button" type="submit" class="button-primary" value="'.__("Delete selected quarantine records",'gotmls').'" onclick="if (confirm(\''.__("Are you sure you want to permanently delete the selected files in the Quarantine?",'gotmls').'\')) { setvalAllFiles(2); loadIframe(\'File Deletion Results\'); } else return false;" /></p><p><b>'.__("The following items highlighted in yellow had been found to contain malicious code, they have been cleaned and the malicious contents have been removed. A record of the infection has been saved here in the Quarantine for your review and could help with any future investigations. The code is safe here and you do not need to do anything further with these files.",'gotmls').'</b></p>
671 <p id="reclean_buttons" style="display: none;"><input id="reclean_button" type="submit" value="'.__("Re-clean re-infected files",'gotmls').'" class="button-primary" onclick="checkAllFiles(false); setvalAllFiles(1); loadIframe(\'Reinfected File Recleaning Results\');" /><b>'.__("The items highlighted in red have been found to be re-infected. The malicious code has returned and needs to be cleaned again.",'gotmls').'</b></p>
672 <ul name="found_Quarantine" id="found_Quarantine" class="GOTMLS_plugin known" style="background-color: #ccc; padding: 0;"><h3 style="margin: 8px 12px;">'.($my_query->post_count>1?'<input type="checkbox" onchange="checkAllFiles(this.checked); document.getElementById(\'quarantine_buttons\').style.display = \'block\';"> '.sprintf(__("Check all %d",'gotmls'),$my_query->post_count):"").__(" Items in Quarantine",'gotmls').'<span class="GOTMLS_date">'.__("Quarantined",'gotmls').'</span><span class="GOTMLS_date">'.__("Date Infected",'gotmls').((isset($_REQUEST["GOTMLS_debug"]))?'</span><span class="GOTMLS_date">'.__("Date Modified",'gotmls').'</span><span class="GOTMLS_date">'.__("Date Changed",'gotmls').'</span><span class="GOTMLS_date">'.__("File Size",'gotmls').'</span><span class="GOTMLS_date">'.__("Threat Found",'gotmls'):"").'</span></h3>';
673 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
674 while ($my_query->have_posts()) {
675 $my_query->the_post();
676 $gif = 'blocked.gif';
677 $threat = 'potential';
678 $action = $post->ID.'" id="check_'.$post->ID.'" onchange="document.getElementById(\'quarantine_buttons\').style.display = \'block\';';
679 $link = GOTMLS_error_link(__("The current/live file is missing or deleted",'gotmls'), $post->ID, $threat);
680 $fa = GOTMLS_threats_found_meta(GOTMLS_object_to_array($post));
681 if (is_file($post->post_title)) {
682 GOTMLS_scanfile($post->post_title);
683 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
684 $gif = 'threat.gif" onload="document.getElementById(\'reclean_buttons\').style.display = \'block\';';
685 $threat = 'known';
686 $action = GOTMLS_encode(realpath($post->post_title)).'" id="ilist_'.$post->ID.'" checked="true';
687 }
688 $link = GOTMLS_error_link(__("View current/live version",'gotmls'), $post->post_title, $threat);
689 } elseif (is_array($postdb = explode(":", $post->post_title.":")) && count($postdb) > 3 && is_numeric($postdb[1])) {
690 if ("options" == substr($postdb[0], -7)) {
691 if ($opt_row = $wpdb->get_row($wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_id` = %s",(INT) $postdb[1]), ARRAY_A))
692 $link = GOTMLS_error_link(__("View Option Record: ",'gotmls').((INT) $postdb[1]), ((INT) $postdb[1]).'.1', $threat);
693 elseif ($opt_row = $wpdb->get_row($SQL = $wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_name` LIKE %s", trim($postdb[2], '"')), ARRAY_A))
694 $link = GOTMLS_error_link(__("View Option Record: ",'gotmls').htmlspecialchars($postdb[2]), $opt_row["option_id"].'.1', $threat);
695 else
696 $link = GOTMLS_error_link(__("View Quarantine Record",'gotmls'), $post->ID, $threat);
697 } else {
698 $link = '<a target="_blank" href="';
699 if ("revision" == $postdb[0])
700 $link .= admin_url('revision.php?revision='.rawurlencode($postdb[1]))."\" title=\"View this revision";
701 else
702 $link .= admin_url('post.php?action=edit&post='.rawurlencode((INT) $postdb[1]))."\" title=\"View current ".GOTMLS_htmlspecialchars($postdb[0]);
703 $link .= "\" id=\"list_edit_".((INT) $postdb[1])."\" class=\"GOTMLS_plugin $threat\">";
704 }
705 }
706 $Q_Page .= '
707 <li id="GOTMLS_quarantine_'.((INT) $post->ID).'" class="GOTMLS_quarantine_item" onmouseover="this.style.fontWeight=\'bold\';" onmouseout="this.style.fontWeight=\'normal\';"><span class="GOTMLS_date">'.GOTMLS_error_link(__("View Quarantine Record",'gotmls'), $post->ID, $threat).$post->post_date_gmt.'</a></span><span class="GOTMLS_date">'.GOTMLS_htmlspecialchars($post->post_modified_gmt).((isset($_REQUEST["GOTMLS_debug"]) && is_file($post->post_title))?'</span><span class="GOTMLS_date">'.gmdate("Y-m-d H:i:s", filemtime($post->post_title)).'</span><span class="GOTMLS_date">'.gmdate("Y-m-d H:i:s", filectime($post->post_title)).'</span><span class="GOTMLS_date">('.filesize($post->post_title).' bytes)</span><span class="GOTMLS_date">( '.$fa.')':"").'</span><input type="checkbox" name="GOTMLS_fix[]" value="'.$action.'" /><img src="'.GOTMLS_images_path.$gif.'" height=16 width=16 alt="Q">'.$link.GOTMLS_htmlspecialchars(str_replace($root_path, "...", $post->post_title))."</a></li>\n";
708 }
709 $Q_Page = GOTMLS_get_pagination($my_query->max_num_pages, "$Q_Page\n</ul>\n</form>");
710 } else
711 $Q_Page = '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
712 wp_reset_query();
713 return $Q_Page;
714 }
715
716 function GOTMLS_box($bTitle, $bContents, $bType = "postbox") {
717 $md5 = md5($bTitle);
718 if (isset($GLOBALS["GOTMLS"]["tmp"]["$bType"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["$bType"]))
719 $GLOBALS["GOTMLS"]["tmp"]["$bType"]["$md5"] = "$bTitle";
720 else
721 $GLOBALS["GOTMLS"]["tmp"]["$bType"] = array("$md5"=>"$bTitle");
722 return '
723 <div id="box_'.$md5.'" class="'.$bType.'"><h3 title="Click to toggle" onclick="if (typeof '.$bType.'_showhide == \'function\'){'.$bType.'_showhide(\'inside_'.$md5.'\');}else{showhide(\'inside_'.$md5.'\');}" style="cursor: pointer;" class="hndle"><span id="title_'.$md5.'">'.$bTitle.'</span></h3>
724 <div id="inside_'.$md5.'" class="inside">
725 '.$bContents.'
726 </div>
727 </div>';
728 }
729
730 function GOTMLS_threats_ver($threats_name) {
731 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"] as $threat_level => $Threats)
732 if (is_array($Threats) && isset($Threats["$threats_name"][0]) && strlen($Threats["$threats_name"][0]) == 5)
733 return $Threats["$threats_name"][0];
734 return $threats_name;
735 }
736
737 function GOTMLS_threats_found_meta($Q_post = array()) {
738 global $wpdb, $table_prefix;
739 $gt = ">"; // This local variable never changes
740 $lt = "<"; // This local variable never changes
741 $SQL = "SELECT `meta_value` AS `Threat`, COUNT(*) AS `Found` FROM `{$wpdb->prefix}postmeta` WHERE `meta_key` = 'GOTMLS_threats_found'";
742 if (isset($Q_post["ID"]) && is_numeric($pID = $Q_post["ID"]) && ($pID > 0))
743 $SQL = $wpdb->prepare("$SQL AND post_id = %s", (INT) $pID);
744 else
745 $pID = 0;
746 $my_query = $wpdb->get_results("$SQL GROUP BY `meta_value`", ARRAY_A);
747 $fa = "";
748 if (is_array($my_query) && count($my_query)) {
749 $f = 1;
750 foreach ($my_query as $rec) {
751 if (isset($rec["Threat"]) && is_string($rec["Threat"]) && is_array($Threat = @GOTMLS_uckserialize($rec["Threat"])) && isset($Threat["DefVer"]) && isset($Threat["SubPos"])) {
752 $ends = explode("-", $Threat["SubPos"]."--", 3);
753 if (strlen($ends[0]) > 0 && strlen($ends[1]) > 0 && is_numeric($ends[1]) && is_numeric($ends[0])) {
754 if ($ends[1] < $ends[0])
755 $ends = array_reverse($ends);
756 $fa .= $lt.'a title="'.GOTMLS_htmlspecialchars($Threat["DefVer"]).'" href="javascript:select_text_range(\'ta_file\', '.$ends[0].', '.$ends[1].');"'.$gt.'['.$f++."]$lt/a$gt ";
757 }
758 }
759 }
760 } else {
761 if (isset($Q_post["post_excerpt"]) && strlen($Q_post["post_excerpt"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"] = @GOTMLS_uckserialize(GOTMLS_decode($Q_post["post_excerpt"])))) {
762 $f = 1;
763 // $fa .= "threats_found: ".count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
764 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
765 $ends = explode("-", "$threats_found--", 3);
766 if (strlen($ends[0]) > 0 && strlen($ends[1]) > 0 && is_numeric($ends[1]) && is_numeric($ends[0])) {
767 if ($ends[1] < $ends[0])
768 $ends = array_reverse($ends);
769 $fa .= $lt.'a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$ends[0].', '.$ends[1].');"'.$gt.'['.$f++."]$lt/a$gt ";
770 if (function_exists("add_post_meta"))
771 add_post_meta($pID, 'GOTMLS_threats_found', array("SubPos" => $ends[0]."-".$ends[1], "DefVer" => GOTMLS_threats_ver($threats_name)));
772 } else {
773 if (is_numeric($threats_found)) {
774 $threats_found = $threats_name;
775 $threats_name = $f;
776 }
777 $fpos = 0;
778 $flen = 0;
779 $potential_threat = GOTMLS_convert_r($threats_found);
780 while (($fpos = strpos($GLOBALS["GOTMLS"]["tmp"]["file_contents"], ($potential_threat), $flen + $fpos)) !== false) {
781 $flen = strlen($potential_threat);
782 $fa .= $lt.'a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.($fpos).', '.($fpos + $flen).');"'.$gt.'['.$f++."]$lt/a$gt ";
783 if (function_exists("add_post_meta"))
784 add_post_meta($pID, 'GOTMLS_threats_found', serialize(array("SubPos" => $fpos."-".($fpos + $flen), "DefVer" => GOTMLS_threats_ver($threats_name))));
785 }
786 }
787 }
788 } else
789 $fa = strlen($Q_post["post_excerpt"])."No Threats Found ";
790 }
791 return $fa;
792 }
793
794 function GOTMLS_view_details($Q_post, $pretext = "") {
795 $title = __("View Details:",'gotmls');
796 $clean_file = GOTMLS_htmlentities($Q_post["post_title"]);
797 $encoded_file_contents = GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
798 if (isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])) {
799 $en = $GLOBALS["GOTMLS"]["tmp"]["encoding"];
800 @header("Content-type: text/html; charset=$en");
801 } else
802 $en = "Unknown";
803 $fa = GOTMLS_threats_found_meta($Q_post);
804 die(GOTMLS_html_tags(array(
805 "html" => array(
806 "head" => array(
807 "title" => "$title $clean_file",
808 "script" => GOTMLS_js_text_range()
809 ),
810 "body" => array(
811 "table" => array(
812 "tr" => array(
813 "td" => "$pretext".
814 GOTMLS_html_tags(array(
815 "div" => array(
816 "b" => "$title",
817 "br id='encoding' /" => "encoding: $en",
818 "br id='size' /" => "size: ".strlen("$encoded_file_contents")." Bytes",
819 "br id='infected' /" => 'infected:'.$Q_post["post_modified_gmt"],
820 "br id='quarantined' /" => 'quarantined:'.$Q_post["post_date_gmt"]
821 )
822 ), array(
823 'div' => 'id="fileperms" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"'
824 )
825 ).
826 GOTMLS_html_tags(array(
827 "div" => GOTMLS_html_tags(array('span' => $title), array('span' => 'onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';"'))."( $fa)"
828 ), array(
829 'div' => 'style="overflow: auto;"'
830 )
831 )
832 ),
833 GOTMLS_html_tags(array(
834 "tr" => array(
835 "td" => array(
836 "textarea" => GOTMLS_htmlentities("$encoded_file_contents")
837 )
838 )
839 ), array(
840 'td' => 'style="height: 100%; padding: 5px 5px 0 0;"',
841 'textarea' => 'id="ta_file" style="width: 100%; height: 100%"'
842 )
843 )
844 )
845 )
846 )
847 ), array(
848 'script' => 'type="text/javascript"',
849 'table' => 'style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;"',
850 'td' => 'style="width: 100%"'
851 )
852 ));
853 }
854
855 function GOTMLS_js_text_range($posttext = "") {
856 return '
857 function select_text_range(ta_id, start, end) {
858 var textBox = document.getElementById(ta_id);
859 var scrolledText = "";
860 scrolledText = textBox.value.substring(0, end);
861 textBox.focus();
862 if (textBox.setSelectionRange) {
863 scrolledText = textBox.value.substring(end);
864 textBox.value = textBox.value.substring(0, end);
865 textBox.scrollTop = textBox.scrollHeight;
866 textBox.value = textBox.value + scrolledText;
867 textBox.setSelectionRange(start, end);
868 } else if (textBox.createTextRange) {
869 var range = textBox.createTextRange();
870 range.collapse(true);
871 range.moveStart("character", start);
872 range.moveEnd("character", end);
873 range.select();
874 } else
875 alert("The highlighting function does not work in your browser");
876 }
877 if (typeof window.parent.showhide === "function")
878 window.parent.showhide("GOTMLS_iFrame", true);
879 '.$posttext;
880 }
881
882 if ((isset($_SERVER["DOCUMENT_ROOT"]) && ($SCRIPT_FILE = str_replace($_SERVER["DOCUMENT_ROOT"], "", (isset($_SERVER["SCRIPT_FILENAME"])?$_SERVER["SCRIPT_FILENAME"]:(isset($_SERVER["SCRIPT_NAME"])?$_SERVER["SCRIPT_NAME"]:"")))) && strlen($SCRIPT_FILE) > strlen("/".basename(__FILE__)) && substr(__FILE__, -1 * strlen($SCRIPT_FILE)) == substr($SCRIPT_FILE, -1 * strlen(__FILE__)))) {
883 if (isset($_REQUEST["page"]) && str_replace('-', '_', $_REQUEST["page"]) == "GOTMLS_View_Quarantine" && isset($_REQUEST["GOTMLS_mt"]) && strlen($_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]])) {
884 $return = GOTMLS_htmlspecialchars(print_r( array("nonce"=>$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]],"mt"=>$_REQUEST["GOTMLS_mt"]),1));
885 try {
886 $wpdb->prefix = $table_prefix;
887 if (isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) {
888 $my_query = $wpdb->get_results($wpdb->prepare("SELECT * FROM `{$wpdb->prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `ID` = %s", (INT) $_REQUEST["id"]), ARRAY_A);
889 if (is_array($my_query) && isset($my_query[0]["post_type"]) && strtolower($my_query[0]["post_type"]) == "gotmls_quarantine") {
890 GOTMLS_load_contents(GOTMLS_decode($my_query[0]["post_content"]));
891 GOTMLS_view_details($my_query[0], '<form style="margin: 0;" method="post" action="?'.GOTMLS_set_nonce(__FUNCTION__."895").'&page=GOTMLS_View_Quarantine" onsubmit="return confirm(\''.GOTMLS_strip4java(__("Are you sure you want to restore this record from the quarantine?",'gotmls')).'\');"><input type="hidden" name="id[]" value="'.$my_query[0]["ID"].'"><input type="submit" value="Restore from Quarantine" style="display: none; background-color: #0C0; float: right;"></form>');
892 } else
893 die('<h3>Item NOT Found in Quarantine</h3>');
894 } else {
895 if (!isset($_REQUEST["not_in"]))
896 $_REQUEST["not_in"] = "trash";
897 $GLOBALS["GOTMLS"]["Quarantine"]["SQL"] = $wpdb->prepare("FROM `{$wpdb->prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` != %s ORDER BY `post_date_gmt` DESC", $_REQUEST["not_in"]);
898 $GLOBALS["GOTMLS"]["Quarantine"]["Count"] = $wpdb->get_var("SELECT COUNT(*) ".$GLOBALS["GOTMLS"]["Quarantine"]["SQL"]);
899 if (isset($_REQUEST["posts_per_page"]) && is_numeric($_REQUEST["posts_per_page"]) && ($_REQUEST["posts_per_page"]))
900 $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"] = (INT) $_REQUEST["posts_per_page"];
901 else
902 $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"] = 200;
903 $paged = GOTMLS_get_pagination(ceil($GLOBALS["GOTMLS"]["Quarantine"]["Count"] / $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"]));
904 $GLOBALS["GOTMLS"]["Quarantine"]["SQL"] .= $wpdb->prepare(" LIMIT %d,%d", (INT) (($GLOBALS["GOTMLS"]["Quarantine"]["paged"] - 1) * $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"]), (INT) $GLOBALS["GOTMLS"]["Quarantine"]["posts_per_page"]);
905 $my_query = $wpdb->get_results("SELECT * ".$GLOBALS["GOTMLS"]["Quarantine"]["SQL"], ARRAY_A);
906 if (is_array($my_query) && count($my_query)) {
907 $Q_Page = $paged.'<form method="POST" action="?page=GOTMLS_View_Quarantine" name="GOTMLS_Form_clean"><input type="hidden" name="'.str_replace('=', '" value="', GOTMLS_set_nonce(__FUNCTION__."897")).'"><p id="quarantine_buttons" style="display: none;"><input id="repair_button" type="submit" value="Restore selected files" class="button-primary" style="background-color: #0C0;" onclick="return confirm(\'Are you sure you want to overwrite the previously cleaned files with the selected files in the Quarantine?\');" /></p><p><b>The following items have been found to contain malicious code, they have been cleaned, and the original infected file contents have been saved here in the Quarantine. The code is safe here and you do not need to do anything further with these files.</b></p>
908 <ul name="found_Quarantine" id="found_Quarantine" class="GOTMLS_plugin known" style="background-color: #ccc; padding: 0;"><h3 style="margin: 8px 12px;">'.(count($my_query)>1?'<input type="checkbox" onchange="checkAllFiles(this.checked); document.getElementById(\'quarantine_buttons\').style.display = \'block\';"> '.sprintf(__("Check all %d",'gotmls'),count($my_query)):"").__(" Items in Quarantine",'gotmls').'<span class="GOTMLS_date">'.__("Quarantined",'gotmls').'</span><span class="GOTMLS_date">'.__("Date Infected",'gotmls').'</span></h3>';
909 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
910 foreach ($my_query as $post_a) {
911 $restored = "";
912 $image = "blocked";
913 if (isset($_REQUEST["id"]) && is_array($_REQUEST["id"]) && in_array($post_a["ID"], $_REQUEST["id"])) {
914 $restored = " read-only disabled";
915 if (GOTMLS_file_put_contents($post_a["post_title"], GOTMLS_decode($post_a["post_content"]))) {
916 $post_a["post_modified_gmt"] = gmdate("Y-m-d H:i:s");
917 $image = "checked";
918 $wpdb->query($wpdb->prepare("UPDATE `{$wpdb->prefix}posts` SET `post_status` = 'pending' WHERE `post_type` = 'GOTMLS_quarantine' AND `ID` = %s", (INT) $post_a["ID"]));
919 }
920 }
921 $Q_Page .= '
922 <li id="GOTMLS_quarantine_'.$post_a["ID"].'" class="GOTMLS_quarantine_item"><span class="GOTMLS_date">'.$post_a["post_date_gmt"].'</span><span class="GOTMLS_date">'.$post_a["post_modified_gmt"].'</span><input'.$restored.' type="checkbox" name="id[]" value="'.$post_a["ID"].'" id="GOTMLS_quarantine_check_'.$post_a["ID"].'" onchange="document.getElementById(\'quarantine_buttons\').style.display = \'block\';" /><img src="'.$image.'.gif" height=16 width=16 alt="Q"><a class="GOTMLS_plugin '.$restored.$post_a["ping_status"].'" target="_blank" href="?page=GOTMLS_View_Quarantine&id='.$post_a["ID"].'&'.GOTMLS_set_nonce(__FUNCTION__."912").'" title="View Quarantined File">'.str_replace($root_path, "...", $post_a["post_title"])."</a></li>\n";
923 }
924 $Q_Page .= "\n</ul>\n</form>$paged";
925 } else
926 $Q_Page = '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
927 die(GOTMLS_html_tags(array("html" => array("body" => GOTMLS_get_header().GOTMLS_box(__("View Quarantine",'gotmls'), $Q_Page)))));
928 }
929 } catch (Exception $e) {
930 die('Caught exception: '.GOTMLS_htmlspecialchars($e->getMessage())."\n");
931 }
932 } else {
933 header("Content-type: image/gif");
934 $img_src = GOTMLS_local_images_path.'GOTMLS-16x16.gif';
935 if (!(file_exists($img_src) && $img_bin = @file_get_contents($img_src)))
936 $img_bin = GOTMLS_decode('R=lGODlhEAAQAIABAAAAAP___yH5BAEAAAEALAAAAAAQABAAAAIshB=Qm-eo2HuJNWdrjlFm3S2hKB7kViKaxZmr98YgSo_jzH6tiU=974MADwUAOw2');
937 die($img_bin);
938 }
939 }
940 $GOTMLS_image_alt = array("wait"=>"...", "checked"=>"&#x2714;", "blocked"=>"X", "question"=>"?", "threat"=>"!");
941 $GOTMLS_dir_at_depth = array();
942 $GOTMLS_dirs_at_depth = array();
943 $GLOBAL_STRING = array("REQUEST" => "&","SERVER" => "&","FILES" => "&");
944 if (isset($_GET) && is_array($_GET))
945 foreach ($_GET as $req => $val)
946 $GLOBAL_STRING["REQUEST"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
947 if (isset($_POST) && is_array($_POST))
948 foreach ($_POST as $req => $val)
949 $GLOBAL_STRING["REQUEST"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
950 if (isset($_SERVER) && is_array($_SERVER))
951 foreach ($_SERVER as $req => $val)
952 $GLOBAL_STRING["SERVER"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
953 if (isset($_FILES) && is_array($_FILES))
954 foreach ($_FILES as $req => $fila)
955 foreach (array("tmp_name","name") as $val)
956 if (isset($fila["$val"]))
957 $GLOBAL_STRING["FILES"] .= "$req.$val=".(is_array($fila["$val"])?print_r($fila["$val"],1):$fila["$val"])."&";
958 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]) && array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"])))
959 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] = array(
960 "RevSlider"=>array("CCIGG", "Revolution Slider Exploit Protection", "This protection is automatically activated because of the widespread attacks on WordPress that have affected so many sites. It is still recommended that you make sure to upgrade any older versions of the Revolution Slider plugin, especially those included in themes that will not update automatically. Even if you don't think you have Revolution Slider on your site it doen't hurt to have this protection enabled.", "SERVER", '/\/admin-ajax\.php/i', "REQUEST", '/\&img=[^\&]*(?<!\.'.implode(')(?<!\.', array_slice($GLOBALS["GOTMLS"]["tmp"]["skip_ext"], 0, 10)).')\&/i'),
961 "Traversal"=>array("CCIGG", "Directory Traversal Protection", "This protection is automatically activated because this type of attack is quite common. This protection can prevent hackers from accessing secure files in parent directories (or user's folders outside the site_root).", "REQUEST", '/[\=\/](\.\.|etc)\//'),
962 "UploadPHP"=>array("CCIGG", "Upload PHP File Protection", "This protection is automatically activated because this type of attack is extremely dangerous. This protection can prevent hackers from uploading malicious code via web scripts.", "FILES", '/name=[^\&]*\.php\&/'));
963 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] as $TP => $VA) {
964 $V = 3;
965 if (is_array($VA) && count($VA) > $V && is_array($VA[$V])) {
966 foreach ($VA[$V] as $reg => $arr) {
967 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $arr;
968 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $reg;
969 }
970 }
971 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"])) {
972 $GLOBALS["GOTMLS"]["detected_attacks"] = "&attack[]=FW_$TP";
973 for ($V = 4; isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V]); $V+=2)
974 if (!isset($GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]]))
975 die($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]." [$V] not in <pre>".GOTMLS_htmlspecialchars(print_r($GLOBAL_STRING,1))."</pre>");
976 elseif (!preg_match($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V], $GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]], $matches))
977 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
978 if ($GLOBALS["GOTMLS"]["detected_attacks"])
979 include(dirname(dirname(__FILE__))."/safe-load/index.php");
980 }
981 }
982 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
983 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"]) && count($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"]) == 4))
984 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"] = $GLOBALS["GOTMLS"]["tmp"]["default"]["msg_position"];
985 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"]))
986 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"] = 2;
987 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
988 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"] = -1;
989 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"])))
990 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"] = $GLOBALS["GOTMLS"]["tmp"]["skip_ext"];
991 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"]))
992 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"] = "";
993 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"])))
994 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"] = array();
995 $GOTMLS_total_percent = 0;
996
997 function GOTMLS_admin_notices() {
998 if (!is_admin())
999 return;
1000 if (is_file(dirname(dirname(dirname(__FILE__)))."/yuzo-related-post/yuzo_related_post.php"))
1001 echo GOTMLS_html_tags(GOTMLS_error_div('It looks like you have <b>"Related Post" plugin By <i>Lenin Zapata</i></b> installed on your site.<br />This plugin was removed from the WordPress Plugin Repository because it contained a major vulnerability that was responsible for a fairly widespread breach to many WordPress sites that had it installed.<br />It is recommended that it be deactivated and deleted until a fix is released that solves this problem.'));
1002 if (!function_exists("mb_detect_encoding"))
1003 echo GOTMLS_html_tags(GOTMLS_error_div('It looks like you don\'t have <b>"mbstring" functions</b> enabled on your server.<br />This Anti-Malware plugin requires Multibyte String compatibility for best results. Please make sure that php-mbstring is installed and configured for the version of PHP running on your server.'));
1004 if ($GLOBALS["GOTMLS"]["tmp"]["HeadersError"])
1005 echo $GLOBALS["GOTMLS"]["tmp"]["HeadersError"];
1006 }
1007 add_action("admin_notices", "GOTMLS_admin_notices");
1008
1009 function GOTMLS_array_recurse($array1, $array2) {
1010 foreach ($array2 as $key => $value) {
1011 if (!isset($array1[$key]) || (isset($array1[$key]) && !is_array($array1[$key])))
1012 $array1[$key] = array();
1013 if (is_array($value))
1014 $value = GOTMLS_array_recurse($array1[$key], $value);
1015 $array1[$key] = $value;
1016 }
1017 return $array1;
1018 }
1019
1020 function GOTMLS_array_replace($array1, $array2) {
1021 foreach ($array2 as $key => $value)
1022 $array1[$key] = $value;
1023 return $array1;
1024 }
1025
1026 function GOTMLS_array_replace_recursive($array1 = array()) {
1027 $args = func_get_args();
1028 $array1 = $args[0];
1029 if (!is_array($array1))
1030 $array1 = array();
1031 for ($i = 1; $i < count($args); $i++)
1032 if (is_array($args[$i]))
1033 $array1 = GOTMLS_array_recurse($array1, $args[$i]);
1034 return $array1;
1035 }
1036
1037 function GOTMLS_update_scan_log($scan_log) {
1038 if (is_array($scan_log)) {
1039 $GLOBALS["GOTMLS"]["log"] = GOTMLS_array_replace_recursive($GLOBALS["GOTMLS"]["log"], $scan_log);
1040 if (isset($GLOBALS["GOTMLS"]["log"]["scan"]["percent"]) && is_numeric($GLOBALS["GOTMLS"]["log"]["scan"]["percent"]) && ($GLOBALS["GOTMLS"]["log"]["scan"]["percent"] >= 100))
1041 $GLOBALS["GOTMLS"]["log"]["scan"]["finish"] = time();
1042 if (isset($GLOBALS["GOTMLS"]["log"]["scan"]))
1043 update_option("GOTMLS_scan_log/".(isset($_SERVER["REMOTE_ADDR"])?GOTMLS_safe_ip($_SERVER["REMOTE_ADDR"]):"0.0.0.0")."/".$GLOBALS["GOTMLS"]["tmp"]["mt"], $GLOBALS["GOTMLS"]["log"]);
1044 }
1045 }
1046
1047 function GOTMLS_loaded() {
1048 if (headers_sent($filename, $linenum)) {
1049 if (!$filename)
1050 $filename = __("an unknown file",'gotmls');
1051 if (!is_numeric($linenum))
1052 $linenum = __("unknown",'gotmls');
1053 $GLOBALS["GOTMLS"]["tmp"]["HeadersError"] = GOTMLS_error_div(sprintf(__('<b>Headers already sent</b> in %1$s on line %2$s.<br />This is not a good sign, it may just be a poorly written plugin but Headers should not have been sent at this point.<br />Check the code in the above mentioned file to fix this problem.','gotmls'), $filename, $linenum));
1054 } elseif (isset($_GET["SESSION"]) && !session_id()) {
1055 @session_start();
1056 if (session_id() && $_GET["SESSION"] == "GOTMLS_debug" && ((isset($_GET["GOTMLS_debug"]) && "SESSION" == $_GET["GOTMLS_debug"]) || !isset($_SESSION["GOTMLS_debug"])))
1057 $_SESSION["GOTMLS_debug"] = array();
1058 }
1059 }
1060 add_action("plugins_loaded", "GOTMLS_loaded");
1061
1062 if (!function_exists("add_action")) {
1063 GOTMLS_loaded();
1064 // GOTMLS_admin_notices();
1065 }
1066
1067 function GOTMLS_get_ext($filename) {
1068 $nameparts = explode(".", ".$filename");
1069 return strtolower($nameparts[(count($nameparts)-1)]);
1070 }
1071
1072 function GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized = true) {
1073 if ($match = @preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["file_contents"], $threats_found)) {
1074 $start = -1;
1075 if (!@preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["new_contents"], $threat_found)) {
1076 $new_contents = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
1077 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
1078 } else
1079 $new_contents = false;
1080 foreach ($threats_found[0] as $find) {
1081 $potential_threat = GOTMLS_convert_r($find);
1082 $flen = strlen($potential_threat);
1083 while (($start = strpos(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"]), $potential_threat, $start+1)) !== false) {
1084 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".($flen+$start)] = "$threat_name";
1085 if ($not_serialized)
1086 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = str_replace($find, "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]);
1087 else
1088 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = substr($GLOBALS["GOTMLS"]["tmp"]["new_contents"], 0, $start).str_repeat(" ", $flen).substr($GLOBALS["GOTMLS"]["tmp"]["new_contents"], $start + $flen);
1089 }
1090 }
1091 if ($not_serialized && $new_contents && strlen($new_contents) < strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"]))
1092 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $new_contents;
1093 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
1094 } else
1095 return $match;
1096 }
1097
1098 function GOTMLS_preg_last_pcre_error() {
1099 $DC = array('PREG_NO_ERROR', 'PREG_INTERNAL_ERROR', 'PREG_BACKTRACK_LIMIT_ERROR', 'PREG_RECURSION_LIMIT_ERROR', 'PREG_BAD_UTF8_ERROR', 'PREG_BAD_UTF8_OFFSET_ERROR');
1100 if (function_exists("preg_last_error") && ($key = (INT) preg_last_error()) && isset($DC[$key]))
1101 return $DC[$key];
1102 else
1103 return "";
1104 }
1105
1106 function GOTMLS_check_threat($check_threats, $file='UNKNOWN') {
1107 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1108 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1109 $filekey = md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"])."O".strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1110 if (is_array($check_threats)) {
1111 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
1112 if (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($check_threats[GOTMLS_wp_version]["$path"])) {
1113 if (($check_threats[GOTMLS_wp_version]["$path"] != $filekey) && ($source = GOTMLS_get_URL(GOTMLS_get_corefile_URL("$path", $check_threats[GOTMLS_wp_version]["$path"]))) && ($check_threats[GOTMLS_wp_version]["$path"] == md5($source)."O".strlen($source))) {
1114 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1115 $len = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1116 if (strlen($source) < $len)
1117 $len = strlen($source);
1118 for ($start = 0, $end = 0; ($start == 0 || $end == 0) && $len > 0; $len--){
1119 if ($start == 0 && substr($source, 0, $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], 0, $len))
1120 $start = $len;
1121 if ($end == 0 && substr($source, -1 * $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], -1 * $len))
1122 $end = $len;
1123 }
1124 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".(strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])-$end)] = "Core File Modified";
1125 }
1126 } else {
1127 foreach ($check_threats as $threat_name=>$threat_definitions) {
1128 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1129 if (is_array($threat_definitions) && count($threat_definitions) > 1 && strlen($def_ver = array_shift($threat_definitions)) == 5 && (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"]) && in_array($threat_name, $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["dont_check"])))) {
1130 while ($threat_definition = array_shift($threat_definitions)) {
1131 $found = GOTMLS_preg_match_all($threat_definition, $threat_name);
1132 if ($found===false && ($err = GOTMLS_preg_last_pcre_error()))
1133 $GLOBALS["GOTMLS"]["tmp"]["errors"]["$def_ver"]["$filekey"] = $err;
1134 }
1135 if (isset($_SESSION["GOTMLS_debug"])) {
1136 $_SESSION["GOTMLS_debug"]["threat_name"] = "$threat_name ($def_ver)";
1137 $file_time = sprintf('%f', (microtime(true) - $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"]));
1138 if (isset($_GET["GOTMLS_debug"]) && is_numeric($_GET["GOTMLS_debug"]) && $file_time > $_GET["GOTMLS_debug"])
1139 echo GOTMLS_htmlspecialchars("\n//GOTMLS_debug $file_time $threat_name $file\n");
1140 if (isset($GLOBALS["GOTMLS"]["tmp"]["errors"]["$def_ver"]["$filekey"]))
1141 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["errors"]["$filekey"] = $GLOBALS["GOTMLS"]["tmp"]["errors"]["$def_ver"]["$filekey"];
1142 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"]))
1143 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] = sprintf('%f', $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] + $file_time);
1144 else
1145 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] = $file_time;
1146 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"]))
1147 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"]++;
1148 else
1149 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"] = 1;
1150 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"])
1151 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"] = $file_time;
1152 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"])
1153 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"] = $file_time;
1154 }
1155 }
1156 }
1157 }
1158 } elseif (strlen($check_threats) && isset($_GET['eli']) && GOTMLS_verify_regex($check_threats)) {
1159 $found = GOTMLS_preg_match_all($check_threats, $check_threats);
1160 if ($found===false && ($err = GOTMLS_preg_last_pcre_error()))
1161 $GLOBALS["GOTMLS"]["tmp"]["errors"]["$check_threats"]["$filekey"] = $err;
1162 }
1163 if (isset($_SESSION["GOTMLS_debug"])) {
1164 $file_time = sprintf('%f', (microtime(true) - $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"]));
1165 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"]))
1166 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] = sprintf('%f', $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] + $file_time);
1167 else
1168 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] = $file_time;
1169 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"]))
1170 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"]++;
1171 else
1172 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"] = 1;
1173 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"])
1174 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"] = $file_time;
1175 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"])
1176 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"] = $file_time;
1177 }
1178 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
1179 }
1180
1181 function GOTMLS_verify_regex($RegExp) {
1182 if (preg_match('/^(\/|\#|\|).+\1[is]*$/', $RegExp))
1183 return $RegExp;
1184 else
1185 return "";
1186 }
1187
1188 function GOTMLS_scanfile($file) {
1189 global $wpdb, $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1190 $gt = ">"; // This local variable never changes
1191 $lt = "<"; // This local variable never changes
1192 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"] = "Scanning...";
1193 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1194 $found = false;
1195 $threat_link = "";
1196 $className = "scanned";
1197 $real_file = realpath($file);
1198 $clean_file = GOTMLS_encode($real_file);
1199 if (is_file($real_file) && ($filesize = filesize($real_file)) && GOTMLS_load_contents(@file_get_contents($real_file))) {
1200 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]))
1201 $whitelist = array_flip($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]);
1202 else
1203 $whitelist = array();
1204 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"])) {
1205 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"] as $whitelist_file=>$non_threats) {
1206 if (is_array($non_threats) && count($non_threats) > 1) {
1207 if (isset($non_threats[0]))
1208 unset($non_threats[0]);
1209 $whitelist = array_merge($whitelist, $non_threats);
1210 }
1211 }
1212 }
1213 if (isset($whitelist[md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'O'.$filesize]))
1214 return GOTMLS_return_threat($className, "checked.gif?$className", $file, $threat_link);
1215 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
1216 if (isset($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && strlen($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && isset($_GET['eli']) && GOTMLS_verify_regex($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && ($found = GOTMLS_check_threat($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"])))
1217 $className = "known";
1218 else {
1219 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
1220 if (isset($_SESSION["GOTMLS_debug"])) {
1221 $_SESSION["GOTMLS_debug"]["file"] = $file;
1222 $_SESSION["GOTMLS_debug"]["last"]["total"] = microtime(true);
1223 }
1224 if (isset($GLOBALS["GOTMLS"]["tmp"]["threat_levels"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threat_levels"])) {
1225 foreach ($GLOBALS["GOTMLS"]["tmp"]["threat_levels"] as $threat_level) {
1226 if ("db_scan" != $threat_level) {
1227 if (isset($_SESSION["GOTMLS_debug"])) {
1228 $_SESSION["GOTMLS_debug"]["threat_level"] = $threat_level;
1229 $_SESSION["GOTMLS_debug"]["last"]["threat_level"] = microtime(true);
1230 }
1231 if (in_array($threat_level, $GLOBALS["GOTMLS"]["log"]["settings"]["check"]) && !$found && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"][$threat_level]) && ($threat_level != "wp_core" || (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]))) && (!isset($GLOBALS["GOTMLS"]["tmp"]["threat_files"]["$threat_level"]) || (substr($file."e", (-1 * strlen($GLOBALS["GOTMLS"]["tmp"]["threat_files"][$threat_level]."e"))) == $GLOBALS["GOTMLS"]["tmp"]["threat_files"][$threat_level]."e")) && ($found = GOTMLS_check_threat($GLOBALS["GOTMLS"]["tmp"]["definitions_array"][$threat_level],$file)))
1232 $className = $threat_level;
1233 }
1234 }
1235 }
1236 if (isset($_SESSION["GOTMLS_debug"])) {
1237 $file_time = round(microtime(true) - $_SESSION["GOTMLS_debug"]["last"]["total"], 5);
1238 if (isset($_SESSION["GOTMLS_debug"]["total"]["total"]))
1239 $_SESSION["GOTMLS_debug"]["total"]["total"] += $file_time;
1240 else
1241 $_SESSION["GOTMLS_debug"]["total"]["total"] = $file_time;
1242 if (isset($_SESSION["GOTMLS_debug"]["total"]["count"]))
1243 $_SESSION["GOTMLS_debug"]["total"]["count"] ++;
1244 else
1245 $_SESSION["GOTMLS_debug"]["total"]["count"] = 1;
1246 if (!isset($_SESSION["GOTMLS_debug"]["total"]["least"]) || $file_time < $_SESSION["GOTMLS_debug"]["total"]["least"])
1247 $_SESSION["GOTMLS_debug"]["total"]["least"] = $file_time;
1248 if (!isset($_SESSION["GOTMLS_debug"]["total"]["most"]) || $file_time > $_SESSION["GOTMLS_debug"]["total"]["most"])
1249 $_SESSION["GOTMLS_debug"]["total"]["most"] = $file_time;
1250 }
1251 }
1252 } else {
1253 GOTMLS_load_contents((is_file($real_file)?(is_readable($real_file)?(filesize($real_file)?__("Failed to read file contents!",'gotmls'):__("Empty file!",'gotmls')):(isset($_GET["eli"])?(@chmod($real_file, $GOTMLS_chmod_file)?__("Fixed file permissions! (try again)",'gotmls'):__("File permissions read-only!",'gotmls')):__("File not readable!",'gotmls'))):__("File does not exist!",'gotmls')));
1254 $className = "errors";
1255 }
1256 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1257 $threat_link = $lt.'a target="GOTMLS_iFrame" href="'.GOTMLS_admin_url('GOTMLS_scan', GOTMLS_set_nonce(__FUNCTION__."1249").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$clean_file).'" id="list_'.$clean_file.'" onclick="loadIframe(\''.str_replace("\"", "&quot;", $lt.'div style="float: left; white-space: nowrap;"'.$gt.GOTMLS_strip4java(__("Examine File",'gotmls')).' ... '.$lt.'/div'.$gt.$lt.'div style="overflow: hidden; position: relative; height: 20px;"'.$gt.$lt.'div style="position: absolute; right: 0px; text-align: right; width: 9000px;"'.$gt.GOTMLS_htmlspecialchars(GOTMLS_strip4java($file), ENT_NOQUOTES))."$lt/div$gt$lt/div$gt');\" class=\"GOTMLS_plugin\"$gt";
1258 if ($className == "errors") {
1259 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="errors";
1260 $threat_link = GOTMLS_error_link($GLOBALS["GOTMLS"]["tmp"]["file_contents"], $file);
1261 $imageFile = "/blocked";
1262 } elseif ($className != "potential") {
1263 if (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1264 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="GOTMLS_fix";
1265 if (GOTMLS_get_nonce()) {
1266 if ($className == "timthumb") {
1267 if (($source = GOTMLS_get_URL("https://storage.googleapis.com/google-code-archive-downloads/v2/code.google.com/timthumb/timthumb.php")) && strlen($source) > 500)
1268 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1269 else
1270 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
1271 } elseif ($className == 'wp_core') {
1272 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
1273 if (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]) && ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"] != md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"])."O".strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])) && ($source = GOTMLS_get_URL(GOTMLS_get_corefile_URL("$path", $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"]))) && ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"] == md5($source)."O".strlen($source)))
1274 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
1275 else
1276 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
1277 } else {
1278 $GOTMLS_no_contents = trim(preg_replace('/\/\*.*?\*\/\s*/s', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
1279 $GOTMLS_no_contents = trim(preg_replace('/\n\s*\/\/.*/', "", $GOTMLS_no_contents));
1280 $GOTMLS_no_contents = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GOTMLS_no_contents));
1281 if (strlen($GOTMLS_no_contents))
1282 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
1283 else
1284 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = "";
1285 }
1286 if (strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]) > 0 && (($Q_post = GOTMLS_write_quarantine($file, $className)) !== false) && ((strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"])==0 && isset($_GET["eli"]) && ($_GET["eli"] == "delete") && @unlink($file)) || (($Write_File = GOTMLS_file_put_contents($file, $GLOBALS["GOTMLS"]["tmp"]["new_contents"])) !== false))) {
1287 echo __("Success!",'gotmls');
1288 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
1289 } else {
1290 echo __("Failed:",'gotmls').' '.(strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])?((is_writable(dirname($file)) && is_writable($file))?(($Q_post===false)?__("failed to quarantine!",'gotmls')." (".GOTMLS_htmlspecialchars($wpdb->last_error).")":((isset($Write_File)&&$Write_File)?"Q=$Q_post: ".__("reason unknown!",'gotmls'):"Q=$Q_post: ".__("failed to write!",'gotmls'))):__("file not writable!",'gotmls')):__("no file contents!",'gotmls'));
1291 if (isset($_GET["eli"]))
1292 echo 'uid='.getmyuid().'('.get_current_user().'),gid='.getmygid().($lt.'br'.$gt.$lt.'pre'.$gt.'file_stat'.print_r(stat($file), true));
1293 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
1294 }
1295 } else {
1296 echo GOTMLS_Invalid_Nonce(__("Failed: ",'gotmls'));
1297 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
1298 }
1299 }
1300 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]=isset($_POST["GOTMLS_fix"])?"GOTMLS_fix=".GOTMLS_htmlspecialchars(print_r($_POST["GOTMLS_fix"],1)):"!potential";
1301 $threat_link = $lt.'input type="checkbox" name="GOTMLS_fix[]" value="'.$clean_file.'" id="check_'.$clean_file.(($className != "wp_core||ifitis")?'" checked="'.$className:'').'" /'.$gt.$threat_link;
1302 $imageFile = "threat";
1303 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1304 echo __("Already Fixed!",'gotmls');
1305 return "/*-->*"."/\nfixedFile('$clean_file');\n/*<!--*"."/";
1306 } else
1307 $imageFile = "question";
1308 return GOTMLS_return_threat($className, $imageFile, $file, str_replace("GOTMLS_plugin", "GOTMLS_plugin $className", $threat_link));
1309 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
1310 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="Already Fixed";
1311 echo __("Already Fixed!",'gotmls');
1312 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
1313 } else {
1314 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="no threat";
1315 return GOTMLS_return_threat($className, ($className=="scanned"?"checked":"blocked").".gif?$className", $file, $threat_link);
1316 }
1317 }
1318
1319 function GOTMLS_db_scan($id = 0) {
1320 global $wpdb;
1321 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && count($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"])) {
1322 if ($id) {
1323 $encoded_id = GOTMLS_encode($id);
1324 $ids = explode(".", $id.'.');
1325 if (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl1' && is_numeric($ids[0]) && ($Q_post = $wpdb->get_row($wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_id` = %s", (INT) $ids[0]), ARRAY_A))) {
1326 $path = 'Option ID: '.$Q_post["option_id"];
1327 $clean_file = $Q_post["option_name"];
1328 $fa = "";
1329 GOTMLS_load_contents($Q_post["option_value"]);
1330 $not_serialized = !(is_array(GOTMLS_uckserialize($GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $Q_post["option_value"])));
1331 $found = 0;
1332 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1333 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
1334 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1335 $threat_name = array_shift($scan_regex);
1336 while ($threat_definition = array_shift($scan_regex))
1337 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1338 }
1339 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1340 $f = 1;
1341 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
1342 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
1343 if ($start > $end)
1344 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
1345 else
1346 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
1347 }
1348 } else
1349 $fa = " No Threats Found";
1350 if (isset($_REQUEST["GOTMLS_fix"]) && is_array($_REQUEST["GOTMLS_fix"]) && in_array($encoded_id, $_REQUEST["GOTMLS_fix"]) && isset($_REQUEST["GOTMLS_fixing"]) && $_REQUEST["GOTMLS_fixing"] > 0) {
1351 GOTMLS_write_quarantine($Q_post, "db_scan");
1352 if ($_REQUEST["GOTMLS_fixing"] > 1) {
1353 echo "<li>Removing $path ... ";
1354 if ($wpdb->query($wpdb->prepare("DELETE FROM `$wpdb->options` WHERE `option_id` = %s", (INT) $Q_post["option_id"]))) {
1355 echo __("Done!",'gotmls');
1356 $li_js .= "/*-->*"."/\nDeletedFile('$encoded_id');\n/*<!--*"."/";
1357 } else {
1358 echo __("Failed to delete!",'gotmls');
1359 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1360 }
1361 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal of Option")));
1362 } else {
1363 echo "<li>Fixing $path ... ";
1364 if ($wpdb->update($wpdb->options, array("option_value" => $GLOBALS["GOTMLS"]["tmp"]["new_contents"]), array('option_id' => $Q_post["option_id"]))) {
1365 echo __("Success!",'gotmls');
1366 $li_js .= "/*-->*"."/\nfixedFile('$encoded_id');\n/*<!--*"."/";
1367 } else {
1368 echo __("Update Failed!",'gotmls');
1369 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1370 }
1371 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal from Option")));
1372 }
1373 return $li_js;
1374 } else {
1375 return '<form style="margin: 0;" method="post" action="'.admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."1367")).'" onsubmit="return confirm(\''.__("Are you sure you want to delete this option?",'gotmls').'\');"><input type="hidden" name="GOTMLS_fixing" value="2"><input type="hidden" name="action" value="GOTMLS_fix"><input type="submit" value="Delete this Option" style="float: right;"><input type="hidden" name="GOTMLS_fix[]" value="'.$encoded_id.'"></form><div id="fileperms" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>Record Details</b><br />encoding: '.(isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])?$GLOBALS["GOTMLS"]["tmp"]["encoding"]:"Unknown").'<br />size: '.strlen(GOTMLS_convert_r(GLOBALS["GOTMLS"]["tmp"]["file_contents"])).' bytes</div><div style="overflow: auto;"><span onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';">'.__("Record Details:",'gotmls').'</span> ('.$fa.' )</div></td></tr><tr><td style="height: 100%"><textarea id="ta_file" style="width: 100%; height: 100%">'.GOTMLS_htmlentities(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>';
1376 }
1377 } elseif (($Q_post = GOTMLS_get_quarantine($ids[0])) && isset($Q_post["post_content"])) {
1378 $path = $Q_post["post_type"].' ID: '.$Q_post["ID"];
1379 $clean_file = $Q_post["post_title"];
1380 $fa = "";
1381 GOTMLS_load_contents($Q_post["post_content"]);
1382 $not_serialized = !(is_array(GOTMLS_uckserialize($GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $Q_post["post_content"])));
1383 $found = 0;
1384 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1385 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
1386 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1387 $threat_name = array_shift($scan_regex);
1388 while ($threat_definition = array_shift($scan_regex))
1389 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1390 }
1391 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1392 $f = 1;
1393 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
1394 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
1395 if ($start > $end)
1396 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
1397 else
1398 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
1399 }
1400 } else
1401 $fa = " No Threats Found";
1402 if (isset($_REQUEST["GOTMLS_fix"]) && is_array($_REQUEST["GOTMLS_fix"]) && in_array($encoded_id, $_REQUEST["GOTMLS_fix"]) && isset($_REQUEST["GOTMLS_fixing"]) && $_REQUEST["GOTMLS_fixing"] > 0) {
1403 if ($_REQUEST["GOTMLS_fixing"] > 1) {
1404 echo "<li>Removing $path ... ";
1405 $Q_post["post_status"] = "trash";
1406 if (wp_update_post($Q_post)) {
1407 echo __("Done!",'gotmls');
1408 $li_js .= "/*-->*"."/\nDeletedFile('$encoded_id');\n/*<!--*"."/";
1409 } else {
1410 echo __("Failed to delete!",'gotmls');
1411 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1412 }
1413 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal of Revision")));
1414 } else {
1415 echo "<li>Fixing $path ... ";
1416 GOTMLS_write_quarantine($Q_post, "db_scan");
1417 $Q_post["post_content"] = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
1418 if (wp_update_post($Q_post)) {
1419 echo __("Success!",'gotmls');
1420 $li_js .= "/*-->*"."/\nfixedFile('$encoded_id');\n/*<!--*"."/";
1421 } else {
1422 echo __("Update Failed!",'gotmls');
1423 $li_js .= "/*-->*"."/\nfailedFile('$encoded_id');\n/*<!--*"."/";
1424 }
1425 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal from Content")));
1426 }
1427 return $li_js;
1428 } else {
1429 return '<form style="margin: 0;" method="post" action="'.admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."1421")).($Q_post["post_type"]=="revision"?'" onsubmit="return confirm(\''.__("Are you sure you want to delete this revision?",'gotmls').'\');"><input type="hidden" name="GOTMLS_fixing" value="2"><input type="hidden" name="action" value="GOTMLS_fix"><input type="submit" value="Delete this revision" style="float: right;"><input type="hidden" name="GOTMLS_fix[]" value="'.$encoded_id:"").'"></form><div id="fileperms" class="shadowed-box rounded-corners" style="display: none; position: absolute; left: 8px; top: 29px; background-color: #ccc; border: medium solid #C00; box-shadow: -3px 3px 3px #666; border-radius: 10px; padding: 10px;"><b>Record Details</b><br />encoding: '.(isset($GLOBALS["GOTMLS"]["tmp"]["encoding"])?$GLOBALS["GOTMLS"]["tmp"]["encoding"]:"Unknown").'<br />size: '.strlen(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"])).' bytes<br />last_modified:'.$Q_post["post_modified_gmt"].'<br />post_type:'.$Q_post["post_type"].'<br />author:'.$Q_post["post_author"].'<br />status:'.$Q_post["post_status"].'</div><div style="overflow: auto;"><span onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';">'.__("Record Details:",'gotmls').'</span> ('.$fa.' )</div></td></tr><tr><td style="height: 100%"><textarea id="ta_file" style="width: 100%; height: 100%">'.GOTMLS_htmlentities(GOTMLS_convert_r($GLOBALS["GOTMLS"]["tmp"]["file_contents"])).'</textarea></td></tr></table>';
1430 }
1431 } else
1432 die(GOTMLS_html_tags(array("html" => array("body" => __("This record no longer exists.",'gotmls')."<br />\n<script type=\"text/javascript\">\nwindow.parent.showhide('GOTMLS_iFrame', true);\n</script>"))));
1433 } else {
1434 $threats_found = array();
1435 $li_js = "";
1436 if (!isset($_REQUEST["eli"]))
1437 $and = " AND `post_status` != 'trash'";
1438 if (isset($_REQUEST["limit"]) && is_numeric($_REQUEST["limit"]))
1439 $and = " LIMIT ".((INT) $_REQUEST["limit"]);
1440 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"])) {
1441 if (isset($_GET["GOTMLS_scan"]) && strlen($_GET["GOTMLS_scan"]) > 8 && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][substr($_GET["GOTMLS_scan"], 8)])) {
1442 $scan_replace = str_replace("db_scan", "Database for ", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1443 $db_scan_a = array(GOTMLS_sanitize(substr($_GET["GOTMLS_scan"], 8)) => $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][substr($_GET["GOTMLS_scan"], 8)]);
1444 } elseif (isset($_GET["GOTMLS_only_file"]) && strlen($_GET["GOTMLS_only_file"]) && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][$_GET["GOTMLS_only_file"]])) {
1445 $scan_replace = str_replace("db_scan", "Database only ".(isset($_GET["limit"]) && is_numeric($_GET["limit"])) ? (INT) $_GET["limit"] : ""." for ", GOTMLS_htmlspecialchars("db_scan=".GOTMLS_decode($_GET["GOTMLS_only_file"])));
1446 $_GET["GOTMLS_scan"] = "db_scan=".GOTMLS_decode($_GET["GOTMLS_only_file"]);
1447 $db_scan_a = array(GOTMLS_decode($_GET["GOTMLS_only_file"]) => $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"][GOTMLS_decode($_GET["GOTMLS_only_file"])]);
1448 } else {
1449 $scan_replace = str_replace("db_scan", "Database", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1450 $db_scan_a = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"];
1451 }
1452 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), $scan_replace));
1453 GOTMLS_flush();
1454 $li_js .= "/*<!--*"."/".GOTMLS_return_threat("dir", "checked", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"])).GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), $scan_replace));
1455 } else {
1456 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("No Definitions for DB Injections!",'gotmls')));
1457 GOTMLS_flush();
1458 $li_js .= GOTMLS_return_threat("error", "question", GOTMLS_htmlspecialchars($_GET["GOTMLS_scan"]));
1459 $db_scan_a = GOTMLS_sanitize($_GET["GOTMLS_scan"]);
1460 }
1461 if (isset($db_scan_a) && is_array($db_scan_a)) {
1462 echo "\n//memory_limit=".@ini_get("memory_limit")."\n";
1463 foreach ($db_scan_a as $scan_sql => $scan_regex) {
1464 $SQL = preg_replace('/\{[a-f0-9]{64}\}/', '%', $wpdb->prepare("SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE %s $and", $scan_sql));
1465 $threat_name = array_shift($scan_regex);
1466 if (($found_row = $wpdb->get_results($SQL, ARRAY_A)) && is_array($found_row) && count($found_row)) {
1467 $val = count($found_row);
1468 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1469 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
1470 foreach ($found_row as $frow) {
1471 $encoded_id = GOTMLS_encode($frow["ID"].'.0');
1472 $found = 0;
1473 if ($frow["post_type"] != "revision" || isset($_REQUEST["eli"])) {
1474 GOTMLS_load_contents($frow["post_content"]);
1475 $not_serialized = !(is_array(GOTMLS_uckserialize($frow["post_content"])));
1476 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1477 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1478 foreach ($scan_regex as $threat_definition)
1479 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1480 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1481 echo str_replace($frow["ID"].'</a>', '</a><a target="_blank" title="Open '.$frow["post_type"].'" href="'.admin_url(($frow["post_type"]=="revision")?'revision.php?revision='.$frow["ID"].'">View Revision: ':'post.php?action=edit&post='.$frow["ID"].'">Edit '.$frow["post_type"].': ').$frow["ID"].'</a>', GOTMLS_return_threat("db_scan", "threat", "$found $threat_name(\"".str_replace('%', '*', trim($scan_sql, "%")).'") in '.$frow["post_type"]."(".(($frow["post_status"]=='inherit')?$frow["post_parent"]:$frow["post_status"]).'):"'.GOTMLS_htmlspecialchars($frow["post_title"]).'":'.$frow["ID"], '<input type="checkbox" name="GOTMLS_fix[]" id="check_'.$encoded_id.'" value="'.$encoded_id.'" checked="true">'.GOTMLS_error_link(__("View DB Injection",'gotmls'), $frow["ID"].'.0', "db_scan")));
1482 $threats_found['row_id_'.$encoded_id] = $threat_name;
1483 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1484 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("post_id"=>$frow["ID"], "scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("No preg_match", 0));//debug
1485 }
1486 }
1487 }
1488 if (($found_row = $wpdb->get_results(preg_replace('/\{[a-f0-9]{64}\}/', '%', $wpdb->prepare("SELECT * FROM `$wpdb->options` WHERE `option_value` LIKE %s", $scan_sql)), ARRAY_A)) && is_array($found_row) && count($found_row)) {
1489 $val = count($found_row);
1490 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1491 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
1492 foreach ($found_row as $frow) {
1493 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
1494 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
1495 $encoded_id = GOTMLS_encode($frow["option_id"].'.1');
1496 $found = 0;
1497 GOTMLS_load_contents($frow["option_value"]);
1498 $not_serialized = !(is_array(GOTMLS_uckserialize($frow["option_value"])));
1499 foreach ($scan_regex as $threat_definition)
1500 $found += GOTMLS_preg_match_all($threat_definition, $threat_name, $not_serialized);
1501 if ($found && !isset($threats_found['row_id_'.$encoded_id])) {
1502 echo GOTMLS_return_threat("db_scan", "threat", "$found $threat_name(\"".str_replace('%', '*', trim($scan_sql, "%")).'") in '."$wpdb->options:".GOTMLS_htmlspecialchars($frow["option_name"]).'":'.$frow["option_id"].'.1', '<input type="checkbox" name="GOTMLS_fix[]" id="check_'.$encoded_id.'" value="'.$encoded_id.'" checked="true">'.GOTMLS_error_link(__("View DB Injection",'gotmls'), $frow["option_id"].'.1', "db_scan"));
1503 $threats_found['row_id_'.$encoded_id] = $threat_name;
1504 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
1505 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("post_id"=>$frow["ID"], "scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("No preg_match", 0));//debug
1506 }
1507 }
1508 }
1509 }
1510 return "$li_js/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1511 }
1512 }
1513 }
1514
1515 function GOTMLS_remove_dots($dir) {
1516 if ($dir != "." && $dir != "..")
1517 return $dir;
1518 }
1519
1520 function GOTMLS_getfiles($dir) {
1521 $files = false;
1522 if (is_dir($dir)) {
1523 if (function_exists("scandir"))
1524 $files = @scandir($dir);
1525 if (is_array($files))
1526 $files = array_filter($files, "GOTMLS_remove_dots");
1527 elseif ($handle = @opendir($dir)) {
1528 $files = array();
1529 while (false !== ($entry = readdir($handle)))
1530 if ($entry != "." && $entry != "..")
1531 $files[] = "$entry";
1532 closedir($handle);
1533 } else
1534 $files = GOTMLS_read_error($dir);
1535 }
1536 return $files;
1537 }
1538
1539 function GOTMLS_decodeBase64($encoded_string) {
1540 if (function_exists("base64_decode"))
1541 $unencoded_string = base64_decode($encoded_string);
1542 elseif (function_exists("mb_convert_encoding"))
1543 $unencoded_string = mb_convert_encoding($encoded_string, "UTF-8", "BASE64");
1544 else
1545 return "Cannot decode: '$encoded_string'";
1546 return "'".str_replace("'", "\\'", str_replace("\\", "\\\\", $unencoded_string))."'";
1547 }
1548
1549 function GOTMLS_decodeHex($encoded_string) {
1550 if (strtolower(substr($encoded_string, 0, 2)) == "\\x")
1551 $dec_string = hexdec($encoded_string);
1552 else
1553 $dec_string = octdec($encoded_string);
1554 return chr($dec_string);
1555 }
1556
1557 function GOTMLS_return_threat($className, $imageFile, $fileName, $link = "") {
1558 global $GOTMLS_image_alt;
1559 $fileNameJS = GOTMLS_strip4java(str_replace("db_scan", "Database", str_replace("db_scan=", "Database Query ", isset($GLOBALS["GOTMLS"]["log"]["scan"]["dir"])?str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $fileName):$fileName)));
1560 $fileName64 = GOTMLS_encode($fileName);
1561 $li_js = "/*-->*"."/";
1562 $imageF = explode(".", $imageFile.".");
1563 if ($className != "scanned")
1564 $li_js .= "\n$className++;\ndivx=document.getElementById('found_$className');\nif (divx) {\n\tvar newli = document.createElement('li');\n\tnewli.innerHTML='<img src=\"".GOTMLS_strip4java(GOTMLS_images_path.$imageFile).".gif\" height=16 width=16 alt=\"".$GOTMLS_image_alt[$imageF[0]]."\" style=\"float: left;\" id=\"$imageFile"."_$fileName64\">".GOTMLS_strip4java($link, true).$fileNameJS.($link?"</a>';\n\tdivx.display='block":"")."';\n\tdivx.appendChild(newli);\n}";
1565 if ($className == "errors")
1566 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx) {\n\tdivx.src='".GOTMLS_images_path."blocked.gif';\n\tdirerrors++;\n}";
1567 elseif (is_file($fileName))
1568 $li_js .= "\nscanned++;\n";
1569 if ($className == "dir")
1570 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx)\n\tdivx.src='".GOTMLS_images_path."checked.gif';";
1571 return $li_js."\n/*<!--*"."/";
1572 }
1573
1574 function GOTMLS_slash($dir = __FILE__) {
1575 if (substr($dir.' ', 1, 1) == ':' || substr($dir.' ', 0, 1) == "\\")
1576 return "\\";
1577 else
1578 return '/';
1579 }
1580
1581 function GOTMLS_trailingslashit($dir = "") {
1582 if (substr(' '.$dir, -1) != GOTMLS_slash($dir))
1583 $dir .= GOTMLS_slash($dir);
1584 return $dir;
1585 }
1586
1587 function GOTMLS_explode_dir($dir, $pre = '') {
1588 if (strlen($pre))
1589 $dir = GOTMLS_slash($dir).$pre.$dir;
1590 return explode(GOTMLS_slash($dir), $dir);
1591 }
1592
1593 function GOTMLS_html_tags($tags, $inner = array()) {
1594 $html = "";
1595 $gt = ">"; // This local variable never changes
1596 if (!is_array($tags))
1597 $tags = array($tags => (is_array($inner)?(isset($inner["contents"])?$inner["contents"]:""):$inner));
1598 foreach ($tags as $tag => $contents) {
1599 if (!is_numeric($tag))
1600 $html .= ($tag=="html"?"<!DOCTYPE html$gt":"")."<$tag".(isset($inner[$tag])?" ".$inner[$tag]:"").$gt;
1601 if (is_array($contents))
1602 $html .= GOTMLS_html_tags($contents, $inner);
1603 else
1604 $html .= $contents;
1605 if ((!is_numeric($tag)) && substr($tag, -1) != '/')
1606 $html .= "</$tag$gt";
1607 }
1608 return $html;
1609 }
1610
1611 function GOTMLS_write_quarantine($file, $className) {
1612 global $wpdb;
1613 $insert = array("post_author"=>GOTMLS_get_current_user_id(), "post_content"=>GOTMLS_encode($GLOBALS["GOTMLS"]["tmp"]["file_contents"]), "post_mime_type"=>md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"]), "ping_status"=>$className, "post_status"=>"private", "post_type"=>"GOTMLS_quarantine", "post_content_filtered"=>GOTMLS_encode($GLOBALS["GOTMLS"]["tmp"]["new_contents"]), "guid"=>GOTMLS_Version);//! comment_status post_password post_name to_ping post_parent menu_order";
1614 if (isset($file["ID"]) && is_numeric($file["ID"])) {
1615 $insert["post_modified"] = $file["post_modified"];
1616 $insert["post_modified_gmt"] = $file["post_modified_gmt"];
1617 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1618 $file = $file["post_type"].':'.$file["ID"].':"'.$file["post_title"].'"';
1619 } elseif (isset($file["option_id"]) && is_numeric($file["option_id"])) {
1620 $insert["post_modified"] = gmdate("Y-m-d H:i:s");
1621 $insert["post_modified_gmt"] = gmdate("Y-m-d H:i:s");
1622 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1623 $file = $wpdb->options.':'.$file["option_id"].':"'.$file["option_name"].'"';
1624 }
1625 $insert["post_title"] = $file;
1626 $insert["post_date"] = gmdate("Y-m-d H:i:s");
1627 $insert["post_date_gmt"] = $insert["post_date"];
1628 if (is_file($file)) {
1629 if (@filemtime($file))
1630 $insert["post_modified"] = gmdate("Y-m-d H:i:s", filemtime($file));
1631 else
1632 $insert["post_modified"] = $insert["post_date"];
1633 if (@filectime($file))
1634 $insert["post_modified_gmt"] = gmdate("Y-m-d H:i:s", filectime($file));
1635 else
1636 $insert["post_modified_gmt"] = $insert["post_date"];
1637 if (!($insert["comment_count"] = @filesize($file)))
1638 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
1639 }
1640 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
1641 $insert["post_excerpt"] = GOTMLS_encode(@serialize($GLOBALS["GOTMLS"]["tmp"]["threats_found"]));
1642 $pinged = array();
1643 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $loc => $threat_name) {
1644 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][0]) && isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1]) && strlen($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][0]) == 5 && strlen($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1]))
1645 $ping = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1];
1646 else
1647 $ping = $threat_name;
1648 if (isset($pinged[$ping]))
1649 $pinged[$ping]++;
1650 else
1651 $pinged[$ping] = 1;
1652 }
1653 $insert["pinged"] = GOTMLS_encode(@serialize($pinged));
1654 }
1655 if ($return = $wpdb->insert($wpdb->posts, $insert))
1656 return $return;
1657 else
1658 die(print_r(array('return'=>($return===false)?"FALSE":$return, 'last_error'=>$wpdb->last_error, 'insert'=>$insert),1));
1659 }
1660
1661 function GOTMLS_get_current_user_id() {
1662 $return = 1;
1663 if (($current_user = @wp_get_current_user()) && (@$current_user->ID > 1))
1664 $return = $current_user->ID;
1665 return $return;
1666 }
1667
1668 function GOTMLS_update_status($status, $percent = -1) {
1669 if (!(isset($GLOBALS["GOTMLS"]["log"]["scan"]["start"]) && is_numeric($GLOBALS["GOTMLS"]["log"]["scan"]["start"])))
1670 $GLOBALS["GOTMLS"]["log"]["scan"]["start"] = time();
1671 $microtime = ceil(time()-$GLOBALS["GOTMLS"]["log"]["scan"]["start"]);
1672 GOTMLS_update_scan_log(array("scan" => array("microtime" => $microtime, "percent" => $percent)));
1673 return "/*-->*"."/\nupdate_status('".GOTMLS_strip4java($status)."', $microtime, $percent);\n/*<!--*"."/";
1674 }
1675
1676 function GOTMLS_flush($tag = "") {
1677 $output = "";
1678 if (($output = @ob_get_contents()) && strlen(trim($output)) > 18) {
1679 @ob_clean();
1680 if (!(isset($_GET["eli"]) && $_GET["eli"] == "debug"))
1681 $output = preg_replace('/\/\*<\!--\*\/.*?\/\*-->\*\//s', "", "$output/*-->*"."/");
1682 echo "$output\n//flushed(".strlen(trim($output)).")\n";
1683 if ($tag)
1684 echo "\n</$tag>\n";
1685 if (@ob_get_length())
1686 @ob_flush();
1687 if ($tag)
1688 echo "<$tag>\n";
1689 echo "/*<!--*"."/";
1690 }
1691 }
1692
1693 function GOTMLS_readdir($dir, $current_depth = 1) {
1694 global $GOTMLS_dirs_at_depth, $GOTMLS_dir_at_depth, $GOTMLS_total_percent;
1695 if ($current_depth) {
1696 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1697 $entries = GOTMLS_getfiles($dir);
1698 if (is_array($entries)) {
1699 echo GOTMLS_return_threat("dirs", "wait", $dir).GOTMLS_update_status(sprintf(__("Preparing %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1700 $files = array();
1701 $directories = array();
1702 foreach ($entries as $entry) {
1703 if (is_dir(GOTMLS_trailingslashit($dir).$entry))
1704 $directories[] = $entry;
1705 else
1706 $files[] = $entry;
1707 }
1708 if (isset($_GET["eli"]) && $_GET["eli"] == "trace" && count($files)) {
1709 $tracer_code = "(base64_decode('".base64_encode('if(isset($_SERVER["REMOTE_ADDR"]) && $_SERVER["REMOTE_ADDR"] == "'.GOTMLS_safe_ip($_SERVER["REMOTE_ADDR"]).'" && is_file("'.GOTMLS_local_images_path.'../safe-load/trace.php")) {include_once("'.GOTMLS_local_images_path.'../safe-load/trace.php");GOTMLS_debug_trace(__FILE__);}')."'));";
1710 foreach ($files as $file)
1711 if (GOTMLS_get_ext($file) == "php" && $filecontents = @file_get_contents(GOTMLS_trailingslashit($dir).$file))
1712 GOTMLS_file_put_contents(GOTMLS_trailingslashit($dir).$file, preg_replace('/^<\?php(?! eval)/is', '<?php eval'.$tracer_code, $filecontents));
1713 }
1714 if ($_REQUEST["scan_type"] == "Quick Scan") {
1715 $GOTMLS_dirs_at_depth[$current_depth] = count($directories);
1716 $GOTMLS_dir_at_depth[$current_depth] = 0;
1717 } else
1718 $GLOBALS["GOTMLS"]["tmp"]["scanfiles"][GOTMLS_encode($dir)] = GOTMLS_strip4java(str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir));
1719 foreach ($directories as $directory) {
1720 $path = GOTMLS_trailingslashit($dir).$directory;
1721 if (isset($_REQUEST["scan_depth"]) && is_numeric($_REQUEST["scan_depth"]) && ($_REQUEST["scan_depth"] != $current_depth) && (!((($Recusive = strpos(GOTMLS_trailingslashit($dir), '/'.$directory.'/')) !== FALSE) && is_dir($dir.substr($dir, $Recusive).substr($dir, $Recusive).substr($dir, $Recusive)))) && !in_array($directory, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"])) {
1722 $current_depth++;
1723 $current_depth = GOTMLS_readdir($path, $current_depth);
1724 } else {
1725 echo GOTMLS_return_threat("skipdirs", "blocked", $path);
1726 $GOTMLS_dir_at_depth[$current_depth] = (isset($GOTMLS_dir_at_depth[$current_depth])?$GOTMLS_dir_at_depth[$current_depth]:0) + 1;
1727 }
1728 }
1729 if ($_REQUEST["scan_type"] == "Quick Scan") {
1730 $echo = "";
1731 echo GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1732 GOTMLS_flush("script");
1733 foreach ($files as $file)
1734 echo GOTMLS_check_file(GOTMLS_trailingslashit($dir).$file);
1735 echo GOTMLS_return_threat("dir", "checked", $dir);
1736 }
1737 } else
1738 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' readdir:'.($entries===false?'('.GOTMLS_fileperms($dir).')':$entries)));
1739 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1740 if ($current_depth-- && $_REQUEST["scan_type"] == "Quick Scan") {
1741 $GOTMLS_dir_at_depth[$current_depth] = (isset($GOTMLS_dir_at_depth[$current_depth])?$GOTMLS_dir_at_depth[$current_depth]:0) + 1;
1742 for ($GOTMLS_total_percent = 0, $depth = $current_depth; $depth >= 0; $depth--) {
1743 if (!isset($GOTMLS_dir_at_depth[$depth]))
1744 $GOTMLS_dir_at_depth[$depth] = 0;
1745 echo "\n//(($GOTMLS_total_percent / $GOTMLS_dirs_at_depth[$depth]) + ($GOTMLS_dir_at_depth[$depth] / $GOTMLS_dirs_at_depth[$depth])) = ";
1746 $GOTMLS_total_percent = (($GOTMLS_dirs_at_depth[$depth]?($GOTMLS_total_percent / $GOTMLS_dirs_at_depth[$depth]):0) + ($GOTMLS_dir_at_depth[$depth] / ($GOTMLS_dirs_at_depth[$depth]+1)));
1747 echo "$GOTMLS_total_percent\n";
1748 }
1749 $GOTMLS_total_percent = floor($GOTMLS_total_percent * 100);
1750 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1751 }
1752 GOTMLS_flush("script");
1753 }
1754 return $current_depth;
1755 }
1756
1757 function GOTMLS_sexagesimal($timestamp = 0) {
1758 if (!is_numeric($timestamp) && strlen($timestamp) == 5) {
1759 $delim = array("=", "-", "-", " ", ":");
1760 foreach (str_split($timestamp) as $bit)
1761 $timestamp .= array_shift($delim).substr("00".(ord($bit)>96?ord($bit)-61:(ord($bit)>64?ord($bit)-55:ord($bit)-48)), -2);
1762 return "20".substr($timestamp, -14);
1763 } else {
1764 $match = '/^(20)?([0-5][0-9])[\-: \/]*(0*[1-9]|1[0-2])[\-: \/]*(0*[1-9]|[12][0-9]|3[01])[\-: \/]*([0-5][0-9])[\-: \/]*([0-5][0-9])$/';
1765 if (preg_match($match, $timestamp))
1766 $date = preg_replace($match, "\\2-\\3-\\4-\\5-\\6", $timestamp);
1767 elseif ($timestamp && strtotime($timestamp))
1768 $date = date("y-m-d-H-i", strtotime($timestamp));
1769 else
1770 $date = gmdate("y-m-d-H-i", time());
1771 foreach (explode("-", $date) as $bit)
1772 $date .= (intval($bit)>35?chr(ord("a")+intval($bit)-36):(intval($bit)>9?chr(ord("A")+intval($bit)-10):substr('0'.$bit, -1)));
1773 return substr($date, -5);
1774 }
1775 }
1776
1777 if (!function_exists('ur1encode')) { function ur1encode($url) {
1778 $return = "";
1779 foreach (str_split($url) as $char)
1780 $return .= '%'.substr('00'.strtoupper(dechex(ord($char))),-2);
1781 return $return;
1782 }}
1783
1784 function GOTMLS_strip4java($item, $htmlentities = false) {
1785 return preg_replace("/\\\\/", "\\\\\\\\", str_replace("'", "'+\"'\"+'", preg_replace('/\\+n|\\+r|\n|\r|\0/', "", ($htmlentities?$item:GOTMLS_htmlentities($item)))));
1786 }
1787
1788 function GOTMLS_error_link($errorTXT, $file = "", $class = "errors") {
1789 global $post, $wpdb;
1790 $encoded_file = GOTMLS_encode($file);
1791 $ids = explode(".", $file.'.');
1792 if (isset($post->post_title))
1793 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($post->post_title, ENT_NOQUOTES));
1794 elseif (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl1' && is_numeric($ids[0]))
1795 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($wpdb->get_var($wpdb->prepare("SELECT CONCAT('option', `option_id`, ': ', `option_name`) FROM `$wpdb->options` WHERE `option_id` = %s", (INT) $ids[0])), ENT_NOQUOTES));
1796 elseif (count($ids) > 2 && 'tbl'.$ids[1] == 'tbl0' && is_numeric($ids[0]))
1797 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($wpdb->get_var($wpdb->prepare("SELECT CONCAT(`post_type`, `ID`, ': ', `post_title`) FROM `$wpdb->posts` WHERE `ID` = %s", (INT) $ids[0])), ENT_NOQUOTES));
1798 else
1799 $js_file = GOTMLS_strip4java(GOTMLS_htmlspecialchars($file, ENT_NOQUOTES));
1800 $nonce_url = GOTMLS_set_nonce(__FUNCTION__."1811");
1801 if (count($ids) == 2 && is_numeric($ids[0])) {
1802 $encoded_file = (INT) $file;
1803 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.GOTMLS_strip4java(__("Examine Quarantined Content",'gotmls')).' ... </div><div style="overflow: hidden; position: relative; height: 20px;"><div style="position: absolute; right: 0px; text-align: right; width: 9000px;">'.$js_file).'</div></div>\');" href="'.GOTMLS_admin_url('GOTMLS_scan', $nonce_url.'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$encoded_file);
1804 } elseif ($file)
1805 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.GOTMLS_strip4java(__("Examine Current Content",'gotmls')).' ... </div><div style="overflow: hidden; position: relative; height: 20px;"><div style="position: absolute; right: 0px; text-align: right; width: 9000px;">'.$js_file).'</div></div>\');" href="'.GOTMLS_admin_url('GOTMLS_scan', $nonce_url.'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$encoded_file);
1806 else
1807 $onclick = 'return false;';
1808 return "<a id=\"list_$encoded_file\" title=\"$errorTXT\" target=\"GOTMLS_iFrame\" onclick=\"$onclick\" class=\"GOTMLS_plugin $class\">";
1809 }
1810
1811 function GOTMLS_check_file($file) {
1812 $filesize = @filesize($file);
1813 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checking ".GOTMLS_strip4java($file)." ($filesize bytes)';\n/*<!--*"."/";
1814 if ($filesize===false)
1815 echo GOTMLS_return_threat("errors", "blocked", $file, GOTMLS_error_link(__("Failed to determine file size!",'gotmls'), $file));
1816 elseif (($filesize==0) || ($filesize>((isset($_GET["eli"])&&is_numeric($_GET["eli"]))?$_GET["eli"]:2934567)))
1817 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file size!",'gotmls')." ($filesize bytes)", $file, "potential"));
1818 elseif (in_array(GOTMLS_get_ext($file), $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/(shim|social[0-9]*)\.png$/i', $file)))
1819 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file extention!",'gotmls'), $file, "potential"));
1820 else {
1821 try {
1822 echo @GOTMLS_scanfile($file);
1823 echo "//debug_fix:".$GLOBALS["GOTMLS"]["tmp"]["debug_fix"];
1824 } catch (Exception $e) {
1825 die("//Exception:".GOTMLS_strip4java($e));
1826 }
1827 }
1828 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checked ".GOTMLS_strip4java($file)."';\n/*<!--*"."/";
1829 }
1830
1831 function GOTMLS_read_error($path) {
1832 global $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1833 $error = error_get_last();
1834 if (!file_exists($path))
1835 return " (Path not found)";
1836 if (!is_readable($path) && isset($_GET["eli"]))
1837 $return = (@chmod($path, (is_dir($path)?$GOTMLS_chmod_dir:$GOTMLS_chmod_file))?"Fixed permissions":"error: ".preg_replace('/[\r\n]/', ' ', print_r($error,1)));
1838 else
1839 $return = (is_array($error) && isset($error["message"])?preg_replace('/[\r\n]/', ' ', print_r($error["message"],1)):"readable?");
1840 return " [".GOTMLS_fileperms($path)."] ( ".filesize($path)." $return)";
1841 }
1842
1843 function GOTMLS_scandir($dir) {
1844 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", GOTMLS_htmlspecialchars($dir))));
1845 GOTMLS_flush();
1846 $li_js = "/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1847 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
1848 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link("Directory Scan Depth set to 0, no files will be scanned!"));
1849 elseif (isset($_GET["GOTMLS_skip_dir"]) && $dir == GOTMLS_decode($_GET["GOTMLS_skip_dir"])) {
1850 if (isset($_GET["GOTMLS_only_file"]) && strlen($_GET["GOTMLS_only_file"]))
1851 echo GOTMLS_return_threat("errors", "blocked", GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"]), GOTMLS_error_link("Failed to read this file!".GOTMLS_read_error(GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"])), GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"])));
1852 else
1853 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(__("Failed to read directory!",'gotmls')).GOTMLS_read_error($dir));
1854 } else {
1855 $files = GOTMLS_getfiles($dir);
1856 if (is_array($files)) {
1857 if (isset($_GET["GOTMLS_only_file"])) {
1858 if (strlen($_GET["GOTMLS_only_file"])) {
1859 $path = GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"]);
1860 if (is_file($path)) {
1861 GOTMLS_check_file($path);
1862 echo GOTMLS_return_threat("dir", "checked", $path);
1863 }
1864 } else {
1865 foreach ($files as $file) {
1866 $path = GOTMLS_trailingslashit($dir).$file;
1867 if (is_file($path)) {
1868 $file_ext = GOTMLS_get_ext($file);
1869 $filesize = @filesize($path);
1870 if ((in_array($file_ext, $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/social[0-9]*\.png$/i', $file))) || ($filesize==0) || ($filesize>((isset($_GET["eli"])&&is_numeric($_GET["eli"]))?$_GET["eli"]:2934567)))
1871 echo GOTMLS_return_threat("skipped", "blocked", $path, GOTMLS_error_link(sprintf(__('Skipped because of file size (%1$s bytes) or file extention (%2$s)!','gotmls'), $filesize, $file_ext), $file, "potential"));
1872 else
1873 echo "/*-->*"."/\nscanfilesArKeys.push('".GOTMLS_encode($dir)."&GOTMLS_only_file=".GOTMLS_encode($file)."');\nscanfilesArNames.push('Re-Checking ".GOTMLS_strip4java($path)."');\n/*<!--*"."/".GOTMLS_return_threat("dirs", "wait", $path);
1874 } elseif (is_dir($path)) {
1875 echo "/*-->*"."/\n//sub-directory $path;\n/*<!--*"."/";
1876 }
1877 }
1878 echo GOTMLS_return_threat("dir", "question", $dir);
1879 }
1880 } else {
1881 foreach ($files as $file) {
1882 $path = GOTMLS_trailingslashit($dir).$file;
1883 if (is_file($path)) {
1884 if (isset($_GET["GOTMLS_skip_file"]) && is_array($_GET["GOTMLS_skip_file"]) && in_array($path, $_GET["GOTMLS_skip_file"])) {
1885 $li_js .= "/*-->*"."/\n//skipped $path;\n/*<!--*"."/";
1886 if ($_GET["GOTMLS_skip_file"][count($_GET["GOTMLS_skip_file"])-1] == $path)
1887 echo GOTMLS_return_threat("errors", "blocked", $path, GOTMLS_error_link(__("Failed to read file!",'gotmls'), $path));
1888 } else {
1889 GOTMLS_check_file($path);
1890 }
1891 } elseif (is_dir($path)) {
1892 $li_js .= "/*-->*"."/\n//sub-directory $path;\n/*<!--*"."/";
1893 }
1894 }
1895 echo GOTMLS_return_threat("dir", "checked", $dir);
1896 }
1897 } else
1898 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' scandir:'.($files===false?' (FALSE)':$files)));
1899 }
1900 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)));
1901 GOTMLS_update_scan_log(array("scan" => array("finish" => time())));
1902 return $li_js;
1903 }
1904
1905 function GOTMLS_safe_ip($ip) {
1906 return preg_replace('/[^0-9\.\:a-f]/i', "", $ip);
1907 }
1908
1909 function GOTMLS_safe_domain($domain) {
1910 return preg_replace('/[^a-z_0-9\-\~\+\.\?\#\/\:\@]/i', "", $domain);
1911 }
1912
1913 function GOTMLS_safe_url($url, $allow = array(' ', '%20')) {
1914 $all = implode("", array_keys($allow));
1915 $url = preg_replace('/[^a-z_0-9\-\~\+\.\?\#\/\:\@\%\$\|\*\(\)\[\]\=\!\&\;'.$all.']/i', "", $url);
1916 foreach ($allow as $al => $low)
1917 $url = str_replace($al, $low, ltrim($url));
1918 return $url;
1919 }
1920
1921 function GOTMLS_reset_settings($item, $key) {
1922 $key_parts = explode("_", $key."_");
1923 if (strlen($key_parts[0]) != 4 && $key_parts[0] != "exclude")
1924 unset($GLOBALS["GOTMLS"]["tmp"]["settings_array"][$key]);
1925 }
1926
1927 function GOTMLS_file_put_contents($file, $content) {
1928 global $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1929 $chmoded_file = false;
1930 $chmoded_dir = false;
1931 if ((is_dir(dirname($file)) || @mkdir(dirname($file), $GOTMLS_chmod_dir, true)) && !is_writable(dirname($file)) && ($GOTMLS_chmod_dir = @fileperms(dirname($file))))
1932 $chmoded_dir = @chmod(dirname($file), 0777);
1933 if (is_file($file) && !is_writable($file) && ($GOTMLS_chmod_file = @fileperms($file)))
1934 $chmoded_file = @chmod($file, 0666);
1935 if (function_exists("file_put_contents"))
1936 $return = @file_put_contents($file, $content);
1937 elseif ($fp = fopen($file, 'w')) {
1938 fwrite($fp, $content);
1939 fclose($fp);
1940 $return = true;
1941 } else
1942 $return = false;
1943 if ($chmoded_file)
1944 @chmod($file, $GOTMLS_chmod_file);
1945 if ($chmoded_dir)
1946 @chmod(dirname($file), $GOTMLS_chmod_dir);
1947 return $return;
1948 }
1949
1950 function GOTMLS_scan_log() {
1951 global $wpdb;
1952 if ($rs = $wpdb->get_row("SELECT substring_index(option_name, '/', -1) AS `mt`, option_name, option_value FROM `$wpdb->options` where option_name like 'GOTMLS_scan_log/%' ORDER BY mt DESC LIMIT 1", ARRAY_A))
1953 $GOTMLS_scan_log = (isset($rs["option_name"])?get_option($rs["option_name"], array()):array());
1954 $units = array("seconds"=>60,"minutes"=>60,"hours"=>24,"days"=>365,"years"=>10);
1955 if (isset($GOTMLS_scan_log["scan"]["start"]) && is_numeric($GOTMLS_scan_log["scan"]["start"])) {
1956 $time = (time() - $GOTMLS_scan_log["scan"]["start"]);
1957 $ukeys = array_keys($units);
1958 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
1959 $time = floor($time/$units[$ukeys[$key]]);
1960 if (1 == $time)
1961 $unit = substr($unit, 0, -1);
1962 $LastScan = "started $time $unit ago";
1963 if (isset($GOTMLS_scan_log["scan"]["finish"]) && is_numeric($GOTMLS_scan_log["scan"]["finish"]) && ($GOTMLS_scan_log["scan"]["finish"] >= $GOTMLS_scan_log["scan"]["start"])) {
1964 $time = ($GOTMLS_scan_log["scan"]["finish"] - $GOTMLS_scan_log["scan"]["start"]);
1965 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
1966 $time = floor($time/$units[$ukeys[$key]]);
1967 if (1 == $time)
1968 $unit = substr($unit, 0, -1);
1969 if ($time)
1970 $LastScan .= " and ran for $time $unit";
1971 else
1972 $LastScan = str_replace("started", "ran", $LastScan);
1973 } else
1974 $LastScan .= " and has not finish";
1975 if (!isset($_GET['Scanlog']))
1976 $LastScan .= '<a style="float: right;" href="'.admin_url('admin.php?page=GOTMLS_View_Quarantine&Scanlog').'">'.GOTMLS_View_Scan_Log_LANGUAGE.'</a><br style="clear: right;">';
1977 } else
1978 $LastScan = "never started ";
1979 return "Last ".(isset($GOTMLS_scan_log["scan"]["type"])?$GOTMLS_scan_log["scan"]["type"]:"Scan")." $LastScan";
1980 }
1981
1982 function GOTMLS_sanitize($unsanitized, $allow = 'a-zA-Z0-9\|\[\]\{\}<>\s\?\*\%\#\&\/=_\~\:;\.,\+-') {
1983 if (is_array($unsanitized)) {
1984 $sanitized = array();
1985 foreach ($unsanitized as $key => $val)
1986 $sanitized[preg_replace('/[^'.$allow.']/', '', $key)] = preg_replace('/[^'.$allow.']/', '', $val);
1987 } else
1988 $sanitized = preg_replace('/[^'.$allow.']/', '', $unsanitized);
1989 return $sanitized;
1990 }
1991
1992 function GOTMLS_get_URL($URL) {
1993 $response = "";
1994 $GLOBALS["GOTMLS"]["get_URL"] = get_option('GOTMLS_get_URL_array', array());
1995 $min = round($GLOBALS["GOTMLS"]["tmp"]["mt"]/60);
1996 if (is_array($GLOBALS["GOTMLS"]["get_URL"])) {
1997 foreach ($GLOBALS["GOTMLS"]["get_URL"] as $URI => $property)
1998 if (!(isset($property["time"]) && is_numeric($property["time"]) && ($property["time"] + 60) > $min))
1999 unset($GLOBALS["GOTMLS"]["get_URL"]["$URI"]);
2000 } else
2001 $GLOBALS["GOTMLS"]["get_URL"] = array();
2002 $URI = md5(preg_replace('/GOTMLS_mt[\[\]]*=[0-9a-f]*/i', "", $URL));
2003 if (isset($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"]) && strlen($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"])) {
2004 $method = "cached";
2005 $response = $GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"];
2006 } else {
2007 $GLOBALS["GOTMLS"]["get_URL"]["$URI"] = array("time" => $min);
2008 if (function_exists($method = "wp_remote_get")) {
2009 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = wp_remote_get($URL, array("sslverify" => false));
2010 if (200 == wp_remote_retrieve_response_code($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]))
2011 $response = wp_remote_retrieve_body($GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method]);
2012 }
2013 if (strlen($response) == 0 && function_exists($method = "curl_exec")) {
2014 $curl_hndl = curl_init();
2015 curl_setopt($curl_hndl, CURLOPT_URL, $URL);
2016 curl_setopt($curl_hndl, CURLOPT_TIMEOUT, 30);
2017 if (isset($_SERVER['HTTP_REFERER']))
2018 $SERVER_HTTP_REFERER = GOTMLS_safe_url($_SERVER['HTTP_REFERER']);
2019 elseif (isset($_SERVER['HTTP_HOST']))
2020 $SERVER_HTTP_REFERER = 'HOST://'.GOTMLS_safe_domain($_SERVER['HTTP_HOST']);
2021 elseif (isset($_SERVER['SERVER_NAME']))
2022 $SERVER_HTTP_REFERER = 'NAME://'.GOTMLS_safe_domain($_SERVER['SERVER_NAME']);
2023 elseif (isset($_SERVER['SERVER_ADDR']))
2024 $SERVER_HTTP_REFERER = 'ADDR://'.GOTMLS_safe_ip($_SERVER['SERVER_ADDR']);
2025 else
2026 $SERVER_HTTP_REFERER = 'NULL://not.anything.com';
2027 curl_setopt($curl_hndl, CURLOPT_REFERER, $SERVER_HTTP_REFERER);
2028 if (isset($_SERVER['HTTP_USER_AGENT']))
2029 curl_setopt($curl_hndl, CURLOPT_USERAGENT, GOTMLS_safe_url($_SERVER['HTTP_USER_AGENT'], array(' ', ' ')));
2030 curl_setopt($curl_hndl, CURLOPT_HEADER, 0);
2031 curl_setopt($curl_hndl, CURLOPT_RETURNTRANSFER, TRUE);
2032 if (!($response = curl_exec($curl_hndl)))
2033 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = curl_error($curl_hndl);
2034 curl_close($curl_hndl);
2035 }
2036 if (strlen($response) == 0 && function_exists($method = "file_get_contents")) {
2037 try {
2038 $response = @file_get_contents($URL).'';
2039 } catch(Exception $e) {
2040 $GLOBALS["GOTMLS"]["get_URL"]["$URI"][$method] = $e->getTrace();
2041 }
2042 }
2043 $GLOBALS["GOTMLS"]["get_URL"]["$URI"]["response"] = $response;
2044 update_option('GOTMLS_get_URL_array', $GLOBALS["GOTMLS"]["get_URL"], 'no');
2045 }
2046 if (isset($_GET["GOTMLS_debug"]) && (strlen($response) == 0 || $_GET["GOTMLS_debug"] == "GOTMLS_get_URL"))
2047 print_r(array("$method $URI:".strlen($response)=>htmlspecialchars($GLOBALS["GOTMLS"]["get_URL"]["$URI"]["time"]." ~ $min: ".count($GLOBALS["GOTMLS"]["get_URL"]))));
2048 return $response;
2049 }
2050