Az - Storage Accounts & Blobs

Tip

Učite i vežbajte AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Učite i vežbajte GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Učite i vežbajte Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Podržite HackTricks

Osnovne informacije

Azure Storage Accounts su fundamentalne usluge u Microsoft Azure koje obezbeđuju skalabilno, sigurno i visoko dostupno cloud skladištenje za razne tipove podataka, uključujući blobs (binary large objects), files, queues, i tables. Služe kao kontejneri koji grupišu ove različite storage servise pod jednim namespace-om radi lakšeg upravljanja.

Glavne opcije konfiguracije:

  • Svaki storage account mora imati uniq name across all Azure.
  • Svaki storage account je deploy-ovan u region ili u Azure extended zone
  • Moguće je odabrati premium verziju storage account-a za bolje performanse
  • Moguće je izabrati među 4 types of redundancy to protect protiv rack, drive i datacenter failures.

Opcije bezbednosne konfiguracije:

  • Require secure transfer for REST API operations: Zahteva TLS u svakoj komunikaciji sa storage-om
  • Allows enabling anonymous access on individual containers: Ako nije omogućeno, neće biti moguće omogućiti anonymous access u budućnosti
  • Enable storage account key access: Ako nije, pristup pomoću Shared Keys će biti zabranjen
  • Minimum TLS version
  • Permitted scope for copy operations: Dozvoljeno sa bilo kog storage account-a, sa bilo kog storage account-a iz istog Entra tenant-a ili sa storage account-a sa private endpoints u istoj virtualnoj mreži.

Blob Storage options:

  • Allow cross-tenant replication
  • Access tier: Hot (često pristupani podaci), Cool i Cold (retko pristupani podaci)

Mrežne opcije

  • Network access:
  • Dozvoljeno sa svih mreža
  • Dozvoljeno sa izabranih virtualnih mreža i IP adresa
  • Onemogući javni pristup i koristi privatni pristup
  • Private endpoints: Omogućava privatnu konekciju do storage account-a iz virtualne mreže

Opcije zaštite podataka:

  • Point-in-time restore for containers: Dozvoljava vraćanje containera u ranije stanje
  • Zahteva da su enabled versioning, change feed, i blob soft delete.
  • Enable soft delete for blobs: Omogućava period zadržavanja u danima za obrisane blobs (čak i prepisane)
  • Enable soft delete for containers: Omogućava period zadržavanja u danima za obrisane containere
  • Enable soft delete for file shares: Omogućava period zadržavanja u danima za obrisane file shares
  • Enable versioning for blobs: Čuva prethodne verzije vaših blobs
  • Enable blob change feed: Čuva logove kreiranja, modifikacije i brisanja promena za blobs
  • Enable version-level immutability support: Omogućava postavljanje vremenski zasnovane politike zadržavanja na nivou naloga koja će se primenjivati na sve verzije blobs.
  • Version-level immutability support i point-in-time restore for containers ne mogu biti enabled istovremeno.

Opcije konfiguracije enkripcije:

  • Encryption type: Moguće je koristiti Microsoft-managed keys (MMK) ili Customer-managed keys (CMK)
  • Enable infrastructure encryption: Omogućava dvostruku enkripciju podataka “for more security”

Storage endpoints

Storage servisEndpoint
Blob storagehttps://.blob.core.windows.net

https://.blob.core.windows.net/?restype=container&comp=list
Data Lake Storagehttps://.dfs.core.windows.net
Azure Fileshttps://.file.core.windows.net
Queue storagehttps://.queue.core.windows.net
Table storagehttps://.table.core.windows.net

Javna izloženost

Ako “Allow Blob public access” je enabled (disabled by default), pri kreiranju containera moguće je:

  • Dati public access to read blobs (treba da znate ime).
  • List container blobs i read ih.
  • Napraviti ga potpuno private

Static website ($web) exposure & leaked secrets

  • Static websites are served from the special $web container over a region-specific endpoint such as https://<account>.z13.web.core.windows.net/.
  • The $web container may report publicAccess: null via the blob API, but files are still reachable through the static site endpoint, so dropping config/IaC artifacts there can leak secrets.
  • Brzi audit workflow:
# Identify storage accounts with static website hosting enabled
az storage blob service-properties show --account-name <acc-name> --auth-mode login
# Enumerate containers (including $web) and their public flags
az storage container list --account-name <acc-name> --auth-mode login
# List files served by the static site even when publicAccess is null
az storage blob list --container-name '$web' --account-name <acc-name> --auth-mode login
# Pull suspicious files directly (e.g., IaC tfvars containing secrets/SAS)
az storage blob download -c '$web' --name iac/terraform.tfvars --file /dev/stdout --account-name <acc-name> --auth-mode login

Revizija anonimnog izlaganja blob-ova

  • Pronađite storage naloge koji mogu izložiti podatke: az storage account list | jq -r '.[] | select(.properties.allowBlobPublicAccess==true) | .name'. Ako je allowBlobPublicAccess false, ne možete postaviti kontejnere kao javne.
  • Ispitajte rizične naloge da potvrdite postavku i druga slaba podešavanja: az storage account show --name <acc> --query '{allow:properties.allowBlobPublicAccess, minTls:properties.minimumTlsVersion}'.
  • Enumerišite izloženost na nivou kontejnera gde je opcija omogućena:
az storage container list --account-name <acc> \
--query '[].{name:name, access:properties.publicAccess}'
  • "Blob": anonimno čitanje dozvoljeno samo kada je ime bloba poznato (bez listanja).
  • "Container": anonimno listanje + čitanje svakog bloba.
  • null: privatno; potrebna autentifikacija.
  • Dokaži pristup bez kredencijala:
  • Ako je publicAccess Container, anonimno listanje radi: curl "https://<acc>.blob.core.windows.net/<container>?restype=container&comp=list".
  • Za oba, Blob i Container, anonimno preuzimanje bloba radi kada je ime poznato:
az storage blob download -c <container> -n <blob> --account-name <acc> --file /dev/stdout
# or via raw HTTP
curl "https://<acc>.blob.core.windows.net/<container>/<blob>"

Povezivanje sa Storage

Ako pronađete bilo koje Storage na koje možete da se povežete, možete koristiti alat Microsoft Azure Storage Explorer za to.

Pristup Storage

RBAC

Moguće je koristiti Entra ID principals sa RBAC roles za pristup storage account-ima i to je preporučeni način.

Access Keys

Storage account-i imaju access keys koje se mogu koristiti za pristup. To pruža full access to the storage account.

Shared Keys & Lite Shared Keys

Moguće je generate Shared Keys potpisane access keys-ovima da bi se autorizovao pristup određenim resursima preko potpisanog URL-a.

Note

Imajte na umu da deo CanonicalizedResource predstavlja resurs storage servisa (URI). Ako je bilo koji deo URL-a enkodovan, treba biti enkodovan i unutar CanonicalizedResource.

Note

Ovo se koristi podrazumevano od strane az cli za autentifikaciju zahteva. Da bi se koristili kredencijali Entra ID principala, navesti parametar --auth-mode login.

  • Moguće je generisati shared key for blob, queue and file services potpisujući sledeće informacije:
StringToSign = VERB + "\n" +
Content-Encoding + "\n" +
Content-Language + "\n" +
Content-Length + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
If-Modified-Since + "\n" +
If-Match + "\n" +
If-None-Match + "\n" +
If-Unmodified-Since + "\n" +
Range + "\n" +
CanonicalizedHeaders +
CanonicalizedResource;
  • Moguće je generisati deljeni ključ za servis tabela potpisivanjem sledećih informacija:
StringToSign = VERB + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
CanonicalizedResource;
  • Moguće je generisati lite shared key for blob, queue and file services potpisivanjem sledećih informacija:
StringToSign = VERB + "\n" +
Content-MD5 + "\n" +
Content-Type + "\n" +
Date + "\n" +
CanonicalizedHeaders +
CanonicalizedResource;
  • Moguće je generisati lite shared key for table services potpisivanjem sledećih informacija:
StringToSign = Date + "\n"
CanonicalizedResource

Zatim, za korišćenje ključa, on se može postaviti u Authorization header prateći sledeću sintaksu:

Authorization="[SharedKey|SharedKeyLite] <AccountName>:<Signature>"
#e.g.
Authorization: SharedKey myaccount:ctzMq410TV3wS7upTBcunJTDLEJwMAZuFPfr0mrrA08=

PUT http://myaccount/mycontainer?restype=container&timeout=30 HTTP/1.1
x-ms-version: 2014-02-14
x-ms-date: Fri, 26 Jun 2015 23:39:12 GMT
Authorization: SharedKey myaccount:ctzMq410TV3wS7upTBcunJTDLEJwMAZuFPfr0mrrA08=
Content-Length: 0

Shared Access Signature (SAS)

Shared Access Signatures (SAS) su sigurni, vremenski ograničeni URL-ovi koji dodjeljuju specifične dozvole za pristup resursima u Azure Storage nalogu bez izlaganja access keys naloga. Dok access keys omogućavaju punu administratorsku kontrolu nad svim resursima, SAS omogućava granularnu kontrolu definisanjem dozvola (npr. read ili write) i vremena isteka.

SAS Types

  • User delegation SAS: Kreira se od strane Entra ID principal koji potpisuje SAS i delegira dozvole sa user-a na SAS. Može se koristiti samo sa blob and data lake storage (docs). Moguće je revoke-ovati sve generisane user delegated SAS.
  • Moguće je generisati delegation SAS sa “više” dozvola nego što user poseduje. Međutim, ako principal nema te dozvole, SAS neće funkcionisati (no privesc).
  • Service SAS: Potpisuje se koristeći jedan od storage account access keys. Može se koristiti da dodeli pristup specifičnim resursima u jednoj storage službi. Ako se key obnovi, SAS prestaje da radi.
  • Account SAS: Takođe se potpisuje jednim od storage account access keys. Dodeljuje pristup resursima preko servisa u okviru storage account-a (Blob, Queue, Table, File) i može uključivati operacije na nivou servisa.

A SAS URL potpisan pomoću access key izgleda ovako:

  • https://<container_name>.blob.core.windows.net/newcontainer?sp=r&st=2021-09-26T18:15:21Z&se=2021-10-27T02:14:21Z&spr=https&sv=2021-07-08&sr=c&sig=7S%2BZySOgy4aA3Dk0V1cJyTSIf1cW%2Fu3WFkhHV32%2B4PE%3D

A SAS URL potpisan kao user delegation izgleda ovako:

  • https://<container_name>.blob.core.windows.net/testing-container?sp=r&st=2024-11-22T15:07:40Z&se=2024-11-22T23:07:40Z&skoid=d77c71a1-96e7-483d-bd51-bd753aa66e62&sktid=fdd066e1-ee37-49bc-b08f-d0e152119b04&skt=2024-11-22T15:07:40Z&ske=2024-11-22T23:07:40Z&sks=b&skv=2022-11-02&spr=https&sv=2022-11-02&sr=c&sig=7s5dJyeE6klUNRulUj9TNL0tMj2K7mtxyRc97xbYDqs%3D

Napomena za neke http params:

  • Parametar se označava datum isteka SAS-a
  • Parametar sp označava dozvole SAS-a
  • sig je potpis koji validira SAS

SAS permissions

Prilikom generisanja SAS-a potrebno je navesti dozvole koje treba dodeliti. U zavisnosti od objekta nad kojim se SAS generiše, mogu biti uključene različite dozvole. Na primer:

  • (a)dd, (c)reate, (d)elete, (e)xecute, (f)ilter_by_tags, (i)set_immutability_policy, (l)ist, (m)ove, (r)ead, (t)ag, (w)rite, (x)delete_previous_version, (y)permanent_delete

SFTP Support for Azure Blob Storage

Azure Blob Storage sada podržava SSH File Transfer Protocol (SFTP), omogućavajući siguran transfer fajlova i upravljanje direktno u Blob Storage bez potrebe za custom rešenjima ili third-party proizvodima.

Key Features

  • Protocol Support: SFTP radi sa Blob Storage nalozima konfigurisanim sa hierarchical namespace (HNS). Ovo organizuje blobs u direktorijume i poddirektorijume radi lakše navigacije.
  • Security: SFTP koristi lokalne korisničke identitete za autentifikaciju i ne integriše se sa RBAC ili ABAC. Svaki lokalni korisnik može da se autentifikuje putem:
  • Azure-generated passwords
  • Public-private SSH key pairs
  • Granular Permissions: Dozvole kao što su Read, Write, Delete i List mogu se dodeliti lokalnim korisnicima za do 100 containers.
  • Networking Considerations: SFTP konekcije se prave preko porta 22. Azure podržava mrežne konfiguracije poput firewalla, private endpoints ili virtual networks za zaštitu SFTP saobraćaja.

Setup Requirements

  • Hierarchical Namespace: HNS mora biti omogućen prilikom kreiranja storage account-a.
  • Supported Encryption: Zahteva Microsoft Security Development Lifecycle (SDL)-odobrene kriptografske algoritme (npr. rsa-sha2-256, ecdsa-sha2-nistp256).
  • SFTP Configuration:
  • Enable SFTP on the storage account.
  • Create local user identities with appropriate permissions.
  • Configure home directories for users to define their starting location within the container.

Permissions

PermissionSymbolDescription
ReadrČitanje sadržaja fajla.
WritewUpload fajlova i kreiranje direktorijuma.
ListlListanje sadržaja direktorijuma.
DeletedBrisanje fajlova ili direktorijuma.
CreatecKreiranje fajlova ili direktorijuma.
Modify OwnershipoPromena vlasnika ili grupe.
Modify PermissionspPromena ACL-ova na fajlovima ili direktorijumima.

Enumeracija

az cli enumeration ```bash # Get storage accounts az storage account list #Get the account name from here

BLOB STORAGE

List containers

az storage container list –account-name

Check if public access is allowed

az storage container show-permission
–account-name
-n

Make a container public

az storage container set-permission
–public-access container
–account-name
-n

List blobs in a container

az storage blob list
–container-name
–account-name

Download blob

az storage blob download
–account-name
–container-name
–name
–file </path/to/local/file>

Create container policy

az storage container policy create
–account-name mystorageaccount
–container-name mycontainer
–name fullaccesspolicy
–permissions racwdl
–start 2023-11-22T00:00Z
–expiry 2024-11-22T00:00Z

QUEUE

az storage queue list –account-name az storage message peek –account-name –queue-name

ACCESS KEYS

az storage account keys list –account-name

Check key policies (expiration time?)

az storage account show -n –query “{KeyPolicy:keyPolicy}”

Once having the key, it’s possible to use it with the argument –account-key

Enum blobs with account key

az storage blob list
–container-name
–account-name
–account-key “ZrF40pkVKvWPUr[…]v7LZw==”

Download a file using an account key

az storage blob download
–account-name
–account-key “ZrF40pkVKvWPUr[…]v7LZw==”
–container-name
–name
–file </path/to/local/file>

Upload a file using an account key

az storage blob upload
–account-name
–account-key “ZrF40pkVKvWPUr[…]v7LZw==”
–container-name
–file </path/to/local/file>

SAS

List access policies

az storage <container|queue|share|table> policy list
–account-name
–container-name

Generate SAS with all permissions using an access key

az storage <container|queue|share|table|blob> generate-sas
–permissions acdefilmrtwxy
–expiry 2024-12-31T23:59:00Z
–account-name
-n

Generate SAS with all permissions using via user delegation

az storage <container|queue|share|table|blob> generate-sas
–permissions acdefilmrtwxy
–expiry 2024-12-31T23:59:00Z
–account-name
–as-user –auth-mode login
-n

Generate account SAS

az storage account generate-sas
–expiry 2024-12-31T23:59:00Z
–account-name
–services qt
–resource-types sco
–permissions acdfilrtuwxy

Use the returned SAS key with the param –sas-token

e.g.

az storage blob show
–account-name
–container-name
–sas-token ‘se=2024-12-31T23%3A59%3A00Z&sp=racwdxyltfmei&sv=2022-11-02&sr=c&sig=ym%2Bu%2BQp5qqrPotIK5/rrm7EMMxZRwF/hMWLfK1VWy6E%3D’
–name ‘asd.txt’

#Local-Users

List users

az storage account local-user list
–account-name
–resource-group

Get user

az storage account local-user show
–account-name
–resource-group
–name

List keys

az storage account local-user list
–account-name
–resource-group

</details>

{{#endtab }}

{{#tab name="Az PowerShell" }}

<details>
<summary>Az PowerShell enumeracija</summary>
```powershell
# Get storage accounts
Get-AzStorageAccount | fl
# Get rules to access the storage account
Get-AzStorageAccount | select -ExpandProperty NetworkRuleSet
# Get IPs
(Get-AzStorageAccount | select -ExpandProperty NetworkRuleSet).IPRules
# Get containers of a storage account
Get-AzStorageContainer -Context (Get-AzStorageAccount -name <NAME> -ResourceGroupName <NAME>).context
# Get blobs inside container
Get-AzStorageBlob -Container epbackup-planetary -Context (Get-AzStorageAccount -name <name> -ResourceGroupName <name>).context
# Get a blob from a container
Get-AzStorageBlobContent -Container <NAME> -Context (Get-AzStorageAccount -name <NAME> -ResourceGroupName <NAME>).context -Blob <blob_name> -Destination .\Desktop\filename.txt

# Create a Container Policy
New-AzStorageContainerStoredAccessPolicy `
-Context (Get-AzStorageAccount -Name <NAME> -ResourceGroupName <NAME>).Context `
-Container <container-name> `
-Policy <policy-name> `
-Permission racwdl `
-StartTime (Get-Date "2023-11-22T00:00Z") `
-ExpiryTime (Get-Date "2024-11-22T00:00Z")
#Get Container policy
Get-AzStorageContainerStoredAccessPolicy `
-Context (Get-AzStorageAccount -Name <NAME> -ResourceGroupName <NAME>).Context `
-Container "storageaccount1994container"

# Queue Management
Get-AzStorageQueue -Context (Get-AzStorageAccount -Name <NAME> -ResourceGroupName <NAME>).Context
(Get-AzStorageQueue -Name <NAME> -Context (Get-AzStorageAccount -name <NAME> -ResourceGroupName <NAME>).Context).QueueClient.PeekMessage().Value

#Blob Container
Get-AzStorageBlob -Container <container-name> -Context $(Get-AzStorageAccount -name "teststorageaccount1998az" -ResourceGroupName "testStorageGroup").Context
Get-AzStorageBlobContent `
-Container <container-name> `
-Blob <blob-name> `
-Destination <local-path> `
-Context $(Get-AzStorageAccount -name "teststorageaccount1998az" -ResourceGroupName "testStorageGroup").Context

Set-AzStorageBlobContent `
-Container <container-name> `
-File <local-file-path> `
-Blob <blob-name> `
-Context $(Get-AzStorageAccount -name "teststorageaccount1998az" -ResourceGroupName "testStorageGroup").Context

# Shared Access Signatures (SAS)
Get-AzStorageContainerAcl `
-Container <container-name> `
-Context (Get-AzStorageAccount -Name <NAME> -ResourceGroupName <NAME>).Context

New-AzStorageBlobSASToken `
-Context $ctx `
-Container <container-name> `
-Blob <blob-name> `
-Permission racwdl `
-ExpiryTime (Get-Date "2024-12-31T23:59:00Z")

Deljeni fajlovi

Az - File Shares

Privilege Escalation

Az - Storage Privesc

Post Exploitation

Az - Blob Storage Post Exploitation

Persistence

Az - Storage Persistence

Izvori

Tip

Učite i vežbajte AWS Hacking:HackTricks Training AWS Red Team Expert (ARTE)
Učite i vežbajte GCP Hacking: HackTricks Training GCP Red Team Expert (GRTE) Učite i vežbajte Azure Hacking: HackTricks Training Azure Red Team Expert (AzRTE)

Podržite HackTricks