-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathspy.ts
More file actions
70 lines (60 loc) · 1.8 KB
/
spy.ts
File metadata and controls
70 lines (60 loc) · 1.8 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
// tslint:disable:no-expression-statement no-let
const Wappalyzer = require('wappalyzer')
import Router = require('koa-router')
type Category = {
id: number
slug: string
name: string
}
type Technology = {
slug: string
name: string
confidence: number
version: string | null
icon: string
website: string
cpe: string | null
categories: ReadonlyArray<Category>
}
const options = {
debug: false,
delay: 0,
headers: {},
maxDepth: 2,
maxUrls: 10,
maxWait: 5000,
recursive: true,
probe: true,
userAgent: 'Wappalyzer',
htmlMaxCols: 2000,
htmlMaxRows: 2000,
}
const wappalyzer = new Wappalyzer(options)
export async function getSpies(ctx: Router.IRouterContext): Promise<any> {
const params = ctx.query
const url = params && params.url
if (!url) {
return { statusCode: 422, body: JSON.stringify({ message: 'Missing attribute - url' }) }
}
let technology_names
try {
await wappalyzer.init()
// Optionally set additional request headers
const headers = {}
const site = await wappalyzer.open(url, headers)
// Optionally capture and output errors
site.on('error', console.error)
const results = await site.analyze()
const technologies: ReadonlyArray<Technology> = results.technologies
const analytics_technologies = technologies.filter((tech: Technology) => {
return tech.categories.some((category: Category) => category.name === 'Analytics')
})
technology_names = analytics_technologies.map((tech: Technology) => tech.name)
// console.log(JSON.stringify(technology_names, null, 2))
} catch (error) {
// console.error(error)
return { statusCode: 400, body: JSON.stringify({ message: 'something went wrong' }) }
}
await wappalyzer.destroy()
return { statusCode: 200, body: JSON.stringify({ spies: technology_names }) }
}