O R G A N I C / F E R T I L I Z E R: 04.07

Apr 5, 2007

os: opening up windows server 2003 service pack 1 for practical functionality...

... or functional practicality or whatever. it's interesting that "secure" has made some things especially troublesome! for instance, out of the box, after applying service pack 1, querying wmi will fail. how do you fix it? you add the account you're using to the local administrators group. now that doesn't sound right since the idea is that we're securing things down. the challenge was to take a user account without elevated permissions and grant it the rights it needs to query wmi without the exposure of adding it to local administrators. it turns out there are three things you have to do to make this work:
  • add the user to "distributed com users" local group
  • grant permission to the wmi namespace for which you wish you allow access (in our case, cimv2)
  • grant permission to service control manager
add the user to "distributed com users" local group:
not much to explain for this. simply add the account to the local group named "distributed com users". i reference an article below. by following this step instead of what's in the article, you can skip anything past #10.
grant permission to the wmi namespace:
when you grant permission, you'll need to grant the following rights:
  • execute methods
  • enable account
  • remote enable
  • read security
you'll also need to grant this permission for "this namespace and all subnamespaces"
grant permission to service control manager:
this step is only necessary if you plan to allow your limited-rights user to query the win32_service class. using sc, you can view the current permissions on scmanager, like this:
  • sc sdshow scmanager
of course that's the easy part. you'll get a big, long sddl in response. assuming your result looks like mine, this is how you want to edit it. by the way, it's all one line in real-life: D:(A;;CC;;;AU)(A;;CCLCRPRC;;;IU)(A;;CCLCRPRC;;;SU)(A;;CCLCRPWPRC;;;SY) (A;;KA;;;BA)(A;;KAFALC;;;[your sid here])S:(AU;FA;KA;;;WD)(AU;OIIOFA;GA;;;WD) remember, that line above is ONE LINE. remove the brackets (duh). put in the sid of the account that you want to grant access. you can use a tool like psgetsid to grab the sid value (or just open adsiedit). once you've got it composed, use this command to apply it:
  • sc sdset scmanager [that long sddl above]
now if you want a really cheesy, automated method that you can deploy to your servers, here's a way to do it. btw, you'll need sc.exe (version specific mentioned in the microsoft article below):

sComputer = "."
Set oServices = GetObject("winmgmts:\\" & sComputer & "\root\cimv2")
Set oCIMV2 = oServices.Get("__SystemSecurity=@")
Set oShell = WScript.CreateObject("WScript.Shell")


Function SetWMIPerms
    sBinSDDL = Array([add binary sddl here])
End Function

Function SetSvcsPerms
    sCommand = "sc sdset scmanager [add that same long sddl]"
    oShell.Run sCommand,0
End Function

Function SetDCOMPerms
    sCommand = "net localgroup " & Chr(34) & "Distributed COM Users" & Chr(34) &_
               " " & Chr(34) & "Domain\User" & Chr(34) & " /ADD"
    oShell.Run sCommand,0
End Function
maybe you're wondering how you get that binary sddl that's mentioned in the first function. if you modify a computer to have the correct permissions as noted in the second bullet, you can run this script against the machine. it'll echo back the binary sddl (looks like a long string of numbers and commas) that will contain the changes you've made. here's the cheesy code:
targetmachine = "."

Set objServices = GetObject("winmgmts:\\" & targetmachine & "\root\cimv2")
Set CimV2 = objServices.Get("__SystemSecurity=@")
ReturnValue = Cimv2.GetSD(arrSD)

If Err <> 0 Then
    WScript.Echo "Method returned error " & ReturnValue
End If

SDString = ""

For I = Lbound(arrSD) To Ubound(arrSD)
    SDString = SDString & arrSD(I) & ","

SDstring = Left(SDstring,Len(SDstring)-1)
WScript.Echo SDString
once you have the binary sddl, drop it into the first function. don't forget to remove the [ ] brackets. good luck. :) credit: this article was a lot of help microsoft's article on applying sddl change on service control manager