Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Ask your PowerShell-related questions, including questions on cmdlet development!
Forum rules
Do not post any licensing information in this forum.

Any code longer than three lines should be added as code using the 'Select Code' dropdown menu or attached as a file.
This topic is 5 years and 5 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked
User avatar
ErnieB
Posts: 56
Last visit: Mon Dec 19, 2022 2:09 am

Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by ErnieB »

Can someone please assist with the following question
I want to be able to force either an NTLM logon or Kerberos logon to an Active Directory Domain controller as a separate user principle
Initially, I simply tried the Windows NET command as follows

net use \DCName\Sharename /user:DomainName\Username password01 and net use \10.10.10.10\Sharename /user:DomainName\Username password01

the first one for Kerberos as the SPN (service principal name) can be obtained and therefore the hash to use with Kerbberos ticket encryption
The second one for NTLM as no SPN can be retrieved based on IP address and therefore fall back to NTLM

I have had very mixed results with the above, therefore I want to look for an alternative method (as I need to feed in lots or username and password to create lots of logons at the
DC e.g. Kerberos or NTLM at will)

So next I tried

[system.reflection.assembly]::LoadWithPartialName('System.DirectoryServices.AccountManagement')
$D = [system.DirectoryServices.AccountManagement.ContextType]::Domain
$PC = [system.DirectoryServices.AccountManagement.PrincipalContext]$D
$M = [system.DirectoryServices.AccountManagement.ContextOptions]::Negotiate

$PC.ValidateCredentials('User01','Password01',$m)

However as one might imagine this only validated the username password combination it did not create a Kerberos TGT for the user for example (which is what I want to do when forcing a kerberos logon)

So my question is please, if there a .NET namespace when given a know username and password you can force the issuance of a TGT (for Kerberos authentication) or NTLM token, logon ?

PS,
I found the following

https://docs.microsoft.com/en-us/previo ... spi_topic1

which allows you to chose the authentication package etc to do a logon, which is basically what I am trying to do, however this is a compiled C++ GUI program and I am looking to do this in a script (PowerShell/C#)

basically pass a Powershell function a username and password and a switch parameter Kerberos or NTLM so the DC authenticates the user with my protocol of choice and it shows up in the DCs security event log as normal (e.g. TGT issued or NTLM)

Thanks very much in advance EB
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by davidc »

[TOPIC MOVED TO WINDOWS POWERSHELL FORUM BY MODERATOR]
David
SAPIEN Technologies, Inc.
User avatar
ErnieB
Posts: 56
Last visit: Mon Dec 19, 2022 2:09 am

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by ErnieB »

Can you please give me the link to the location where my question has been moved as I cannot find it, thanks
User avatar
davidc
Posts: 5913
Last visit: Mon Jul 08, 2019 8:55 am
Been upvoted: 2 times

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by davidc »

Sure, its the Windows PowerShell forum:

viewforum.php?f=18
David
SAPIEN Technologies, Inc.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by jvierra »

The remoting create remote session. There is no local session or logon event. All parts of the session are on the remote system only. That is what remoting means.
User avatar
ErnieB
Posts: 56
Last visit: Mon Dec 19, 2022 2:09 am

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by ErnieB »

Hello,
Thanks for the replies

I am not trying to remote to the DC as it were, but rather create an authentication event. For example, I want to emulate (in a very crude sense) load on a DC when say 1000 users authentication to the DC (either via Kerberos and therefore the user obtains a TGT or NTLM). I have fudged this by mapping a drive to the DC using the DCs IP address (NTLM) or name (so SPN can be looked up) Kerberos. However, this is a very crude method and I wanted a more elegant way. I post I found uses SSPI and authentication pages and used a compiled C++ program. However, as I am doing this in PowerShell ideally I wanted a C# class to active the same thing.


Thanks very much
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by jvierra »

Using alternate credentials is the same as remoting. You are asking the remote system to authenticate for you using a different account. There will be no TKT in your session. It will only exists during the remote connection in the remote session.

To use the Account Management classes we would do this:

Code: Select all

Add-Type -AssemblyName System.DirectoryServices.AccountManagement
$ctx = [system.DirectoryServices.AccountManagement.PrincipalContext]::new('Domain', 'TESTNET','Negotiate')
$ctx.ValidateCredentials('user01', 'password01')
"TESTNET" is the domain name and "Negotiate" is the connection options. You can use more than one like this:

$ctx = [system.DirectoryServices.AccountManagement.PrincipalContext]::new('Domain', 'TESTNET','Negotiate,Signed')

Once you have the CTX you can run the "Validate" in a loop. This will not load test as each validate does not create a session. It just ask the server to check the credentials. To load test you will likely use a query to cause a session the be created and authenticated. This would have to be done from a multi=threaded application to cause concurrency and produce load. There are numerous tools that can be downloaded that can do this. The tools are usually run from multiple PCs to force a load. Each PC can handle a group of tests in parallel ad run them continuously. These are standard load testing tools for AD. They mostly use the raw ADSI API and are faster and more efficient than the Net classes.
jvierra
Posts: 15439
Last visit: Tue Nov 21, 2023 6:37 pm
Answers: 30
Has voted: 4 times
Been upvoted: 33 times

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by jvierra »

Please also understand that "ValidateCredentials" does NOT create a login session. The only login that is used is the user account executing the call.

There is no create session for AD. Sessions are validated via the TKT that a user obtains when logging into Windows. All authentication is don by Windows. An ADSI call can use credentials but each ADSI call only passes a TKT if Kerberos is used. If Kerberos is down then NTLM will be tried next. That will do a full NTLM authentication and that will show on the DC event log. The NTLM session will disappear immediately after the command completes. That is why for both mapping a drive to the DC targeted will allow all connections for the user authenticated by the mapping.
User avatar
ErnieB
Posts: 56
Last visit: Mon Dec 19, 2022 2:09 am

Re: Creating a Kerberos or NTLM logon to an Active Directory Domain Controller at will.

Post by ErnieB »

Thanks very much for your time and the excellent details I appreciate it :)
This topic is 5 years and 5 days old and has exceeded the time allowed for comments. Please begin a new topic or use the search feature to find a similar but newer topic.
Locked