Windows Vista Tips

Windows Vista Tips > Newsgroups > Windows Server > Server Security > Get access token information using vbscript ?

Reply
Thread Tools Display Modes

Get access token information using vbscript ?

 
 
Vilius Mockūnas
Guest
Posts: n/a

 
      08-15-2009
Hello,

Is it possible to get access token information using vbscript ?

thanks
Vilius


 
Reply With Quote
 
 
 
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      08-16-2009

"Vilius Mockūnas" <> wrote in message
news:%...
> Hello,
>
> Is it possible to get access token information using vbscript ?
>
> thanks
> Vilius


Most of the information in the access token provided to a user when they
authenticate is identical to the information you get when you retrieve the
value of the tokenGroups attribute of the user object. This is an
operational attribute, meaning the values are constructed by AD upon
request. It is a multi-valued array of security group SID's. Each SID value
is itself a byte array. An example for the current user could be:
===========
Option Explicit
Dim objSysInfo, strUserDN, objUser
Dim arrbytSIDs, j, arrstrGroupSIDs()
Dim strHexSID

' Bind to current user object.
Set objSysInfo = CreateObject("ADSystemInfo")
strUserDN = objSysInfo.UserName
Set objUser = GetObject("LDAP://" & strUserDN)

' Retrieve tokenGroups attribute.
objUser.GetInfoEx Array("tokenGroups"), 0
arrbytSIDs = objUser.Get("tokenGroups")

' Convert into an array of hex string values.
If (UBound(arrbytSIDs) = -1) Then
' No group SID values, do nothing.
ElseIf (TypeName(arrbytSIDs) = "Byte()") Then
' One group SID.
ReDim arrstrGroupSIDs(0)
arrstrGroupSIDs(0) = OctetToHexStr(arrbytSIDs)
Else
' More than one SID value in the array.
ReDim arrstrGroupSIDs(UBound(arrbytSIDs))
For j = 0 To UBound(arrbytSIDs)
arrstrGroupSIDs(j) = OctetToHexStr(arrbytSIDs(j))
Next
End If

' Display the SID values.
' Display both hex and decimal values.
For Each strHexSID In arrstrGroupSIDs
Wscript.Echo strHexSID
Wscript.Echo HexSIDToDec(strHexSID)
Next

Function OctetToHexStr(ByVal arrbytOctet)
' Function to convert OctetString (byte array) to Hex string.
Dim k
OctetToHexStr = ""
For k = 1 To Lenb(arrbytOctet)
OctetToHexStr = OctetToHexStr _
& Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
Next
End Function

Function HexSIDToDec(ByVal strSID)
' Function to convert most hex SID values to decimal format.

Dim arrbytSID, lngTemp, j

ReDim arrbytSID(Len(strSID)/2 - 1)
For j = 0 To UBound(arrbytSID)
arrbytSID(j) = CInt("&H" & Mid(strSID, 2*j + 1, 2))
Next

If (UBound(arrbytSID) = 11) Then
HexSIDToDec = "S-" & arrbytSID(0) & "-" _
& arrbytSID(1) & "-" & arrbytSID(8)

Exit Function
End If

If (UBound(arrbytSID) = 15) Then
HexSIDToDec = "S-" & arrbytSID(0) & "-" _
& arrbytSID(1) & "-" & arrbytSID(8)

lngTemp = arrbytSID(15)
lngTemp = lngTemp * 256 + arrbytSID(14)
lngTemp = lngTemp * 256 + arrbytSID(13)
lngTemp = lngTemp * 256 + arrbytSID(12)

HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

Exit Function
End If

HexSIDToDec = "S-" & arrbytSID(0) & "-" _
& arrbytSID(1) & "-" & arrbytSID(8)

lngTemp = arrbytSID(15)
lngTemp = lngTemp * 256 + arrbytSID(14)
lngTemp = lngTemp * 256 + arrbytSID(13)
lngTemp = lngTemp * 256 + arrbytSID(12)

HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

lngTemp = arrbytSID(19)
lngTemp = lngTemp * 256 + arrbytSID(18)
lngTemp = lngTemp * 256 + arrbytSID(17)
lngTemp = lngTemp * 256 + arrbytSID(16)

HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

lngTemp = arrbytSID(23)
lngTemp = lngTemp * 256 + arrbytSID(22)
lngTemp = lngTemp * 256 + arrbytSID(21)
lngTemp = lngTemp * 256 + arrbytSID(20)

HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)

If (UBound(arrbytSID) > 23) Then
lngTemp = arrbytSID(25)
lngTemp = lngTemp * 256 + arrbytSID(24)

HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
End If

End Function


 
Reply With Quote
 
PaulM
Guest
Posts: n/a

 
      08-16-2009


Not sure right now, maybe someone else would know.


"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:#...
>
> "Vilius Mockūnas" <> wrote in message
> news:%...
>> Hello,
>>
>> Is it possible to get access token information using vbscript ?
>>
>> thanks
>> Vilius

>
> Most of the information in the access token provided to a user when they
> authenticate is identical to the information you get when you retrieve the
> value of the tokenGroups attribute of the user object. This is an
> operational attribute, meaning the values are constructed by AD upon
> request. It is a multi-valued array of security group SID's. Each SID
> value is itself a byte array. An example for the current user could be:
> ===========
> Option Explicit
> Dim objSysInfo, strUserDN, objUser
> Dim arrbytSIDs, j, arrstrGroupSIDs()
> Dim strHexSID
>
> ' Bind to current user object.
> Set objSysInfo = CreateObject("ADSystemInfo")
> strUserDN = objSysInfo.UserName
> Set objUser = GetObject("LDAP://" & strUserDN)
>
> ' Retrieve tokenGroups attribute.
> objUser.GetInfoEx Array("tokenGroups"), 0
> arrbytSIDs = objUser.Get("tokenGroups")
>
> ' Convert into an array of hex string values.
> If (UBound(arrbytSIDs) = -1) Then
> ' No group SID values, do nothing.
> ElseIf (TypeName(arrbytSIDs) = "Byte()") Then
> ' One group SID.
> ReDim arrstrGroupSIDs(0)
> arrstrGroupSIDs(0) = OctetToHexStr(arrbytSIDs)
> Else
> ' More than one SID value in the array.
> ReDim arrstrGroupSIDs(UBound(arrbytSIDs))
> For j = 0 To UBound(arrbytSIDs)
> arrstrGroupSIDs(j) = OctetToHexStr(arrbytSIDs(j))
> Next
> End If
>
> ' Display the SID values.
> ' Display both hex and decimal values.
> For Each strHexSID In arrstrGroupSIDs
> Wscript.Echo strHexSID
> Wscript.Echo HexSIDToDec(strHexSID)
> Next
>
> Function OctetToHexStr(ByVal arrbytOctet)
> ' Function to convert OctetString (byte array) to Hex string.
> Dim k
> OctetToHexStr = ""
> For k = 1 To Lenb(arrbytOctet)
> OctetToHexStr = OctetToHexStr _
> & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
> Next
> End Function
>
> Function HexSIDToDec(ByVal strSID)
> ' Function to convert most hex SID values to decimal format.
>
> Dim arrbytSID, lngTemp, j
>
> ReDim arrbytSID(Len(strSID)/2 - 1)
> For j = 0 To UBound(arrbytSID)
> arrbytSID(j) = CInt("&H" & Mid(strSID, 2*j + 1, 2))
> Next
>
> If (UBound(arrbytSID) = 11) Then
> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
> & arrbytSID(1) & "-" & arrbytSID(8)
>
> Exit Function
> End If
>
> If (UBound(arrbytSID) = 15) Then
> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
> & arrbytSID(1) & "-" & arrbytSID(8)
>
> lngTemp = arrbytSID(15)
> lngTemp = lngTemp * 256 + arrbytSID(14)
> lngTemp = lngTemp * 256 + arrbytSID(13)
> lngTemp = lngTemp * 256 + arrbytSID(12)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> Exit Function
> End If
>
> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
> & arrbytSID(1) & "-" & arrbytSID(8)
>
> lngTemp = arrbytSID(15)
> lngTemp = lngTemp * 256 + arrbytSID(14)
> lngTemp = lngTemp * 256 + arrbytSID(13)
> lngTemp = lngTemp * 256 + arrbytSID(12)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> lngTemp = arrbytSID(19)
> lngTemp = lngTemp * 256 + arrbytSID(18)
> lngTemp = lngTemp * 256 + arrbytSID(17)
> lngTemp = lngTemp * 256 + arrbytSID(16)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> lngTemp = arrbytSID(23)
> lngTemp = lngTemp * 256 + arrbytSID(22)
> lngTemp = lngTemp * 256 + arrbytSID(21)
> lngTemp = lngTemp * 256 + arrbytSID(20)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> If (UBound(arrbytSID) > 23) Then
> lngTemp = arrbytSID(25)
> lngTemp = lngTemp * 256 + arrbytSID(24)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
> End If
>
> End Function
>
>

 
Reply With Quote
 
Vilius Mockūnas
Guest
Posts: n/a

 
      08-16-2009
Hello,

But this one only works for domain accounts ?

V

"Richard Mueller [MVP]" <rlmueller-> wrote in
message news:%...
>
> "Vilius Mockūnas" <> wrote in message
> news:%...
>> Hello,
>>
>> Is it possible to get access token information using vbscript ?
>>
>> thanks
>> Vilius

>
> Most of the information in the access token provided to a user when they
> authenticate is identical to the information you get when you retrieve the
> value of the tokenGroups attribute of the user object. This is an
> operational attribute, meaning the values are constructed by AD upon
> request. It is a multi-valued array of security group SID's. Each SID
> value is itself a byte array. An example for the current user could be:
> ===========
> Option Explicit
> Dim objSysInfo, strUserDN, objUser
> Dim arrbytSIDs, j, arrstrGroupSIDs()
> Dim strHexSID
>
> ' Bind to current user object.
> Set objSysInfo = CreateObject("ADSystemInfo")
> strUserDN = objSysInfo.UserName
> Set objUser = GetObject("LDAP://" & strUserDN)
>
> ' Retrieve tokenGroups attribute.
> objUser.GetInfoEx Array("tokenGroups"), 0
> arrbytSIDs = objUser.Get("tokenGroups")
>
> ' Convert into an array of hex string values.
> If (UBound(arrbytSIDs) = -1) Then
> ' No group SID values, do nothing.
> ElseIf (TypeName(arrbytSIDs) = "Byte()") Then
> ' One group SID.
> ReDim arrstrGroupSIDs(0)
> arrstrGroupSIDs(0) = OctetToHexStr(arrbytSIDs)
> Else
> ' More than one SID value in the array.
> ReDim arrstrGroupSIDs(UBound(arrbytSIDs))
> For j = 0 To UBound(arrbytSIDs)
> arrstrGroupSIDs(j) = OctetToHexStr(arrbytSIDs(j))
> Next
> End If
>
> ' Display the SID values.
> ' Display both hex and decimal values.
> For Each strHexSID In arrstrGroupSIDs
> Wscript.Echo strHexSID
> Wscript.Echo HexSIDToDec(strHexSID)
> Next
>
> Function OctetToHexStr(ByVal arrbytOctet)
> ' Function to convert OctetString (byte array) to Hex string.
> Dim k
> OctetToHexStr = ""
> For k = 1 To Lenb(arrbytOctet)
> OctetToHexStr = OctetToHexStr _
> & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
> Next
> End Function
>
> Function HexSIDToDec(ByVal strSID)
> ' Function to convert most hex SID values to decimal format.
>
> Dim arrbytSID, lngTemp, j
>
> ReDim arrbytSID(Len(strSID)/2 - 1)
> For j = 0 To UBound(arrbytSID)
> arrbytSID(j) = CInt("&H" & Mid(strSID, 2*j + 1, 2))
> Next
>
> If (UBound(arrbytSID) = 11) Then
> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
> & arrbytSID(1) & "-" & arrbytSID(8)
>
> Exit Function
> End If
>
> If (UBound(arrbytSID) = 15) Then
> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
> & arrbytSID(1) & "-" & arrbytSID(8)
>
> lngTemp = arrbytSID(15)
> lngTemp = lngTemp * 256 + arrbytSID(14)
> lngTemp = lngTemp * 256 + arrbytSID(13)
> lngTemp = lngTemp * 256 + arrbytSID(12)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> Exit Function
> End If
>
> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
> & arrbytSID(1) & "-" & arrbytSID(8)
>
> lngTemp = arrbytSID(15)
> lngTemp = lngTemp * 256 + arrbytSID(14)
> lngTemp = lngTemp * 256 + arrbytSID(13)
> lngTemp = lngTemp * 256 + arrbytSID(12)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> lngTemp = arrbytSID(19)
> lngTemp = lngTemp * 256 + arrbytSID(18)
> lngTemp = lngTemp * 256 + arrbytSID(17)
> lngTemp = lngTemp * 256 + arrbytSID(16)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> lngTemp = arrbytSID(23)
> lngTemp = lngTemp * 256 + arrbytSID(22)
> lngTemp = lngTemp * 256 + arrbytSID(21)
> lngTemp = lngTemp * 256 + arrbytSID(20)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>
> If (UBound(arrbytSID) > 23) Then
> lngTemp = arrbytSID(25)
> lngTemp = lngTemp * 256 + arrbytSID(24)
>
> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
> End If
>
> End Function
>
>



 
Reply With Quote
 
Richard Mueller [MVP]
Guest
Posts: n/a

 
      08-16-2009

Yes, this only applies to domain accounts. For local accounts you can bind
with the WinNT provider and retrieve the objectSID attribute and treat it
the same way, as a single-valued SID value, which is a byte array, and
convert to hex or decimal format. But I know of no way to retrieve the
equivalent of tokenGroups.

--
Richard Mueller
MVP Directory Services
Hilltop Lab - http://www.rlmueller.net
--

"Vilius Mockūnas" <> wrote in message
news:...
> Hello,
>
> But this one only works for domain accounts ?
>
> V
>
> "Richard Mueller [MVP]" <rlmueller-> wrote in
> message news:%...
>>
>> "Vilius Mockūnas" <> wrote in message
>> news:%...
>>> Hello,
>>>
>>> Is it possible to get access token information using vbscript ?
>>>
>>> thanks
>>> Vilius

>>
>> Most of the information in the access token provided to a user when they
>> authenticate is identical to the information you get when you retrieve
>> the value of the tokenGroups attribute of the user object. This is an
>> operational attribute, meaning the values are constructed by AD upon
>> request. It is a multi-valued array of security group SID's. Each SID
>> value is itself a byte array. An example for the current user could be:
>> ===========
>> Option Explicit
>> Dim objSysInfo, strUserDN, objUser
>> Dim arrbytSIDs, j, arrstrGroupSIDs()
>> Dim strHexSID
>>
>> ' Bind to current user object.
>> Set objSysInfo = CreateObject("ADSystemInfo")
>> strUserDN = objSysInfo.UserName
>> Set objUser = GetObject("LDAP://" & strUserDN)
>>
>> ' Retrieve tokenGroups attribute.
>> objUser.GetInfoEx Array("tokenGroups"), 0
>> arrbytSIDs = objUser.Get("tokenGroups")
>>
>> ' Convert into an array of hex string values.
>> If (UBound(arrbytSIDs) = -1) Then
>> ' No group SID values, do nothing.
>> ElseIf (TypeName(arrbytSIDs) = "Byte()") Then
>> ' One group SID.
>> ReDim arrstrGroupSIDs(0)
>> arrstrGroupSIDs(0) = OctetToHexStr(arrbytSIDs)
>> Else
>> ' More than one SID value in the array.
>> ReDim arrstrGroupSIDs(UBound(arrbytSIDs))
>> For j = 0 To UBound(arrbytSIDs)
>> arrstrGroupSIDs(j) = OctetToHexStr(arrbytSIDs(j))
>> Next
>> End If
>>
>> ' Display the SID values.
>> ' Display both hex and decimal values.
>> For Each strHexSID In arrstrGroupSIDs
>> Wscript.Echo strHexSID
>> Wscript.Echo HexSIDToDec(strHexSID)
>> Next
>>
>> Function OctetToHexStr(ByVal arrbytOctet)
>> ' Function to convert OctetString (byte array) to Hex string.
>> Dim k
>> OctetToHexStr = ""
>> For k = 1 To Lenb(arrbytOctet)
>> OctetToHexStr = OctetToHexStr _
>> & Right("0" & Hex(Ascb(Midb(arrbytOctet, k, 1))), 2)
>> Next
>> End Function
>>
>> Function HexSIDToDec(ByVal strSID)
>> ' Function to convert most hex SID values to decimal format.
>>
>> Dim arrbytSID, lngTemp, j
>>
>> ReDim arrbytSID(Len(strSID)/2 - 1)
>> For j = 0 To UBound(arrbytSID)
>> arrbytSID(j) = CInt("&H" & Mid(strSID, 2*j + 1, 2))
>> Next
>>
>> If (UBound(arrbytSID) = 11) Then
>> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
>> & arrbytSID(1) & "-" & arrbytSID(8)
>>
>> Exit Function
>> End If
>>
>> If (UBound(arrbytSID) = 15) Then
>> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
>> & arrbytSID(1) & "-" & arrbytSID(8)
>>
>> lngTemp = arrbytSID(15)
>> lngTemp = lngTemp * 256 + arrbytSID(14)
>> lngTemp = lngTemp * 256 + arrbytSID(13)
>> lngTemp = lngTemp * 256 + arrbytSID(12)
>>
>> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>>
>> Exit Function
>> End If
>>
>> HexSIDToDec = "S-" & arrbytSID(0) & "-" _
>> & arrbytSID(1) & "-" & arrbytSID(8)
>>
>> lngTemp = arrbytSID(15)
>> lngTemp = lngTemp * 256 + arrbytSID(14)
>> lngTemp = lngTemp * 256 + arrbytSID(13)
>> lngTemp = lngTemp * 256 + arrbytSID(12)
>>
>> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>>
>> lngTemp = arrbytSID(19)
>> lngTemp = lngTemp * 256 + arrbytSID(18)
>> lngTemp = lngTemp * 256 + arrbytSID(17)
>> lngTemp = lngTemp * 256 + arrbytSID(16)
>>
>> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>>
>> lngTemp = arrbytSID(23)
>> lngTemp = lngTemp * 256 + arrbytSID(22)
>> lngTemp = lngTemp * 256 + arrbytSID(21)
>> lngTemp = lngTemp * 256 + arrbytSID(20)
>>
>> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>>
>> If (UBound(arrbytSID) > 23) Then
>> lngTemp = arrbytSID(25)
>> lngTemp = lngTemp * 256 + arrbytSID(24)
>>
>> HexSIDToDec = HexSIDToDec & "-" & CStr(lngTemp)
>> End If
>>
>> End Function
>>
>>

>
>



 
Reply With Quote
 
 
 
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Get access token information using vbscript ? Vilius Mockūnas Scripting 4 08-16-2009 08:12 PM
Active Directory VBScript to get user's OU information Daniel Active Directory 5 07-10-2009 09:41 PM
Access Token Limitation desktop Active Directory 5 11-03-2006 01:20 PM
Access token not updated? Bryan Linton Windows Small Business Server 2 07-30-2004 04:24 PM
Vbscript to copy MS Access tables from another database Stable Scripting 8 02-18-2004 06:27 PM



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59