Skip to content

Commit 0a2b79c

Browse files
committed
Tidyup parser
1 parent 09af023 commit 0a2b79c

File tree

1 file changed

+29
-29
lines changed

1 file changed

+29
-29
lines changed

lib/rex/parser/group_policy_preferences.rb

Lines changed: 29 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ def self.parse(data)
2727
xml.elements.to_a("//Properties").each do |node|
2828
epassword = node.attributes['cpassword']
2929
next if epassword.to_s.empty?
30-
pass = self.decrypt(epassword)
30+
password = self.decrypt(epassword)
3131

3232
user = node.attributes['runAs'] if node.attributes['runAs']
3333
user = node.attributes['accountName'] if node.attributes['accountName']
3434
user = node.attributes['username'] if node.attributes['username']
3535
user = node.attributes['userName'] if node.attributes['userName']
36-
user = node.attributes['newName'] unless node.attributes['newName'].nil? or node.attributes['newName'].empty?
36+
user = node.attributes['newName'] unless node.attributes['newName'].nil? || node.attributes['newName'].empty?
3737
changed = node.parent.attributes['changed']
3838

3939
# Printers and Shares
@@ -56,18 +56,18 @@ def self.parse(data)
5656

5757
result = {
5858
:USER => user,
59-
:PASS => pass,
59+
:PASS => password,
6060
:CHANGED => changed
6161
}
6262

63-
result.merge!({ :EXPIRES => expires }) unless expires.nil? or expires.empty?
64-
result.merge!({ :NEVER_EXPIRE => never_expires }) unless never_expires.nil? or never_expires.empty?
65-
result.merge!({ :DISABLED => disabled }) unless disabled.nil? or disabled.empty?
66-
result.merge!({ :PATH => path }) unless path.nil? or path.empty?
67-
result.merge!({ :DATASOURCE => dsn }) unless dsn.nil? or dsn.empty?
68-
result.merge!({ :DRIVER => driver }) unless driver.nil? or driver.empty?
69-
result.merge!({ :TASK => app_name }) unless app_name.nil? or app_name.empty?
70-
result.merge!({ :SERVICE => service }) unless service.nil? or service.empty?
63+
result.merge!({ :EXPIRES => expires }) unless expires.nil? || expires.empty?
64+
result.merge!({ :NEVER_EXPIRE => never_expires }) unless never_expires.nil? || never_expires.empty?
65+
result.merge!({ :DISABLED => disabled }) unless disabled.nil? || disabled.empty?
66+
result.merge!({ :PATH => path }) unless path.nil? || path.empty?
67+
result.merge!({ :DATASOURCE => dsn }) unless dsn.nil? || dsn.empty?
68+
result.merge!({ :DRIVER => driver }) unless driver.nil? || driver.empty?
69+
result.merge!({ :TASK => app_name }) unless app_name.nil? || app_name.empty?
70+
result.merge!({ :SERVICE => service }) unless service.nil? || service.empty?
7171

7272
attributes = []
7373
node.elements.each('//Attributes//Attribute') do |dsn_attribute|
@@ -82,7 +82,7 @@ def self.parse(data)
8282
results << result
8383
end
8484

85-
return results
85+
results
8686
end
8787

8888
def self.create_tables(results, filetype, domain=nil, dc=nil)
@@ -102,19 +102,19 @@ def self.create_tables(results, filetype, domain=nil, dc=nil)
102102
table << ["TYPE", filetype]
103103
table << ["USERNAME", result[:USER]]
104104
table << ["PASSWORD", result[:PASS]]
105-
table << ["DOMAIN CONTROLLER", dc] unless dc.nil? or dc.empty?
106-
table << ["DOMAIN", domain] unless domain.nil? or domain.empty?
105+
table << ["DOMAIN CONTROLLER", dc] unless dc.nil? || dc.empty?
106+
table << ["DOMAIN", domain] unless domain.nil? || domain.empty?
107107
table << ["CHANGED", result[:CHANGED]]
108-
table << ["EXPIRES", result[:EXPIRES]] unless result[:EXPIRES].nil? or result[:EXPIRES].empty?
109-
table << ["NEVER_EXPIRES?", result[:NEVER_EXPIRE]] unless result[:NEVER_EXPIRE].nil? or result[:NEVER_EXPIRE].empty?
110-
table << ["DISABLED", result[:DISABLED]] unless result[:DISABLED].nil? or result[:DISABLED].empty?
111-
table << ["PATH", result[:PATH]] unless result[:PATH].nil? or result[:PATH].empty?
112-
table << ["DATASOURCE", result[:DSN]] unless result[:DSN].nil? or result[:DSN].empty?
113-
table << ["DRIVER", result[:DRIVER]] unless result[:DRIVER].nil? or result[:DRIVER].empty?
114-
table << ["TASK", result[:TASK]] unless result[:TASK].nil? or result[:TASK].empty?
115-
table << ["SERVICE", result[:SERVICE]] unless result[:SERVICE].nil? or result[:SERVICE].empty?
116-
117-
unless result[:ATTRIBUTES].nil? or result[:ATTRIBUTES].empty?
108+
table << ["EXPIRES", result[:EXPIRES]] unless result[:EXPIRES].nil? || result[:EXPIRES].empty?
109+
table << ["NEVER_EXPIRES?", result[:NEVER_EXPIRE]] unless result[:NEVER_EXPIRE].nil? || result[:NEVER_EXPIRE].empty?
110+
table << ["DISABLED", result[:DISABLED]] unless result[:DISABLED].nil? || result[:DISABLED].empty?
111+
table << ["PATH", result[:PATH]] unless result[:PATH].nil? || result[:PATH].empty?
112+
table << ["DATASOURCE", result[:DSN]] unless result[:DSN].nil? || result[:DSN].empty?
113+
table << ["DRIVER", result[:DRIVER]] unless result[:DRIVER].nil? || result[:DRIVER].empty?
114+
table << ["TASK", result[:TASK]] unless result[:TASK].nil? || result[:TASK].empty?
115+
table << ["SERVICE", result[:SERVICE]] unless result[:SERVICE].nil? || result[:SERVICE].empty?
116+
117+
unless result[:ATTRIBUTES].nil? || result[:ATTRIBUTES].empty?
118118
result[:ATTRIBUTES].each do |dsn_attribute|
119119
table << ["ATTRIBUTE", "#{dsn_attribute[:A_NAME]} - #{dsn_attribute[:A_VALUE]}"]
120120
end
@@ -123,7 +123,7 @@ def self.create_tables(results, filetype, domain=nil, dc=nil)
123123
tables << table
124124
end
125125

126-
return tables
126+
tables
127127
end
128128

129129
# Decrypts passwords using Microsoft's published key:
@@ -132,8 +132,8 @@ def self.decrypt(encrypted_data)
132132
unless encrypted_data
133133
return ""
134134
end
135-
136-
pass = ""
135+
136+
password = ""
137137
padding = "=" * (4 - (encrypted_data.length % 4))
138138
epassword = "#{encrypted_data}#{padding}"
139139
decoded = Rex::Text.decode_base64(epassword)
@@ -145,12 +145,12 @@ def self.decrypt(encrypted_data)
145145
aes.key = key
146146
plaintext = aes.update(decoded)
147147
plaintext << aes.final
148-
pass = plaintext.unpack('v*').pack('C*') # UNICODE conversion
148+
password = plaintext.unpack('v*').pack('C*') # UNICODE conversion
149149
rescue OpenSSL::Cipher::CipherError => e
150150
puts "Unable to decode: \"#{encrypted_data}\" Exception: #{e}"
151151
end
152152

153-
return pass
153+
password
154154
end
155155

156156
end

0 commit comments

Comments
 (0)