Obtaining a remote shell on DC01 with PsExec as offsec
PS C:\Windows\system32> C:\Users\mary\Desktop\Lateral_Movement\PsExec64.exe /accepteula \\DC01 cmd.exe
PsExec v2.34 - Execute processes remotely
Copyright (C) 2001-2021 Mark Russinovich
Sysinternals - www.sysinternals.com
Microsoft Windows [Version 10.0.17763.2183]
(c) 2018 Microsoft Corporation. All rights reserved.
C:\Windows\system32>whoami
corp\offsec
C:\Windows\system32>hostname
dc01
If a user account is successfully impersonated then a logon event is generated on the machine it occurred on. This logon event ID is 4624.
Checking the status of the Logon audit policy
PS C:\Windows\system32> auditpol /get /category:"Logon/Logoff"
System audit policy
Category/Subcategory Setting
Logon/Logoff
Logon Success and Failure
Logoff Success
...
Important fields:
Subject: Lists the account that initiated the authentication event.
Logon Type: Indicates the type of logon that occurred.
New Logon: Lists the account, the initiated impersonation event, and the targeted account.
Logon Types
Logon type
#
Authenticators accepted
Reusable credentials in LSA session
Examples
Interactive (also known as, Logon locally)
2
Password, Smartcard,
other
Yes
Console logon;
RUNAS;
Hardware remote control solutions (such as Network KVM or Remote Access / Lights-Out Card in server)
IIS Basic Auth (before IIS 6.0)
Network
3
Password,
NT Hash,
Kerberos ticket
No (except if delegation is enabled, then Kerberos tickets present)
NET USE;
RPC calls;
Remote registry;
IIS integrated Windows auth;
SQL Windows auth;
Batch
4
Password (stored as LSA secret)
Yes
Scheduled tasks
Service
5
Password (stored as LSA secret)
Yes
Windows services
NetworkCleartext
8
Password
Yes
IIS Basic Auth (IIS 6.0 and newer);
Windows PowerShell with CredSSP
NewCredentials
9
Password
Yes
RUNAS /NETWORK
RemoteInteractive
10
Password, Smartcard,
other
Yes
Remote Desktop (formerly known as "Terminal Services")
Detecting NewCrednetials logons by searching for LogonType 9 and EventID 4624
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4624)]]
and
*[EventData[Data[@Name='LogonType'] and (Data='9')]]
</Select>
</Query>
</QueryList>
PS C:\Windows\system32> C:\Users\mary\Desktop\Lateral_Movement\Audit-NewCredentialsLogons.ps1
TimeStamp SubjectUserName TargetUserName
--------- --------------- --------------
2022-03-18T11:10:56.9064979Z mary offsec
2022-03-18T11:10:34.8463294Z mary offsec
...
XPath XML for PSExec service installation
<QueryList>
<Query Id="0" Path="System">
<Select Path="System">
*[System[(EventID=7045)]]
and
*[EventData[Data[@Name='ServiceName'] and (Data='PSEXESVC')]]
or
*[System[(EventID=7036)]]
and
*[EventData[Data[@Name='param1'] and (Data='PSEXESVC')]]
</Select>
</Query>
</QueryList>
Detecting PsExec service installation
PS C:\Users\offsec\Desktop\Lateral_Movement> .\Audit-PsExec.ps1
TimeStamp Event Details
--------- ----- -------
2022-03-18T08:07:31.717432600Z 7036 Service PSEXESVC is running
2022-03-18T08:07:31.670551100Z 7045 Service PSEXESVC installed using %SystemRoot%\PSEXESVC.exe as LocalSystem
XPath XML for Network logons
<QueryList>
<Query Id="0" Path="Security">
<Select Path="Security">*[System[(EventID=4624)]]
and
*[EventData[Data[@Name='LogonType'] and (Data='3')]]
and
*[EventData[Data[@Name='AuthenticationPackageName'] and (Data='NTLM')]]
</Select>
</Query>
</QueryList>
PS C:\Users\offsec\Desktop\Lateral_Movement> .\Audit-PassTheHash.ps1
TimeStamp Event Details
--------- ----- -------
2022-03-18T08:07:31.717432600Z 7036 Service PSEXESVC is running
2022-03-18T08:07:31.677554700Z 4624 offsec logged in remotely from CLIENT03
2022-03-18T08:07:31.670551100Z 7045 Service PSEXESVC installed using %SystemRoot%\PSEXESVC.exe as LocalSystem
2022-03-18T08:07:31.530198300Z 4624 offsec logged in remotely from CLIENT03
Brute Force Domain Credentials
Creating a custom PowerShell function named Get-BadPwdCount
Discovering the PDC and creating a search root string
Listing failed logon attempts with Get-BadPwdCount
PS C:\Users\offsec\Desktop\Lateral_Movement> . .\Get-BadPwdCount.ps1
PS C:\Users\offsec\Desktop\Lateral_Movement> Get-BadPwdCount -List | Sort BadPwdCount -Descending
SamAccountName BadPwdCount
-------------- -----------
jane 10
ben 2
Retrievin the lockout threshold with net accounts
PS C:\Users\offsec\Desktop\Lateral_Movement> net accounts
Force user logoff how long after time expires?: Never
Minimum password age (days): 1
Maximum password age (days): 42
Minimum password length: 3
Length of password history maintained: 24
Lockout threshold: 25
Lockout duration (minutes): 30
Lockout observation window (minutes): 30
Computer role: PRIMARY
The command completed successfully.
We could also search through all failed logon events (4625)
Terminal Services
By default, there are two logs that will trace RDP remote connection events, namely TerminalServices-LocalSessionManager and TerminalServices-RemoteConnectionManager.
Local Session Manager logs will include information about the local terminal session on the current machine, whereas the Remote Connection Manager logs will include information about the terminal sessions events that were triggered from a remote computer.
When an RDP logon prompt is displayed, event ID 261 is created in the Remote Connection Manager logs.
If there's a successful authentication and connection then event ID 1149 is created.