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