# T1078.004 - Valid Accounts: Cloud Accounts

## Description from ATT&CK

> Valid accounts in cloud environments may allow adversaries to perform actions to achieve Initial Access, Persistence, Privilege Escalation, or Defense Evasion. Cloud accounts are those created and configured by an organization for use by users, remote support, services, or for administration of resources within a cloud service provider or SaaS application. Cloud Accounts can exist solely in the cloud; alternatively, they may be hybrid-joined between on-premises systems and the cloud through syncing or federation with other identity sources such as Windows Active Directory.(Citation: AWS Identity Federation)(Citation: Google Federating GC)(Citation: Microsoft Deploying AD Federation)
> 
> Service or user accounts may be targeted by adversaries through [Brute Force](https://attack.mitre.org/techniques/T1110), [Phishing](https://attack.mitre.org/techniques/T1566), or various other means to gain access to the environment. Federated or synced accounts may be a pathway for the adversary to affect both on-premises systems and cloud environments - for example, by leveraging shared credentials to log onto [Remote Services](https://attack.mitre.org/techniques/T1021). High privileged cloud accounts, whether federated, synced, or cloud-only, may also allow pivoting to on-premises environments by leveraging SaaS-based [Software Deployment Tools](https://attack.mitre.org/techniques/T1072) to run commands on hybrid-joined devices.
> 
> An adversary may create long lasting [Additional Cloud Credentials](https://attack.mitre.org/techniques/T1098/001) on a compromised cloud account to maintain persistence in the environment. Such credentials may also be used to bypass security controls such as multi-factor authentication.
> 
> Cloud accounts may also be able to assume [Temporary Elevated Cloud Access](https://attack.mitre.org/techniques/T1548/005) or other privileges through various means within the environment. Misconfigurations in role assignments or role assumption policies may allow an adversary to use these mechanisms to leverage permissions outside the intended scope of the account. Such over privileged accounts may be used to harvest sensitive data from online storage accounts and databases through [Cloud API](https://attack.mitre.org/techniques/T1059/009) or other methods. For example, in Azure environments, adversaries may target Azure Managed Identities, which allow associated Azure resources to request access tokens. By compromising a resource with an attached Managed Identity, such as an Azure VM, adversaries may be able to [Steal Application Access Token](https://attack.mitre.org/techniques/T1528)s to move laterally across the cloud environment.(Citation: SpecterOps Managed Identity 2022)

[Source](https://attack.mitre.org/techniques/T1078/004)

## Atomic Tests

- [Atomic Test #1: Creating GCP Service Account and Service Account Key](#atomic-test-1-creating-gcp-service-account-and-service-account-key)
- [Atomic Test #2: Azure Persistence Automation Runbook Created or Modified](#atomic-test-2-azure-persistence-automation-runbook-created-or-modified)
- [Atomic Test #3: GCP - Create Custom IAM Role](#atomic-test-3-gcp---create-custom-iam-role)

### Atomic Test #1: Creating GCP Service Account and Service Account Key

GCP Service Accounts can be used to gain intial access as well as maintain persistence inside Google Cloud.

**Supported Platforms:** Google-workspace, Iaas:gcp

**auto_generated_guid:** `9fdd83fd-bd53-46e5-a716-9dec89c8ae8e`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| project-id | ID of the project, you want to create service account as well as service account key for | string | art-project-1|
| service-account-name | Name of the service account | string | gcp-art-service-account-1|
| service-account-email | Email of the service account | string | gcp-art-service-account-1@art-project-1.iam.gserviceaccount.com|
| output-key-file | Email of the service account | string | gcp-art-service-account-1.json|

#### Attack Commands: Run with `sh`!

```sh
gcloud config set project #{project-id}
gcloud iam service-accounts create #{service-account-name}
gcloud iam service-accounts keys create #{output-key-file} --iam-account=#{service-account-email}
```

#### Cleanup Commands

```sh
gcloud iam service-accounts delete #{service-account-email} --quiet
```

#### Dependencies: Run with `sh`!

##### Description: Requires gcloud

###### Check Prereq Commands

```sh
if [ -x "$(command -v gcloud)" ]; then exit 0; else exit 1; fi;
```

###### Get Prereq Commands

```sh
echo "Please Install Google Cloud SDK before running this atomic test : https://cloud.google.com/sdk/docs/install"
```

##### Description: Check if user is logged in

###### Check Prereq Commands

```sh
gcloud config get-value account
```

###### Get Prereq Commands

```sh
gcloud auth login --no-launch-browser
```

### Atomic Test #2: Azure Persistence Automation Runbook Created or Modified

Identifies when an Azure Automation runbook is created or modified. An adversary may create or modify an Azure
Automation runbook to execute malicious code and maintain persistence in their target's environment.

**Supported Platforms:** Iaas:azure

**auto_generated_guid:** `348f4d14-4bd3-4f6b-bd8a-61237f78b3ac`

#### Inputs

| Name | Description | Type | Default Value |
|------|-------------|------|---------------|
| resource_group | Name of the resource group | string | ART-ResourceGroupName-T1078-004|
| runbook_name | Name of the runbook name | string | ART-RunbookName-T1078-004|
| automation_account_name | Name of the automation account name | string | ART-AutomationAccountName-T1078-004|

#### Attack Commands: Run with `powershell`!

```powershell
New-AzAutomationRunbook -Name #{runbook_name} -Type PowerShell -ResourceGroupName #{resource_group} -Description 'my-test-runbook' -AutomationAccountName #{automation_account_name}
```

#### Cleanup Commands

```powershell
Remove-AzAutomationRunbook -AutomationAccountName #{automation_account_name} -Name #{runbook_name} -ResourceGroupName #{resource_group} -Force
Remove-AzAutomationAccount -ResourceGroupName #{resource_group} -Name #{automation_account_name} -Force
Remove-AzResourceGroup -Name #{resource_group} -Force
echo "Cleanup should be completed. Run 'terraform destroy` to ensure remaining resources are also deleted."
cd "$PathToAtomicsFolder/T1078.004/src/T1078.004-2/"
terraform destroy -auto-approve
```

#### Dependencies: Run with `powershell`!

##### Description: Check if terraform is installed.

###### Check Prereq Commands

```powershell
terraform version
```

###### Get Prereq Commands

```powershell
echo "Please install terraform via https://developer.hashicorp.com/terraform/tutorials/aws-get-started/install-cli (URL accurate as of Nov. 15, 2024)."
```

##### Description: Check if Azure CLI and Azure Powershell are installed.

* L