Skip to content

Commit 4ef3de8

Browse files
committed
get some more test cases
1 parent 1fb4216 commit 4ef3de8

File tree

2 files changed

+44
-10
lines changed

2 files changed

+44
-10
lines changed

lib/rex/parser/group_policy_preferences.rb

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -129,14 +129,40 @@ def self.create_tables(results, filetype, domain=nil, dc=nil)
129129
# Decrypts passwords using Microsoft's published key:
130130
# http://msdn.microsoft.com/en-us/library/cc422924.aspx
131131
def self.decrypt(encrypted_data)
132-
unless encrypted_data
133-
return ""
134-
end
132+
password = ""
133+
return password unless encrypted_data
135134

136135
password = ""
137-
padding = "=" * (4 - (encrypted_data.length % 4))
138-
epassword = "#{encrypted_data}#{padding}"
139-
decoded = Rex::Text.decode_base64(epassword)
136+
retries = 0
137+
original_data = encrypted_data.dup
138+
139+
begin
140+
mod = encrypted_data.length % 4
141+
142+
# PowerSploit code strips the last character, unsure why...
143+
case mod
144+
when 1
145+
encrypted_data = encrypted_data[0..-2]
146+
when 2, 3
147+
padding = '=' * (4 - mod)
148+
encrypted_data = "#{encrypted_data}#{padding}"
149+
end
150+
151+
# Strict base64 decoding used here
152+
decoded = encrypted_data.unpack('m0').first
153+
rescue ::ArgumentError => e
154+
# Appears to be some junk UTF-8 Padding appended at times in
155+
# Win2k8 (not in Win2k8R2)
156+
# Lets try stripping junk and see if we can decrypt
157+
if retries < 8
158+
retries += 1
159+
original_data = original_data[0..-2]
160+
encrypted_data = original_data
161+
retry
162+
else
163+
return password
164+
end
165+
end
140166

141167
key = "\x4e\x99\x06\xe8\xfc\xb6\x6c\xc9\xfa\xf4\x93\x10\x62\x0f\xfe\xe8\xf4\x96\xe8\x06\xcc\x05\x79\x90\x20\x9b\x09\xa4\x33\xb6\x6c\x1b"
142168
aes = OpenSSL::Cipher::Cipher.new("AES-256-CBC")

spec/lib/rex/parser/group_policy_preferences_spec.rb

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,13 @@
7777
</Groups>
7878
'
7979

80-
cpassword_utf7 = 'EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wFSuDccBEp/4l5EuKnwF0WS•ªH~AA'
80+
# Win2k8 appears to append some junk padding in some cases
81+
cpassword_win2k8 = []
82+
# Win2k8R2 - EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wEMON8tIIslS6707RU1F7Bh
83+
cpassword_win2k8 << ['EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wEMON8tIIslS6707RU1F7BhTµkp', 'N3v3rGunnaG!veYo']
84+
cpassword_win2k8 << ['EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wGSwOI7Be//GJdxd5YYXUQHTµkp', 'N3v3rGunnaG!veYou']
85+
# Win2k8R2 - EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wFSuDccBEp/4l5EuKnwF0WS
86+
cpassword_win2k8 << ['EqWFlA4kn2T6PHvGi09M7seHuqCYK/slkJWIl7mK+wFSuDccBEp/4l5EuKnwF0WS»YÂVAA', 'N3v3rGunnaG!veYouUp']
8187
cpassword_normal = "j1Uyj3Vx8TY9LtLZil2uAuZkFQA/4latT76ZwgdHdhw"
8288
cpassword_bad = "blah"
8389

@@ -102,9 +108,11 @@
102108
result.should eq("")
103109
end
104110

105-
it 'Decrypts a cpassword containing UTF7' do
106-
result = GPP.decrypt(cpassword_utf7)
107-
result.should eq('N3v3rGunnaG!veYouUp')
111+
it 'Decrypts a cpassword containing junk padding' do
112+
cpassword_win2k8.each do |encrypted, expected|
113+
result = GPP.decrypt(encrypted)
114+
result.should eq(expected)
115+
end
108116
end
109117

110118
##

0 commit comments

Comments
 (0)