Add js field to NPM driver

main
Elbert Alias 8 years ago
parent 66c703c2fa
commit 996c72d0fa

@ -37,6 +37,8 @@ class Driver {
this.wappalyzer.apps = json.apps; this.wappalyzer.apps = json.apps;
this.wappalyzer.categories = json.categories; this.wappalyzer.categories = json.categories;
this.wappalyzer.parseJsPatterns();
this.wappalyzer.driver.log = (message, source, type) => this.log(message, source, type); this.wappalyzer.driver.log = (message, source, type) => this.log(message, source, type);
this.wappalyzer.driver.displayApps = detected => this.displayApps(detected); this.wappalyzer.driver.displayApps = detected => this.displayApps(detected);
} }
@ -120,6 +122,30 @@ class Driver {
.finally(() => { .finally(() => {
this.timer('browser.wait end'); this.timer('browser.wait end');
const headers = this.getHeaders(browser);
const html = this.getHtml(browser);
const scripts = this.getScripts(browser);
const js = this.getJs(browser);
console.log(js);
this.wappalyzer.analyze(pageUrl.hostname, pageUrl.href, {
headers,
html,
js,
scripts
});
const links = browser.body.getElementsByTagName('a');
resolve(links);
});
});
});
});
}
getHeaders(browser) {
const headers = {}; const headers = {};
browser.resources['0'].response.headers._headers.forEach(header => { browser.resources['0'].response.headers._headers.forEach(header => {
@ -130,6 +156,10 @@ class Driver {
headers[header[0]].push(header[1]); headers[header[0]].push(header[1]);
}); });
return headers;
}
getHtml(browser) {
let html = ''; let html = '';
try { try {
@ -138,26 +168,45 @@ class Driver {
this.wappalyzer.log(error.message, 'browser', 'error'); this.wappalyzer.log(error.message, 'browser', 'error');
} }
const vars = Object.getOwnPropertyNames(browser.window); return html;
}
getScripts(browser) {
const scripts = Array.prototype.slice const scripts = Array.prototype.slice
.apply(browser.document.scripts) .apply(browser.document.scripts)
.filter(s => s.src) .filter(s => s.src)
.map(s => s.src); .map(s => s.src);
this.wappalyzer.analyze(pageUrl.hostname, pageUrl.href, { return scripts;
headers, }
html,
env: vars,
scripts
});
const links = browser.body.getElementsByTagName('a'); getJs(browser) {
const patterns = this.wappalyzer.jsPatterns;
const js = {};
resolve(links); 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) { crawl(pageUrl, index = 1, depth = 1) {

@ -16,7 +16,7 @@
js[appName][chain] = {}; js[appName][chain] = {};
patterns[appName][chain].forEach((pattern, index) => { patterns[appName][chain].forEach((pattern, index) => {
const value = detect(chain); const value = detectJs(chain);
if ( value ) { if ( value ) {
js[appName][chain][index] = value; js[appName][chain][index] = value;
@ -32,7 +32,7 @@
} }
}()); }());
function detect(chain) { function detectJs(chain) {
const properties = chain.split('.'); const properties = chain.split('.');
const value = properties.reduce((parent, property) => { const value = properties.reduce((parent, property) => {

@ -509,6 +509,9 @@ class Wappalyzer {
* Analyze JavaScript variables * Analyze JavaScript variables
*/ */
analyzeJs(app, results) { analyzeJs(app, results) {
console.log(app, results);
Object.keys(results).forEach(string => { Object.keys(results).forEach(string => {
Object.keys(results[string]).forEach(index => { Object.keys(results[string]).forEach(index => {
const pattern = this.jsPatterns[app.name][string][index]; const pattern = this.jsPatterns[app.name][string][index];