Merge branch 'js-field'

main
Elbert Alias 7 years ago
commit 33c53bd639

@ -6,7 +6,7 @@ set -eu
echo "Validating apps.json..." echo "Validating apps.json..."
jsonlint-cli -s schema.json src/apps.json jsonlint-cli -tps schema.json src/apps.json > /tmp/apps.json && mv /tmp/apps.json src/apps.json
echo "Validating regular expressions..." echo "Validating regular expressions..."

@ -35,9 +35,9 @@
}, },
"required": true "required": true
}, },
"env": { "js": {
"type": [ "string", "array" ], "type": "object",
"items": { "additionalProperties": {
"type": "string" "type": "string"
} }
}, },

@ -38,6 +38,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, meta, context) => this.displayApps(detected, meta, context); this.wappalyzer.driver.displayApps = (detected, meta, context) => this.displayApps(detected, meta, context);
} }
@ -123,6 +125,28 @@ 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);
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 => {
@ -133,6 +157,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 {
@ -141,26 +169,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) {

@ -1,58 +1,58 @@
/** global: browser */ /** global: browser */
if ( typeof browser !== 'undefined' && typeof document.body !== 'undefined' ) { if ( typeof browser !== 'undefined' && typeof document.body !== 'undefined' ) {
try {
var html = document.documentElement.outerHTML; var html = document.documentElement.outerHTML;
if ( html.length > 50000 ) { if ( html.length > 50000 ) {
html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length); html = html.substring(0, 25000) + html.substring(html.length - 25000, html.length);
} }
var scripts = Array.prototype.slice const scripts = Array.prototype.slice
.apply(document.scripts) .apply(document.scripts)
.filter(s => s.src) .filter(script => script.src)
.map(s => s.src); .map(script => script.src);
try {
browser.runtime.sendMessage({ browser.runtime.sendMessage({
id: 'analyze', id: 'analyze',
subject: { html }, subject: { html, scripts },
source: 'content.js' source: 'content.js'
}); });
const script = document.createElement('script');
script.onload = () => {
addEventListener('message', event => {
if ( event.data.id !== 'js' ) {
return;
}
browser.runtime.sendMessage({ browser.runtime.sendMessage({
id: 'analyze', id: 'analyze',
subject: { scripts }, subject: {
js: event.data.js
},
source: 'content.js' source: 'content.js'
}); });
}, true);
var container = document.createElement('wappalyzerData'); ( chrome || browser ).runtime.sendMessage({
id: 'init_js',
container.setAttribute('id', 'wappalyzerData'); subject: {},
container.setAttribute('style', 'display: none');
var script = document.createElement('script');
script.setAttribute('id', 'wappalyzerEnvDetection');
script.setAttribute('src', browser.extension.getURL('js/inject.js'));
container.addEventListener('wappalyzerEvent', (event => {
var env = event.target.childNodes[0].nodeValue;
document.documentElement.removeChild(container);
document.documentElement.removeChild(script);
env = env.split(' ').slice(0, 500);
browser.runtime.sendMessage({
id: 'analyze',
subject: { env },
source: 'content.js' source: 'content.js'
}, response => {
postMessage({
id: 'patterns',
patterns: response.patterns
}, '*');
}); });
}), true); };
script.setAttribute('id', 'wappalyzer');
script.setAttribute('src', browser.extension.getURL('js/inject.js'));
document.documentElement.appendChild(container); document.body.appendChild(script);
document.documentElement.appendChild(script); } catch (e) {
} catch(e) {
log(e); log(e);
} }
} }

@ -75,6 +75,8 @@ fetch('../apps.json')
wappalyzer.apps = json.apps; wappalyzer.apps = json.apps;
wappalyzer.categories = json.categories; wappalyzer.categories = json.categories;
wappalyzer.parseJsPatterns();
categoryOrder = Object.keys(wappalyzer.categories).sort((a, b) => wappalyzer.categories[a].priority - wappalyzer.categories[b].priority); categoryOrder = Object.keys(wappalyzer.categories).sort((a, b) => wappalyzer.categories[a].priority - wappalyzer.categories[b].priority);
}) })
.catch(error => { .catch(error => {
@ -191,6 +193,12 @@ browser.webRequest.onCompleted.addListener(request => {
categories: wappalyzer.categories categories: wappalyzer.categories
}; };
break;
case 'init_js':
response = {
patterns: wappalyzer.jsPatterns
};
break; break;
default: default:
} }

@ -1,16 +1,43 @@
(function() { (function() {
try { try {
var i, environmentVars = '', e = document.createEvent('Events'); addEventListener('message', (event => {
if ( event.data.id !== 'patterns' ) {
return;
}
const patterns = event.data.patterns || {};
const js = {};
Object.keys(patterns).forEach(appName => {
js[appName] = {};
e.initEvent('wappalyzerEvent', true, false); Object.keys(patterns[appName]).forEach(chain => {
js[appName][chain] = {};
for ( i in window ) { patterns[appName][chain].forEach((pattern, index) => {
environmentVars += i + ' '; const value = detectJs(chain);
if ( value ) {
js[appName][chain][index] = value;
} }
});
});
});
document.getElementById('wappalyzerData').appendChild(document.createComment(environmentVars)); postMessage({ id: 'js', js }, '*');
document.getElementById('wappalyzerData').dispatchEvent(e); }), false);
} catch(e) { } catch(e) {
// Fail quietly // Fail quietly
} }
}()); }());
function detectJs(chain) {
const properties = chain.split('.');
const value = properties.reduce((parent, property) => {
return parent && parent.hasOwnProperty(property) ? parent[property] : null;
}, window);
return typeof value === 'string' ? value : !!value;
}

Binary file not shown.

Before

Width:  |  Height:  |  Size: 247 B

Binary file not shown.

Before

Width:  |  Height:  |  Size: 140 B

@ -18,6 +18,7 @@ class Wappalyzer {
this.apps = {}; this.apps = {};
this.categories = {}; this.categories = {};
this.driver = {}; this.driver = {};
this.jsPatterns = {};
this.detected = {}; this.detected = {};
this.hostnameCache = {}; this.hostnameCache = {};
@ -87,6 +88,12 @@ class Wappalyzer {
} }
}) })
if ( data.js ) {
Object.keys(data.js).forEach(appName => {
this.analyzeJs(apps[appName], data.js[appName]);
});
}
Object.keys(apps).forEach(appName => { Object.keys(apps).forEach(appName => {
var app = apps[appName]; var app = apps[appName];
@ -249,6 +256,17 @@ class Wappalyzer {
return parsed; return parsed;
} }
/**
* Parse JavaScript patterns
*/
parseJsPatterns() {
Object.keys(this.apps).forEach(appName => {
if ( this.apps[appName].js ) {
this.jsPatterns[appName] = this.parsePatterns(this.apps[appName].js);
}
});
}
resolveExcludes(apps) { resolveExcludes(apps) {
var excludes = []; var excludes = [];
@ -487,6 +505,25 @@ 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];
const value = results[string][index];
if ( pattern.regex.test(value) ) {
this.addDetected(app, pattern, 'js', value);
}
});
});
}
/** /**
* Analyze robots.txt * Analyze robots.txt
*/ */

Loading…
Cancel
Save