> For the complete documentation index, see [llms.txt](https://nk0.gitbook.io/dfir/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://nk0.gitbook.io/dfir/enterprise-architecture/the-cloud/azure/attacking-azure/initial-access/authenticated-recon.md).

# Authenticated Recon

## Automation

### o365Recon

Automate all of the below commands with o365Recon.

{% embed url="<https://github.com/nyxgeek/o365recon>" %}

```powershell
#Recon
Import-Module MSOnline
Import-Module AzureAD
.\o365recon.ps1 -azure
```

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2F8nunrxHxFDIaDO7zQ45X%2Fimage.png?alt=media&amp;token=27f8c387-459d-4973-8244-7f64cdf01f51" alt=""><figcaption></figcaption></figure>

### AzureBloodHound

Visualize recon.&#x20;

{% embed url="<https://github.com/BloodHoundAD/AzureHound>" %}

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FAih4afrfAVvsJ87NtkDT%2Fimage.png?alt=media&amp;token=4dde6863-61e7-4189-a108-6f80de46ca37" alt=""><figcaption></figcaption></figure>

Custom queries for Azure are helpful.

{% embed url="<https://github.com/hausec/Bloodhound-Custom-Queries>" %}

## AADInternals

{% embed url="<https://aadinternals.com/aadinternals/>" %}

```powershell
#Login to azure
Install-Module AADInternals
Import-Module AADInternals
Get-AADIntAccessTokenForAzureCoreManagement -SaveToCache
asd@vk1zm.onmicrosoft.com
```

### Subscriptions

```powershell
# Get all subscriptions of the current tenant
Get-AADIntAzureSubscriptions
```

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FIPfTZCkWbuUJAiGT2GP9%2Fimage.png?alt=media&amp;token=c6f03bc7-c2ae-4b41-89f1-14b2250d386d" alt=""><figcaption></figcaption></figure>

### SharePoint

```powershell
#Sharepoint Enumeration
Get-AADIntSPOServiceInformation
```

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FjWJeVnbvQdyzZMdrL8Qc%2Fimage.png?alt=media&amp;token=3671a25f-4d53-4990-a4e6-0ec8b1e0baea" alt=""><figcaption></figcaption></figure>

### Service Principals

<pre class="language-powershell"><code class="lang-powershell"><strong>#Drilldown into Service Principals
</strong>Get-ADIntServicePrincipals > doc.txt
<strong>Get-ADIntServicePrincipals -ClientIDs &#x3C;AppPrincipalID>
</strong></code></pre>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FmY2kZpCiL7IWRfEMyYqN%2Fimage.png?alt=media&amp;token=8cd4a63b-4023-4799-9286-21d153259ddb" alt=""><figcaption></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FDGArRO9EnkZdByu6Z7lv%2Fimage.png?alt=media&amp;token=35f504a8-5633-46f1-ae39-0e9d722e7f1c" alt=""><figcaption></figcaption></figure>

### Conditional Access Policies

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FQC80MGB3QLE2H4VOfecs%2Fimage.png?alt=media&amp;token=2ff113e4-5e25-4591-af43-dec6f97582a8" alt=""><figcaption><p>What is it?</p></figcaption></figure>

Conditional Access Policies are stored and displayed as JSON.

<pre class="language-powershell"><code class="lang-powershell"><strong>#Display info for Conditional Access Policies
</strong><strong>Get-ADIntConditionalAccessPolicies
</strong></code></pre>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FHOdRmNpkzKCLSF0sS70q%2Fimage.png?alt=media&amp;token=5ae9d0dd-b749-4ea6-975d-bee4981ff572" alt=""><figcaption><p>Policy named geolocation that enables MFA for all users.</p></figcaption></figure>

### MFASweep/Conditional Access Policies

{% embed url="<https://github.com/dafthack/MFASweep>" %}

Uses APIs to see if a user can authenticate or is blocked by Access Policies.

<pre class="language-powershell"><code class="lang-powershell"><strong>#Check to see if user can login to any resource or is blocked
</strong><strong>Import-Module .\MFASweep.ps1
</strong><strong>Invoke-MFASweep -Username USERNAME@DOMAIN.onmicrosoft.com -Password 'PASSWORD'
</strong><strong>
</strong>##Each individual module can be run separately if needed as well.##

#Microsoft Graph API
Invoke-GraphAPIAuth -Username targetuser@targetdomain.com -Password Winter2020 
<strong>
</strong><strong>#Azure Service Management API
</strong>Invoke-AzureManagementAPIAuth -Username targetuser@targetdomain.com -Password Winter2020 

#Microsoft 365 Exchange Web Services
Invoke-EWSAuth -Username targetuser@targetdomain.com -Password Winter2020 
<strong>
</strong><strong>#Microsoft 365 Web Portal
</strong>Invoke-O365WebPortalAuth -Username targetuser@targetdomain.com -Password Winter2020 

#Microsoft 365 Web Portal w/ Mobile User Agent
Invoke-O365WebPortalAuthMobile -Username targetuser@targetdomain.com -Password Winter2020 
<strong>
</strong><strong>#Microsoft 365 Active Sync
</strong>Invoke-O365ActiveSyncAuth -Username targetuser@targetdomain.com -Password Winter2020 

#ADFS
Invoke-ADFSAuth -Username targetuser@targetdomain.com -Password Winter2020 

</code></pre>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FTuBMoMkLE13294bk4fyW%2Fimage.png?alt=media&amp;token=fc0c0ce2-2822-4801-9a50-451cb43d3a8a" alt=""><figcaption><p>MFASweep output</p></figcaption></figure>

### Unified Audit Log Settings

Important to know what traces your leaving behind for defense evasion.

<pre class="language-powershell"><code class="lang-powershell"><strong>#Saves Access Token
</strong><strong>Get-ADIntAccessTokenForEXO -SaveToCache
</strong><strong>
</strong><strong>#Shows UAL Settings
</strong><strong>Get-ADIntUnifiedAuditLogSettings | Select Unified
</strong></code></pre>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FBpLy7dFBYrrSYF8ZkIPf%2Fimage.png?alt=media&amp;token=072a6ca8-1fc6-4cf9-ba16-4a44ffbac518" alt=""><figcaption></figcaption></figure>

### Enumerate Users

Obtaining detailed information on a user can help identify their location for Conditional Access Policy bypasses.

```powershell
#Enumerate all users
Get-ADDIntUsers | Select UserPrincipalName, ObjectID, ImmuatableID

#Drilldown into user
Get-ADDIntUsers -UserPrincipalName USERNAME
```

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2F8B4yBWIqHqCP4dy8Gxaq%2Fimage.png?alt=media&amp;token=44009500-3f9f-4f80-b06a-52336b723fdb" alt=""><figcaption><p>Get-ADDIntUsers | Select UserPrincipalName, ObjectID, ImmuatableID</p></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FO4072DZ6nzcH1kXOZ9Aj%2Fimage.png?alt=media&amp;token=b4ddae70-ab75-4bed-b823-787b9f6cb1a1" alt=""><figcaption></figcaption></figure>

### Enumerating Administrators

```powershell
#List Global Admins
Get-AADIntGlocalAdmins

#Recon
$results = Invoke-AADIntReconAsInsider

#Select specific groups from recon output
$results.roleInformation | Where Memebers -ne $null | select Name.Members
```

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FiBKAHQ8MEHpSLBdnNC68%2Fimage.png?alt=media&amp;token=9bd0d268-28c3-42a3-a815-8f94d3a35fec" alt=""><figcaption><p>Get-AADIntGlocalAdmins</p></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2Fss7Hl0d6Th19KxPobU72%2Fimage.png?alt=media&amp;token=e84556d8-527b-4ce0-86e3-d32d68e1e815" alt=""><figcaption></figcaption></figure>

### Enumerating Sync Account

```powershell
#Get Sync account
Get-AADIntSyncConfiguration
```

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FhKAfMWZK7Be3FMepdtJR%2Fimage.png?alt=media&amp;token=98a49fc8-6cb2-44f9-bfb0-c0c1f3e65a30" alt=""><figcaption></figcaption></figure>

## Detect

* API calls are not logged within Azure, so AADInternals will not detected.
* Azure Sign-Ins are logged but difficult to baseline.

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FzxEL7a7eJYDFE6I0fPY4%2Fimage.png?alt=media&amp;token=0cf864f4-8986-4a2a-8776-d2a6fb1b0feb" alt=""><figcaption><p>Interactive</p></figcaption></figure>

<figure><img src="https://3278866189-files.gitbook.io/~/files/v0/b/gitbook-x-prod.appspot.com/o/spaces%2Fu4e057u3LTRKJEHFetwE%2Fuploads%2FCxKnkeNKd1lUlfcyzQ7Y%2Fimage.png?alt=media&amp;token=c3abe722-5dd2-4952-919f-bb8ef4a9e7bb" alt=""><figcaption><p>Non-Interactive</p></figcaption></figure>

* Application header can be forged, so it is unreliable to baseline.

Below is a list of Application IDs and their name used for sign-ins.

{% embed url="<https://learn.microsoft.com/en-us/troubleshoot/azure/active-directory/verify-first-party-apps-sign-in>" %}
