...until now I didn't know that there is a way to build .inf templates. Do you think I could create one and merge it with our "base" security template, so I could receive decent permission and auditing settings by just applying that policy file? Would be great -
- although exactly today (before reading your post) I perfectionized my version using setacl.exe (please see below).
#include <Constants.au3>
#include <GUIConstants.au3>
#include <GUIConstantsEx.au3>
#include <WindowsConstants.au3>
#include <StaticConstants.au3>
#include <String.au3>
#include <file.au3>
#include <Array.au3>
; Define global variables
; ==================================================================================================
Global $s_IniFile = "setACLs.ini"
Global $i_OSbits = _OSBits
()
Global $i_height
; Check if the INI-File exists
; ==================================================================================================
$i_RVal = FileExists($s_IniFile)
If $i_RVal <> 1 Then
MsgBox(16, "SetACLs", "Error! INI-File " & $s_IniFile & " not found!", "")
Exit
EndIf
; Run da shi-i-iiit!
; ==================================================================================================
_setACLs
()
; Function _setACLs to harden ACLs on security relevant files and directories specified in the INI-File
; ==============================================================================================
Func _setACLs
()
; Ask for the password to access the ToolsShare
$s_ToolsServer = IniRead($s_IniFile, "Settings", "ToolsServer", "")
$s_AdminPassC = InputBox("SetACLs", "Please enter the password of an Administrator with access: ", "", "*", 300, 120)
If $s_AdminPassC = '' Then
MsgBox(16, "SetACLs", "Error! Empty credentials supplied - you are not allowed to access the share!", "")
Exit
Else
Local $i_return = 0
DriveMapDel($s_ToolsServer & "\c$")
If DriveMapAdd("", $s_ToolsServer & "\c$", 0, "Administrator", $s_AdminPassC) = $i_return Then
MsgBox(16, "SetACLs", "Error! Wrong credentials supplied - you are not allowed to access the share!", "")
Exit
EndIf
EndIf
; Logon to the ToolsServer
$s_InfoValue = """Logging on to " & $s_ToolsServer & "..."""
_InfoGui
($s_InfoValue, 45)
RunWait(@ComSpec & " /c " & "net use " & $s_ToolsServer & "\postinstall /username: Administrator " & $s_AdminPassC, "", @SW_HIDE)
GUIDelete()
; Set a variable containing the right filename for SetACL.exe depending on the local machines bit count (x32 or x64)
$s_ToolsShare = IniRead($s_IniFile, "Settings", "ToolsShare", "")
If Not $i_OSbits = 32 Then
$s_ACLtool = "SetACL-x64.exe"
Else
$s_ACLtool = "SetACL-x32.exe"
EndIf
; Check if the chosen setacl*.exe is accessible
$i_RVal = FileExists($s_ToolsShare & "\" & $s_ACLtool)
If $i_RVal <> 1 Then
MsgBox(16, "D5100 SetACLs", "Error!" & @CRLF & @CRLF & $s_ToolsShare & "\" & $s_ACLtool & @CRLF & @CRLF & "...is not accessible!", "")
Exit
EndIf
; Do a first run for the file and directory permissions (DACLs)
; Check how many of the 20 possible Objects have dACLs defined in the INI-File ($i_Dcounter)
Local $i_Dcounter = 0
For $i = 0 To 19
$s_dACLobject = "dACLobject_" & $i
If IniRead($s_IniFile, "Settings", $s_dACLobject, "") <> "" Then
$i_Dcounter = $i_Dcounter + 1
EndIf
Next
; Create the array $a_dACLobjects (dynamically in size depending on $i_counter's value)
Local $a_dACLobjects[$i_Dcounter]
For $i = 0 To $i_Dcounter - 1
$s_dACLobject = "dACLobject_" & $i
If IniRead($s_IniFile, "Settings", $s_dACLobject, "") <> "" Then
$a_dACLobjects[$i] = IniRead($s_IniFile, "Settings", $s_dACLobject, "")
EndIf
Next
; Set the ACLs for all objects specified in the INI-File
Global $s_YesNo_P
For $i = 0 To UBound($a_dACLobjects) - 1
; set SuccessAuditing for "Everyone"
; inherit settings for "This folder and files only"
; do not inherit
If $s_YesNo_P = "" Then
$s_cmd = $s_ToolsShare & "\" & $s_ACLtool & " -on ""c:\\"" -ot file -actn ace -ace ""n:S-1-1-0;m:revoke;s:y"" -ace ""n:S-1-5-32-545;m:revoke;s:y"" -ace ""n:S-1-5-32-547;m:revoke;s:y"" -ace ""n:S-1-5-32-544;p:full;s:y"" -ace ""n:S-1-5-18;p:full;s:y"
$s_InfoValue = "Using """ & $s_ACLtool & """ to set dACLS (Permissions) on: " & @CRLF & @CRLF & "C:" & @CRLF & "(This folder and files only)"
_InfoGui
($s_InfoValue, 25)
RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE)
$s_YesNo_P = "No"
GUIDelete()
EndIf
; revoke AllAccess for "Everyone", "Users" and "Power Users"
; set FullAccess for "Administrators" and "System"
; copy inherited permissions
; inherit the new ones recursivly
$s_cmd = $s_ToolsShare & "\" & $s_ACLtool & " -on """ & $a_dACLobjects[$i] & """ -ot file -actn ace -ace ""n:S-1-1-0;m:revoke;i:sc,so;s:y"" -ace ""n:S-1-5-32-545;m:revoke;i:sc,so;s:y"" -ace ""n:S-1-5-32-547;m:revoke;i:sc,so;s:y"" -ace ""n:S-1-5-32-544;p:full;i:sc,so;s:y"" -ace ""n:S-1-5-18;p:full;i:sc,so;s:y"" -actn clear -clr ""dacl"" -actn rstchldrn -rst ""dacl" ; -rec cont_obj"
ConsoleWrite("Command = " & $s_cmd & @CRLF)
$s_InfoValue = "Using """ & $s_ACLtool & """ to set dACLS (Permissions) on: " & @CRLF & @CRLF & $a_dACLobjects[$i]
_InfoGui
($s_InfoValue, 35)
RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE)
GUIDelete()
Next
; Do a second run for the file and directory auditing (SACLs)
; Check how many of the 20 possible Objects have sACLs defined in the INI-File ($i_Scounter)
Local $i_Scounter = 0
For $i = 0 To 19
$s_sACLobject = "sACLobject_" & $i
If IniRead($s_IniFile, "Settings", $s_sACLobject, "") <> "" Then
$i_Scounter = $i_Scounter + 1
EndIf
Next
; Create the array $a_sACLobjects (dynamically in size depending on $i_counter's value)
Local $a_sACLobjects[$i_Scounter]
For $i = 0 To $i_Scounter - 1
$s_sACLobject = "sACLobject_" & $i
If IniRead($s_IniFile, "Settings", $s_sACLobject, "") <> "" Then
$a_sACLobjects[$i] = IniRead($s_IniFile, "Settings", $s_sACLobject, "")
EndIf
Next
; Set auditing for C:\ once and cycle as long as there are objects within the array
Global $s_YesNo_A
For $i = 0 To UBound($a_sACLobjects) - 1
; set SuccessAuditing for "Everyone"
; inherit settings for "This folder and files only"
; do not inherit
If $s_YesNo_A = "" Then
$s_cmd = $s_ToolsShare & "\" & $s_ACLtool & " -on ""c:\\"" -ot file -actn ace -ace ""n:S-1-1-0;p:full;m:aud_succ;i:so,np;w:sacl;s:y"
$s_InfoValue = "Using """ & $s_ACLtool & """ to set sACLS (Auditing) on: " & @CRLF & @CRLF & "C:" & @CRLF & "(This folder and files only)"
_InfoGui
($s_InfoValue, 25)
RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE)
$s_YesNo_A = "No"
GUIDelete()
EndIf
; set SuccessAuditing for "Everyone"
; copy inherited settings
; inherit settings recursivly
$s_cmd = $s_ToolsShare & "\" & $s_ACLtool & " -on """ & $a_sACLobjects[$i] & """ -ot file -actn ace -ace ""n:S-1-1-0;p:full;m:aud_succ;i:so,sc;w:sacl;s:y"" -actn setprot -op ""sacl:p_c"" -actn clear -clr ""sacl"" -actn rstchldrn -rst ""sacl" ; -rec cont_obj
$s_InfoValue = "Using """ & $s_ACLtool & """ to set sACLS (Auditing) on: " & @CRLF & @CRLF & $a_sACLobjects[$i]
_InfoGui
($s_InfoValue, 35)
RunWait(@ComSpec & " /c " & $s_cmd, "", @SW_HIDE)
GUIDelete()
Next
EndFunc ;==>_setACLs
; Function _OSBits to check if the host's OS is 32 or 64bits, returns "64" or "32"
; ==============================================================================================
Func _OSBits
()
Local $tOS = DllStructCreate("char[256]")
Local $aGSWD = DllCall("Kernel32.dll", "int", "GetSystemWow64Directory", "ptr", DllStructGetPtr($tOS), "int", 256)
If IsArray($aGSWD) And DllStructGetData($tOS, 1) Then Return 64
Return 32
EndFunc ;==>_OSBits
; Function _InfoGUI to display an info about the task currently processed.
; ==============================================================================================
Func _InfoGUI
($InfoValue, $i_height)
GUICreate("", 320, 100, -1, -1, $WS_Popup, $WS_EX_TOOLWINDOW, "")
GUICtrlCreateLabel($InfoValue, 0, $i_height, 320, -1, $SS_center)
GUISetState(@SW_SHOW)
Sleep(500)
EndFunc ;==>_InfoGUI
;#####################################################################
;#
;# Christoph Herdeg, August 2008
;#
http://www.cs-it-solutions.de;#
;#####################################################################
;#
;# Preface
;# ===================
;# "SetACLs.exe" is a utility to set drive, folder and file permissions and auditing settings of a
;# local machine to compliance with ITCS104.
;#
;# General Information
;# ===================
;#
;# This utility is intended to be used from whereever you want.
;#
;# [Settings] contains all settings, e.g, the following:
;#
;# - The name of the Server the ToolsShare resides on
;# - The locations where the needed external tools and software reside
;# - The dACLobject_N - entries where targets can be defined to receive dACLs
;# - The sACLobject_N - entries where targets can be defined to receive sACLs
;#
;# Compatibility
;# ===================
;# A few words on compatibility: this utility has been tested and should work on:
;#
;# - Windows 2000 Workstation, Server and Advanced Server
;# - Windows XP Professional x86 and x64
;# - Windows Server 2003 Standard, Enterprise and Datacenter x86 and x64
;# - Windows Vista Enterprise and Ultimate x86 and x64
;# - Windows Server 2008 Standard, Enterprise and Datacenter x86 and x64
;#
;# Supported are all different languages of the above operating systems as long as western characters
;# are used.
;#
;# Liability/warranty
;# ===================
;# As you will have understood by now this tool comes "as is" and without any free support. If you need
;# bugfixes or enhancements of any kind, please feel free to contact me: mailto:info@cs-it-solutions.de
;#
;#####################################################################
[Settings]
;#####################################################################
;#
;# General Settings Section
;#
;#####################################################################
;# UNC-Name of the server the tools used by this program reside on
;#####################################################################
ToolsServer=\\Server
;#####################################################################
;# UNC-Name of the share the tools used by this program reside on ("\\Server\Share\Directory")
;# If you move the contents of this share to another location, please keep the existing directory structure.
;#####################################################################
ToolsShare=\\Server\Share\SetACLs\Tools
;#####################################################################
;# Here up to 20 objects may be defined to set dACLs on. The dACLs of the objects defined
;# here are set to to the following ITSC104 compliant values:
;#
;# "COMPUTERNAME\System" = FullAccess
;# "COMPUTERNAME\Administrators" = FullAccess
;# "COMPUTERNAME\Users" = NoAccess
;# "COMPUTERNAME\PowerUsers" = NoAccess
;# "COMPUTERNAME\Everyone" = NoAccess
;#
;# The First Object has to be "dACLobject_0" and NOT "dACLobject_1".
;#####################################################################
dACLobject_0=c:\WINDOWS\repair
dACLobject_1=c:\WINDOWS\security
dACLobject_2=c:\WINDOWS\system32\config
dACLobject_3=c:\WINDOWS\system32\dllcache
dACLobject_4=c:\WINDOWS\system32\GroupPolicy
dACLobject_5=
dACLobject_6=
dACLobject_7=
dACLobject_8=
dACLobject_9=
dACLobject_10=
dACLobject_11=
dACLobject_12=
dACLobject_13=
dACLobject_14=
dACLobject_15=
dACLobject_16=
dACLobject_17=
dACLobject_18=
dACLobject_19=
;#####################################################################
;# Here up to 20 objects may be defined to set sACLs on. The sACLs of the objects defined
;# here are set to to the following ITSC104 compliant values:
;#
;# "COMPUTERNAME\Everyone" = Audit All Successfull access attempts
;#
;# The root folder C: and the objects within are always configured with the sACLs above;
;# if you need other objects to be audited, just enter their base folders below.
;#
;# The First Object has to be "sACLobject_0" and NOT "sACLobject_1".
;#####################################################################
sACLobject_0=c:\Windows
sACLobject_1=c:\Windows\system
sACLobject_2=
sACLobject_3=
sACLobject_4=
sACLobject_5=
sACLobject_6=
sACLobject_7=
sACLobject_8=
sACLobject_9=
sACLobject_10=
sACLobject_11=
sACLobject_12=
sACLobject_13=
sACLobject_14=
sACLobject_15=
sACLobject_16=
sACLobject_17=
sACLobject_18=
sACLobject_19=
So...if you (or anybody else) uses my code, please upgrade...I managed to implement inheritance and some cleaning and "houskeeping". There will be one more update in the next months containing the possibility of entering a free number of *ACLobjects in the INI-File. I've got such a function working within another script but have no time at all to insert it here.