From 94a4ee530625bb988e4dd12e7a66e867385b84b9 Mon Sep 17 00:00:00 2001 From: Elbert Alias <77259+AliasIO@users.noreply.github.com> Date: Fri, 12 Jun 2020 09:10:44 +1000 Subject: [PATCH] Add wappalyzer-core NPM package, fix priority sorting --- src/README.md | 39 +++++++++++++++++++++++++++ src/drivers/npm/core.js | 25 +++++++++++++++++ src/drivers/webextension/js/driver.js | 8 +----- src/package.json | 30 +++++++++++++++++++++ src/wappalyzer.js | 37 ++++++++++++++----------- 5 files changed, 117 insertions(+), 22 deletions(-) create mode 100644 src/README.md create mode 100755 src/drivers/npm/core.js create mode 100644 src/package.json diff --git a/src/README.md b/src/README.md new file mode 100644 index 000000000..3c475aa18 --- /dev/null +++ b/src/README.md @@ -0,0 +1,39 @@ +# Wappalyzer core + +[Wappalyzer](https://www.wappalyzer.com/) indentifies technologies on websites. + +## Installation + +```shell +$ npm i wappalyzer-core +``` + +## Usage + +```javascript +#!/usr/bin/env node + +const fs = require('fs') +const Wappalyzer = require('./wappalyzer') + +// See https://www.wappalyzer.com/docs/dev/specification +const { apps: technologies, categories } = JSON.parse( + fs.readFileSync('./apps.json') +) + +Wappalyzer.setTechnologies(technologies) +Wappalyzer.setCategories(categories) + +const detections = Wappalyzer.analyze({ + url: 'https://example.github.io/', + meta: { generator: ['WordPress'] }, + headers: { server: ['Nginx'] }, + scripts: ['jquery-3.0.0.js'], + cookies: { awselb: [''] }, + html: '
' +}) + +const results = Wappalyzer.resolve(detections) + +console.log(results) +``` diff --git a/src/drivers/npm/core.js b/src/drivers/npm/core.js new file mode 100755 index 000000000..660fdd264 --- /dev/null +++ b/src/drivers/npm/core.js @@ -0,0 +1,25 @@ +#!/usr/bin/env node + +const fs = require('fs') +const Wappalyzer = require('./wappalyzer') + +// See https://www.wappalyzer.com/docs/dev/specification +const { apps: technologies, categories } = JSON.parse( + fs.readFileSync('./apps.json') +) + +Wappalyzer.setTechnologies(technologies) +Wappalyzer.setCategories(categories) + +const detections = Wappalyzer.analyze({ + url: 'https://example.github.io/', + meta: { generator: ['WordPress'] }, + headers: { server: ['Nginx'] }, + scripts: ['jquery-3.0.0.js'], + cookies: { awselb: [''] }, + html: '
' +}) + +const results = Wappalyzer.resolve(detections) + +console.log(results) diff --git a/src/drivers/webextension/js/driver.js b/src/drivers/webextension/js/driver.js index 7369600db..c5b81e1d4 100644 --- a/src/drivers/webextension/js/driver.js +++ b/src/drivers/webextension/js/driver.js @@ -311,13 +311,7 @@ const Driver = { categories.some(({ id }) => id === pinnedCategory) ) - ;({ icon } = pinned || - technologies.sort(({ categories: a }, { categories: b }) => { - const max = (value) => - value.reduce((max, { priority }) => Math.max(max, priority)) - - return max(a) > max(b) ? -1 : 1 - })[0] || { icon }) + ;({ icon } = pinned || technologies[0] || { icon }) } const tabs = await promisify(chrome.tabs, 'query', { url }) diff --git a/src/package.json b/src/package.json new file mode 100644 index 000000000..82ca88dcf --- /dev/null +++ b/src/package.json @@ -0,0 +1,30 @@ +{ + "name": "wappalyzer-core", + "description": "Identify technology on websites", + "keywords": [ + "analyze", + "identify", + "detect", + "detector", + "technology", + "cms", + "framework", + "library", + "software" + ], + "homepage": "https://www.wappalyzer.com", + "version": "6.0.7", + "author": "Wappalyzer", + "license": "MIT", + "repository": { + "type": "git", + "url": "https://github.com/aliasio/wappalyzer" + }, + "funding": { + "url": "https://github.com/sponsors/aliasio" + }, + "main": "wappalyzer.js", + "files": [ + "wappalyzer.js" + ] +} diff --git a/src/wappalyzer.js b/src/wappalyzer.js index dbbc74ebc..379b558a1 100644 --- a/src/wappalyzer.js +++ b/src/wappalyzer.js @@ -51,21 +51,28 @@ const Wappalyzer = { Wappalyzer.resolveExcludes(resolved) Wappalyzer.resolveImplies(resolved) - return resolved.map( - ({ - technology: { name, slug, categories, icon, website }, - confidence, - version - }) => ({ - name, - slug, - categories: categories.map((id) => Wappalyzer.getCategory(id)), - confidence, - version, - icon, - website - }) - ) + const priority = ({ technology: { categories } }) => + categories.reduce((max, id) => + Math.max(max, Wappalyzer.getCategory(id).priority) + ) + + return resolved + .sort((a, b) => (priority(a) > priority(b) ? 1 : -1)) + .map( + ({ + technology: { name, slug, categories, icon, website }, + confidence, + version + }) => ({ + name, + slug, + categories: categories.map((id) => Wappalyzer.getCategory(id)), + confidence, + version, + icon, + website + }) + ) }, resolveVersion({ version, regex }, match) {