2015-06-07 15:09:02 +00:00
|
|
|
# encoding: utf-8
|
2015-07-15 13:15:18 +00:00
|
|
|
# copyright: 2015, Vulcano Security GmbH
|
2015-06-07 15:09:02 +00:00
|
|
|
# license: All rights reserved
|
|
|
|
|
2015-04-17 13:37:17 +00:00
|
|
|
require 'json'
|
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# return JSON object
|
2015-09-05 14:07:54 +00:00
|
|
|
def gpo(policy_path, policy_name)
|
|
|
|
file = ::File.read(::File.join ::File.dirname(__FILE__), 'gpo.json')
|
2015-08-03 00:40:08 +00:00
|
|
|
gpo_hash = JSON.parse(file)
|
2015-09-04 07:59:30 +00:00
|
|
|
key = 'Machine--' + policy_path + '--' + policy_name
|
2015-07-26 10:30:12 +00:00
|
|
|
gpo_hash[key]
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# Group Policy
|
2015-08-28 23:09:35 +00:00
|
|
|
class GroupPolicy < Vulcano.resource(1)
|
|
|
|
name 'group_policy'
|
2015-07-26 10:30:12 +00:00
|
|
|
|
2015-09-09 16:37:16 +00:00
|
|
|
def get_registry_value(entry)
|
2015-07-26 10:30:12 +00:00
|
|
|
keys = entry['registry_information'][0]
|
|
|
|
cmd = "(Get-Item 'Registry::#{keys['path']}').GetValue('#{keys['key']}')"
|
2015-08-30 02:33:15 +00:00
|
|
|
command_result ||= vulcano.run_command(cmd)
|
2015-09-05 14:07:54 +00:00
|
|
|
val = { exit_code: command_result.exit_status.to_i, data: command_result.stdout }
|
2015-07-26 10:30:12 +00:00
|
|
|
val
|
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-09-09 16:37:16 +00:00
|
|
|
def convert_value(value)
|
2015-07-26 10:30:12 +00:00
|
|
|
val = value.strip
|
|
|
|
val = val.to_i if val.match(/^\d+$/)
|
2015-09-04 07:59:30 +00:00
|
|
|
val
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# returns nil, if not existant or value
|
|
|
|
def method_missing(meth)
|
|
|
|
# map gpo to registry key
|
|
|
|
entry = gpo(@name, meth.to_s)
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# get data
|
2015-09-09 16:37:16 +00:00
|
|
|
val = get_registry_value(entry)
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
# verify data
|
|
|
|
if (val[:exit_code] == 0)
|
2015-09-09 16:37:16 +00:00
|
|
|
return convert_value(val[:data])
|
2015-07-26 10:30:12 +00:00
|
|
|
else
|
2015-09-04 07:59:30 +00:00
|
|
|
return nil
|
2015-04-17 13:37:17 +00:00
|
|
|
end
|
2015-07-26 10:30:12 +00:00
|
|
|
end
|
2015-04-17 13:37:17 +00:00
|
|
|
|
2015-07-26 10:30:12 +00:00
|
|
|
def to_s
|
|
|
|
'Group Policy'
|
2015-04-17 13:37:17 +00:00
|
|
|
end
|
|
|
|
end
|