Add js field to NPM driver

main
Elbert Alias 7 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,34 +122,17 @@ class Driver {
.finally(() => { .finally(() => {
this.timer('browser.wait end'); this.timer('browser.wait end');
const headers = {}; const headers = this.getHeaders(browser);
const html = this.getHtml(browser);
browser.resources['0'].response.headers._headers.forEach(header => { const scripts = this.getScripts(browser);
if ( !headers[header[0]] ){ const js = this.getJs(browser);
headers[header[0]] = [];
}
headers[header[0]].push(header[1]);
});
let html = '';
try { console.log(js);
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);
this.wappalyzer.analyze(pageUrl.hostname, pageUrl.href, { this.wappalyzer.analyze(pageUrl.hostname, pageUrl.href, {
headers, headers,
html, html,
env: vars, js,
scripts 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) { crawl(pageUrl, index = 1, depth = 1) {
this.timer('crawl'); this.timer('crawl');

@ -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];

Loading…
Cancel
Save