Internal Reconnaissance is one of the first steps an attacker will take once they have compromised a user or computer on the internal network. This usually involves using tools or scripts to enumerate and collect information to help them identify where they should try and compromise next on the internal network to get what they need. An example of a tool that is commonly used for internal reconnaissance is BloodHound which can map out paths for an attacker.
Almost all common enumeration methods used can be executed by an unprivileged user.
There are multiple types of reconnaissance that attackers can do to find information about the network they have penetrated. These types of information include but are not limited to:
There are multiple protocols that can be utilised for reconnaissance to get this information which makes it extremely hard to block and detect for blue teams. In this post I will go over how to use NetCease, a tool which Microsoft has released, to block session enumeration for unprivileged users and then SAMRi10, a script which Microsoft has released to help block queries to the Remote SAM (MS-SAMR Protocol)
Session Enumeration is one of the reconnaissance methods that an attacker will use after compromising a system on an internal network. It is a way for an attacker to detect where users and service accounts are logged in which can then be used in line with other reconnaissance methods to prioritise which hosts to attempt to compromise first. For Example: hosts with administrators logged in.
Note: Default permissions in Windows 10 have been changed to stop attackers doing this, however, it is still worth checking.
Net Cease is a short PowerShell script that Itai Grady and Tal Be’ery from Microsoft released in 2016. This PowerShell script is used to change the Registry Key which controls the NetSessionEnum method permissions. The reason why this is completed by script and not just manual instructions is because it is only editable in a reg binary value.
Path: HKEY_LOCAL_MACHINE/SYSTEM/CurrentControlSet/Services/LanmanServer/DefaultSecurity
Name: SrvsvcSessionInfo
The default value of the SrvsvcSessionInfo registry key is the Access Control List which allows the use of the NetSessionEnum method. This is assigned to the following:
The Authenticated Users Permission is what makes this insecure and easy for attackers to perform reconnaissance. What the Net Cease Script does is to back up the current registry value and then amend the permissions, so the following ACE’s are in the ACL:
Now if you want to view the security descriptor for yourself then you can use the following PowerShell snippet which will show you the ACL. There is also a script on the TechNet Gallery called NetSessEnumPerm.ps1 which can output a bit nicer than the below.
#Registry Key Information
$key = "HKLM:SYSTEMCurrentControlSetServicesLanmanServerDefaultSecurity"
$name = "SrvsvcSessionInfo"
#Get the Registry Key and Value
$Reg_Key = Get-Item -Path $key
$BtyeValue = $reg_Key.GetValue($name, $null)
#Create a CommonSecurityDescriptor Object using the Byte Value
$Security_Descriptor = New-Object -TypeName System.Security.AccessControl.CommonSecurityDescriptor -ArgumentList $true, $false, $ByteValue, 0
#Output of the ACL to make it simple to see for document. Use only $Security_Descriptor.DiscretionaryAcl if you want to see the full ACL!
$Security_Descriptor.DiscretionaryAcl | Select-Object SecurityIdentifier, ACEType | Format-Table -AutoSize
Note: Information on Well-Known SID’s can be found here
An easy way to test session enumeration is to use the NetSess tool from Joeware.net but there are plenty of options for tools that utilise this including SharpHound collector. Make sure when doing that you are using a user account that is not a member of Administrators, Server Operators or Power Users.
Netsess.exe [Computer]
Netsess.exe [Computer]
Netsess.exe [Computer]
Attackers can perform reconnaissance using the SAMR Protocol which can remotely query devices but can also query Active Directory. Using this method of reconnaissance, an attacker can find highly privileged groups and users, as well as local users and groups for every system on the network without any administrative privileges. Tools such as BloodHound can then automatically map this information into attack paths to compromise Active Directory.
Microsoft Introduced protections for querying the Remote SAM with Windows 10 and in 2017 introduced updates for previous operating systems down to Windows 7 and Server 2008 R2 using the RestrictRemoteSAM registry key, which is a string (REG_SZ) that will contain the SDDL of the security descriptor that protects Remote SAM calls.
In the anniversary edition of Windows 10 (1607) and Windows Server 2016 and later the default SDDL has been changed to only allow local administrators to query the Remote SAM.
Below is a table breaking down the requirements, default behaviour and protection options for all operating systems.
OS | KB Required | Who can query (Default) | Remote SAM Protection Options |
Prior to Windows 7 and Server 2008 R2 | N/A | Any domain user | None |
Windows 7 | KB 4012218 | Any domain user | Registry Key or Group Policy |
Windows Server 2008 R2 | KB 4012218 | Any domain user | Registry Key or Group Policy |
Windows 8.1 | KB 4102219 | Any domain user | Registry Key or Group Policy |
Windows Server 2012 | KB 4012220 | Any domain user | Registry Key or Group Policy |
Windows Server 2012 R2 | KB 4012219 | Any domain user | Registry Key or Group Policy |
Windows 10 1507 | KB 4012606 | Any domain user | Registry Key or Group Policy |
Windows 10 1511 | KB 4103198 | Any domain user | Registry Key or Group Policy |
Windows 10 1607 and later | N/A | Local Administrators | Registry Key or Group Policy |
Windows Server 2016 and later | N/A | Local Administrators | Registry Key or Group Policy |
There are two ways in which Microsoft natively lets administrators set this option which is through Registry or through Group Policy. There is also a 3rd lesser-known method that a Microsoft Researcher came out called SAMRi10 (Samaritan) which helps companies who require needing granular access that is easily editable.
The RestrictRemoteSAM registry key is available for administrators to update as they wish with the SDDL. Below is the information on where the key is located and the default value that Windows 10 sets which is SYSTEM for Ownership and Primary Group and read_control access for Built-in Administrators.
Path: HKLM/System/CurrentControlSet/Control/Lsa
Name: RestrictRemoteSAM
Value: O:SYG:SYD:(A;;RC;;;BA)
To check that the SDDL is correct before applying the change you can use the ConvertFrom-SDDLString command in PowerShell to convert it to a security descriptor that is easier to read.
The Group Policy and Local Security Policy settings allow administrators to set this easily. This can work well for administrators who wish to set the same value across every system or multiple groups of systems (e.g. Allowing Remote SAM Connections for all servers in a specific OU or set of application servers).
The details about the setting are as follows:
Policy Name | Network access: Restrict clients allowed to make remote calls to SAM |
Location | Computer Configuration|Windows Settings|Security Settings|Local Policies|Security Options |
Possible Values | – Not defined – Defined, along with the security descriptor for users and groups who are allowed or denied to use SAMRPC to remotely access either the local SAM or Active Directory. |
SAMRi10 is a PowerShell script that Itai Grady released initially to help secure Remote SAM before it was introduced properly by Microsoft. However, whilst it may sound like its no longer needed it does offer a key benefit which Microsoft’s default does not which is it creates a new local group and delegates access for the group to be able to perform the Remote SAM calls making it possible for administrators to control this fully in Group Policy Preferences or just manually granting accounts when required.
The SAMRi10 script does the following:
StealthINTERCEPT and STEALTHbits Activity Monitor can monitor LDAP queries and then pass them to StealthDEFEND which can detect multiple reconnaissance scenarios and queries out of the box including but not limited to BloodHound, queries for all SPN’s and queries for all accounts with password never expires.
StealthAUDIT’s attack path analyser can provide admins with insight into their Active Directory ACL’s which attackers may look for so they can plug any gaps before they happen.
Joe is a Security Researcher at Stealthbits – Now part of Netwrix. An expert in Active Directory, Windows, and a wide variety of enterprise software platforms and technologies, Joe researches new security risks, complex attack techniques, and associated mitigations and detections.
Learn why Active Directory security should be a priority for your organization and ways to mitigate against a data breach with this free white paper!
Read more© 2022 Stealthbits Technologies, Inc.
Leave a Reply