#85605 - 2002-05-02 08:37 PM
Re: Get SID
|
Bryce
KiX Supporter
   
Registered: 2000-02-29
Posts: 3167
Loc: Houston TX
|
you can use the ADSID interface to pull the sid of a given user...
code:
$sidobj = createobject("adssid") $sidobj.setas(5,"WinNT://@ldomain/@userid,user") $sid = $sidobj.getas(1)
$sid will look like this.
010500000000000515000000FD77B15654FA5551235F636BE8030000
but for easy registry editing... you want a sid value like the one returned by the @sid macro.
S-1-5-21-1454471165-1364589140-1801674531-1000
Oh the math! ![[Smile]](images/icons/smile.gif) [ 02 May 2002, 20:39: Message edited by: Bryce ]
|
|
Top
|
|
|
|
#85606 - 2002-05-02 08:39 PM
Re: Get SID
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I can give a Perl program that suits your need, but have yet to venture down that path in KiXtart. Shawn had a HexSid UDF but that isn't the right format.
|
|
Top
|
|
|
|
#85607 - 2002-05-02 08:49 PM
Re: Get SID
|
Shawn
Administrator
   
Registered: 1999-08-13
Posts: 8611
|
Right you are, but you could use the liner notes of that UDF to write your own FormatSID() UDF
With everyones forgiveness, I`m going to repost it here because I can never find this thing when I go looking for it:
code:
break on
; ; Redirect output to file: usage kix32 script $out=filename ;
if $out del "$out" $=redirectoutput("$out") endif
; Get the domain object ...
$domain = getobject("WinNT://TASSIE")
; Filter for just groups ...
$domain.filter="group",""
; For ach group, display group name and getrid() ...
for each $object in $domain
$rid = getrid($object.adspath)
?"object: " $object.name " rid: " $rid next
exit
function GetRID($adspath) ; ; ; Function GetRID($ADsPath) ; ; Returns the Relative Identifier (RID) of the AD object specified ; ; Requires: 1) Windows 2000 or WindowsNT/9x /w ADSI installed ; 2) ADsSecurity.DLL (from the ADSI SDK) ; ; Usage: ; $rid = GetRID("WinNT://@LDOMAIN/@USERID,USER") ; $rid = GetRID("WinNT://@WKSTA/ADMINISTRATORS,GROUP") ; dim $adssid,$object,$sid,$sac,$rid ; ; Set initial function return value to zero ; $getrid = 0 ; ; Create the ADsSID Security Object. This object (dll) is part of the MS ADSI 2.5 SDK ; available for download at Microsoft. ADsSecurity must be manually installed from the ; reskit with the command: regsvr32 adssecurity.dll ; $adssid = createobject("adssid") ; if $adssid = 0 return endif ; ; Get a handle to the object specified in the function call ... ; $object = getobject("$adspath") ; if $object = 0 $adssid=0 return endif ; ; Call ADsSID to convert the objects ADsPath to a string version of the object's SID ; ADsSID is a black-box COM object. You put something in (SetAs) in a particular format ; (5=ADsPath), then you pull something out (GetAs) under a different format (1=SIDstring). ; This "SIDstring" is the elusive conversion of a non-variant byte-array that we are looking ; to achieve ... ; $adssid.setas(5,$adspath) ; put ADsPath in ; $sid = $adssid.getas(1) ; take SIDstring out ; ; Check to make sure we got a valid SID string ... ; if not $sid $object=0 $adssid=0 return endif ; ; EXTRACT RID FROM SID: ; ; ADsSID returns the Object's SID as a text string in the following format: ; ; 010500000000000515000000DCF4DC3B1525AF47A837D665F4010000 ; ; This is actually the SID for the Administrator account on my Win2K workstation. The SID ; string can than be broken down into the following component parts: ; ; 01 - Revision ; 05 - SubAuthority Count ; 000000000005 - Identifier Authority ; 15000000 - SubAuthority 1 (DOMAIN INDENTIFIER) ; DCF4DC3B - SubAuthority 2 (DOMAIN INDENTIFIER) ; 1525AF47 - SubAuthority 3 (DOMAIN INDENTIFIER) ; A837D665 - SubAuthority 4 (DOMAIN INDENTIFIER) ; F4010000 - SubAuthority 5 (RID) ; ; Notice that the SubAuthority count is 5 and there are 5 trailing (matching) SubAuthorities. Most ; well known SIDs (Everyone,Users,Power Users) have only 2 SubAuthorities - so you must account ; for (n) number of these. The object's RID is always the last SubAuthority in the SID. As well, ; The number string is ass-backwards in terms of converting it to a real number (using val() and &) ; so we have to normalize this using some binary math ... ; ; Extract the SID SubAuthority Count (SAC) from the SID. ; $sac = val(substr($sid,3,2)) ; if not $sac $object=0 $adssid=0 return endif ; ; Extract RID from SID (last sub-authority) ; $rid = substr($sid,17+($sac*8)-8,8) ; if not $rid $object=0 $adssid=0 return endif ; ; Convert RID little-endian , just re-reverse the bytes and convert to decimal ... ; Me smoke'm big peace-pipe when done - thanks for reading this far - ; For example this: "DCF4DC3B" becomes this: "3BDCF4DC" ; $getrid = val("&"+substr($rid,7,2)+substr($rid,5,2)+substr($rid,3,2)+substr($rid,1,2)) ; ; Cleanup ; $object=0 $adssid=0 ; endfunction
-Shawn [ 02 May 2002, 20:50: Message edited by: Shawn ]
|
|
Top
|
|
|
|
#85608 - 2002-05-03 02:44 AM
Re: Get SID
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
Thanks Guys!
I took a bit of this and a bit of that, stirred well, and here's what I ended up with. Maybe someone could Murphy-proof it and make it into a UDF. code:
break on
$sidobj = createobject("adssid") $sidobj.setas(5,"WinNT://@ldomain/@userid,user") $sid = $sidobj.getas(1)
"ADSI SID = " + $sid ?
$Rev = val(substr($sid,1,2)) $SAC = val(substr($sid,3,2))
$Result = "S-" + $Rev + "-" + $SAC For $X = 1 to $SAC $Result = $Result + "-"+Val("&"+substr($sid,8*$X+15,2)+substr($sid,8*$X+13,2)+substr($sid,8*$X+11,2)+substr($sid,8*$X+9,2)) Next
"Translated SID = "+ $Result ?
"KiX Macro @@SID = "+@SID ?
get $_
exit 1
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
|
Top
|
|
|
|
#85609 - 2002-05-03 03:49 AM
Re: Get SID
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Les, great work.
I think that adding a line and altering the next makes it more accurate when parsing the hex sid. The Indentity Authority is a 48-bit string. code:
$IdentAuth = Val("&" + substr($sid,5,12))
$Result = "S-" + $Rev + "-" + $IdentAuth
instead of code:
$Result = "S-" + $Rev + "-" + $SAC
[ 03 May 2002, 03:50: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#85610 - 2002-05-03 03:50 AM
Re: Get SID
|
Les
KiX Master
   
Registered: 2001-06-11
Posts: 12734
Loc: fortfrances.on.ca
|
OK, wrapped it up as a UDF. If nobody finds fault with it I'll post it in the UDF section.
code:
break on
$SID = GetSID("WinNT://ff/lligetfa,USER") ? $SID
Get $_ Exit 1
function GetSID($adspath) ;Returns the ASCII Security Identifier (SID) of the ADSI object specified ; ; Requires: ; 1) Windows 2000 or WindowsNT/9x /w ADSI installed ; 2) ADsSecurity.DLL (from the ADSI SDK) ; ; Usage: ; $SID = GetSID("WinNT://@LDOMAIN/@USERID,USER") dim $rev,$sidobj,$sid,$sac,$x $GetSID=0
$sidobj=createobject("adssid") $sidobj.setas(5,$adspath) $sid=$sidobj.getas(1)
if not $sid $sidobj=0 return endif
$Rev=val(substr($sid,1,2)) ; Extract the SubAuthority Count (SAC) from the SID $SAC=val(substr($sid,3,2))
$GetSID="S-"+$Rev+"-"+$SAC ; Convert SID little-endian, just re-reverse the bytes and convert to decimal...
For $X=1 to $SAC $GetSID=$GetSID+"-"+Val("&"+substr($sid,8*$X+15,2)+substr($sid,8*$X+13,2)+substr($sid,8*$X+11,2)+substr($sid,8*$X+9,2)) Next $sidobj=0
EndFunction
Note: A revised (corrected version) of this code has been posted to GetSID() - Returns SID and converts it to string format [ 04 May 2002, 20:23: Message edited by: LLigetfa ]
_________________________
Give a man a fish and he will be back for more. Slap him with a fish and he will go away forever.
|
|
Top
|
|
|
|
#85611 - 2002-05-03 04:58 AM
Re: Get SID
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
Les, try this with your code.
Domain/administrators,group
This will demonstrate the code issue in the post just before your last post.
From MSDN: http://msdn.microsoft.com/library/default.asp?url=/library/en-us/security/Security/sid_components.asp
quote: The following example uses this notation to display the well-known domain-relative SID of the local Administrators group:
S-1–5-32-544
[ 03 May 2002, 05:00: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#85613 - 2002-05-03 05:14 AM
Re: Get SID
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I believe that Shawn's format is correct. My guess is that there is a little confusion. quote: 01 05 000000000005 15000000 BC2E7001 633DBD3D 0E6D055C F4010000
The second item is only a count that represents the number of items that follow the "Identifier Authority". Five in this case.
This is the hex sid of the domain/Administrators, group
01 02 000000000005 20000000 20020000
Two items follow the "Identifier Authority" -> 000000000005 [ 03 May 2002, 05:25: Message edited by: Howard Bullock ]
|
|
Top
|
|
|
|
#85615 - 2002-05-03 06:19 AM
Re: Get SID
|
Howard Bullock
KiX Supporter
   
Registered: 2000-09-15
Posts: 5809
Loc: Harrisburg, PA USA
|
I know exactly what you're saying. Unfortunately, I am one of those sick pups that programs for fun. If you didn't post that code, I would have had to write it tomorrow.
|
|
Top
|
|
|
|
Moderator: Shawn, ShaneEP, Ruud van Velsen, Arend_, Jochen, Radimus, Glenn Barnas, Allen, Mart
|
0 registered
and 756 anonymous users online.
|
|
|