{"id":1508,"date":"2015-04-12T23:28:34","date_gmt":"2015-04-13T03:28:34","guid":{"rendered":"http:\/\/adsecurity.org\/?p=1508"},"modified":"2018-04-12T18:02:54","modified_gmt":"2018-04-12T22:02:54","slug":"spn-scanning-service-discovery-without-network-port-scanning","status":"publish","type":"post","link":"https:\/\/adsecurity.org\/?p=1508","title":{"rendered":"SPN Scanning &#8211; Service Discovery without Network Port Scanning"},"content":{"rendered":"<p>The best way to discover services in an Active Directory environment is through what I call &#8220;SPN Scanning.&#8221;<\/p>\n<p>The primary benefit of SPN scanning for an attacker over network port scanning is that SPN scanning doesn&#8217;t require connections to every IP on the network to check service ports. SPN scanning performs service discovery via LDAP queries to a Domain Controller. Since SPN queries are part of normal Kerberos ticket behavior, it is difficult, if not infeasible to detect, while netowkr port scanning is pretty obvious.<\/p>\n<p><a title=\"SPNs\" href=\"https:\/\/adsecurity.org\/?page_id=183\">Service Principal Names (SPNs)<\/a> are required for discovery of services that leverage Kerberos authentication.<\/p>\n<p><!--more--><\/p>\n<p>From the <a href=\"https:\/\/msdn.microsoft.com\/en-us\/library\/cc233855.aspx\">Microsoft Kerberos specification<\/a>:<\/p>\n<blockquote><p>An SPN is a string of the following format. For more information on the &lt;alphanum&gt; element, see [RFC2396] section 1.6.<br \/>\nSPN = serviceclass &#8220;\/&#8221; hostname [&#8220;:&#8221;port] [&#8220;\/&#8221; servicename]<br \/>\nserviceclass = alphanum<br \/>\nservicename = alphanum<br \/>\nWhere:<br \/>\nserviceclass is a string that identifies the class of the service, such as &#8220;www&#8221; for a Web service or &#8220;ldap&#8221; for a directory service.<br \/>\nhostname ([RFC2396] section 3.2.2) is a string that is the name of the system. This SHOULD be the fully qualified domain name (FQDN).<br \/>\nport ([RFC2396] section 3.2.2) is a number that is the port number for the service.<\/p>\n<p>The servicename segment is a string that is the distinguished name (DN), objectGuid, Internet host name, or fully qualified domain name (FQDN) for the service.<br \/>\nAn application can supply a name of the form &#8220;RestrictedKrbHost\/&lt;hostname&gt;&#8221; when its callers have provided the hostname but not the correct SPN for the service. Applications SHOULD NOT use &#8220;RestrictedKrbHost\/&lt;hostname&gt;&#8221; due to the security considerations in section 5.1.2. Applications calling GSS-API directly MUST provide a target name which SHOULD be an SPN&lt;28&gt; for their service applications for Kerberos authentication.<\/p><\/blockquote>\n<p>Some of the more interesting services and example <a title=\"SPNs\" href=\"https:\/\/adsecurity.org\/?page_id=183\">SPNs<\/a>:<\/p>\n<ul>\n<li>SQL servers, instances, ports, etc.\n<ul>\n<li><span style=\"color: #0000ff;\">MSSQLSvc<\/span>\/adsmsSQLAP01.adsecurity.org<span style=\"color: #003300;\">:1433<\/span><\/li>\n<\/ul>\n<\/li>\n<li>Exchange\n<ul>\n<li><span style=\"color: #0000ff;\">exchangeMDB<\/span>\/adsmsEXCAS01.adsecurity.org<\/li>\n<\/ul>\n<\/li>\n<li>RDP\n<ul>\n<li><span style=\"color: #0000ff;\">TERMSERV<\/span>\/adsmsEXCAS01.adsecurity.org<\/li>\n<\/ul>\n<\/li>\n<li>WSMan \/ WinRM \/ PS Remoting\n<ul>\n<li><span style=\"color: #0000ff;\">WSMAN<\/span>\/adsmsEXCAS01.adsecurity.org<\/li>\n<\/ul>\n<\/li>\n<li>Hyper-V Host\n<ul>\n<li><span style=\"color: #0000ff;\">Microsoft Virtual Console Service<\/span>\/adsmsHV01.adsecurity.org<\/li>\n<\/ul>\n<\/li>\n<li>VMWare VCenter\n<ul>\n<li><span style=\"color: #0000ff;\">STS<\/span>\/adsmsVC01.adsecurity.org<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p>Here&#8217;s the result of a PowerShell script I wrote that performs SPN scanning for Microsoft SQL Servers.<\/p>\n<p><a href=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/04\/Discover-PSMSSQLServers-ADSECLab.png\"><img loading=\"lazy\" decoding=\"async\" class=\"alignnone wp-image-1509\" src=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/04\/Discover-PSMSSQLServers-ADSECLab.png\" alt=\"Discover-PSMSSQLServers-ADSECLab\" width=\"607\" height=\"455\" srcset=\"https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/04\/Discover-PSMSSQLServers-ADSECLab.png 744w, https:\/\/adsecurity.org\/wp-content\/uploads\/2015\/04\/Discover-PSMSSQLServers-ADSECLab-300x225.png 300w\" sizes=\"auto, (max-width: 607px) 100vw, 607px\" \/><\/a>I wrote<\/p>\n<p>PowerShell script: <a href=\"https:\/\/github.com\/PyroTek3\/PowerShell-AD-Recon\/blob\/master\/Discover-PSMSSQLServers\">Discover-PSMSSQLServers on GitHub<br \/>\n<\/a><br \/>\nI covered some of this in a <a title=\"Active Directory Pentest Recon Part 1: SPN Scanning aka Mining Kerberos ServicePrincipalNames\" href=\"https:\/\/adsecurity.org\/?p=230\">previous post on SPN Scanning<\/a>.<\/p>\n<p>&nbsp;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>The best way to discover services in an Active Directory environment is through what I call &#8220;SPN Scanning.&#8221; The primary benefit of SPN scanning for an attacker over network port scanning is that SPN scanning doesn&#8217;t require connections to every IP on the network to check service ports. SPN scanning performs service discovery via LDAP &hellip; <\/p>\n<p><a class=\"more-link btn\" href=\"https:\/\/adsecurity.org\/?p=1508\">Continue reading<\/a><\/p>\n","protected":false},"author":2,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[11,4,2],"tags":[473,123,3,472,477,478,471,732,475,476,474],"class_list":["post-1508","post","type-post","status-publish","format-standard","hentry","category-microsoft-security","category-technical-reading","category-technical-reference","tag-discoversqlservers","tag-exchange","tag-hyperv","tag-networkportscanning","tag-powershellremoting","tag-rdp","tag-spnscanning","tag-sql","tag-vmware","tag-winrm","tag-wsman","item-wrap"],"_links":{"self":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1508","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/users\/2"}],"replies":[{"embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=1508"}],"version-history":[{"count":8,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1508\/revisions"}],"predecessor-version":[{"id":3980,"href":"https:\/\/adsecurity.org\/index.php?rest_route=\/wp\/v2\/posts\/1508\/revisions\/3980"}],"wp:attachment":[{"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=1508"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=1508"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/adsecurity.org\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=1508"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}