From 8d6d92dd1fd0f46082f9f6d0f6f7cf853a3bce08 Mon Sep 17 00:00:00 2001 From: Elbert Alias Date: Thu, 18 Dec 2014 08:38:30 +1100 Subject: [PATCH] Analyze headers in PhantomJS driver --- drivers/phantomjs/js/driver.js | 64 +++++++++++++++++++++++++++------- 1 file changed, 51 insertions(+), 13 deletions(-) diff --git a/drivers/phantomjs/js/driver.js b/drivers/phantomjs/js/driver.js index 782c9c412..21eab12a7 100644 --- a/drivers/phantomjs/js/driver.js +++ b/drivers/phantomjs/js/driver.js @@ -1,5 +1,5 @@ (function() { - var url, json, app, categories, page; + var url; try { if ( require('system').args.length > 1 ) { @@ -17,23 +17,53 @@ * Log messages to console */ log: function(args) { - console.log(args.message); + //if ( args.type !== 'debug' ) { + console.log(args.message); + //} }, /** * Display apps */ displayApps: function() { - var count = wappalyzer.detected[url] ? Object.keys(wappalyzer.detected[url]).length.toString() : '0'; - - console.log(count); + var + app, + apps = [], + cats = [], + count = wappalyzer.detected[url] ? Object.keys(wappalyzer.detected[url]).length : 0; + + if ( count ) { + for ( app in wappalyzer.detected[url] ) { + + wappalyzer.apps[app].cats.forEach(function(cat) { + cats.push(wappalyzer.categories[cat]); + }); + + apps.push({ + application: app, + confidence: wappalyzer.detected[url][app].confidenceTotal, + version: wappalyzer.detected[url][app].version, + categories: cats + }); + } + + console.log(JSON.stringify(apps)); + } }, /** * Initialize */ init: function() { - json = JSON.parse(require('fs').read('apps.json')); + var + page, hostname, + headers = {}; + a = document.createElement('a'), + json = JSON.parse(require('fs').read('apps.json')); + + a.href = url.replace(/#.*$/, ''); + + hostname = a.hostname; wappalyzer.apps = json.apps; wappalyzer.categories = json.categories; @@ -44,16 +74,24 @@ console.log(message); }; - page.open(url, function(status) { - var a, hostname; + page.onResourceReceived = function(response) { + if ( response.url.replace(/\/$/, '') === url.replace(/\/$/, '') ) { + if ( response.redirectURL ) { + url = response.redirectURL; - a = document.createElement('a'); + return; + } - a.href = url.replace(/#.*$/, ''); - - hostname = a.hostname; + if ( response.bodySize && response.stage === 'start' && response.contentType.indexOf('text/html') !== -1 ) { + response.headers.forEach(function(header) { + headers[header.name.toLowerCase()] = header.value; + }); + } + } + }; - wappalyzer.analyze(hostname, url, { html: page.content }); + page.open(url, function() { + wappalyzer.analyze(hostname, url, { html: page.content, headers: headers }); phantom.exit(); });