-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
150 lines (111 loc) · 5.45 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
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
"use strict";
// Dependencies
const puppeteer = require("puppeteer")
const request = require("request")
const chalk = require("chalk")
const delay = require("delay")
const fs = require("fs")
// Variables
const args = process.argv.slice(2)
var MailsHunter = {
links: [],
emails: [],
dork: ""
}
// Functions
async function dump(){
const browser = await puppeteer.launch({ headless: true, argvs: ["--no-sandbox", "--disable-setuid-sandbox"] })
const page = await browser.newPage()
await page.setUserAgent("Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/78.0.3904.97 Safari/537.36")
await page.goto(`https://www.bing.com/search?q=site:pastebin.com intext:(${mailshunter.dork})`)
const pageContent = await page.content()
if(pageContent.indexOf("There are no results for") !== -1){
console.log(`${chalk.grey("[") + chalk.yellowBright("WARNING") + chalk.grey("]")} Something went wrong while gathering some links, please try again later.`)
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} Aborting..`)
return browser.close()
}
var pageIndex = 1
await page.waitForSelector("#b_results > li> h2 > a").catch(()=>{
console.log(`${chalk.grey("[") + chalk.yellowBright("WARNING") + chalk.grey("]")} Something went wrong while gathering some links, please try again later.`)
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} Aborting..`)
browser.close()
process.exit()
})
const links = await page.$$eval("#b_results > li> h2 > a", elems =>{
return elems.map(elem => elem.getAttribute("href"))
})
for( const link of links ) mailshunter.links.push(link)
pageIndex += 1
grabber()
async function grabber(){
await page.click(`#b_results > li.b_pag > nav > ul > li:nth-of-type(${pageIndex}) > a`).catch(()=>{
console.log(`${chalk.grey("[") + chalk.yellowBright("WARNING") + chalk.grey("]")} Max page detected, aborting links gatherer.`)
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} ${mailshunter.links.length} links has been gathered. Continuing to phase 2.`)
browser.close()
return ES(page)
})
await page.waitForSelector("#b_results > li> h2 > a")
const links = await page.$$eval("#b_results > li> h2 > a", elems =>{
return elems.map(elem => elem.getAttribute("href"))
})
for( const link of links ) mailshunter.links.push(link)
if(pageIndex == args[1]){
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} ${mailshunter.links.length} links has been gathered. Continuing to phase 2.`)
await browser.close()
return ES(page)
}
pageIndex++
grabber()
}
}
async function ES(page){
if(!mailshunter.links.length){
console.log(`${chalk.grey("[") + chalk.yellowBright("WARNING") + chalk.grey("]")} No links found on MailsHunter data.`)
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} Aborting..`)
process.exit()
}
var linkIndex = 0
grabber()
async function grabber(){
request(`${mailshunter.links[linkIndex]}`, function(err, res, body){
if(err){
linkIndex++
return grabber()
}
parse()
async function parse(){
await delay(1000)
const emails = body.match(/[a-zA-Z0-9_.+-]+@[a-zA-Z0-9.-]+/g)
if(!emails){
linkIndex++
if(linkIndex == mailshunter.links.length){
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} ${mailshunter.emails.length} emails found. Continuing to the final phase.`)
return finish()
}
grabber()
}else{
linkIndex++
for( const email of emails ) if(email.match(".")) mailshunter.emails.push(email)
if(linkIndex === mailshunter.links.length){
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} ${mailshunter.emails.length} emails found. Continuing to the final phase.`)
return finish()
}
grabber()
}
}
})
}
}
function finish(){
if(!mailshunter.emails.length) return console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} No emails found, exiting.`)
const emails = []
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} Saving the emails that has been found to the output you specified.`)
for( const email of mailshunter.emails ) emails.push(email)
fs.writeFileSync(args[2], emails.join("\n"), "utf8")
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} Emails has been saved, exiting.`)
}
// Main
if(!args.length) return console.log(`node index.js <emailServices> <maxPage> <output>`)
for( const service of args[0].split(":") ) mailshunter.dork.length ? mailshunter.dork = service : mailshunter.dork += ` OR ${service}`
console.log(`${chalk.grey("[") + chalk.blueBright("INFO") + chalk.grey("]")} Looks like the arguments are good. Continuing to phase 1.`)
dump()