PHP driver functional

main
ElbertF 12 years ago
parent 5523ffb1a7
commit 4fb4042eed

@ -86,12 +86,12 @@ want to port Wappalyzer to a new platform.
**PHP**
Work in progress. Getting started on Debian Linux:
Getting the PHP driver up and running on Debian Linux:
* `# aptitude install php5-dev php-pear libv8-dev`
* `# pecl install channel://pecl.php.net/v8js-0.1.3`
* `# echo "extension=v8js.so" > /etc/php5/conf.d/v8js.ini`
* `$ php drivers/php/driver.php`
* `$ php drivers/php/wappalyzer.php http://wappalyzer.com`
Screenshot

@ -1440,7 +1440,7 @@
headers: { 'Set-Cookie': /fe_typo_user/ },
meta: { 'generator': /TYPO3/i },
html: /(<(script[^>]* src|link[^>]* href)=[^>]*fileadmin|<!--TYPO3SEARCH)/i,
url: /\/typo3/i
url: /\/typo3\//i
},
'Ubercart': {
cats: [ 6 ],

@ -1440,7 +1440,7 @@
headers: { 'Set-Cookie': /fe_typo_user/ },
meta: { 'generator': /TYPO3/i },
html: /(<(script[^>]* src|link[^>]* href)=[^>]*fileadmin|<!--TYPO3SEARCH)/i,
url: /\/typo3/i
url: /\/typo3\//i
},
'Ubercart': {
cats: [ 6 ],

@ -1440,7 +1440,7 @@
headers: { 'Set-Cookie': /fe_typo_user/ },
meta: { 'generator': /TYPO3/i },
html: /(<(script[^>]* src|link[^>]* href)=[^>]*fileadmin|<!--TYPO3SEARCH)/i,
url: /\/typo3/i
url: /\/typo3\//i
},
'Ubercart': {
cats: [ 6 ],

@ -1440,7 +1440,7 @@
headers: { 'Set-Cookie': /fe_typo_user/ },
meta: { 'generator': /TYPO3/i },
html: /(<(script[^>]* src|link[^>]* href)=[^>]*fileadmin|<!--TYPO3SEARCH)/i,
url: /\/typo3/i
url: /\/typo3\//i
},
'Ubercart': {
cats: [ 6 ],

@ -1,5 +1,5 @@
(function() {
if ( wappalyzer == null ) return;
if ( wappalyzer == null ) { return };
var w = wappalyzer;
@ -8,7 +8,7 @@
* Log messages to console
*/
log: function(args) {
if ( console != null ) console[args.type](args.message);
if ( console != null ) { console[args.type](args.message) };
},
/**

@ -0,0 +1,121 @@
<?php
class Driver
{
public
$debug = false,
$curlUserAgent = 'Mozilla/5.0 (X11; Linux x86_64; rv:15.0) Gecko/20100101 Firefox/15.0.1',
$curlFollowLocation = true,
$curlTimeout = 5,
$curlMaxRedirects = 3
;
protected
$v8,
$host,
$url,
$html,
$headers = array()
;
/**
* Constructor
*/
public function __construct()
{
$this->v8 = new V8Js();
}
/**
* Analyze a website
* @param string $url
*/
public function analyze($url)
{
try {
$this->load(array('wappalyzer.js', 'apps.js', 'driver.js'));
$result = $this->curl($url);
$json = json_encode(array(
'host' => $this->host,
'url' => $this->url,
'html' => $this->html,
'headers' => $this->headers
));
return $this->v8->executeString('
w.driver.debug = ' . ( $this->debug ? 'true' : 'false' ) . ';
w.driver.data = ' . $json . ';
w.driver.init();
');
} catch ( V8JsException $e ) {
throw new DriverException('JavaScript error: ' . $e->getMessage());
}
}
/**
* Load and execute one or more JavaScript files
* @param mixed $files
*/
protected function load($files)
{
if ( !is_array($files) ) {
$files = array($files);
}
foreach ( $files as $file ) {
$this->v8->executeString(file_get_contents('js/' . $file), $file);
}
}
/**
* Perform a cURL request
* @param string $url
*/
protected function curl($url)
{
$ch = curl_init($url);
curl_setopt_array($ch, array(
CURLOPT_SSL_VERIFYPEER => false,
CURLOPT_HEADER => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_FOLLOWLOCATION => $this->curlFollowLocation,
CURLOPT_MAXREDIRS => $this->curlMaxRedirects,
CURLOPT_TIMEOUT => $this->curlTimeout,
CURLOPT_USERAGENT => $this->curlUserAgent
));
$response = curl_exec($ch);
if ( curl_errno($ch) !== 0 ) {
throw new DriverException('cURL error: ' . curl_error($ch));
}
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if ( $httpCode != 200 ) {
throw new DriverException('cURL request returned HTTP code ' . $httpCode);
}
$this->url = curl_getinfo($ch, CURLINFO_EFFECTIVE_URL);
$this->host = parse_url($url, PHP_URL_HOST);
$headerSize = curl_getinfo($ch, CURLINFO_HEADER_SIZE);
$this->html = substr($response, $headerSize);
$lines = array_slice(explode("\r\n", trim(substr($response, 0, $headerSize))), 1);
foreach ( $lines as $line ) {
if ( strpos(trim($line), ': ') !== false ) {
list($key, $value) = explode(': ', $line);
$this->headers[$key] = $value;
}
}
}
}

@ -0,0 +1,4 @@
<?php
class DriverException extends Exception
{ }

@ -1,5 +0,0 @@
<?php
$v8 = new V8Js();
var_dump($v8->executeString('print("Hello, world!");'));

@ -0,0 +1,23 @@
<?php
require('DriverException.php');
require('Driver.php');
try {
$driver = new Driver;
$options = getopt("abc");
var_dump($argv);
exit;
$detectedApps = $driver->analyze('http://wappalyzer.com');
echo implode("\n", $detectedApps) . "\n";
exit(1);
} catch ( DriverException $e ) {
exit('x');
echo $e->getMessage() . "\n";
exit(0);
}

File diff suppressed because it is too large Load Diff

@ -0,0 +1,31 @@
var w = wappalyzer;
w.driver = {
debug: false,
data: {},
/**
* Log messages to console
*/
log: function(args) {
if ( w.driver.debug ) { print(args.type + ': ' + args.message + "\n"); }
},
/**
* Initialize
*/
init: function() {
w.analyze(w.driver.data.host, w.driver.data.url, {
html: w.driver.data.html,
headers: w.driver.data.headers
});
return w.detected[w.driver.data.url];
},
/**
* Dummy
*/
displayApps: function() {
}
};

@ -0,0 +1,256 @@
/**
* Wappalyzer v2
*
* Created by Elbert F <info@elbertf.com>
*
* License: GPLv3 http://www.gnu.org/licenses/gpl-3.0.txt
*/
var wappalyzer = wappalyzer || (function() {
//'use strict';
/**
* Call driver functions
*/
var driver = function(func, args) {
if ( typeof w.driver[func] !== 'function' ) {
w.log('not implemented: w.driver.' + func, 'warn');
return;
}
if ( func !== 'log' ) { w.log('w.driver.' + func); }
return w.driver[func](args);
};
/**
* Main script
*/
var w = {
// Cache detected applications per URL
ping: {},
detected: [],
config: {
environment: 'dev', // dev | live
version: false,
websiteURL: 'http://wappalyzer.com/',
twitterURL: 'https://twitter.com/Wappalyzer',
githubURL: 'https://github.com/ElbertF/Wappalyzer',
firstRun: false,
upgraded: false
},
/**
* Log messages to console
*/
log: function(message, type) {
if ( w.config.environment === 'dev' ) {
if ( type == null ) { type = 'debug'; }
driver('log', { message: '[wappalyzer ' + type + '] ' + message, type: type });
}
},
/**
* Initialize
*/
init: function() {
w.log('w.init');
// Checks
if ( w.driver == null ) {
w.log('no driver, exiting');
return;
}
if ( w.apps == null || w.categories == null ) {
w.log('apps.js not loaded, exiting');
return;
}
// Initialize driver
driver('init', function() {
if ( w.config.firstRun ) {
driver('goToURL', { url: w.config.websiteURL + 'installed' });
w.config.firstRun = false;
}
if ( w.config.upgraded ) {
driver('goToURL', { url: w.config.websiteURL + 'upgraded' });
w.config.upgraded = false;
}
});
},
/**
* Analyze the request
*/
analyze: function(hostname, url, data) {
w.log('w.analyze');
var i, app, type, regex, match, content, meta, header, apps = [];
if ( w.detected[url] == null ) { w.detected[url] = []; }
if ( data ) {
for ( app in w.apps ) {
for ( type in w.apps[app] ) {
if ( w.detected[url].indexOf(app) !== -1 || apps.indexOf(app) !== -1 ) { continue; } // Skip if the app has already been detected
switch ( type ) {
case 'url':
if ( w.apps[app].url.test(url) ) { apps.push(app); }
break;
case 'html':
if ( data[type] == null ) { break; }
if ( w.apps[app][type].test(data[type]) ) { apps.push(app); }
break;
case 'script':
if ( data['html'] == null ) { break; }
regex = /<script[^>]+src=("|')([^"']+)\1/ig;
while ( match = regex.exec(data['html']) ) {
if ( w.apps[app][type].test(match[2]) ) {
apps.push(app);
break;
}
}
break;
case 'meta':
if ( data['html'] == null ) { break; }
regex = /<meta[^>]+>/ig;
while ( match = regex.exec(data['html']) ) {
for ( meta in w.apps[app][type] ) {
if ( new RegExp('name=["\']' + meta + '["\']', 'i').test(match) ) {
content = match.toString().match(/content=("|')([^"']+)("|')/i);
if ( content && content.length == 4 && w.apps[app].meta[meta].test(content[2]) ) {
apps.push(app);
break;
}
}
}
}
break;
case 'headers':
if ( data[type] == null ) { break; }
for ( header in w.apps[app].headers ) {
if ( data[type][header] != null && w.apps[app][type][header].test(data[type][header]) ) {
apps.push(app);
break;
}
}
break;
case 'env':
if ( data[type] == null ) { break; }
for ( i in data[type] ) {
if ( w.apps[app][type].test(data[type][i]) ) {
apps.push(app);
break;
}
}
break;
}
}
}
// Implied applications
var i, j, k, implied;
for ( i = 0; i < 3; i ++ ) {
for ( j in apps ) {
if ( w.apps[apps[j]] && w.apps[apps[j]].implies ) {
for ( k in w.apps[apps[j]].implies ) {
implied = w.apps[apps[j]].implies[k];
if ( !w.apps[implied] ) {
w.log('Implied application ' + implied + ' does not exist');
continue;
}
if ( w.detected[url].indexOf(implied) === -1 && apps.indexOf(implied) === -1 ) {
apps.push(implied);
}
}
}
}
}
w.log(apps.length + ' apps detected: ' + apps.join(', '));
// Keep history of detected apps
var i, app, match;
for ( i in apps ) {
app = apps[i];
// Per hostname
if ( /^[a-z0-9._\-]+\.[a-z]+/.test(hostname) && !/(dev\.|\/admin|\.local)/.test(url) ) {
if ( typeof w.ping.hostnames === 'undefined' ) {
w.ping.hostnames = {};
}
if ( typeof w.ping.hostnames[hostname] === 'undefined' ) {
w.ping.hostnames[hostname] = { applications: {}, meta: {} };
}
if ( typeof w.ping.hostnames[hostname].applications[app] === 'undefined' ) {
w.ping.hostnames[hostname].applications[app] = 1;
}
w.ping.hostnames[hostname].applications[app] ++;
}
// Per URL
if ( w.detected[url].indexOf(app) === -1 ) { w.detected[url].push(app); }
}
// Additional information
if ( typeof w.ping.hostnames !== 'undefined' && typeof w.ping.hostnames[hostname] !== 'undefined' ) {
if ( data.html != null ) {
match = data.html.match(/<html[^>]*[: ]lang="([^"]+)"/);
if ( match != null && match.length ) {
w.ping.hostnames[hostname].meta['language'] = match[1];
}
}
}
if ( w.ping.hostnames != null && Object.keys(w.ping.hostnames).length >= 50 ) { driver('ping'); }
apps = null;
data = null;
}
driver('displayApps');
}
};
return w;
})();

@ -0,0 +1,34 @@
<?php
require('DriverException.php');
require('Driver.php');
try {
if ( php_sapi_name() !== 'cli' ) {
exit('Run me from the command line');
}
$url = !empty($argv[1]) ? $argv[1] : '';
if ( !$url ) {
echo "Usage: php {$argv[0]} <url>\n";
exit(0);
}
$driver = new Driver;
$detectedApps = $driver->analyze($url);
if ( $detectedApps ) {
echo implode("\n", $detectedApps) . "\n";
} else {
echo "No applications detected\n";
}
exit(0);
} catch ( Exception $e ) {
echo $e->getMessage() . "\n";
exit(1);
}

@ -20,3 +20,6 @@ ln -f share/js/lib/jquery.min.js drivers/html/js/lib
ln -f share/js/apps.js drivers/html/js/
ln -f share/js/wappalyzer.js drivers/html/js/
ln -f share/js/apps.js drivers/php/js/
ln -f share/js/wappalyzer.js drivers/php/js/

@ -1440,7 +1440,7 @@
headers: { 'Set-Cookie': /fe_typo_user/ },
meta: { 'generator': /TYPO3/i },
html: /(<(script[^>]* src|link[^>]* href)=[^>]*fileadmin|<!--TYPO3SEARCH)/i,
url: /\/typo3/i
url: /\/typo3\//i
},
'Ubercart': {
cats: [ 6 ],

Loading…
Cancel
Save