This repository has been archived by the owner on May 24, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
62 lines (53 loc) · 1.41 KB
/
index.js
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
const qs = require('qs')
const path = require('path')
const fs = require('fs')
const unique = require('array-unique')
const isValidDomain = require('is-valid-domain')
const {exec} = require('shelljs')
const urlparse = require('url-parse')
function scanner(opts) {
opts = opts || {}
let domains = []
if (opts.filepath) {
const filepath = path.resolve(opts.filepath)
const lines = fs.readFileSync(filepath, 'utf-8').split(/\r?\n/)
for (let i = 0; i < lines.length; i++) {
const line = lines[i]
const str = line.replace(/"/gi, '')
if (isValidDomain(str)) {
domains.push(str)
continue
}
const { hostname } = urlparse(str)
if (hostname) {
domains.push(hostname)
}
}
}
if (Array.isArray(opts.sites)) {
const urls = opts.sites
for (let i = 0; i < urls.length; i++) {
const url = urls[i]
if (isValidDomain(url)) {
domains.push(url)
continue
}
const { hostname } = urlparse(url)
if (hostname) {
domains.push(hostname)
}
}
}
domains = unique(domains)
for (let i = 0; i < domains.length; i++) {
const domain = domains[i]
const child = exec(`aws s3 ls --recursive s3://${domain}`, {silent:true})
if (child.stdout) {
console.log(domain)
console.log(child.stdout)
} else {
console.log(`not public: ${domain}`)
}
}
}
module.exports = scanner