Thanks to visit codestin.com
Credit goes to github.com

Skip to content

ashdsetty/Detection

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

81 Commits
 
 
 
 
 
 
 
 

Repository files navigation

Azure Hacking

Iniitial Access

Background - Azure vs ASDK

Microsoft has an on-premise Azure environment called Azure Stack which is meant primarily for enterprise usage. There is also a version called Azure Stack Development Kit (ASDK) which is free.

Main Differences:

  • Scalability
    • ASDK runs on a single instance with limited resources and all of its roles run as separate VMs handled by Hyper-V. This causes some internal architectural differences.
  • ASDK doesn’t run the latest software as Azure does, but is a couple of versions behind.
  • Compared to Azure, ASDK has a very limited number of features.

Azure Stack Overview

Azure Stack Overview

  • AzS-ACS01 - Azure Stack storage services.
  • AzS-ADFS01 - Active Directory Federation Services (ADFS).
  • AzS-CA01 - Certificate authority services for Azure Stack role services.
  • AzS-DC01 - Active Directory, DNS, and DHCP services for Microsoft Azure Stack.
  • AzS-ERCS01 - Emergency Recovery Console VM.
  • AzS-GWY01 - Edge gateway services such as VPN site-to-site connections for tenant networks.
  • AzS-NC01 - Network Controller, which manages Azure Stack network services.
  • AzS-SLB01 - Load-balancing multiplexer services in Azure Stack for both tenants and Azure Stack infrastructure services.
  • AzS-SQL01 - Internal data store for Azure Stack infrastructure roles.
  • AzS-WAS01 - Azure Stack administrator portal and Azure Resource Manager services.
  • AzS-WASP01 - Azure Stack user (tenant) portal and Azure Resource Manager services.
  • AzS-XRP01 - Infrastructure management controller for Microsoft Azure Stack, including the Compute, Network, and Storage resource providers.
  • AzS-SRNG01 - Support Ring VM hosting the log collection service for Azure Stack.

Main Virtual Machines:

  • ARM Layer: AzS-WAS01, AzS-WASP01
  • RP Layer + Infrastructure Control Layer: AzS-XRP01

Issues:

Service Fabric Explorer is a web tool pre-installed in the machine that takes the role of the RP and Infrastructure Control Layer. This enables us to view the internal services which are built as Service Fabric Applications, which is located in the RP layer. Some of the URLs of the services from the SFE don't require authentication, which can lead to vulnerabilities in the entire stack.

Vulnerabilities

  1. CVE-2019-1234 - spoofing

If exploited, the issue would have enabled a remote hacker to unauthorizedly access screenshots and sensitive information of any virtual machine running on Azure infrastructure — it doesn't matter if they're running on a shared, dedicated or isolated virtual machines.

  1. CVE-2019-1372 - remote code execution

An attacker who successfully exploited this vulnerability could allow an unprivileged function run by the user to execute code in the context of NT AUTHORITY\system thereby escaping the Sandbox.

Azure AD Recon (AADInternals)

Install this powershell module to perform recon.

Commands:

Install-Module AADInternals
Import-Module AADInternals
Invoke-AADIntReconAsOutsider -DomainName company.com | Format-Table
Invoke-AADIntUserEnumerationAsOutsider -UserName "[email protected]

# Get login information for a domain
Get-AADIntLoginInformation -Domain company.com

Intrusion - Execution

Password Spraying

Password Spraying Github Link

https://github.com/dafthack/MailSniper

Target a group of Office 365 accounts and use a generalized password list (created through python script).

Use the accounts found through the Outsider Recon Powershell scripts.

Password Spraying Scripts:

https://github.com/mysoc/detection-sandbox/blob/master/pspray.ps1

https://github.com/mysoc/detection-sandbox/blob/master/O365-spray.ps1

User Enumeration

Invoke-AADIntUserEnumerationAsOutsider -UserName "[email protected]"

You can use a text file of users (userlist) :

Get-Content .\users.txt | Invoke-AADIntUserEnumerationAsOutsider

Use guest account from password spraying

# Get tenant details
Get-AADIntTenantDetails

# Prompt for credentials and retrieve & store access token to cache
Get-AADIntAccessTokenForAADGraph -SaveToCache

# Prompt for credentials and save the token to cache
Get-AADIntAccessTokenForAzureCoreManagement -SaveToCache

# List the user's tenants
Get-AADIntAzureTenants

Stage 1: If we know the user id or upn of any user of the tenant, we can list all the groups (including teams and roles) the user is member of. As a result, we now know the ids of those groups, and we can retrieve the list of members of those groups.

# Invoke the user enumeration
$results = Invoke-AADIntUserEnumerationAsGuest -GroupMembers -Manager -Subordinates -Roles
# List group information
$results.Groups | Select-Object displayName,id,membershiprule,description
$results.Groups | Select-Object displayName,id,members

Now we have the list of all external users of the tenant

Stage 2: Now we can retrieve the same information (groups and their members) for each user found at stage 1!

# Invoke the user enumeration for the known user including group members
$results = Invoke-AADIntUserEnumerationAsGuest -UserName "[email protected]" -GroupMembers -Manager -Subordinates -Roles
# List group information
$results.Groups | Select-Object displayName,id,membershiprule,description

# Listing the group information reveals another typical configuration. 
There is a dynamic group for all organisation members: this allows guest users to access all users of the tenant

# List role information
$results.Roles | Select-Object id,members

Phishing - Azure App

Resources

https://github.com/mdsecactivebreach/o365-attack-toolkit

https://www.mdsec.co.uk/2019/07/introducing-the-office-365-attack-toolkit/

https://www.youtube.com/watch?v=JZjrvpacfDY

  1. Background - requires victim to own a web application hosted by an Azure tenant.

  2. Spear phishing campaign

  3. The link in the email directs the user to the attacker-controlled website (e.g., https://myapp.malicious.com) which seamlessly redirects the victim to Microsoft’s login page. The authentication flow is handled entirely by Microsoft, so using multi-factor authentication isn’t a viable mitigation.

Once the user logs into their O365 instance, a token will be generated for the malicious app and the user will be prompted to authorize and give it the permissions it needs.

token

  1. On the attacker’s side, here are the MS Graph API permissions that are being requested:

Permissions Requested by Malicious App

The attacker has control over the application’s name and the icon. The URL is a valid Microsoft URL and the certificate is valid.

Under the application’s name, however, is the name of the attacker’s tenant and a warning message, neither of which can be hidden. An attacker’s hope is that a user will be in a rush, see the familiar icon, and move through this screen as quickly and thoughtlessly as they’d move through a terms of service notice.

By clicking “Accept”, the victim grants the aplication the permissions on behalf of their user—i.e., the application can read the victim’s emails and access any files they have access to.

This step is the only one that requires the victim’s consent — from this point forward, the attacker has complete control over the user’s account and resources.

After granting consent to the application, the victim will be redirected to a website of our choice. A nice trick can be to map the user’s recent file access and redirect them to an internal SharePoint document so the redirection is less suspicious.

Post Intrusion - Persistance forward

  1. Reconnaissance (enumerating users, groups, objects in the user’s 365 tenant)
# Get tenant details
Get-AADIntTenantDetails
  1. Spear phishing (internal-to-internal)

  2. Stealing files and emails from Office 365

  3. API metadata:

  • gain access to metadata for every single user in the organization
  • shows the victim’s calendar events. Can also set up meetings on their behalf, view existing meetings, and even free up time in their day by deleting meetings they set in the future.
  • see any file the user accessed in OneDrive or SharePoint. You can also download or modify files (malicious macros for persistence).
  • When accessing a file via this API, Azure generates a unique link. This link is accessible by anyone from any location—even if the organization does not allow anonymous sharing links for normal 365 users.
  • complete access to our victim’s email. We can see the recipients of any message, filter by high priority emails, send emails (i.e., spear phish other users), and more.
  • By reading the user’s emails, you can identify the most common and vulnerable contacts, send internal spear-phishing emails that come from our victim, and infect his peers. You can also use the victim’s email account to exfiltrate data that you find in 365.
  • Microsoft also provides insights about the victim’s peers using the API. The peer data could be used to pinpoint other users that the victim had the most interaction with
  • modify the user’s files with the right permissions. (potential: One option is to turn the malicious Azure app into ransomware that remotely encrypts files that the user has access to on SharePoint and OneDrive)
  1. AWS Lambda

  2. Azure Persistance - Adds an Automation Account with excessive privileges that can be used to add new accounts (with Subscription Owner permissions) to AzureAD via a single POST request.

Process

  • Create a new Automation Account
  • Import a new runbook that creates an AzureAD user with Owner permissions for the subscription*
  • Sample runbook for this Blog located here – https://github.com/NetSPI/MicroBurst
  • Add the AzureAD module to the Automation account
  • Update the Azure Automation Modules
  • Assign “User Administrator” and “Subscription Owner” rights to the automation account
  • Add a webhook to the runbook
  • Eventually lose your access…
  • Trigger the webhook with a post request to create the new user

Resources

Office 365 Hacking

Vulnerabilities

  1. SAML - A vulnerability in Microsoft Office 365 SAML Service Provider implementation allowed for cross domain authentication bypass affecting all federated domains. An attacker exploiting this vulnerability could gain unrestricted access to a victim’s Office 365 account, including access to their email, files stored in OneDrive etc.

Resources

Detection - Filebeat

Create an Event Hub

  1. Create a Resource Group (if necessary): standard options, note down the name

  2. Create an Event Hub: Create a Resource -> Event Hubs -> Add (Create event hubs namespace)

  • select correct subscription, resource group from step 1, standard options

  • note down name

  1. Go to Event Hubs Namespace page, select Event Hubs in the left menu, at the top of the window, click + Event Hub
  • note down name, create

Check Permissions and Get Connection String

  1. Go to event hubs namespace -> Setting -> Shared Access Policies: Under Claims, make sure that the manage permission is enabled

namespace

  1. Under Policy, click on RootManageSharedAccessKey: Note down the primary key connection string

connection string

Logic App

Connect to your Event Hub

When asked to connect to event hub

Retrieve the following information by following these instructions:

  • Go to Log Analytics Workspace -> Settings -> Agents Management
  • Note Down Workspace ID and Primary Key

workspace

When asked for connection to event hub. click manually enter connection information, use the following fields

  • Connection Name: Custom name
  • Workspace Key: Same key retrieved from earlier
  • Workspace ID: Same ID retrieved from earlier

Export Activity Log to Event Hub

  1. Go to Activity Log

  2. Diagnostic Settings -> Add Diagnostic Setting -> Select all logs

  3. Click Archive to storage account -> Select your preferred storage account

  4. Click Stream to an event hub -> Input namespace -> input event hub name (insights-operational-logs) -> input policy name (RootManageSharedAccessKey)

activity log

  1. Save

Export Audit Log to Event Hub

  1. Go to Azure Active Directory that you want to collect logs from

audit log

  1. Export Data Settings

export setting

  1. Add Diagnostic Setting

diagnostic setting

  1. Click Stream to an event hub -> Input namespace -> input event hub name (insights-operational-logs) -> input policy name (RootManageSharedAccessKey)

Example Settings:

settings

  1. Save

Add Event Hubs Trigger

  1. Create a blank logic app, this will open up the logic app designer

  2. In the search box, enter event hubs

event hubs

  1. Provide the info for the trigger:
  • event hub name: insights-operational-logs
  • content type: application/json

example

Add Event Hubs Parse Json

  1. Add new step in logic app designer

  2. Search parse json (Under Data Operations) -> Click Parse Json action -> Enter Body in content field

data operations

  1. For the schema, use this script:
CLICK ME

Copy this script, add to Body in Parse Json field

{
    "properties": {
        "body": {
            "properties": {
                "ContentData": {
                    "type": "string"
                },
                "Properties": {
                    "properties": {
                        "ProfileName": {
                            "type": "string"
                        },
                        "x-opt-enqueued-time": {
                            "type": "string"
                        },
                        "x-opt-offset": {
                            "type": "string"
                        },
                        "x-opt-sequence-number": {
                            "type": "number"
                        }
                    },
                    "type": "object"
                },
                "SystemProperties": {
                    "properties": {
                        "EnqueuedTimeUtc": {
                            "type": "string"
                        },
                        "Offset": {
                            "type": "string"
                        },
                        "PartitionKey": {},
                        "SequenceNumber": {
                            "type": "number"
                        }
                    },
                    "type": "object"
                }
            },
            "type": "object"
        },
        "headers": {
            "properties": {
                "Cache-Control": {
                    "type": "string"
                },
                "Content-Length": {
                    "type": "string"
                },
                "Content-Type": {
                    "type": "string"
                },
                "Date": {
                    "type": "string"
                },
                "Expires": {
                    "type": "string"
                },
                "Location": {
                    "type": "string"
                },
                "Pragma": {
                    "type": "string"
                },
                "Retry-After": {
                    "type": "string"
                },
                "Timing-Allow-Origin": {
                    "type": "string"
                },
                "Transfer-Encoding": {
                    "type": "string"
                },
                "Vary": {
                    "type": "string"
                },
                "X-AspNet-Version": {
                    "type": "string"
                },
                "X-Powered-By": {
                    "type": "string"
                },
                "x-ms-request-id": {
                    "type": "string"
                }
            },
            "type": "object"
        }
    },
    "type": "object"
}

parse json

Compose

  1. Add New step -> Data Operations -> Actions -> Compose

  2. Select Body

compose

Send Data

  1. Add New Step -> Search Data Collector -> CLick on Send Data (Azure Log Analytics Data Collector)

data collector

  1. Enter Fields: Outputs under JSON Request Body, Create a name for logs, Add time as a new parameter

send data

  1. Click Save

  2. Run to test if it works

Resources

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors