Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to determine if a string is a User SID?

Tags:

c#

windows

In Windows Operating System, user SIDs are represented with a string such as :

S-5-1-76-1812374880-3438888550-261701130-6117

Is there any way that I can identify that such a string is a valid User SID?

Thanks.

like image 745
Chibueze Opata Avatar asked Apr 19 '13 07:04

Chibueze Opata


People also ask

What is a user's SID?

The SID (Security IDentifier) is a unique ID number that a computer or domain controller uses to identify you. It is a string of alphanumeric characters assigned to each user on a Windows computer, or to each user, group, and computer on a domain-controlled network such as Indiana University's Active Directory.

What is the SID for the user admin?

SID (Security IDentifier) is a unique identifier that is assigned to users, groups, computers, or other security objects when they are created in Windows or Active Directory domain.

How do I convert SID to username?

You can use the command line (cmd) to convert SID to username using the wmic command. Using the wmic command to get user account, specify the user SID in the where clause to get a user from SID.


2 Answers

If you need to check SID is SID, use SecurityIdentifier constructor inside try\catch.

This will not validate that this sid belongs to anyone\anything in the whole world.


SIDs are

  • Always start with S
  • For current, always continue with -1- (this is SID version, and there is only one)
  • Continues with single SID_IDENTIFIER_AUTHORITY which is not more than 6 bytes, means this value is not more than 281474976710656 (15 characters)
  • Continues with [1..14] - separated SID_IDENTIFIER_SUBAUTHORITY which are not more than 4 bytes wide (10 characters max)
  • Optionally ends with RID - separated which is not more than 4 bytes wide (10 characters max)

More detailed refer to MS-AZOD, chapter 1.1.1.2

like image 102
filimonic Avatar answered Sep 29 '22 18:09

filimonic


I found this slight variation helpful which allows for some well known security identifiers. For example, the well known sid Everyone S-1-1-0

^S-\d-(\d+-){1,14}\d+$
like image 24
Phillip Fleischer Avatar answered Sep 29 '22 19:09

Phillip Fleischer