Search This Blog

Showing posts with label kerberos. Show all posts
Showing posts with label kerberos. Show all posts

Jan 5, 2023

How AD decides Kerberos encryption type per user/computer basis

Supposed that there is no GPO to enforce supported ciphers, on a per principal basis, it is determined as below:


If msDS-SupportedEncryptedTypes is populated, then use values defined in this attribute. It's a 5-bit flag
      • bit 0   DES-CBC-CRC
      • bit 1   DES-CBC-MD5
      • bit 2   RC4-HMAC
      • bit 3   AES128-CTS-HMAC-SHA1-96
      • bit 4   AES256-CTS-HMAC-SHA1-96
If msDS-SupportedEncryptedTypes is NOT populated, then AD reads values in userAccoutControl

              • if 0x200000 is set, DES will be used
              • if 0x200000 is not set, default to RC4 for 2008/7 and later

          Default behavior:
          • Computer account: msDS-SupportedEncryptedTypes set. OS 2008/Win7 and newer: DES is disabled
          • User account: msDS-SupportedEncryptedTypes is not set so RC4 is used see here, unless userAccountControl forces DES
          • Referral Ticket/Trust object: higher of DES/RC4 that is mutually supported by client and authenticating domain. If both client and trust don't have any custom value set, cipher is RC4.

            NOTE/WARNING: If you enabled "AES" support on trust using GUI, only AES will be supported; RC4 will be disabled. If you want to add "AES" on top of RC4, use ksetup to change trust.
          PS. Above behavior is always for Service Ticket.
              Since TGT is meant for DCs to read, it always uses what DC supports, and is irrelevant to what is defined on individual accounts.

          Sample Script to find risky users

          #Bitwise AND: 1.2.840.113556.1.4.803
          #Bitwise OR : 1.2.840.113556.1.4.804
          # 2097152 is 0x200000, bit mask for userAccountControl DES enforced
          # 3 is 0b11, covers the last 2 bits of msDS-SupportedEncryptionTypes, which enables DES

          # list users who
              # user object, and
              # enabled, and
                  # supportedType set with DES, or
                  # supportedTYpe not set but userAccountControl DES set
                  
          $ldapfilter=@("(&",`
              "(objectclass=user)",`                                                         # user Object
              "(!(userAccountControl:1.2.840.113556.1.4.803:=2))",`                          # enabled
              "(|",` 
                  "(msDS-SupportedEncryptionTypes:1.2.840.113556.1.4.803:=3)",`              # DES defined in supportedType
                  "(&",`                                                                     # or DES not set in supported type but in userAccountControl
                      "(!(msDS-SupportedEncryptionTypes=*))",`                                   
                      "(userAccountControl:1.2.840.113556.1.4.803:=2097152)",`
                  ")",`
               ")",`
          ")")
          $ldapfilter = $ldapfilter -join ""
          $u=get-aduser -ldapfilter $ldapfilter -server foo.bar -Properties msDS-SupportedEncryptionTypes,enabled,userAccountControl,UseDESKeyOnly

          Nov 24, 2021

          Kerberos Flow Chart / Kerberos sessions keys / AS and TGS

          1. Normal Flow


          2. Forwarded Delegation


          3. s4u Extension


          A kerberos client is issued 2 type session keys:
          1. Session key that is used for communication with TGS
          2. Session key that is used for communication with service provider

          The process of getting # 1 type session key is called "authentication". It's issued by Authentication Service (AS, for AD, AS resides on same machine as KDC). 
          1. Client(machine) sends AS request(contains user ID in cleartext) on behalf of user to AS.
          2. AS sends back session key type 1 back to client, encrypted with user's hash). AS also sends back TGT ( same session key plus other info such as session key valid duration) . TGT is not readable to client, it's encrypted with TGS' key (krbtgt hash)
          3. Later on, user will use this session key to encrypt messages to TGS
          4. AS (AD DC) never stores the session key. It's always the client to keep and present session key to TGS. This is achieved by sending TGT back to TGS (remember in step 2 above, TGT is encrypted with TGS' key so TGS can read the content and get the session key). In other words, session key becomes a timed common knowledge between TGS and client 


          The process of getting #2 type session key can be roughly called "authorization" (actual access evaluation happens on resource provider, based on the Service Ticket presented). It's the process to get Service Ticket, which can be later presented to service provider. 
          1. client sends a service request, one of the content of this request is its ID/time, encrypted with type #1 session key above. Along side the TGT (again this TGT is not readable to client, but it's readable to TGS/DC) 
          2. TGS/DC decrypts TGT to get session key #1 so it can validate client ID /timestamp 
          3. If matched, TGS sends back 2 things 
            1. type #2 session key, encrypted with type #1 session key so client can read and use type #2 session key for communication with service provider
            2. Service Ticket (not readable to client, but only for client to hold it and present to service provider). This is encrypted with service provider's key so only service provider can read it
            3. In client's request, it specify a SPN for TGS to locate service provider's key
          4. Client presents ST to service provider, along side its own ID, encrypted with type# session key
          In short, neither TGS, nor service provide keeps any session keys. It's client's responsibility to obtain (Thru AS and TGS) to get those session keys, and present them to TGS/SP. 

          Oct 30, 2017

          Top Ten Issues with Active Directory Trusts and Corporate Mergers

           Top Ten Issues with Active Directory Trusts and Corporate Mergers

          Really excellent article on multiple topics.

          copy of whole article:


          Hey Everyone. Randy, Premier Field Engineer, here to discuss some lessons learned from working with a recent merger between two corporations. I don’t have enough time or space to go into the details of this major endeavor, so I am going to talk about this experience with a “Top Ten Countdown” style BLOG POST. I’m sure there are many other headaches seen in the field and I would love to hear about them in the comments section. Maybe I can start to consolidate all this into a Wiki about Partnerships and Mergers between two dueling Active Directory environments. Let’s get started:
          1. This one being the most important! Never establish multiple trust paths: I have had the same conversation with countless engineers when doing phone support, about setting up both a Forest Trust between the two Forest Roots, and also an External Trust between two child domains in each of the forests. This should never be done under any circumstances. The argument is often “But this is a shortcut trust.” A Shortcut Trust is between two different domains in the same forest. I have also seen arguments where certain applications (here is an example) that are performing logon routines are not able to query a forest, and therefore need a direct trust. There is likely a newer version of the application without this requirement. If there is not an update or competitive product without this requirement, then it is time to do some soul searching on what is more important. The crux of the issue is different technologies providing the trust path between the same domains, each having different characteristics and limitations. One workflow may use the enumeration of trusted domains and hit one of these limitations based on the technology invoked.
          2. Beware of CNAME (alias) records in DNS: This is true regardless of traversing a trust, or in the local domain. The behavior of how SPNs are formatted in the client’s request has dramatically changed over various versions of Windows. This article talks about this behavior, although it is not that straight forward about why it is a problem. When accessing a resource using Kerberos Authentication, the client has to construct a Service Principal Name based on the Host Name offering that service. Take a look at the example Below:
          clip_image002
          Here we have a File Server (FileServ1.adatum.com) hosting a Share (\\SalesReports\Monthly.) In DNS, we configure a Cname record to direct any DNS query for SalesReports.adatum.com, to the physical host of website Fileserv1.adatum.com.
          In Windows XP and SMBv1: We would ask the KDC/Domain Controller for CIFS/SalesReports, because that was the hostname supplied in the UNC Path.
          In Vista and SMBv2: We would ask the KDC/Domain Controller for CIFS/FileSrv1.adatum.com, because that was the hostname resolved in the DNS CNAME query.
          In Windows 8: We once again returned to the original behavior of asking for CIFS/SalesReports, and adding the “NETDOM COMPUTERNAME /ADD” to supply an alternate name that would register the SPN for you.
          The recommendation from Microsoft is to avoid CNAME records if at all possible. This will avoid a variety of headaches because you could see unexpected outcomes as you use other network transports like HTTP.
          3. Use Fully Qualified Domain Names: When joining a domain, writing logon scripts, or configuring an application setting that requires a computer or domain name, I have just made this a habit ever since about 2003. There are plenty of ways that Windows can overcome flat names, but why not keep it simple wherever you can. By supplying the FQDN, we tell DNS exactly what we want without confusion. Here is a short list of problems you will avoid:
          1. Same Host Names exist in multiple domains
          2. Time delays having to parse through the domain suffix search order to look for a match
          3. Kerberos KDC knowing which realm to forward the ticket request
          4. Disjoined Name Spaces or Unorthodox Naming Conventions
          The next two items on the list are related to FQDN.
          4. Kerberos Forest Search Order: In some situations, flat names may be used and will format the SPN request made by the client as “HTTP/ServerName” (for example) and not include the domain suffix. The domain suffix is important because the user will always go to its local domain’s KDC which uses the domain suffix to identify which Kerberos Realm it should direct the user. There is a GPO setting that can be configured either for the client or the KDC which lists out other realms where it can check for a matching SPN. A configuration that I found useful is to list the Workstation Forest in the KFSO GPO applied to the workstation. This was helpful in a situation where users have been migrated to the new AD Forest, but their workstations have yet to be migrated. Let’s watch this play out in a cartoon entitled “The Adventures of Joey Adatum!”
          clip_image004
          clip_image006
          The beauty of this solution is that there would be no performance impact (as described in the TechNet documentation) because the workstation is just asking its local Forest and would only be relevant if the logged on user was from a different Forest.
          5. DFS Namespaces: To continue on the topic of domain suffixes, update DFSN to use DNS FQDN’s. This will ensure that any cross forest usage of DFS Namespaces will resolve correctly. Another important aspect is the Special Names Table generated for the forest. The Special Names Table is a list stored on each Windows client that it gets from the DC. It is a listing of domain names that the DFS client needs to recognize when resolving a UNC path as either a Domain-Based DFSN or a regular Server Name. A Two-Way Forest trust will not give you any problems with populating this table for the partner forest. If you start playing with One-Way, or External Trusts, you might not get the results you are looking for, especially when child domains are involved. You can see the Special Names Table by using “dfsutil /spcinfo” on a client that has the DFS RSAT tools installed. See the example below when running dfsutil /spcinfo on a workstation in Widgets.Adatum.com:
          clip_image008
          One-Way Trust:
          C:\temp>dfsutil /spcinfo
          [*][WidgetDC1.widgets.adatum.com*widgets]
          [*][widgets.adatum.com]
          [-][adatum]
          [-][adatum.com]
          [-][widgets]
          [-][widgets.adatum.com]
          Two-Way Trust:
          C:\temp>dfsutil /spcinfo
          [*][WidgetDC1.widgets.adatum.com*widgets]
          [*][widgets.adatum.com]
          [-][adatum]
          [-][adatum.com]
          [-][widgets]
          [-][widgets.adatum.com]
          [-][Contoso]
          [-][Contoso.com]
          [-][Asia]
          [-][Asia.Contoso.com]
          The good news is Windows 8 & 10 clients seem to behave, and I only found this to be an issue with Windows 7 / 2008 systems. This can be a major problem with new SMB Hardening recommendations for \\*\Sysvol and \\*\Netlogon. If you have a One-Way trust and Windows 7 clients with SMB hardening, then they won’t be getting group policy across the forest because Kerberos will fail.
          6. Will users log on interactively or via RDP to systems across the Forest Trust? I am including this as a separate line item because it will likely be the biggest headache that you encounter. The two items above on our list are examples of problems you might face. It would be helpful to really think through these situations and see where Network Access would be sufficient.
          7. Don’t forget about udp port 389: Firewall configuration is always important when troubleshooting cross forest failures. Make sure all the required ports are open for Active Directory, udp 389 is often forgotten, but very important for DC Discovery operations.
          8. Site Affiliation: For optimal performance, we want to make sure that we are choosing resources located near our physical location. I won’t go into detail, because a great BLOG POST was written eight years ago that still reigns true today.
          9. Make security policies consistent: Why are domain controllers all located in a single OU? Answer: To make sure they all get the same GPO Security Settings. When we establish a trust between two Active Directories, we are extending our trust boundary beyond the local forest to our partner. You want to pay careful attention to conflicting settings that would break communications. Here is a classic KB article which describes numerous potential conflicts. Make sure you work together on a common security baseline for both AD Forests. If this is going to be a long term relationship, I recommend a solution in place to identify a naming convention for GPOs with sensitive settings and routinely synchronize or compare these GPOs. Some tools that may help in this effort are the Security Compliance Manager (free!), or Advanced Group Policy Manager (requires MDOP license)
          10. Be aware of your partner’s vulnerabilities: When you open your doors to a partner environment, you could be exposing yourself to all the threats they encounter. Here are some questions to ask:
          1. How do they enforce system health compliance?
          2. How do they deliver patching and security updates?
          3. Are they running legacy operating systems?
          4. What are their Password Policies?
          5. How many Domain Admins do they have, and are any of them service accounts?
          6. Have they reported security breaches in the past?
          Whenever your users traverse the trust, they could be exposed to credential theft. In turn, their users are now your users. Whatever vulnerabilities and compromises they face, are now your problems. You can set up various roadblocks to prevent these issues.
          1. Don’t let privileged accounts logon interactively and restrict what they can access over the network. Stay away from Legacy Operating Systems.
          2. Consider Security Considerations for Trusts, implement measures like SID Filtering or Selective Trusts.
          3. Secure Privileged Access with a Tier Administration Model and other mitigations.
          These are just a few examples of considerations. Just keep in mind that this is a major endeavor and should be well planned. Also, think outside of the box. This may be time to consider hosting services in Azure and merging the two forests in Azure AD, while keeping your on premise nice and isolated.
          Good Luck,
          Randy “Trust me” Turner

          Sep 11, 2014

          Kerberos event 4/Target account name is incorrect/ troubleshooting

          This error is reported whenever the service provider (e.g. file server) cannot decrypt a service ticket that was sent to it. This is caused by the fact that the ticket was encrypted by one machine then sent to a different machine. In this case, the second machine doesn't have the private key to decrypt the ticket.

          Troubleshooting steps

          - make sure there is not duplicate SPN for the service you are trying to get. For example, if you want to access \\serverName1\sharePath and get above error; or on a file server you see kerberos event 4, you want to check if there is duplicate SPN host\serverName*. In the past, it takes a little effort to find duplicate SPNs, but started Windows7/2008, you can run setspn -X to find all duplicated SPNs in your domain

          - make sure you don't have duplicate DNS entries for same server to different IPs (unless the server does have multiple IP, and all DNS entries are correct).

          - if access using FQDN works but not short name (e.g. \\server.FQDN.com\sharePath works but not \\server\sharePath), and you have WINS in your environment, make sure the target server register correct 20h record (File Server) in WINS

          - If your target computer has multiple names (mostly added by command netdom computername), then you should make sure you add SPNs for all the alias you have. For example, if you have a server has both names as server1 and server2, you should below spn registered in AD:

          • host/server1.fqdn.com
          • host/server1
          • host/server2.fqdn.com
          • host/server2
          - make sure you don't have hosts file entries that resolve to wrong IP

          - Log into the system that actually owns wrong IP, make sure it's not registering wrong name. For DNS, check NIC TCP/IP stack; for WINS, check "netdom computername localhost /enum", as well as check HKLM\CCS\Services\lanmanserver\parameters\OptionalNames

          Oct 5, 2011

          Token Size vs. Paged Pool - draft

          This is mostly a complete copy from microsoft.com

          When users access a resource using Windows authentication and authorization (for example logging on to a workstation or accessing a file share), an “access token” is built to represent that user.
                The number of SIDs (representing group membership, etc) in that token largely determines how much kernel memory space (Paged Pool) is required to store each copy of the token.
                These allocations follow a “stair-step” pattern, as follows:
                At approximately 84 SIDs, allocation jumps from 4KB to 8KB.
                At approximately 177 SIDs, allocation jumps from 8KB to 12KB.
                At approximately 270 SIDs, allocation jumps from 12KB to 16KB.
                At approximately 363 SIDs, allocation jumps from 16KB to 20KB and so on.