-
Notifications
You must be signed in to change notification settings - Fork 26
/
EmailGen.rb
executable file
·159 lines (121 loc) · 4.02 KB
/
EmailGen.rb
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
151
152
153
154
155
156
157
158
159
#!/usr/bin/env ruby
require "mechanize"
require "nokogiri"
require "optparse"
require "ruby-progressbar"
require "json"
require "./lib/e.rb"
require "./lib/hunter.rb"
trap("SIGINT") do
puts("\nBye Bye, thanks for using EmailGen by Navisec Delta :)")
exit(130)
end
ARGV << "-h" if ARGV.empty?
options = {}
optparse = OptionParser.new do |opts|
# Set a banner, displayed at the top
# of the help screen.
opts.banner = "Usage: EmailGen.rb "
# Define the options, and what they do
options[:company] = false
opts.on("-c", "--company \"Company, Inc\"", "Name of Company on LinkedIn") do |company|
options[:company] = company
end
options[:domain] = false
opts.on("-d", "--domain company.com", "Domain name used with Email") do |domain|
options[:domain] = domain
end
options[:location] = false
opts.on("-l", "--location New Jersey", "Location to search profiles for") do |location|
options[:location] = location
end
options[:format] = false
opts.on("-f", "--format \"{first}.{last}@{domain}\"", "Format of email") do |email_format|
options[:format] = email_format
end
options[:autodetect] = false
opts.on("-a", "--autodetect", "Auto Detect Format of email from Hunter (requires API key)") do
options[:autodetect] = true
end
options[:results] = false
opts.on("-r", "--results", "Results levels") do
options[:results] = true
end
options[:outfile] = false
opts.on("-o", "--outfile emails.txt", "File to save the results") do |outfile|
options[:outfile] = outfile
end
# This displays the help screen, all programs are
# assumed to have this option.
opts.on("-h", "--help", "Display this screen") do
puts(opts)
exit
end
end
@agent = Mechanize.new
def company_name(domain)
company_name = ""
search_url = "https://www.bing.com/search?q=%2Bsite%3Alinkedin.com%2Fcompany%2F%20%22#{domain}%22&qs=ds&form=QBRE"
html = @agent.get(search_url).body
page = Nokogiri::HTML(html)
return page.css("li.b_algo")[0].css("h2").css("a").text.split(" | ")[0]
end
optparse.parse!
if options[:domain]
puts(" _____ _ _ ____\n| ____|_ __ ___ __ _(_) |/ ___| ___ _ __\n| _| | '_ ` _ \\ / _` | | | | _ / _ \\ '_ \\\n| |___| | | | | | (_| | | | |_| | __/ | | |\n|_____|_| |_| |_|\\__,_|_|_|\\____|\\___|_| |_|\n\nAuthor: pry0cc | NaviSec Delta | delta.navisec.io\n ")
puts("[*] Initializing EmailGen...")
load_tokens = false
begin
require "./tokens.rb"
load_tokens = true
rescue LoadError
end
if @hunter_key
puts("[+] Autodetect enabled!")
if !options[:format]
hunter = Hunter.new(@hunter_key)
pre_format = hunter.get_format(options[:domain])
if pre_format
options[:format] = pre_format + "@{domain}"
puts("Detected format from hunter as '#{options[:format]}'")
else
puts("[-] Autodetection from hunter failed, please specify a format")
exit
end
else
puts("Using user-specified format as #{options[:format]}")
end
if !options[:company]
company = company_name(options[:domain])
if company
options[:company] = company
puts("Detected name as '#{company}'")
else
puts("[-] Autodetection of company name failed, please specify domain")
exit
end
else
puts("Using user-specified company name as #{options[:company]}")
end
else
if !options[:company] or !options[:format]
puts("[-] Tokens could not be loaded, please either create it or specify --company and --format")
exit
end
end
egen = EmailGen.new(options[:domain], options[:company], options[:format], location = options[:location])
puts("[+] Starting scan against #{options[:company]}")
emails = egen.scan
puts("[*] Scan complete! Generated #{emails.length} emails!")
puts("")
if options[:outfile]
file = File.open(options[:outfile], "w+")
emails.each do |email|
file.write(email + "\n")
end
file.close
puts("[+] Emails saved to #{options[:outfile]}")
else
puts(emails)
end
end