-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathWPVersion.php
More file actions
76 lines (56 loc) · 2.4 KB
/
Copy pathWPVersion.php
File metadata and controls
76 lines (56 loc) · 2.4 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
<?php
class WPVersion {
/*
* check
*
* Performs a number of increasingly aggressive checks on a
* target domain to try and identify the WordPress version.
*
* @domain (string) The domain to perform the lookup for.
* @return (string)
*/
public function check($domain) {
$version = false;
// Tidy up the domain
$domain = 'http://'.$domain.'/';
// Feed first - most sites seem to have this enabled.
if(!$version) $version = $this->checkFeedReferences($domain);
// Now try looking at the site source code.
if(!$version) $version = $this->checkCodeReferences($domain);
return $version;
}
private function checkCodeReferences($domain) {
// Get homepage source code
$html = $this->get($domain);
if(!$html) return false;
// Check meta tags
preg_match('/content="WordPress (\*|\d+(\.\d+){0,2}(\.\*)?)"/', $html, $matches);
if($matches) return $matches[1];
// Check for references to ?ver - requires more precise version numbers
preg_match('/wp-emoji-release.min.js\?ver=(\*|\d+(\.\d+){1,2}(\.\*)?)/', $html, $matches);
if($matches) return $matches[1];
return false;
}
private function checkFeedReferences($domain) {
// Get feed file
$html = $this->get($domain.'feed/');
if(!$html) return false;
// Check for generator tag
preg_match('/wordpress.org\/\?v=(\*|\d+(\.\d+){0,2}(\.\*)?)/', $html, $matches);
if($matches) return $matches[1];
return false;
}
private function get($url) {
// Use Chrome UA to help prevent instant blocks from security plugins
$headers = array(
'User-Agent: Mozilla/5.0 (Windows NT 6.3; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/55.0.2883.87 Safari/537.36'
);
$ch = curl_init($url);
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
$result = curl_exec($ch);
return $result;
}
}