> 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="/files/9MVyldP7eLU93xLq1crA" alt=""><figcaption></figcaption></figure>

### AzureBloodHound

Visualize recon.&#x20;

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

<figure><img src="/files/V3fvCkiizyHzkRlEAK5V" 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="/files/CunL1Kw0cEsU4luPD8I2" alt=""><figcaption></figcaption></figure>

### SharePoint

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

<figure><img src="/files/dnVbEkv2jeWJFMPwiQ0M" 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="/files/ISKoE2fxjtoZHG3RFTPg" alt=""><figcaption></figcaption></figure>

<figure><img src="/files/3mT7WckRJyEaCn605IGG" alt=""><figcaption></figcaption></figure>

### Conditional Access Policies

<figure><img src="/files/fMPrO5eUgzL5ten7wPaO" 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="/files/gsgS0J9FdEoPAuEYFW7P" 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="/files/ROZ8gT1MStyLyC9u2uDl" 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="/files/9HZValR65dVcXKgHIe8Z" 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="/files/44SfXXURGvHlQujsv4He" alt=""><figcaption><p>Get-ADDIntUsers | Select UserPrincipalName, ObjectID, ImmuatableID</p></figcaption></figure>

<figure><img src="/files/Q1ExbI8eWN7KDOMUxf7y" 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="/files/TQQ8aMJ31zWEeshJDBJj" alt=""><figcaption><p>Get-AADIntGlocalAdmins</p></figcaption></figure>

<figure><img src="/files/r739w5tYop5YWTVxDYG1" alt=""><figcaption></figcaption></figure>

### Enumerating Sync Account

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

<figure><img src="/files/QmfP53u3uH7LK8GGQVFV" 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="/files/CWFjt4egCIGHCbxSp8Xz" alt=""><figcaption><p>Interactive</p></figcaption></figure>

<figure><img src="/files/UrduZQtBz4BiBSutlFht" 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>" %}
