PluginProbe ʕ •ᴥ•ʔ
Anti-Malware Security and Brute-Force Firewall / 4.18.63
Anti-Malware Security and Brute-Force Firewall v4.18.63
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 7 years ago question.gif 13 years ago threat.gif 13 years ago wait.gif 14 years ago
index.php
1345 lines
1 <?php
2 /**
3 * GOTMLS Plugin Global Variables and Functions
4 * @package GOTMLS
5 */
6
7 if (!function_exists("GOTMLS_define")) {
8 function GOTMLS_define($DEF, $val) {
9 if (!defined($DEF))
10 define($DEF, $val);
11 }}
12
13 $file = basename(__FILE__);
14 GOTMLS_define("GOTMLS_local_images_path", substr(__FILE__, 0, strlen(__FILE__) - strlen($file)));
15 GOTMLS_define("GOTMLS_plugin_path", substr(dirname(__FILE__), 0, strlen(dirname(__FILE__)) - strlen(basename(dirname(__FILE__)))));
16 if (is_file(GOTMLS_plugin_path.$file) && ($contents = @file_get_contents(GOTMLS_plugin_path.$file)) && preg_match('/\nversion:\s*([0-9\.]+)/i', $contents, $match))
17 GOTMLS_define("GOTMLS_Version", $match[1]);
18 else
19 GOTMLS_define("GOTMLS_Version", "Unknown");
20 GOTMLS_define("GOTMLS_require_version", "3.3");
21 if (isset($wp_version) && ($wp_version))
22 GOTMLS_define("GOTMLS_wp_version", $wp_version);
23 if (!function_exists("__")) {
24 function __($text, $domain = "gotmls") {
25 return $text;
26 }}
27
28 function GOTMLS_htmlentities($TXT, $flags = ENT_COMPAT, $encoding = "UTF-8") {
29 $prelen = strlen($TXT);
30 if ($prelen == 0)
31 return "";
32 $encoded = htmlentities($TXT, $flags, $encoding);
33 if (strlen($encoded) == 0) {
34 $encoding = "ISO-8859-1";
35 $encoded = htmlentities($TXT, $flags, $encoding);
36 }
37 if (strlen($encoded) == 0)
38 $encoded = __("Failed to encode HTML entities!",'gotmls');
39 $GLOBALS["GOTMLS"]["tmp"]["encoding"] = $encoding;
40 return $encoded;
41 }
42
43 function GOTMLS_htmlspecialchars($TXT, $flags = ENT_COMPAT, $encoding = "UTF-8") {
44 $prelen = strlen($TXT);
45 if ($prelen == 0)
46 return "";
47 $encoded = htmlspecialchars($TXT, $flags, $encoding);
48 if (strlen($encoded) == 0) {
49 $encoding = "ISO-8859-1";
50 $encoded = htmlspecialchars($TXT, $flags, $encoding);
51 }
52 if (strlen($encoded) == 0)
53 $encoded = __("Failed to encode HTML characters!",'gotmls');
54 $GLOBALS["GOTMLS"]["tmp"]["encoding"] = $encoding;
55 return $encoded;
56 }
57
58 $bad = array("eval", "preg_replace", "auth_pass");
59 $GLOBALS["GOTMLS"] = array(
60 "tmp"=>array("HeadersError"=>"", "onLoad"=>"", "file_contents"=>"", "new_contents"=>"", "threats_found"=>array(),
61 "skip_dirs" => array(".", ".."), "scanfiles" => array(), "nonce"=>array(),
62 "mt" => ((isset($_REQUEST["mt"])&&is_numeric($_REQUEST["mt"]))?$_REQUEST["mt"]:microtime(true)),
63 "threat_files" => array("htaccess"=>".htaccess","timthumb"=>"thumb.php"),
64 "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"),
65 "apache" => array(),
66 "skip_ext"=>array("png", "jpg", "jpeg", "gif", "bmp", "tif", "tiff", "psd", "svg", "doc", "docx", "ttf", "fla", "flv", "mov", "mp3", "pdf", "css", "pot", "po", "mo", "so", "exe", "zip", "7z", "gz", "rar"),
67 "execution_time" => 60,
68 "default" => array("msg_position" => array("80px", "40px", "400px", "600px")),
69 "Definition" => array("Default" => "CCIGG"),
70 "definitions_array" => array(
71 "potential"=>array(
72 $bad[0]=>array("CCIGG", "/[^a-z_\\/'\"]".$bad[0]."\\(.+\\)+\\s*;/i"),
73 $bad[1]." /e"=>array("CCIGG", "/".$bad[1]."[\\s*\\(]+(['\"])([\\!\\/\\#\\|\\@\\%\\^\\*\\~]).+?\\2[imsx]*e[imsx]*\\1\\s*,[^,]+,[^\\)]+[\\);\\s]+/i"),
74 $bad[2]=>array("CCIGG", "/\\\$".$bad[2]."\\s*=.+;/i"),
75 "function add_action wp_enqueue_script json2"=>array("CCIGG", "/json2\\.min\\.js/i"),
76 "Tagged Code"=>array("CCIGG", "/\\#(\\w+)\\#.+?\\#\\/\\1\\#/is"),
77 "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")),
78 )
79 )
80 );
81 if (isset($_SERVER["HTTP_HOST"]))
82 $SERVER_HTTP = 'HOST://'.$_SERVER["HTTP_HOST"];
83 elseif (isset($_SERVER["SERVER_NAME"]))
84 $SERVER_HTTP = 'NAME://'.$_SERVER["SERVER_NAME"];
85 elseif (isset($_SERVER["SERVER_ADDR"]))
86 $SERVER_HTTP = 'ADDR://'.$_SERVER["SERVER_ADDR"];
87 else
88 $SERVER_HTTP = "NULL://not.anything.com";
89 if (isset($_SERVER["SERVER_PORT"]) && $_SERVER["SERVER_PORT"])
90 $SERVER_HTTP .= ":".$_SERVER["SERVER_PORT"];
91 $SERVER_parts = explode(":", $SERVER_HTTP.":");
92 if ((isset($_SERVER["HTTPS"]) && ($_SERVER["HTTPS"] == "on" || $_SERVER["HTTPS"] == 1)) || (count($SERVER_parts) > 2 && $SERVER_parts[2] == "443"))
93 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "https:";
94 else
95 $GLOBALS["GOTMLS"]["tmp"]["protocol"] = "http:";
96 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"]);
97 GOTMLS_define("GOTMLS_plugin_home", $GLOBALS["GOTMLS"]["tmp"]["protocol"]."//gotmls.net/");
98
99 if (!function_exists("GOTMLS_encode")) {
100 function GOTMLS_encode($unencoded_string) {
101 if (function_exists("base64_encode"))
102 $encoded_string = base64_encode($unencoded_string);
103 elseif (function_exists("mb_convert_encoding"))
104 $encoded_string = mb_convert_encoding($unencoded_string, "BASE64", "UTF-8");
105 else
106 $encoded_string = "Cannot encode: $unencoded_string function_exists: ";
107 $encoded_array = explode("=", $encoded_string."=");
108 return strtr($encoded_array[0], "+/0", "-_=").(count($encoded_array)-1);
109 }}
110
111 if (!function_exists("GOTMLS_decode")) {
112 function GOTMLS_decode($encoded_string) {
113 $tail = 0;
114 if (strlen($encoded_string) > 1 && is_numeric(substr($encoded_string, -1)) && substr($encoded_string, -1) > 0)
115 $tail = substr($encoded_string, -1) - 1;
116 else
117 $encoded_string .= "$tail";
118 $encoded_string = strtr(substr($encoded_string, 0, -1), "-_=", "+/0").str_repeat("=", $tail);
119 if (function_exists("base64_decode"))
120 return base64_decode($encoded_string);
121 elseif (function_exists("mb_convert_encoding"))
122 return mb_convert_encoding($encoded_string, "UTF-8", "BASE64");
123 else
124 return "Cannot decode: $encoded_string";
125 }}
126
127 GOTMLS_define("GOTMLS_Failed_to_list_LANGUAGE", __("Failed to list files in directory!",'gotmls'));
128 GOTMLS_define("GOTMLS_Run_Quick_Scan_LANGUAGE", __("Quick Scan",'gotmls'));
129 GOTMLS_define("GOTMLS_View_Quarantine_LANGUAGE", __("View Quarantine",'gotmls'));
130 GOTMLS_define("GOTMLS_View_Scan_Log_LANGUAGE", __("View Scan Log",'gotmls'));
131 GOTMLS_define("GOTMLS_require_version_LANGUAGE", sprintf(__("This Plugin requires WordPress version %s or higher",'gotmls'), GOTMLS_require_version));
132 GOTMLS_define("GOTMLS_Scan_Settings_LANGUAGE", __("Scan Settings",'gotmls'));
133 GOTMLS_define("GOTMLS_Loading_LANGUAGE", __("Loading, Please Wait ...",'gotmls'));
134 GOTMLS_define("GOTMLS_Automatically_Fix_LANGUAGE", __("Automatically Fix SELECTED Files Now",'gotmls'));
135
136 if (!defined("ABSPATH")) {
137 define("ABSPATH", dirname(dirname(__FILE__)).'/safe-load/');
138 $root_path = dirname(ABSPATH);
139 while (strlen($root_path) > 1 && !is_file($root_path."/wp-config.php"))
140 $root_path = dirname($root_path);
141 if (is_file($root_path."/wp-config.php"))
142 include_once($root_path."/wp-config.php");
143 else
144 die("No wp-config!");
145 }
146
147 function GOTMLS_update_option($index, $value = array()) {
148 return update_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($value)));
149 }
150
151 function GOTMLS_get_option($index, $value = array()) {
152 if (is_array($tmp = get_option('GOTMLS_'.$index.'_array', array())) && count($tmp)) {
153 GOTMLS_update_option($index, $tmp);
154 delete_option('GOTMLS_'.$index.'_array');
155 } else
156 $tmp = $value;
157 return unserialize(GOTMLS_decode(get_option('GOTMLS_'.$index.'_blob', GOTMLS_encode(serialize($tmp)))));
158 }
159
160 $GOTMLS_chmod_file = (0644);
161 $GOTMLS_chmod_dir = (0755);
162 $GLOBALS["GOTMLS"]["tmp"]["nonce"] = get_option('GOTMLS_nonce_array', array());
163 $GLOBALS["GOTMLS"]["tmp"]["settings_array"] = get_option('GOTMLS_settings_array', array());
164 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"] = GOTMLS_get_option('definitions', $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]);
165 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])."/"));
166 $GLOBALS["GOTMLS"]["log"] = get_option('GOTMLS_scan_log/'.(isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:"0.0.0.0").'/'.$GLOBALS["GOTMLS"]["tmp"]["mt"], array());
167 if (!(isset($GLOBALS["GOTMLS"]["log"]["settings"]) && is_array($GLOBALS["GOTMLS"]["log"]["settings"])))
168 $GLOBALS["GOTMLS"]["log"]["settings"] = $GLOBALS["GOTMLS"]["tmp"]["settings_array"];
169
170 GOTMLS_define("GOTMLS_installation_key", md5(GOTMLS_siteurl));
171 GOTMLS_define("GOTMLS_update_home", "//updates.gotmls.net/".GOTMLS_installation_key."/");
172
173 if (!function_exists("GOTMLS_Invalid_Nonce")) {
174 function GOTMLS_Invalid_Nonce($pre = "//Error: ") {
175 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"]])?$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]:" !found"):" !len(".strlen($_REQUEST["GOTMLS_mt"]).")")):" GOTMLS_mt !set");
176 }}
177
178 if (!function_exists("GOTMLS_set_nonce")) {
179 function GOTMLS_set_nonce($context = "NULL") {
180 $hour = round(($GLOBALS["GOTMLS"]["tmp"]["mt"]/60)/60);
181 $transient_name = md5(GOTMLS_installation_key.GOTMLS_plugin_path.$hour);
182 foreach ($GLOBALS["GOTMLS"]["tmp"]["nonce"] as $nonce_key => $nonce_value)
183 if (($nonce_value > $hour) || (($nonce_value + 24) < $hour))
184 unset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$nonce_key]);
185 if (!isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name])) {
186 $GLOBALS["GOTMLS"]["tmp"]["nonce"][$transient_name] = $hour;
187 if (!update_option('GOTMLS_nonce_array', $GLOBALS["GOTMLS"]["tmp"]["nonce"]))
188 return ("$context=DB-err:".preg_replace('/[\r\n]+/', " ", GOTMLS_htmlspecialchars(print_r($GLOBALS["GOTMLS"]["tmp"]["nonce"],1).$wpdb->last_error)));
189 }
190 return 'GOTMLS_mt='.$transient_name;
191 }}
192
193 if (!function_exists("GOTMLS_get_nonce")) {
194 function GOTMLS_get_nonce() {
195 if (isset($_REQUEST["GOTMLS_mt"])) {
196 if (is_array($_REQUEST["GOTMLS_mt"])) {
197 foreach ($_REQUEST["GOTMLS_mt"] as $_REQUEST_GOTMLS_mt)
198 if (strlen($_REQUEST_GOTMLS_mt) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST_GOTMLS_mt]))
199 return $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST_GOTMLS_mt];
200 return 0;
201 } elseif (strlen($_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]]))
202 return $GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]];
203 else
204 return "";
205 } else
206 return false;
207 }}
208
209 function GOTMLS_fileperms($file) {
210 if ($prm = @fileperms($file)) {
211 if (($prm & 0xC000) == 0xC000)
212 $ret = "s";
213 elseif (($prm & 0xA000) == 0xA000)
214 $ret = "l";
215 elseif (($prm & 0x8000) == 0x8000)
216 $ret = "-";
217 elseif (($prm & 0x6000) == 0x6000)
218 $ret = "b";
219 elseif (($prm & 0x4000) == 0x4000)
220 $ret = "d";
221 elseif (($prm & 0x2000) == 0x2000)
222 $ret = "c";
223 elseif (($prm & 0x1000) == 0x1000)
224 $ret = "p";
225 else
226 $ret = "u";
227 $ret .= (($prm & 0x0100)?"r":"-").(($prm & 0x0080)?"w":"-");
228 $ret .= (($prm & 0x0040)?(($prm & 0x0800)?"s":"x" ):(($prm & 0x0800)?"S":"-"));
229 $ret .= (($prm & 0x0020)?"r":"-").(($prm & 0x0010)?"w":"-");
230 $ret .= (($prm & 0x0008)?(($prm & 0x0400)?"s":"x" ):(($prm & 0x0400)?"S":"-"));
231 $ret .= (($prm & 0x0004)?"r":"-").(($prm & 0x0002)?"w":"-");
232 $ret .= (($prm & 0x0001)?(($prm & 0x0200)?"t":"x" ):(($prm & 0x0200)?"T":"-"));
233 return $ret;
234 } else
235 return "stat failed!";
236 }
237
238 function GOTMLS_file_details($file) {
239 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:'.date(" Y-m-d H:i:s ", filemtime(realpath($file))).'<br />changed:'.date(" Y-m-d H:i:s ", filectime(realpath($file))).'</div>';
240 }
241
242 if (isset($_GET["SESSION"]) && is_numeric($_GET["SESSION"]) && preg_match('|(.*?/gotmls\.js\?SESSION=)|', GOTMLS_script_URI, $match)) {
243 header("Content-type: text/javascript");
244 if (is_file(GOTMLS_plugin_path."safe-load/session.php"))
245 require_once(GOTMLS_plugin_path."safe-load/session.php");
246 if (isset($_SESSION["GOTMLS_SESSION_TEST"]))
247 die("/* GOTMLS SESSION PASS */\nif('undefined' != typeof stopCheckingSession && stopCheckingSession)\n\tclearTimeout(stopCheckingSession);\nshowhide('GOTMLS_patch_searching', true);\nif (autoUpdateDownloadGIF = document.getElementById('autoUpdateDownload'))\n\tdonationAmount = autoUpdateDownloadGIF.src.replace(/^.+\?/,'');\nif ((autoUpdateDownloadGIF.src == donationAmount) || donationAmount=='0') {\n\tif (patch_searching_div = document.getElementById('GOTMLS_patch_searching')) {\n\t\tif (autoUpdateDownloadGIF.src == donationAmount)\n\t\t\tpatch_searching_div.innerHTML = '<span style=\"color: #F00;\">".__("You must register and donate to use this feature!",'gotmls')."</span>';\n\t\telse\n\t\t\tpatch_searching_div.innerHTML = '<span style=\"color: #F00;\">".__("This feature is available to those who have donated!",'gotmls')."</span>';\n\t}\n} else {\n\tshowhide('GOTMLS_patch_searching');\n\tshowhide('GOTMLS_patch_button', true);\n}\n");
248 else {
249 $_SESSION["GOTMLS_SESSION_TEST"] = $_GET["SESSION"] + 1;
250 if ($_GET["SESSION"] > 0)
251 die("/* GOTMLS SESSION FAIL */\nif('undefined' != typeof stopCheckingSession && stopCheckingSession)\n\tclearTimeout(stopCheckingSession);\ndocument.getElementById('GOTMLS_patch_searching').innerHTML = '<div class=\"error\">".__("Your Server could not start a Session!",'gotmls')."</div>';");
252 else
253 die("/* GOTMLS SESSION TEST */\nif('undefined' != typeof stopCheckingSession && stopCheckingSession)\n\tclearTimeout(stopCheckingSession);\nstopCheckingSession = checkupdateserver('".$match[0].$_SESSION["GOTMLS_SESSION_TEST"]."', 'GOTMLS_patch_searching');");
254 }
255 } elseif ((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__)))) {
256 if (isset($_GET["page"]) && $_GET["page"] == "GOTMLS-View-Quarantine" && isset($_REQUEST["GOTMLS_mt"]) && strlen($_REQUEST["GOTMLS_mt"]) == 32 && isset($GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]])) {
257 $return = (print_r( array("nonce"=>$GLOBALS["GOTMLS"]["tmp"]["nonce"][$_REQUEST["GOTMLS_mt"]],"mt"=>($_REQUEST["GOTMLS_mt"])),1));
258 try {
259 $Q_Paged = '<form method="POST" name="GOTMLS_Form_page"><input type="hidden" id="GOTMLS_paged" name="paged" value="1">';//<div style="float: left;">Page:</div>';
260 $Q_Page = '
261 <style>
262 #found_Quarantine {
263 line-height: 1.4em;
264 font-size: 13px;
265 }
266 #GOTMLS-right-sidebar {float: right; margin-right: 0px;}
267 span.GOTMLS_date {float: right; width: 135px; white-space: nowrap; font-size: 11px;}
268 .GOTMLS_page {float: left; border-radius: 10px; padding: 0 5px;}
269 .GOTMLS_quarantine_item {margin: 4px 12px;}
270 .rounded-corners {margin: 10px; border-radius: 10px; -moz-border-radius: 10px; -webkit-border-radius: 10px; border: 1px solid #000;}
271 .shadowed-box {box-shadow: -3px 3px 3px #666; -moz-box-shadow: -3px 3px 3px #666; -webkit-box-shadow: -3px 3px 3px #666;}
272 .sidebar-box {background-color: #CCC;}
273 .GOTMLS-scanlog li a {display: none;}
274 .GOTMLS-scanlog li:hover a {display: block;}
275 .GOTMLS-sidebar-links {list-style: none;}
276 .GOTMLS-sidebar-links li img {margin: 3px; height: 16px; vertical-align: middle;}
277 .GOTMLS-sidebar-links li {margin-bottom: 0 !important;}
278 .popup-box {background-color: #FFC; display: none; position: absolute; left: 0px; z-index: 10;}
279 .shadowed-text {text-shadow: #00F -1px 1px 1px;}
280 .sub-option {float: left; margin: 3px 5px;}
281 .inside p {margin: 10px;}
282 .GOTMLS_li, .GOTMLS_plugin li {list-style: none;}
283 .GOTMLS_plugin {margin: 5px; background: #cfc; border: 1px solid #0C0; padding: 0 5px; border-radius: 3px;}
284 .GOTMLS_plugin.disabled, .GOTMLS_plugin.read-only {background: #9f9; border: 1px solid #0f0;}
285 .GOTMLS_plugin.known, .GOTMLS_plugin.db_scan, .GOTMLS_plugin.htaccess, .GOTMLS_plugin.timthumb, .GOTMLS_plugin.errors {background: #f99; border: 1px solid #f00;}
286 .GOTMLS_plugin.potential, .GOTMLS_plugin.wp_core, .GOTMLS_plugin.skipdirs, .GOTMLS_plugin.skipped {background: #ffc; border: 1px solid #fc6;}
287 .GOTMLS ul li {margin-left: 12px;}
288 .GOTMLS h2 {margin: 0 0 10px;}
289 .postbox {margin-right: 10px;}
290 #pastDonations li {list-style: none;}
291 #quarantine_buttons {float: right;}//position: absolute; right: 0px; top: -54px; margin: 0px; padding: 0px;}
292 #quarantine_buttons input.button-primary {margin-right: 20px;}
293 #main-page-title {
294 background: url("//gravatar.com/avatar/5feb789dd3a292d563fea3b885f786d6?s=64") no-repeat scroll 0 0 transparent;
295 height: 64px;
296 line-height: 58px;
297 margin: 10px 0 0 0;
298 max-width: 600px;
299 padding: 0 110px 0 84px;
300 }
301 #main-page-title h1 {
302 background: url("//gravatar.com/avatar/8151cac22b3fc543d099241fd573d176?s=64") no-repeat scroll top right transparent;
303 height: 64px;
304 line-height: 32px;
305 margin: 0;
306 padding: 0 84px 0 0;
307 display: table-cell;
308 text-align: center;
309 vertical-align: middle;
310 }
311 </style>
312 <script type="text/javascript">
313 function showhide(id) {
314 divx = document.getElementById(id);
315 if (divx) {
316 if (divx.style.display == "none" || arguments[1]) {
317 divx.style.display = "block";
318 divx.parentNode.className = (divx.parentNode.className+"close").replace(/close/gi,"");
319 return true;
320 } else {
321 divx.style.display = "none";
322 return false;
323 }
324 }
325 }
326 function checkAllFiles(check) {
327 var checkboxes = new Array();
328 checkboxes = document["GOTMLS_Form_clean"].getElementsByTagName("input");
329 for (var i=0; i<checkboxes.length; i++)
330 if (checkboxes[i].type == "checkbox")
331 checkboxes[i].checked = check;
332 }
333 </script>
334 <form method="POST" action="?'.(isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?$_SERVER["QUERY_STRING"]:"page=GOTMLS-View-Quarantine&".GOTMLS_set_nonce(__FUNCTION__."256")).'" target="GOTMLS_iFrame" name="GOTMLS_Form_clean">';
335 if (isset($_REQUEST["id"]) && is_numeric($_REQUEST["id"])) {
336 $my_query = $wpdb->get_results("SELECT * FROM `{$table_prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private' AND `ID` = ".$_REQUEST["id"], ARRAY_A);
337 if (is_array($my_query) && count($my_query) && ($Q_post = $my_query[0]) && isset($Q_post["post_type"]) && $Q_post["post_type"] == "GOTMLS_quarantine" && isset($Q_post["post_status"]) && $Q_post["post_status"] == "private") {
338 $clean_file = $Q_post["post_title"];
339 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = GOTMLS_decode($Q_post["post_content"]);
340 $fa = "";
341 if (isset($Q_post["post_excerpt"]) && strlen($Q_post["post_excerpt"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"] = @unserialize(GOTMLS_decode($Q_post["post_excerpt"])))) {
342 $f = 1;
343 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
344 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
345 if (strlen($end) > 0 && is_numeric($start) && is_numeric($end)) {
346 if ($start < $end)
347 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
348 else
349 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$end.', '.$start.');">['.$f++.']</a>';
350 } else {
351 if (is_numeric($threats_found)) {
352 $threats_found = $threats_name;
353 $threats_name = $f;
354 }
355 $fpos = 0;
356 $flen = 0;
357 $potential_threat = str_replace("\r", "", $threats_found);
358 while (($fpos = strpos(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"]), ($potential_threat), $flen + $fpos)) !== false) {
359 $flen = strlen($potential_threat);
360 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.($fpos).', '.($fpos + $flen).');">['.$f++.']</a>';
361 }
362 }
363 }
364 }
365 die("\n".'<script type="text/javascript">
366 function select_text_range(ta_id, start, end) {
367 var textBox = document.getElementById(ta_id);
368 var scrolledText = "";
369 scrolledText = textBox.value.substring(0, end);
370 textBox.focus();
371 if (textBox.setSelectionRange) {
372 scrolledText = textBox.value.substring(end);
373 textBox.value = textBox.value.substring(0, end);
374 textBox.scrollTop = textBox.scrollHeight;
375 textBox.value = textBox.value + scrolledText;
376 textBox.setSelectionRange(start, end);
377 } else if (textBox.createTextRange) {
378 var range = textBox.createTextRange();
379 range.collapse(true);
380 range.moveStart("character", start);
381 range.moveEnd("character", end);
382 range.select();
383 } else
384 alert("The highlighting function does not work in your browser");
385 }
386 </script><table style="top: 0px; left: 0px; width: 100%; height: 100%; position: absolute;"><tr><td style="width: 100%"><form style="margin: 0;" method="post" action="?'.GOTMLS_set_nonce(__FUNCTION__."1522").'&page=GOTMLS-View-Quarantine" onsubmit="return confirm(\''.__("Are you sure you want to restore this file from the quarantine?",'gotmls').'\');"><input type="hidden" name="id[]" value="'.$Q_post["ID"].'"><input type="submit" value="RESTORE from Quarantine" style="display: none; background-color: #0C0; float: right;"></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>File 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 />infected:'.$Q_post["post_modified_gmt"].'<br />quarantined:'.$Q_post["post_date_gmt"].'</div><div style="overflow: auto;"><span onmouseover="document.getElementById(\'fileperms\').style.display=\'block\';" onmouseout="document.getElementById(\'fileperms\').style.display=\'none\';">'.__("File 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>');
387 } else
388 die('<h3>Item NOT Found in Quarantine</h3>');
389 } else {
390 $my_query = $wpdb->get_results("SELECT * FROM `{$table_prefix}posts` WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private' ORDER BY `post_date_gmt` DESC", ARRAY_A);
391 if (is_array($my_query) && count($my_query)) {
392 $Q_Page .= '<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>
393 <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>';
394 $root_path = implode(GOTMLS_slash(), array_slice(GOTMLS_explode_dir(__FILE__), 0, (2 + intval($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_level"])) * -1));
395 foreach ($my_query as $post_a) {
396 $restored = "";
397 $image = "blocked";
398 if (isset($_REQUEST["id"]) && is_array($_REQUEST["id"]) && in_array($post_a["ID"], $_REQUEST["id"])) {
399 $restored = " read-only disabled";
400 if (GOTMLS_file_put_contents($post_a["post_title"], GOTMLS_decode($post_a["post_content"]))) {
401 $post_a["post_modified_gmt"] = date("Y-m-d H:i:s");
402 $image = "checked";
403 $wpdb->query("UPDATE `{$table_prefix}posts` SET `post_status` = 'pending' WHERE `post_type` = 'GOTMLS_quarantine' AND `post_status` = 'private' AND `ID` = ".$post_a["ID"]);
404 }
405 }
406 $Q_Page .= '
407 <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__."191").'" title="View Quarantined File">'.str_replace($root_path, "...", $post_a["post_title"])."</a></li>\n";
408 }
409 $Q_Page .= "\n</ul>";
410 for ($p = 1; $p <= 0; $p++) {
411 $Q_Paged .= '<input class="GOTMLS_page" type="submit" value="'.$p.'"'.((isset($_POST["paged"]) && $_POST["paged"] == $p) || (!isset($_POST["paged"]) && 1 == $p)?" DISABLED":"").' onclick="document.getElementById(\'GOTMLS_paged\').value = \''.$p.'\';">';
412 }
413 } else
414 $Q_Page .= '<h3>'.__("No Items in Quarantine",'gotmls').'</h3>';
415 $return = "$Q_Paged\n</form><br style=\"clear: left;\" />\n$Q_Page\n</form>\n$Q_Paged\n</form><br style=\"clear: left;\" />\n";
416 die("$return");
417 }
418 } catch (Exception $e) {
419 die('Caught exception: '. $e->getMessage(). "\n");
420 }
421 } else {
422 header("Content-type: image/gif");
423 $img_src = GOTMLS_local_images_path.'GOTMLS-16x16.gif';
424 if (!(file_exists($img_src) && $img_bin = @file_get_contents($img_src)))
425 $img_bin = GOTMLS_decode('R=lGODlhEAAQAIABAAAAAP___yH5BAEAAAEALAAAAAAQABAAAAIshB=Qm-eo2HuJNWdrjlFm3S2hKB7kViKaxZmr98YgSo_jzH6tiU=974MADwUAOw2');
426 die($img_bin);
427 }
428 } elseif (isset($_GET["no_error_reporting"]))
429 @error_reporting(0);
430
431 if (function_exists("plugins_url"))
432 GOTMLS_define("GOTMLS_images_path", plugins_url('/', __FILE__));
433 elseif (function_exists("plugin_dir_url"))
434 GOTMLS_define("GOTMLS_images_path", plugin_dir_url(__FILE__));
435 elseif (isset($_SERVER["DOCUMENT_ROOT"]) && ($_SERVER["DOCUMENT_ROOT"]) && strlen($_SERVER["DOCUMENT_ROOT"]) < __FILE__ && substr(__FILE__, 0, strlen($_SERVER["DOCUMENT_ROOT"])) == $_SERVER["DOCUMENT_ROOT"])
436 GOTMLS_define("GOTMLS_images_path", substr(dirname(__FILE__), strlen($_SERVER["DOCUMENT_ROOT"])));
437 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"])
438 GOTMLS_define("GOTMLS_images_path", substr(dirname($_SERVER["SCRIPT_FILENAME"]), strlen($_SERVER["DOCUMENT_ROOT"])));
439 else
440 GOTMLS_define("GOTMLS_images_path", "/wp-content/plugins/update/images/");
441
442 $GOTMLS_image_alt = array("wait"=>"...", "checked"=>"&#x2714;", "blocked"=>"X", "question"=>"?", "threat"=>"!");
443 $GOTMLS_dir_at_depth = array();
444 $GOTMLS_dirs_at_depth = array();
445 $GLOBAL_STRING = array("REQUEST" => "&","SERVER" => "&","FILES" => "&");
446 if (isset($_REQUEST) && is_array($_REQUEST))
447 foreach ($_REQUEST as $req => $val)
448 $GLOBAL_STRING["REQUEST"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
449 if (isset($_SERVER) && is_array($_SERVER))
450 foreach ($_SERVER as $req => $val)
451 $GLOBAL_STRING["SERVER"] .= "$req=".(is_array($val)?print_r($val,1):$val)."&";
452 if (isset($_FILES) && is_array($_FILES))
453 foreach ($_FILES as $req => $fila)
454 foreach (array("tmp_name","name") as $val)
455 if (isset($fila["$val"]))
456 $GLOBAL_STRING["FILES"] .= "$req.$val=".(is_array($fila["$val"])?print_r($fila["$val"],1):$fila["$val"])."&";
457 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]) && array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"])))
458 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] = array(
459 "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'),
460 "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", '/=[\s\/]*\.\.\//'),
461 "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\&/'));
462 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"] as $TP => $VA) {
463 $V = 3;
464 if (is_array($VA) && count($VA) > $V && is_array($VA[$V])) {
465 foreach ($VA[$V] as $reg => $arr) {
466 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $arr;
467 $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V++] = $reg;
468 }
469 }
470 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"]) && $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["firewall"]["$TP"])) {
471 $GLOBALS["GOTMLS"]["detected_attacks"] = "&attack[]=FW_$TP";
472 for ($V = 4; isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V]); $V+=2)
473 if (!isset($GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]]))
474 die($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]." [$V] not in <pre>".GOTMLS_htmlspecialchars(print_r($GLOBAL_STRING,1))."</pre>");
475 elseif (!preg_match($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V], $GLOBAL_STRING[$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["firewall"]["$TP"][$V-1]], $matches))
476 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
477 if ($GLOBALS["GOTMLS"]["detected_attacks"])
478 include(dirname(dirname(__FILE__))."/safe-load/index.php");
479 }
480 }
481 $GLOBALS["GOTMLS"]["detected_attacks"] = "";
482 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))
483 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["msg_position"] = $GLOBALS["GOTMLS"]["tmp"]["default"]["msg_position"];
484 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"]))
485 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_what"] = 2;
486 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"]))
487 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["scan_depth"] = -1;
488 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"])))
489 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_ext"] = $GLOBALS["GOTMLS"]["tmp"]["skip_ext"];
490 if (!isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"]))
491 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["check_custom"] = "";
492 if (!(isset($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"])))
493 $GLOBALS["GOTMLS"]["tmp"]["settings_array"]["exclude_dir"] = array();
494 $GOTMLS_total_percent = 0;
495 function GOTMLS_admin_notices() {
496 if (!is_admin())
497 return;
498 elseif ($GLOBALS["GOTMLS"]["tmp"]["HeadersError"])
499 echo $GLOBALS["GOTMLS"]["tmp"]["HeadersError"];
500 }
501
502 function GOTMLS_array_recurse($array1, $array2) {
503 foreach ($array2 as $key => $value) {
504 if (!isset($array1[$key]) || (isset($array1[$key]) && !is_array($array1[$key])))
505 $array1[$key] = array();
506 if (is_array($value))
507 $value = GOTMLS_array_recurse($array1[$key], $value);
508 $array1[$key] = $value;
509 }
510 return $array1;
511 }
512
513 function GOTMLS_array_replace($array1, $array2) {
514 foreach ($array2 as $key => $value)
515 $array1[$key] = $value;
516 return $array1;
517 }
518
519 function GOTMLS_array_replace_recursive($array1 = array()) {
520 $args = func_get_args();
521 $array1 = $args[0];
522 if (!is_array($array1))
523 $array1 = array();
524 for ($i = 1; $i < count($args); $i++)
525 if (is_array($args[$i]))
526 $array1 = GOTMLS_array_recurse($array1, $args[$i]);
527 return $array1;
528 }
529
530 function GOTMLS_update_scan_log($scan_log) {
531 if (is_array($scan_log)) {
532 $GLOBALS["GOTMLS"]["log"] = GOTMLS_array_replace_recursive($GLOBALS["GOTMLS"]["log"], $scan_log);
533 if (isset($GLOBALS["GOTMLS"]["log"]["scan"]["percent"]) && is_numeric($GLOBALS["GOTMLS"]["log"]["scan"]["percent"]) && ($GLOBALS["GOTMLS"]["log"]["scan"]["percent"] >= 100))
534 $GLOBALS["GOTMLS"]["log"]["scan"]["finish"] = time();
535 if (isset($GLOBALS["GOTMLS"]["log"]["scan"]))
536 update_option("GOTMLS_scan_log/".(isset($_SERVER["REMOTE_ADDR"])?$_SERVER["REMOTE_ADDR"]:"0.0.0.0")."/".$GLOBALS["GOTMLS"]["tmp"]["mt"], $GLOBALS["GOTMLS"]["log"]);
537 }
538 }
539
540 function GOTMLS_loaded() {
541 if (headers_sent($filename, $linenum)) {
542 if (!$filename)
543 $filename = __("an unknown file",'gotmls');
544 if (!is_numeric($linenum))
545 $linenum = __("unknown",'gotmls');
546 $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>';
547 } elseif (isset($_GET["SESSION"]) && !session_id()) {
548 @session_start();
549 if (session_id() && $_GET["SESSION"] == "GOTMLS_debug" && !isset($_SESSION["GOTMLS_debug"]))
550 $_SESSION["GOTMLS_debug"]=array();
551 }
552 }
553
554 if (!function_exists("add_action")) {
555 GOTMLS_loaded();
556 // GOTMLS_admin_notices();
557 }
558
559 function GOTMLS_get_ext($filename) {
560 $nameparts = explode(".", ".$filename");
561 return strtolower($nameparts[(count($nameparts)-1)]);
562 }
563
564 function GOTMLS_preg_match_all($threat_definition, $threat_name) {
565 if (@preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["file_contents"], $threats_found)) {
566 $start = -1;
567 if (!@preg_match_all($threat_definition, $GLOBALS["GOTMLS"]["tmp"]["new_contents"], $threat_found)) {
568 $new_contents = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
569 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
570 } else
571 $new_contents = false;
572 foreach ($threats_found[0] as $find) {
573 $potential_threat = str_replace("\r", "", $find);
574 $flen = strlen($potential_threat);
575 while (($start = strpos(str_replace("\r", "", $GLOBALS["GOTMLS"]["tmp"]["file_contents"]), $potential_threat, $start+1)) !== false)
576 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".($flen+$start)] = "$threat_name";
577 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = str_replace($find, "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]);
578 }
579 if ($new_contents && strlen($new_contents) < strlen($GLOBALS["GOTMLS"]["tmp"]["new_contents"]))
580 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $new_contents;
581 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
582 } else
583 return false;
584 }
585
586 function GOTMLS_check_threat($check_threats, $file='UNKNOWN') {
587 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
588 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
589 if (is_array($check_threats)) {
590 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
591 if (substr($file, 0, strlen(ABSPATH)) == ABSPATH && isset($check_threats[GOTMLS_wp_version]["$path"])) {
592 if (($check_threats[GOTMLS_wp_version]["$path"] != md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"])."O".strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])) && ($source = GOTMLS_get_URL("http://core.svn.wordpress.org/tags/".GOTMLS_wp_version."$path")) && ($check_threats[GOTMLS_wp_version]["$path"] == md5($source)."O".strlen($source))) {
593 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
594 $len = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
595 if (strlen($source) < $len)
596 $len = strlen($source);
597 for ($start = 0, $end = 0; ($start == 0 || $end == 0) && $len > 0; $len--){
598 if ($start == 0 && substr($source, 0, $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], 0, $len))
599 $start = $len;
600 if ($end == 0 && substr($source, -1 * $len) == substr($GLOBALS["GOTMLS"]["tmp"]["file_contents"], -1 * $len))
601 $end = $len;
602 }
603 $GLOBALS["GOTMLS"]["tmp"]["threats_found"]["$start-".(strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])-$end)] = "Core File Modified";
604 }
605 } else {
606 foreach ($check_threats as $threat_name=>$threat_definitions) {
607 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
608 if (is_array($threat_definitions) && count($threat_definitions) > 1 && strlen(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"]))))
609 while ($threat_definition = array_shift($threat_definitions))
610 GOTMLS_preg_match_all($threat_definition, $threat_name);
611 if (isset($_SESSION["GOTMLS_debug"])) {
612 $_SESSION["GOTMLS_debug"]["threat_name"] = $threat_name;
613 $file_time = round(microtime(true) - $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"], 5);
614 if (isset($_GET["GOTMLS_debug"]) && is_numeric($_GET["GOTMLS_debug"]) && $file_time > $_GET["GOTMLS_debug"])
615 echo "\n//GOTMLS_debug $file_time $threat_name $file\n";
616 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"]))
617 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] += $file_time;
618 else
619 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["total"] = $file_time;
620 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"]))
621 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"] ++;
622 else
623 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["count"] = 1;
624 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"])
625 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["least"] = $file_time;
626 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"])
627 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_name"]]["most"] = $file_time;
628 }
629 }
630 }
631 } elseif (strlen($check_threats) && isset($_GET['eli']) && substr($check_threats, 0, 1) == '/')
632 GOTMLS_preg_match_all($check_threats, $check_threats);
633 if (isset($_SESSION["GOTMLS_debug"])) {
634 $file_time = round(microtime(true) - $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"], 5);
635 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"]))
636 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] += $file_time;
637 else
638 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["total"] = $file_time;
639 if (isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"]))
640 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"] ++;
641 else
642 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["count"] = 1;
643 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"]) || $file_time < $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"])
644 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["least"] = $file_time;
645 if (!isset($_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"]) || $file_time > $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"])
646 $_SESSION["GOTMLS_debug"][$_SESSION["GOTMLS_debug"]["threat_level"]]["most"] = $file_time;
647 }
648 return count($GLOBALS["GOTMLS"]["tmp"]["threats_found"]);
649 }
650
651 function GOTMLS_scanfile($file) {
652 global $wpdb, $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
653 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="Scanning...";
654 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
655 $gt = ">";
656 $lt = "<";
657 $found = false;
658 $threat_link = "";
659 $className = "scanned";
660 $real_file = realpath($file);
661 $clean_file = GOTMLS_encode($real_file);
662 if (is_file($real_file) && ($filesize = filesize($real_file)) && ($GLOBALS["GOTMLS"]["tmp"]["file_contents"] = @file_get_contents($real_file))) {
663 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]))
664 $whitelist = array_flip($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]);
665 else
666 $whitelist = array();
667 if (isset($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"])) {
668 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["whitelist"] as $whitelist_file=>$non_threats) {
669 if (is_array($non_threats) && count($non_threats) > 1) {
670 if (isset($non_threats[0]))
671 unset($non_threats[0]);
672 $whitelist = array_merge($whitelist, $non_threats);
673 }
674 }
675 }
676 if (isset($whitelist[md5($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'O'.$filesize]))
677 return GOTMLS_return_threat($className, "checked.gif?$className", $file, $threat_link);
678 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $GLOBALS["GOTMLS"]["tmp"]["file_contents"];
679 if (isset($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && strlen($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"]) && isset($_GET['eli']) && substr($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"], 0, 1) == '/' && ($found = GOTMLS_check_threat($GLOBALS["GOTMLS"]["log"]["settings"]["check_custom"])))
680 $className = "known";
681 else {
682 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
683 if (isset($_SESSION["GOTMLS_debug"])) {
684 $_SESSION["GOTMLS_debug"]["file"] = $file;
685 $_SESSION["GOTMLS_debug"]["last"]["total"] = microtime(true);
686 }
687 if (isset($GLOBALS["GOTMLS"]["tmp"]["threat_levels"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threat_levels"])) {
688 foreach ($GLOBALS["GOTMLS"]["tmp"]["threat_levels"] as $threat_level) {
689 if ("db_scan" != $threat_level) {
690 if (isset($_SESSION["GOTMLS_debug"])) {
691 $_SESSION["GOTMLS_debug"]["threat_level"] = $threat_level;
692 $_SESSION["GOTMLS_debug"]["last"]["threat_level"] = microtime(true);
693 }
694 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"]))) && (!array_key_exists($threat_level, $GLOBALS["GOTMLS"]["tmp"]["threat_files"]) || (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)))
695 $className = $threat_level;
696 }
697 }
698 }
699 if (isset($_SESSION["GOTMLS_debug"])) {
700 $file_time = round(microtime(true) - $_SESSION["GOTMLS_debug"]["last"]["total"], 5);
701 if (isset($_SESSION["GOTMLS_debug"]["total"]["total"]))
702 $_SESSION["GOTMLS_debug"]["total"]["total"] += $file_time;
703 else
704 $_SESSION["GOTMLS_debug"]["total"]["total"] = $file_time;
705 if (isset($_SESSION["GOTMLS_debug"]["total"]["count"]))
706 $_SESSION["GOTMLS_debug"]["total"]["count"] ++;
707 else
708 $_SESSION["GOTMLS_debug"]["total"]["count"] = 1;
709 if (!isset($_SESSION["GOTMLS_debug"]["total"]["least"]) || $file_time < $_SESSION["GOTMLS_debug"]["total"]["least"])
710 $_SESSION["GOTMLS_debug"]["total"]["least"] = $file_time;
711 if (!isset($_SESSION["GOTMLS_debug"]["total"]["most"]) || $file_time > $_SESSION["GOTMLS_debug"]["total"]["most"])
712 $_SESSION["GOTMLS_debug"]["total"]["most"] = $file_time;
713 }
714 }
715 } else {
716 $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'));
717 // $threat_link = GOTMLS_error_link($GLOBALS["GOTMLS"]["tmp"]["file_contents"], $real_file);
718 $className = "errors";
719 }
720 if (count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
721 $threat_link = $lt.'a target="GOTMLS_iFrame" href="'.admin_url('admin-ajax.php?action=GOTMLS_scan&'.GOTMLS_set_nonce(__FUNCTION__."687").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$clean_file.preg_replace('/\&(GOTMLS_scan|mt|GOTMLS_mt|action)=/', '&last_\1=', isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?"&".$_SERVER["QUERY_STRING"]:"")).'" id="list_'.$clean_file.'" onclick="loadIframe(\''.str_replace("\"", "&quot;", $lt.'div style="float: left; white-space: nowrap;"'.$gt.__("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;
722 if ($className == "errors") {
723 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="errors";
724 $threat_link = GOTMLS_error_link($GLOBALS["GOTMLS"]["tmp"]["file_contents"], $file);
725 $imageFile = "/blocked";
726 } elseif ($className != "potential") {
727 if (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
728 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="GOTMLS_fix";
729 if (GOTMLS_get_nonce()) {
730 if ($className == "timthumb") {
731 if (($source = GOTMLS_get_URL("http://$className.googlecode.com/svn/trunk/$className.php")) && strlen($source) > 500)
732 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
733 else
734 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
735 } elseif ($className == 'wp_core') {
736 $path = str_replace("//", "/", "/".str_replace("\\", "/", substr($file, strlen(ABSPATH))));
737 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("http://core.svn.wordpress.org/tags/".GOTMLS_wp_version."$path")) && ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["wp_core"][GOTMLS_wp_version]["$path"] == md5($source)."O".strlen($source)))
738 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = $source;
739 else
740 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = "";
741 } else {
742 $GOTMLS_no_contents = trim(preg_replace('/\/\*.*?\*\/\s*/s', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
743 $GOTMLS_no_contents = trim(preg_replace('/\n\s*\/\/.*/', "", $GOTMLS_no_contents));
744 $GOTMLS_no_contents = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GOTMLS_no_contents));
745 if (strlen($GOTMLS_no_contents))
746 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = trim(preg_replace('/'.$lt.'\?(php)?\s*(\?'.$gt.'|$)/is', "", $GLOBALS["GOTMLS"]["tmp"]["new_contents"]));
747 else
748 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = "";
749 }
750 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))) {
751 echo __("Success!",'gotmls');
752 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
753 } else {
754 echo __("Failed:",'gotmls').' '.(strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"])?((is_writable(dirname($file)) && is_writable($file))?(($Q_post===false)?__("failed to quarantine!",'gotmls')." (".$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'));
755 if (isset($_GET["eli"]))
756 echo 'uid='.getmyuid().'('.get_current_user().'),gid='.getmygid().($lt.'br'.$gt.$lt.'pre'.$gt.'file_stat'.print_r(stat($file), true));
757 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
758 }
759 } else {
760 echo GOTMLS_Invalid_Nonce(__("Failed: ",'gotmls'));
761 return "/*--{$gt}*"."/\nfailedFile('$clean_file');\n/*{$lt}!--*"."/";
762 }
763 }
764 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]=isset($_POST["GOTMLS_fix"])?"GOTMLS_fix=".GOTMLS_htmlspecialchars(print_r($_POST["GOTMLS_fix"],1)):"!potential";
765 $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;
766 $imageFile = "threat";
767 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
768 echo __("Already Fixed!",'gotmls');
769 return "/*-->*"."/\nfixedFile('$clean_file');\n/*<!--*"."/";
770 } else
771 $imageFile = "question";
772 return GOTMLS_return_threat($className, $imageFile, $file, str_replace("GOTMLS_plugin", "GOTMLS_plugin $className", $threat_link));
773 } elseif (isset($_POST["GOTMLS_fix"]) && is_array($_POST["GOTMLS_fix"]) && in_array($clean_file, $_POST["GOTMLS_fix"])) {
774 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="Already Fixed";
775 echo __("Already Fixed!",'gotmls');
776 return "/*--{$gt}*"."/\nfixedFile('$clean_file');\n/*{$lt}!--*"."/";
777 } else {
778 $GLOBALS["GOTMLS"]["tmp"]["debug_fix"]="no threat";
779 return GOTMLS_return_threat($className, ($className=="scanned"?"checked":"blocked").".gif?$className", $file, $threat_link);
780 }
781 }
782
783 function GOTMLS_db_scan($id = 0) {
784 global $wpdb;
785 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"])) {
786 if ($id) {
787 if (($Q_post = GOTMLS_get_quarantine($id)) && isset($Q_post["post_content"])) {
788 $path = 'Post ID: '.$Q_post["ID"];
789 $clean_file = $Q_post["post_title"];
790 $fa = "";
791 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $Q_post["post_content"];
792 $GLOBALS["GOTMLS"]["tmp"]["new_contents"] = ($Q_post["post_content"]);
793 $found = 0;
794 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
795 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
796 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
797 $threat_name = array_shift($scan_regex);
798 while ($threat_definition = array_shift($scan_regex))
799 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
800 }
801 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && count($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
802 $f = 1;
803 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $threats_found => $threats_name) {
804 list($start, $end, $junk) = explode("-", "$threats_found--", 3);
805 if ($start > $end)
806 $fa .= 'ERROR['.($f++).']: Threat_size{'.$threats_found.'} Content_size{'.strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]).'}';
807 else
808 $fa .= ' <a title="'.GOTMLS_htmlspecialchars($threats_name).'" href="javascript:select_text_range(\'ta_file\', '.$start.', '.$end.');">['.$f++.']</a>';
809 }
810 } else
811 $fa = " No Threats Found";
812 if (isset($_REQUEST["GOTMLS_fix"]) && is_array($_REQUEST["GOTMLS_fix"]) && in_array(GOTMLS_encode($id), $_REQUEST["GOTMLS_fix"]) && isset($_REQUEST["GOTMLS_fixing"]) && $_REQUEST["GOTMLS_fixing"] > 0) {
813 if ($_REQUEST["GOTMLS_fixing"] > 1) {
814 echo "<li>Removing $path ... ";
815 $Q_post["post_status"] = "trash";
816 if (wp_update_post($Q_post)) {
817 echo __("Done!",'gotmls');
818 $li_js .= "/*-->*"."/\nDeletedFile('$id');\n/*<!--*"."/";
819 } else {
820 echo __("Failed to delete!",'gotmls');
821 $li_js .= "/*-->*"."/\nfailedFile('$id');\n/*<!--*"."/";
822 }
823 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Removal from Content")));
824 } else {
825 echo "<li>Fixing $path ... ";
826 GOTMLS_write_quarantine($Q_post, "db_scan");
827 $Q_post["post_content"] = $GLOBALS["GOTMLS"]["tmp"]["new_contents"];
828 if (wp_update_post($Q_post)) {
829 echo __("Success!",'gotmls');
830 $li_js .= "/*-->*"."/\nfixedFile('$id');\n/*<!--*"."/";
831 } else {
832 echo __("Update Failed!",'gotmls');
833 $li_js .= "/*-->*"."/\nfailedFile('$id');\n/*<!--*"."/";
834 }
835 GOTMLS_update_scan_log(array("scan" => array("finish" => time(), "type" => "Restoration from Quarantine")));
836 }
837 return $li_js;
838 } else {
839 return admin_url('admin-ajax.php?'.GOTMLS_set_nonce(__FUNCTION__."805")).($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="'.GOTMLS_encode($Q_post["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>';
840 }
841 } else
842 die(GOTMLS_html_tags(array("html" => array("body" => __("This record no longer exists in the posts table.",'gotmls')."<br />\n<script type=\"text/javascript\">\nwindow.parent.showhide('GOTMLS_iFrame', true);\n</script>"))));
843 } else {
844 $threats_found = array();
845 if (!isset($_REQUEST["eli"]))
846 $and = " AND `post_status` != 'trash'";
847 foreach ($GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"] as $scan_sql => $scan_regex) {
848 $SQL = preg_replace('/\{[a-f0-9]{64}\}/', '%', $wpdb->prepare("SELECT * FROM `$wpdb->posts` WHERE `post_content` LIKE %s $and", $scan_sql));
849 $threat_name = array_shift($scan_regex);
850 if (($found_row = $wpdb->get_results($SQL, ARRAY_A)) && is_array($found_row) && count($found_row)) {
851 $val = count($found_row);
852 if (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
853 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("$val Rows", 0));//debug
854 foreach ($found_row as $frow) {
855 $found = 0;
856 if ($frow["post_type"] != "revision" || isset($_REQUEST["eli"])) {
857 $GLOBALS["GOTMLS"]["tmp"]["file_contents"] = $frow["post_content"];
858 $GLOBALS["GOTMLS"]["tmp"]["threats_found"] = array();
859 $GLOBALS["GOTMLS"]["log"]["scan"]["last_threat"] = microtime(true);
860 foreach ($scan_regex as $threat_definition)
861 $found += GOTMLS_preg_match_all($threat_definition, $threat_name);
862 if ($found && !isset($threats_found['row_id_'.$frow["ID"]])) {
863 $li_js = 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_'.$frow["ID"].'" value="'.GOTMLS_encode($frow["ID"]).'" checked="true">'.GOTMLS_error_link(__("View DB Injection",'gotmls'), $frow["ID"], "db_scan"));
864 if (isset($_REQUEST["eli"]))
865 echo str_replace($frow["ID"].'</a>', '</a><a target="_blank" title="Edit '.$frow["post_type"].'" href="'.admin_url(($frow["post_type"]=="revision")?'revision.php?revision='.$frow["ID"]:'post.php?action=edit&post='.$frow["ID"]).'">EDIT: '.$frow["ID"].'</a>', $li_js);
866 else
867 echo $li_js;
868 $threats_found['row_id_'.$frow["ID"]] = $threat_name;
869 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
870 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
871 }
872 }
873 } elseif (isset($_REQUEST["eli"]) && ($_REQUEST["eli"] == "debug"))
874 echo GOTMLS_return_threat("db_scan", "question", (print_r(array("db_scan"=>$GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["db_scan"], "scan_regex:"=>$scan_regex,"SQL:"=>$SQL),1)), GOTMLS_error_link("No Rows", 0));//debug
875 }
876 }
877 }
878 }
879
880 function GOTMLS_remove_dots($dir) {
881 if ($dir != "." && $dir != "..")
882 return $dir;
883 }
884
885 function GOTMLS_getfiles($dir) {
886 $files = false;
887 if (is_dir($dir)) {
888 if (function_exists("scandir"))
889 $files = @scandir($dir);
890 if (is_array($files))
891 $files = array_filter($files, "GOTMLS_remove_dots");
892 elseif ($handle = @opendir($dir)) {
893 $files = array();
894 while (false !== ($entry = readdir($handle)))
895 if ($entry != "." && $entry != "..")
896 $files[] = "$entry";
897 closedir($handle);
898 } else
899 $files = GOTMLS_read_error($dir);
900 }
901 return $files;
902 }
903
904 function GOTMLS_decodeBase64($encoded_string) {
905 if (function_exists("base64_decode"))
906 $unencoded_string = base64_decode($encoded_string);
907 elseif (function_exists("mb_convert_encoding"))
908 $unencoded_string = mb_convert_encoding($encoded_string, "UTF-8", "BASE64");
909 else
910 return "Cannot decode: '$encoded_string'";
911 return "'".str_replace("'", "\\'", str_replace("\\", "\\\\", $unencoded_string))."'";
912 }
913
914 function GOTMLS_decodeHex($encoded_string) {
915 if (strtolower(substr($encoded_string, 0, 2)) == "\\x")
916 $dec_string = hexdec($encoded_string);
917 else
918 $dec_string = octdec($encoded_string);
919 return chr($dec_string);
920 }
921
922 function GOTMLS_return_threat($className, $imageFile, $fileName, $link = "") {
923 global $GOTMLS_image_alt;
924 $fileNameJS = GOTMLS_strip4java(str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $fileName));
925 $fileName64 = GOTMLS_encode($fileName);
926 $li_js = "/*-->*"."/";
927 if ($className != "scanned")
928 $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[$imageFile]."\" style=\"float: left;\" id=\"$imageFile"."_$fileName64\">".GOTMLS_strip4java($link, true).$fileNameJS.($link?"</a>';\n\tdivx.display='block":"")."';\n\tdivx.appendChild(newli);\n}";
929 if ($className == "errors")
930 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx) {\n\tdivx.src='".GOTMLS_images_path."blocked.gif';\n\tdirerrors++;\n}";
931 elseif (is_file($fileName))
932 $li_js .= "\nscanned++;\n";
933 if ($className == "dir")
934 $li_js .= "\ndivx=document.getElementById('wait_$fileName64');\nif (divx)\n\tdivx.src='".GOTMLS_images_path."checked.gif';";
935 return $li_js."\n/*<!--*"."/";
936 }
937
938 function GOTMLS_slash($dir = __FILE__) {
939 if (substr($dir.' ', 1, 1) == ':' || substr($dir.' ', 0, 1) == "\\")
940 return "\\";
941 else
942 return '/';
943 }
944
945 function GOTMLS_trailingslashit($dir = "") {
946 if (substr(' '.$dir, -1) != GOTMLS_slash($dir))
947 $dir .= GOTMLS_slash($dir);
948 return $dir;
949 }
950
951 function GOTMLS_explode_dir($dir, $pre = '') {
952 if (strlen($pre))
953 $dir = GOTMLS_slash($dir).$pre.$dir;
954 return explode(GOTMLS_slash($dir), $dir);
955 }
956
957 function GOTMLS_html_tags($tags, $inner = array()) {
958 $html = "";
959 $gt = ">";
960 if (!is_array($tags))
961 return $html;
962 foreach ($tags as $tag => $contents) {
963 $html .= ($tag=="html"?"<!DOCTYPE html$gt":"")."<$tag".(isset($inner[$tag])?" ".$inner[$tag]:"").$gt;
964 if (is_array($contents))
965 $html .= GOTMLS_html_tags($contents, $inner);
966 else
967 $html .= $contents;
968 $html .= "</$tag$gt";
969 }
970 return $html;
971 }
972
973 function GOTMLS_write_quarantine($file, $className) {
974 global $wpdb;
975 $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";
976 if (isset($file["ID"]) && is_numeric($file["ID"])) {
977 $insert["post_modified"] = $file["post_modified"];
978 $insert["post_modified_gmt"] = $file["post_modified_gmt"];
979 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
980 $file = $file["post_type"].':'.$file["ID"].':"'.$file["post_title"].'"';
981 }
982 $insert["post_title"] = $file;
983 $insert["post_date"] = date("Y-m-d H:i:s");
984 $insert["post_date_gmt"] = $insert["post_date"];
985 if (is_file($file)) {
986 if (@filemtime($file))
987 $insert["post_modified"] = date("Y-m-d H:i:s", @filemtime($file));
988 else
989 $insert["post_modified"] = $insert["post_date"];
990 if (@filectime($file))
991 $insert["post_modified_gmt"] = date("Y-m-d H:i:s", @filectime($file));
992 else
993 $insert["post_modified_gmt"] = $insert["post_date"];
994 if (!($insert["comment_count"] = @filesize($file)))
995 $insert["comment_count"] = strlen($GLOBALS["GOTMLS"]["tmp"]["file_contents"]);
996 }
997 if (isset($GLOBALS["GOTMLS"]["tmp"]["threats_found"]) && is_array($GLOBALS["GOTMLS"]["tmp"]["threats_found"])) {
998 $insert["post_excerpt"] = GOTMLS_encode(@serialize($GLOBALS["GOTMLS"]["tmp"]["threats_found"]));
999 $pinged = array();
1000 foreach ($GLOBALS["GOTMLS"]["tmp"]["threats_found"] as $loc => $threat_name) {
1001 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]))
1002 $ping = $GLOBALS["GOTMLS"]["tmp"]["definitions_array"]["$className"]["$threat_name"][1];
1003 else
1004 $ping = $threat_name;
1005 if (isset($pinged[$ping]))
1006 $pinged[$ping]++;
1007 else
1008 $pinged[$ping] = 1;
1009 }
1010 $insert["pinged"] = GOTMLS_encode(@serialize($pinged));
1011 }
1012 if ($return = $wpdb->insert($wpdb->posts, $insert))
1013 return $return;
1014 else
1015 die(print_r(array('return'=>($return===false)?"FALSE":$return, 'last_error'=>$wpdb->last_error, 'insert'=>$insert),1));
1016 }
1017
1018 function GOTMLS_get_current_user_id() {
1019 $return = 1;
1020 if (($current_user = @wp_get_current_user()) && (@$current_user->ID > 1))
1021 $return = $current_user->ID;
1022 return $return;
1023 }
1024
1025 function GOTMLS_update_status($status, $percent = -1) {
1026 if (!(isset($GLOBALS["GOTMLS"]["log"]["scan"]["start"]) && is_numeric($GLOBALS["GOTMLS"]["log"]["scan"]["start"])))
1027 $GLOBALS["GOTMLS"]["log"]["scan"]["start"] = time();
1028 $microtime = ceil(time()-$GLOBALS["GOTMLS"]["log"]["scan"]["start"]);
1029 GOTMLS_update_scan_log(array("scan" => array("microtime" => $microtime, "percent" => $percent)));
1030 return "/*-->*"."/\nupdate_status('".GOTMLS_strip4java($status)."', $microtime, $percent);\n/*<!--*"."/";
1031 }
1032
1033 function GOTMLS_flush($tag = "") {
1034 $output = "";
1035 if (($output = @ob_get_contents()) && strlen(trim($output)) > 18) {
1036 @ob_clean();
1037 $output = preg_replace('/\/\*<\!--\*\/.*?\/\*-->\*\//s', "", "$output/*-->*"."/");
1038 echo "$output\n//flushed(".strlen(trim($output)).")\n";
1039 if ($tag)
1040 echo "\n</$tag>\n";
1041 if (@ob_get_length())
1042 @ob_flush();
1043 if ($tag)
1044 echo "<$tag>\n/*<!--*"."/";
1045 }
1046 }
1047
1048 function GOTMLS_readdir($dir, $current_depth = 1) {
1049 global $GOTMLS_dirs_at_depth, $GOTMLS_dir_at_depth, $GOTMLS_total_percent;
1050 if ($current_depth) {
1051 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1052 $entries = GOTMLS_getfiles($dir);
1053 if (is_array($entries)) {
1054 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);
1055 $files = array();
1056 $directories = array();
1057 foreach ($entries as $entry) {
1058 if (is_dir(GOTMLS_trailingslashit($dir).$entry))
1059 $directories[] = $entry;
1060 else
1061 $files[] = $entry;
1062 }
1063 if (isset($_GET["eli"]) && $_GET["eli"] == "trace" && count($files)) {
1064 $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__);}')."'));";
1065 foreach ($files as $file)
1066 if (GOTMLS_get_ext($file) == "php" && $filecontents = @file_get_contents(GOTMLS_trailingslashit($dir).$file))
1067 GOTMLS_file_put_contents(GOTMLS_trailingslashit($dir).$file, preg_replace('/^<\?php(?! eval)/is', '<?php eval'.$tracer_code, $filecontents));
1068 }
1069 if ($_REQUEST["scan_type"] == "Quick Scan") {
1070 $GOTMLS_dirs_at_depth[$current_depth] = count($directories);
1071 $GOTMLS_dir_at_depth[$current_depth] = 0;
1072 } else
1073 $GLOBALS["GOTMLS"]["tmp"]["scanfiles"][GOTMLS_encode($dir)] = GOTMLS_strip4java(str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir));
1074 foreach ($directories as $directory) {
1075 $path = GOTMLS_trailingslashit($dir).$directory;
1076 if (isset($_REQUEST["scan_depth"]) && is_numeric($_REQUEST["scan_depth"]) && ($_REQUEST["scan_depth"] != $current_depth) && !in_array($directory, $GLOBALS["GOTMLS"]["tmp"]["skip_dirs"])) {
1077 $current_depth++;
1078 $current_depth = GOTMLS_readdir($path, $current_depth);
1079 } else {
1080 echo GOTMLS_return_threat("skipdirs", "blocked", $path);
1081 $GOTMLS_dir_at_depth[$current_depth]++;
1082 }
1083 }
1084 if ($_REQUEST["scan_type"] == "Quick Scan") {
1085 $echo = "";
1086 echo GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1087 GOTMLS_flush("script");
1088 foreach ($files as $file)
1089 echo GOTMLS_check_file(GOTMLS_trailingslashit($dir).$file);
1090 echo GOTMLS_return_threat("dir", "checked", $dir);
1091 }
1092 } else
1093 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' readdir:'.($entries===false?'('.GOTMLS_fileperms($dir).')':$entries)));
1094 @set_time_limit($GLOBALS["GOTMLS"]["tmp"]['execution_time']);
1095 if ($current_depth-- && $_REQUEST["scan_type"] == "Quick Scan") {
1096 $GOTMLS_dir_at_depth[$current_depth]++;
1097 for ($GOTMLS_total_percent = 0, $depth = $current_depth; $depth >= 0; $depth--) {
1098 echo "\n//(($GOTMLS_total_percent / $GOTMLS_dirs_at_depth[$depth]) + ($GOTMLS_dir_at_depth[$depth] / $GOTMLS_dirs_at_depth[$depth])) = ";
1099 $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)));
1100 echo "$GOTMLS_total_percent\n";
1101 }
1102 $GOTMLS_total_percent = floor($GOTMLS_total_percent * 100);
1103 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)), $GOTMLS_total_percent);
1104 }
1105 GOTMLS_flush("script");
1106 }
1107 return $current_depth;
1108 }
1109
1110 function GOTMLS_sexagesimal($timestamp = 0) {
1111 if (!is_numeric($timestamp) && strlen($timestamp) == 5) {
1112 $delim = array("=", "-", "-", " ", ":");
1113 foreach (str_split($timestamp) as $bit)
1114 $timestamp .= array_shift($delim).substr("00".(ord($bit)>96?ord($bit)-61:(ord($bit)>64?ord($bit)-55:ord($bit)-48)), -2);
1115 return "20".substr($timestamp, -14);
1116 } else {
1117 $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])$/';
1118 if (preg_match($match, $timestamp))
1119 $date = preg_replace($match, "\\2-\\3-\\4-\\5-\\6", $timestamp);
1120 elseif ($timestamp && strtotime($timestamp))
1121 $date = date("y-m-d-H-i", strtotime($timestamp));
1122 else
1123 $date = date("y-m-d-H-i", time());
1124 foreach (explode("-", $date) as $bit)
1125 $date .= (intval($bit)>35?chr(ord("a")+intval($bit)-36):(intval($bit)>9?chr(ord("A")+intval($bit)-10):substr('0'.$bit, -1)));
1126 return substr($date, -5);
1127 }
1128 }
1129
1130 if (!function_exists('ur1encode')) { function ur1encode($url) {
1131 $return = "";
1132 foreach (str_split($url) as $char)
1133 $return .= '%'.substr('00'.strtoupper(dechex(ord($char))),-2);
1134 return $return;
1135 }}
1136
1137 function GOTMLS_strip4java($item, $htmlentities = false) {
1138 return preg_replace("/\\\\/", "\\\\\\\\", str_replace("'", "'+\"'\"+'", preg_replace('/\\+n|\\+r|\n|\r|\0/', "", ($htmlentities?$item:GOTMLS_htmlentities($item)))));
1139 }
1140
1141 function GOTMLS_error_link($errorTXT, $file = "", $class = "errors") {
1142 global $post;
1143 $encoded_file = GOTMLS_encode($file);
1144 if (is_numeric($file) && isset($post->post_title)) {
1145 $encoded_file = $file;
1146 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.__("Examine Quarantined Content",'gotmls').' ... </div><div style="overflow: hidden; position: relative; height: 20px;"><div style="position: absolute; right: 0px; text-align: right; width: 9000px;">'.GOTMLS_strip4java($post->post_title)).'</div></div>\');" href="'.admin_url('admin-ajax.php?action=GOTMLS_scan&'.GOTMLS_set_nonce(__FUNCTION__."744").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$file);
1147 } elseif ($file)
1148 $onclick = 'loadIframe(\''.str_replace("\"", "&quot;", '<div style="float: left; white-space: nowrap;">'.__("Examine Content",'gotmls').' ... </div><div style="overflow: hidden; position: relative; height: 20px;"><div style="position: absolute; right: 0px; text-align: right; width: 9000px;">'.GOTMLS_htmlspecialchars(GOTMLS_strip4java($file), ENT_NOQUOTES)).'</div></div>\');" href="'.admin_url('admin-ajax.php?action=GOTMLS_scan&'.GOTMLS_set_nonce(__FUNCTION__."746").'&mt='.$GLOBALS["GOTMLS"]["tmp"]["mt"].'&GOTMLS_scan='.$encoded_file.preg_replace('/\&(GOTMLS_scan|mt|GOTMLS_mt|action)=/', '&last_\1=', isset($_SERVER["QUERY_STRING"])&&strlen($_SERVER["QUERY_STRING"])?"&".$_SERVER["QUERY_STRING"]:""));
1149 else
1150 $onclick = 'return false;';
1151 return "<a id=\"list_$encoded_file\" title=\"$errorTXT\" target=\"GOTMLS_iFrame\" onclick=\"$onclick\" class=\"GOTMLS_plugin $class\">";
1152 }
1153
1154 function GOTMLS_check_file($file) {
1155 $filesize = @filesize($file);
1156 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checking ".GOTMLS_strip4java($file)." ($filesize bytes)';\n/*<!--*"."/";
1157 if ($filesize===false)
1158 echo GOTMLS_return_threat("errors", "blocked", $file, GOTMLS_error_link(__("Failed to determine file size!",'gotmls'), $file));
1159 elseif (($filesize==0) || ($filesize>((isset($_GET["eli"])&&is_numeric($_GET["eli"]))?$_GET["eli"]:1234567)))
1160 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file size!",'gotmls')." ($filesize bytes)", $file, "potential"));
1161 elseif (in_array(GOTMLS_get_ext($file), $GLOBALS["GOTMLS"]["tmp"]["skip_ext"]) && !(preg_match('/(shim|social[0-9]*)\.png$/i', $file)))
1162 echo GOTMLS_return_threat("skipped", "blocked", $file, GOTMLS_error_link(__("Skipped because of file extention!",'gotmls'), $file, "potential"));
1163 else {
1164 try {
1165 echo @GOTMLS_scanfile($file);
1166 echo "//debug_fix:".$GLOBALS["GOTMLS"]["tmp"]["debug_fix"];
1167 } catch (Exception $e) {
1168 die("//Exception:".GOTMLS_strip4java($e));
1169 }
1170 }
1171 echo "/*-->*"."/\ndocument.getElementById('status_text').innerHTML='Checked ".GOTMLS_strip4java($file)."';\n/*<!--*"."/";
1172 }
1173
1174 function GOTMLS_read_error($path) {
1175 global $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1176 $error = error_get_last();
1177 if (!file_exists($path))
1178 return " (Path not found)";
1179 if (!is_readable($path) && isset($_GET["eli"]))
1180 $return = (@chmod($path, (is_dir($path)?$GOTMLS_chmod_dir:$GOTMLS_chmod_file))?"Fixed permissions":"error: ".preg_replace('/[\r\n]/', ' ', print_r($error,1)));
1181 else
1182 $return = (is_array($error) && isset($error["message"])?preg_replace('/[\r\n]/', ' ', print_r($error["message"],1)):"readable?");
1183 return " [".GOTMLS_fileperms($path)."] ( ".filesize($path)." $return)";
1184 }
1185
1186 function GOTMLS_scandir($dir) {
1187 echo "/*<!--*"."/".GOTMLS_update_status(sprintf(__("Scanning %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", GOTMLS_htmlspecialchars($dir))));
1188 GOTMLS_flush();
1189 $li_js = "/*-->*"."/\nscanNextDir(-1);\n/*<!--*"."/";
1190 if (isset($_GET["GOTMLS_skip_dir"]) && $dir == GOTMLS_decode($_GET["GOTMLS_skip_dir"])) {
1191 if (isset($_GET["GOTMLS_only_file"]) && strlen($_GET["GOTMLS_only_file"]))
1192 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"])));
1193 else
1194 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(__("Failed to read directory!",'gotmls')).GOTMLS_read_error($dir));
1195 } else {
1196 $files = GOTMLS_getfiles($dir);
1197 if (is_array($files)) {
1198 if (isset($_GET["GOTMLS_only_file"])) {
1199 if (strlen($_GET["GOTMLS_only_file"])) {
1200 $path = GOTMLS_trailingslashit($dir).GOTMLS_decode($_GET["GOTMLS_only_file"]);
1201 if (is_file($path)) {
1202 GOTMLS_check_file($path);
1203 echo GOTMLS_return_threat("dir", "checked", $path);
1204 }
1205 } else {
1206 foreach ($files as $file) {
1207 $path = GOTMLS_trailingslashit($dir).$file;
1208 if (is_file($path)) {
1209 $file_ext = GOTMLS_get_ext($file);
1210 $filesize = @filesize($path);
1211 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"]:1234567)))
1212 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"));
1213 else
1214 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);
1215 }
1216 }
1217 echo GOTMLS_return_threat("dir", "question", $dir);
1218 }
1219 } else {
1220 foreach ($files as $file) {
1221 $path = GOTMLS_trailingslashit($dir).$file;
1222 if (is_file($path)) {
1223 if (isset($_GET["GOTMLS_skip_file"]) && is_array($_GET["GOTMLS_skip_file"]) && in_array($path, $_GET["GOTMLS_skip_file"])) {
1224 $li_js .= "/*-->*"."/\n//skipped $path;\n/*<!--*"."/";
1225 if ($path == $_GET["GOTMLS_skip_file"][count($_GET["GOTMLS_skip_file"])-1])
1226 echo GOTMLS_return_threat("errors", "blocked", $path, GOTMLS_error_link(__("Failed to read file!",'gotmls'), $path));
1227 } else {
1228 GOTMLS_check_file($path);
1229 }
1230 }
1231 }
1232 echo GOTMLS_return_threat("dir", "checked", $dir);
1233 }
1234 } else
1235 echo GOTMLS_return_threat("errors", "blocked", $dir, GOTMLS_error_link(GOTMLS_Failed_to_list_LANGUAGE.' scandir:'.($files===false?' (FALSE)':$files)));
1236 }
1237 echo GOTMLS_update_status(sprintf(__("Scanned %s",'gotmls'), str_replace(dirname($GLOBALS["GOTMLS"]["log"]["scan"]["dir"]), "...", $dir)));
1238 GOTMLS_update_scan_log(array("scan" => array("finish" => time())));
1239 return $li_js;
1240 }
1241
1242 function GOTMLS_reset_settings($item, $key) {
1243 $key_parts = explode("_", $key."_");
1244 if (strlen($key_parts[0]) != 4 && $key_parts[0] != "exclude")
1245 unset($GLOBALS["GOTMLS"]["tmp"]["settings_array"][$key]);
1246 }
1247
1248 function GOTMLS_file_put_contents($file, $content) {
1249 global $GOTMLS_chmod_file, $GOTMLS_chmod_dir;
1250 $chmoded_file = false;
1251 $chmoded_dir = false;
1252 if ((is_dir(dirname($file)) || @mkdir(dirname($file), $GOTMLS_chmod_dir, true)) && !is_writable(dirname($file)) && ($GOTMLS_chmod_dir = @fileperms(dirname($file))))
1253 $chmoded_dir = @chmod(dirname($file), 0777);
1254 if (is_file($file) && !is_writable($file) && ($GOTMLS_chmod_file = @fileperms($file)))
1255 $chmoded_file = @chmod($file, 0666);
1256 if (function_exists("file_put_contents"))
1257 $return = @file_put_contents($file, $content);
1258 elseif ($fp = fopen($file, 'w')) {
1259 fwrite($fp, $content);
1260 fclose($fp);
1261 $return = true;
1262 } else
1263 $return = false;
1264 if ($chmoded_file)
1265 @chmod($file, $GOTMLS_chmod_file);
1266 if ($chmoded_dir)
1267 @chmod(dirname($file), $GOTMLS_chmod_dir);
1268 return $return;
1269 }
1270
1271 function GOTMLS_scan_log() {
1272 global $wpdb;
1273 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))
1274 $GOTMLS_scan_log = (isset($rs["option_name"])?get_option($rs["option_name"], array()):array());
1275 $units = array("seconds"=>60,"minutes"=>60,"hours"=>24,"days"=>365,"years"=>10);
1276 if (isset($GOTMLS_scan_log["scan"]["start"]) && is_numeric($GOTMLS_scan_log["scan"]["start"])) {
1277 $time = (time() - $GOTMLS_scan_log["scan"]["start"]);
1278 $ukeys = array_keys($units);
1279 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
1280 $time = floor($time/$units[$ukeys[$key]]);
1281 if (1 == $time)
1282 $unit = substr($unit, 0, -1);
1283 $LastScan = "started $time $unit ago";
1284 if (isset($GOTMLS_scan_log["scan"]["finish"]) && is_numeric($GOTMLS_scan_log["scan"]["finish"]) && ($GOTMLS_scan_log["scan"]["finish"] >= $GOTMLS_scan_log["scan"]["start"])) {
1285 $time = ($GOTMLS_scan_log["scan"]["finish"] - $GOTMLS_scan_log["scan"]["start"]);
1286 for ($unit = $ukeys[0], $key=0; (isset($units[$ukeys[$key]]) && $key < (count($ukeys) - 1) && $time >= $units[$ukeys[$key]]); $unit = $ukeys[++$key])
1287 $time = floor($time/$units[$ukeys[$key]]);
1288 if (1 == $time)
1289 $unit = substr($unit, 0, -1);
1290 if ($time)
1291 $LastScan .= " and ran for $time $unit";
1292 else
1293 $LastScan = str_replace("started", "ran", $LastScan);
1294 } else
1295 $LastScan .= " and has not finish";
1296 if (!isset($_GET['Scanlog']))
1297 $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;">';
1298 } else
1299 $LastScan = "never started ";
1300 return "Last ".(isset($GOTMLS_scan_log["scan"]["type"])?$GOTMLS_scan_log["scan"]["type"]:"Scan")." $LastScan";
1301 }
1302
1303 function GOTMLS_get_URL($URL) {
1304 $response = "";
1305 $GLOBALS["GOTMLS"]["get_URL"] = array("URL" => $URL);
1306 if (function_exists($method = "wp_remote_get")) {
1307 $GLOBALS["GOTMLS"]["get_URL"][$method] = wp_remote_get($URL, array("sslverify" => false));
1308 if (200 == wp_remote_retrieve_response_code($GLOBALS["GOTMLS"]["get_URL"][$method]))
1309 $response = wp_remote_retrieve_body($GLOBALS["GOTMLS"]["get_URL"][$method]);
1310 }
1311 if (strlen($response) == 0 && function_exists($method = "curl_exec")) {
1312 $curl_hndl = curl_init();
1313 curl_setopt($curl_hndl, CURLOPT_URL, $URL);
1314 curl_setopt($curl_hndl, CURLOPT_TIMEOUT, 30);
1315 if (isset($_SERVER['HTTP_REFERER']))
1316 $SERVER_HTTP_REFERER = $_SERVER['HTTP_REFERER'];
1317 elseif (isset($_SERVER['HTTP_HOST']))
1318 $SERVER_HTTP_REFERER = 'HOST://'.$_SERVER['HTTP_HOST'];
1319 elseif (isset($_SERVER['SERVER_NAME']))
1320 $SERVER_HTTP_REFERER = 'NAME://'.$_SERVER['SERVER_NAME'];
1321 elseif (isset($_SERVER['SERVER_ADDR']))
1322 $SERVER_HTTP_REFERER = 'ADDR://'.$_SERVER['SERVER_ADDR'];
1323 else
1324 $SERVER_HTTP_REFERER = 'NULL://not.anything.com';
1325 curl_setopt($curl_hndl, CURLOPT_REFERER, $SERVER_HTTP_REFERER);
1326 if (isset($_SERVER['HTTP_USER_AGENT']))
1327 curl_setopt($curl_hndl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
1328 curl_setopt($curl_hndl, CURLOPT_HEADER, 0);
1329 curl_setopt($curl_hndl, CURLOPT_RETURNTRANSFER, TRUE);
1330 if (!($response = curl_exec($curl_hndl)))
1331 $GLOBALS["GOTMLS"]["get_URL"][$method] = curl_error($curl_hndl);
1332 curl_close($curl_hndl);
1333 }
1334 if (strlen($response) == 0 && function_exists($method = "file_get_contents")) {
1335 try {
1336 $response = @file_get_contents($URL).'';
1337 } catch(Exception $e) {
1338 $GLOBALS["GOTMLS"]["get_URL"][$method] = $e->getTrace();
1339 }
1340 }
1341 if (isset($_GET["GOTMLS_debug"]) && (strlen($response) == 0 || $_GET["GOTMLS_debug"] == "GOTMLS_get_URL"))
1342 print_r(array("$method:".strlen($response)=>$GLOBALS["GOTMLS"]["get_URL"]));
1343 return $response;
1344 }
1345