From 996c72d0fabcc6be9ae7115b43f9aa6a76c49bd0 Mon Sep 17 00:00:00 2001 From: Elbert Alias Date: Tue, 19 Dec 2017 08:49:20 +1100 Subject: [PATCH] Add js field to NPM driver --- src/drivers/npm/driver.js | 95 ++++++++++++++++++++------- src/drivers/webextension/js/inject.js | 4 +- src/wappalyzer.js | 3 + 3 files changed, 77 insertions(+), 25 deletions(-) diff --git a/src/drivers/npm/driver.js b/src/drivers/npm/driver.js index d15961ac9..5a03ce015 100644 --- a/src/drivers/npm/driver.js +++ b/src/drivers/npm/driver.js @@ -37,6 +37,8 @@ class Driver { this.wappalyzer.apps = json.apps; this.wappalyzer.categories = json.categories; + this.wappalyzer.parseJsPatterns(); + this.wappalyzer.driver.log = (message, source, type) => this.log(message, source, type); this.wappalyzer.driver.displayApps = detected => this.displayApps(detected); } @@ -120,34 +122,17 @@ class Driver { .finally(() => { this.timer('browser.wait end'); - const headers = {}; - - browser.resources['0'].response.headers._headers.forEach(header => { - if ( !headers[header[0]] ){ - headers[header[0]] = []; - } - - headers[header[0]].push(header[1]); - }); - - let html = ''; + const headers = this.getHeaders(browser); + const html = this.getHtml(browser); + const scripts = this.getScripts(browser); + const js = this.getJs(browser); - try { - html = browser.html(); - } catch ( e ) { - this.wappalyzer.log(error.message, 'browser', 'error'); - } - - const vars = Object.getOwnPropertyNames(browser.window); - const scripts = Array.prototype.slice - .apply(browser.document.scripts) - .filter(s => s.src) - .map(s => s.src); + console.log(js); this.wappalyzer.analyze(pageUrl.hostname, pageUrl.href, { headers, html, - env: vars, + js, scripts }); @@ -160,6 +145,70 @@ class Driver { }); } + getHeaders(browser) { + const headers = {}; + + browser.resources['0'].response.headers._headers.forEach(header => { + if ( !headers[header[0]] ){ + headers[header[0]] = []; + } + + headers[header[0]].push(header[1]); + }); + + return headers; + } + + getHtml(browser) { + let html = ''; + + try { + html = browser.html(); + } catch ( e ) { + this.wappalyzer.log(error.message, 'browser', 'error'); + } + + return html; + } + + getScripts(browser) { + const scripts = Array.prototype.slice + .apply(browser.document.scripts) + .filter(s => s.src) + .map(s => s.src); + + return scripts; + } + + getJs(browser) { + const patterns = this.wappalyzer.jsPatterns; + const js = {}; + + Object.keys(patterns).forEach(appName => { + js[appName] = {}; + + Object.keys(patterns[appName]).forEach(chain => { + js[appName][chain] = {}; + + patterns[appName][chain].forEach((pattern, index) => { + const properties = chain.split('.'); + + let value = properties.reduce((parent, property) => { + return parent && parent.hasOwnProperty(property) ? parent[property] : null; + }, browser.window); + + value = typeof value === 'string' ? value : !!value; + + if ( value ) { + js[appName][chain][index] = value; + } + }); + }); + }); + + return js; + } + crawl(pageUrl, index = 1, depth = 1) { this.timer('crawl'); diff --git a/src/drivers/webextension/js/inject.js b/src/drivers/webextension/js/inject.js index a105360c4..ec504586f 100644 --- a/src/drivers/webextension/js/inject.js +++ b/src/drivers/webextension/js/inject.js @@ -16,7 +16,7 @@ js[appName][chain] = {}; patterns[appName][chain].forEach((pattern, index) => { - const value = detect(chain); + const value = detectJs(chain); if ( value ) { js[appName][chain][index] = value; @@ -32,7 +32,7 @@ } }()); -function detect(chain) { +function detectJs(chain) { const properties = chain.split('.'); const value = properties.reduce((parent, property) => { diff --git a/src/wappalyzer.js b/src/wappalyzer.js index e85ae576d..8bef45597 100644 --- a/src/wappalyzer.js +++ b/src/wappalyzer.js @@ -509,6 +509,9 @@ class Wappalyzer { * Analyze JavaScript variables */ analyzeJs(app, results) { + + console.log(app, results); + Object.keys(results).forEach(string => { Object.keys(results[string]).forEach(index => { const pattern = this.jsPatterns[app.name][string][index];