-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathfind-subdomains.js
executable file
·58 lines (47 loc) · 1.61 KB
/
find-subdomains.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
#!/usr/bin/env node
const request = require('superagent')
const url = require('url')
const fs = require('fs')
const path = require('path')
const pkg = require('./package.json')
const getRawResponse = domain => {
return new Promise((resolve, reject) => {
request.get(`https://crt.sh/?q=%.${domain}&output=json`)
.then(res => resolve(res.text))
.catch(err => {
if (err.statusCode !== 200) return reject(err)
return resolve(err.rawResponse)
})
})
}
const printBanner = () => {
const fileData = fs.readFileSync(path.join(__dirname, 'banner.txt'), 'utf8')
console.log(`${fileData} Version ${pkg.version}\n`)
}
const clearUrl = target => {
let domain = target
if (/^(https?:|www\.)/i.test(target)) domain = url.parse(target).hostname || domain
// domain = domain.replace(/.*www\./i, '') // TODO: not need multiple replace
return domain
}
;(async () => {
printBanner()
if (process.argv.length !== 3) {
console.log(`usage: find-subdomains DOMAIN`)
process.exit(1)
}
const target = process.argv[2]
const domain = clearUrl(target)
console.log(`[*] TARGET: ${domain}\n`)
let response
try {
response = await getRawResponse(domain)
} catch (err) {
console.log(`[X] Information not available! (${err.statusCode})`)
return process.exit(1)
}
const jsonData = JSON.parse(`[${response.trim().replace(/}{/g, '},{')}]`)
const subdomains = Array.from(new Set(jsonData.map(_ => _.name_value))).sort((a, b) => a[0].charCodeAt() - b[0].charCodeAt())
for (const _ of subdomains) console.log(`[+] ${_}`)
console.log('\n[*] Done. Have a nice day! ;).')
})()