1
jhwong@netskope.com
@jenkohwong
September 13, 2019
1
AWS Temporary Credentials
Challenges in prevention, detection, mitigation
@jenkohwong
• netskope threat research team
• windows security, vulnerability scanning,
routers/appliances, av/as, threat intel,
exploits/pen-testing
• product / engineering
• science in space (ISS)
2
Agenda
• Attack Scenario: Temporary Tokens
• Defender Viewpoint: Challenges
• Dos & Don’ts
• Generalized Approach to the Problem
3
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate privileges
with compromised
access key A
or temp token B
§ AssumeRole
§ new temp token
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Attack Scenario: S3 (authenticated)
AWS Cloud
compromised
access key A
Attacker
1
Compromised Credentials
AWS Cloud
compromised
access key A
Attacker
1
Compromised Credentials
AWS Cloud
compromised
access key A
Attacker
1
Compromised Credentials
AWS Cloud
compromised
access key A
Attacker
1
generate
temp token B
temp token B AWS STS
2
Generate Temp Credentials
AWS Cloud
compromised
access key A
Attacker
1
generate
temp token B
temp token B AWS STS
2
Generate Temp Credentials
Discovery
Discovery
Account
of the stolen
access key
User
who owns
the key
Groups
of the user
other Users
aws sts get-access-key-info --access-key-id <any key>
(works for perm keys, temp keys, in and outside of your account)
https://docs.aws.amazon.com/IAM/latest/UserGuide/document-history.html
Discovery
Attached Policy
of the user
can Assume Role
JenkoBucketRole
Discovery and JenkoBucketRole
has a policy
that can perform
any action on
jenko-bucket6
Discovery
can
AssumeRole
belongs
to
compromised
access key A
jenko-bucket6
jenko_temp_user JenkoBucketRole
can do
Action: “s3:*”
on
Discovery
can
AssumeRole
belongs
to
compromised
access key A
jenko-bucket6
jenko_temp_user JenkoBucketRole
can do
Action: “s3:*”
on?
Discovery
can
AssumeRole
belongs
to
compromised
access key A
jenko-bucket6
jenko_temp_user JenkoBucketRole
can do
Action: “s3:*”
on?
AWS Cloud
access key A
jenko-bucket6
AssumeRole
JenkoBucketRole
Privilege Escalation Details
AWS STS
temp token B
temp token A’
temp token B’Attacker
temp token A’
temp token B’
can
AssumeRole
belongs
to
compromised
access key A
jenko-bucket6
jenko_temp_user JenkoBucketRole
can do
Action: “s3:*”
on
AWS Cloud
access key A
jenko-bucket6
AssumeRole
JenkoBucketRole
Privilege Escalation Details
AWS STS
temp token B
temp token A’
temp token B’Attacker
temp token A’
temp token B’
AWS Cloud
compromised
access key A
Attacker
1
generate
temp token B
temp token B AWS STS
2
escalate
privileges with
compromised
access key A
or temp token B
3
Data Exfiltration
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Data Exfiltration
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Data Exfiltration
Defender Viewpoint
22
Defender Viewpoint
• Assumptions
• AWS experience
• CloudTrail/CloudWatch
• Less knowledge of temp credentials
• Starting Point
• External party re: leaked data
• Events/Alarms
23
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Defender Viewpoint: Challenges
Detect:
1.CloudTrail/Watch
detects Data Exfil
(action/destination)
2. Privilege Escalation?
3. Correlation / Anomaly
detection?
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Defender Viewpoint: Challenges
Investigate:
1. Logs: access key A
AssumeRole
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Defender Viewpoint: Challenges
Investigate:
1. Logs: access key A
AssumeRole
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Defender Viewpoint: Challenges
Investigate:
1. Logs: access key A
AssumeRole
2. JenkoBucketRole valid,
not overprivileged,
assigned to correct
users
3. user interview =>
compromised key
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Defender Viewpoint: Challenges
Mitigate/Remediate:
1. Delete access key A
2. Key rotation
3. Change Console
password
4. User training
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate
privileges with
compromised
access key A
or temp token B
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Defender Viewpoint: Challenges
Mitigate/Remediate:
1. Delete access key A
2. Key rotation
3. Change Console
password
4. User training
Defender Viewpoint: Challenges
• GetSessionToken and the returned
temp token B are troubling
• We're seeing STS and temp tokens
• A temp token is returned similar to
AssumeRole
• Reading up...we see we have
another set of access keys floating
around
30
STS Temp Tokens
• Expiration/Timing:
• 15 minutes to 36 hours
• +CloudTrail event latency (from API call to logging on S3) of at least 20 minutes
• Temporary tokens generated by AWS (e.g. passing roles to services like EC2) usually have
shorter time frames (1 hour). But automatically refreshed, so an attacker who’s gained control
of an EC2 instance only needs to refresh their tokens every hour.
• API Access
• Can use any service that the original user has privileges for, except…
• Sessions using temporary tokens cannot create more temporary tokens
• Within STS, can only invoke AssumeRole
• Many techniques for Privilege escalation (AssumeRole), not a barrier (follow rhino)
31
STS Temp Tokens
Unmanaged
• Untracked, no way to list current active ones or historically generated
• Not in Console, no CLI/API command to ListGeneratedTokens
• This does not exist for temporary tokens:
32
Logging
• Creation/usage are logged but you would have to parse and persist from CloudTrail
Defensive Viewpoint: Temp Tokens
33
Detect
Update CloudWatch/SIEM
filters to detect
• Creation:
GetSessionToken
AssumeRole actions
• Usage: accessKeyId =~
ASIA*[1]
[1]https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_access-keys-audit
AWS Cloud
Attacker
generate
temp token B
temp token B AWS STS
sessions
temp token B’ S3 Bucket
1
2
4
Defender Viewpoint: Temp Tokens
Mitigate/Remediate:
1. Can’t delete temp
token
2. a) Restrict Role[1]
b) Delete User[2]
3. Update Remediation
Playbook
4. Revoke Active Session
for Role[3]
AssumeRole
JenkoBucketRole
temp token B’
1
belongs
to
all keys/tokens jenko_temp_user
2
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_access-keys-audit
[2] https://aws.amazon.com/premiumsupport/knowledge-center/potential-account-compromise/
[3] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_access-keys-audit
[2] https://aws.amazon.com/premiumsupport/knowledge-center/potential-account-compromise/
[3] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
AWS Cloud
Attacker
generate
temp token B
temp token B AWS STS
sessions
temp token B’ S3 Bucket
1
2
4
Defender Viewpoint: Temp Tokens
Mitigate/Remediate:
1. Can’t delete temp
token
2. a) Restrict Role
b) Delete User
3. Update Remediation
Playbook
4. Revoke Active Session
for Role
AssumeRole
JenkoBucketRole
temp token B’
1
belongs
to
all keys/tokens jenko_temp_user
2
AWS Cloud
Attacker
generate
temp token B
temp token B AWS STS
sessions
temp token B’ S3 Bucket
1
Defender Viewpoint: Temp Tokens
Prevention:
GetSessionToken
1. Can’t prevent[1]
AssumeRole
JenkoBucketRole
temp token B’
generated
from
all keys/tokens jenko_temp_user[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html
Prevention:
GetSessionToken
1. Can’t prevent[1]
AWS Cloud
Attacker
generate
temp token B
temp token B AWS STS
sessions
temp token B’ S3 Bucket
1
AssumeRole
JenkoBucketRole
temp token B’
generated
from
all keys/tokens jenko_temp_user
Defender Viewpoint: Temp Tokens
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html
AWS Cloud
Attacker
generate
temp token B
temp token B AWS STS
sessions
temp token B’ S3 Bucket
1
Prevention:
GetSessionToken
1. Can’t prevent[1]
2. Can’t MFA-protect
3. Can’t use IAM
permissions boundaries
AssumeRole
JenkoBucketRole
temp token B’
2
3
generated
from
all keys/tokens jenko_temp_user
max perms
Defender Viewpoint: Temp Tokens
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html
[2] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
AWS Cloud
Attacker
generate
temp token B
temp token B AWS STS
sessions
temp token B’ S3 Bucket
1
4
Prevention:
GetSessionToken
1. Can’t prevent[1]
2. Can’t MFA-protect
3. Can’t use IAM
permissions boundaries
AssumeRole
4. Can restrict
5. Can Revoke active
sessions for Role[2]
AssumeRole
JenkoBucketRole
temp token B’
2
5
3
generated
from
all keys/tokens jenko_temp_user
max perms
Defender Viewpoint: Temp Tokens
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html
[2] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
RED
- Generate temp credentials for backdoor access
- Combine temp credentials with presigned-urls, lambdas, log attacks
- Consider lambdas as a means to persist temp credentials
- Assess whether logging/alerting for temp credentials is being done
40
BLUE
• Plan ASAP
• manage temp token usage especially remediation/recovery
• Prevention
• lockdown access keys (aws:sourceIp/aws:sourceVpc[1]/MFA)
• isolate temp token usage in separate accounts
• service-only IAMUsers in separate accounts
• minimal privileges for AssumeRole and PassRole
• Detection
• alert on GetSessionToken
• alert on temp tokens (ASIA*)
• harden CloudTrail/CloudWatch/SIEM
• AWS Config (IAM,Lambda)
41
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html
BLUE
• Mitigation/Remediation
• review/revise remediation playbook
• do not use GetSessionToken, use AssumeRole
• maybe don’t use temp tokens at all…permanent access keys
• use revoke active sessions for role(aws:TokenIssueTime[1])
• create/test a recovery plan from compromised temp tokens
• AWS Config (IAM,Lambda)
• Provisioning/Inventory
• track temp tokens that are created in a datastore
• use wrapper code for custom apps that need temp tokens
• for AWS-generated tokens (IoT, AssumeRole) have to parse logs
42
[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html
AWS Cloud
compromised
access key A
Attacker
generate
temp token B
temp token B AWS STS
escalate privileges
with compromised
access key A
or temp token B
§ AssumeRole
§ new temp token
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Never…we have #1 and #3 locked down…
44
Services that
work with Temp
Credentials
(AssumeRole)
45
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
46
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
Services that
work with Temp
Credentials
(AssumeRole)
47
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
Services that
work with Temp
Credentials
(AssumeRole)
48
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
Services that
work with Temp
Credentials
(AssumeRole)
49
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
Services that
work with Temp
Credentials
(AssumeRole)
50
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
Services that
work with Temp
Credentials
(AssumeRole)
51
https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
AWS Cloud
AssumeRole
AWS STS
temp token
Attacker
X.509
certificate
GET
curl --cert cert.pem --key
private.key -H "x-amzn-iot-
thingname: vacuum-iot-thing" --
cacert AmazonRootCA1.pem
https://d6juort4q58376.credentia
ls.iot.us-east-
2.amazonaws.com/role-
aliases/IoTRoleAlias/credentials
Services that
work with Temp
Credentials
(AssumeRole)
AWS Cloud
compromised
access key A
Attacker
AWS STS
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Attack Scenario: EC2 (authenticated)
EC2
escalate privileges
with compromised
access key A
§ PassRole
§ RunInstance
§ metadata svc
§ temp token
AWS Cloud
compromised
access key A
Attacker
AWS STS
S3 Bucket
access S3
Bucket
data
exfiltration
3
1
2
4
5
Attack Scenario: EC2 (authenticated)
EC2
escalate privileges
with compromised
access key A
§ PassRole
§ RunInstance
§ metadata svc
§ temp token
Metadata Service:
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role>
{ "Code" : "Success",
"LastUpdated" : "2012-04-26T16:39:16Z",
…
"Expiration" : "2017-05-17T15:09:54Z" },
"AccessKeyId" : "ASIAIOSFODNN7EXAMPLE",
"SecretAccessKey" : "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
AWS Cloud
AWS STS
S3 Bucket
access S3
Bucket
data
exfiltration
1
2
3
4
Attack Scenario: EC2 (network)
EC2
Network service
exploit EC2
§ metadata svc
§ temp token
Attacker
Metadata Service:
curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role>
{ "Code" : "Success",
"LastUpdated" : "2012-04-26T16:39:16Z",
…
"Expiration" : "2017-05-17T15:09:54Z" },
"AccessKeyId" : "ASIAIOSFODNN7EXAMPLE",
"SecretAccessKey" : "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
Mitigation
Active Defense - Dynamically Locking AWS Credentials to Your Environment
55Netflix: https://medium.com/swlh/active-defense-dynamically-locking-aws-credentials-to-your-environment-47a9c920e704
What’s the big deal?
• Doesn’t this boil down to:
• “Don’t be stupid about security and don’t allow GetSessionToken.”
• Temporary access keys ~ Permanent keys
• Except
• AssumeRole is ubiquitous and EC2 Privilege attacks leverage this
• Any ”user” can create temporary access keys (GetSessionToken) and you can’t stop it
• what if sudo returned a temporary username/password?
• Surface Area
• Blue techniques for prevention, detection, mitigation/remediation,
provisioning/inventory of temp keys are different enough that you need to
review => complicated, different, distracting, and bad.
• Red techniques using temp keys can make prevention, detection,
mitigation/remediation, provisioning/inventory more complicated, confusing
at the minimum => different, distracting, and an opportunity.
56
Generalized Approach
57
ATTACKER
Tactics
[1]
Initial
Access
Execution Persistence Privilege
Escalation
Defense
Evasion
Credential
Access
Discovery Lateral
Movement
Collection C2 Exfiltration Impact
Techniques Stolen
Credentials in
Cloud (e.g.
github,
Pastebin)
GetSession
Token
AssumeRole
<elevated
role>
Use Temp
Tokens
Copy
temporary
credentials
from Privilege
Escalation
<many> AssumeRole
<any role>
Bucket
Object Copy
/ Replication
Destroy
Buckets
or Objects
DEFENDER
Prevent • IP/VPC
whitelist
• MFA
n/a IP/VPC
whitelist role
policy
conditions
• IP/VPC
whitelist role
policy
conditions
• metadata
proxy with
secret
header
MFA MFA
Detect Filter on
failed auth
Filter on
GetSession
Token
Anomaly
Detection /
UBA?
Filter on
“ASIA*”
and
GetToken
• Filter on
API calls
• Correlate
• UBA
Anomaly
Detection /
UBA?
Anomaly
Detection /
UBA?
Mitigate /
Remediate
Delete and
recreate user
using CFT
Delete and
recreate
user using
CFT
Revoke Role
Sessions
Conditions
Revoke Role
Sessions
Conditions
[1] Mitre Att&ck: https://attack.mitre.org
Thank you
Slides:
https://drive.google.com/file/d/1E7-
WV9wLEZ8IGRZGhE6BAyrUCcbR
9yd4/view?usp=sharing
58
jhwong@netskope.com
@jenkohwong

AWS temporary credentials challenges in prevention detection mitigation

  • 1.
    1 jhwong@netskope.com @jenkohwong September 13, 2019 1 AWSTemporary Credentials Challenges in prevention, detection, mitigation
  • 2.
    @jenkohwong • netskope threatresearch team • windows security, vulnerability scanning, routers/appliances, av/as, threat intel, exploits/pen-testing • product / engineering • science in space (ISS) 2
  • 3.
    Agenda • Attack Scenario:Temporary Tokens • Defender Viewpoint: Challenges • Dos & Don’ts • Generalized Approach to the Problem 3
  • 4.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B § AssumeRole § new temp token S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Attack Scenario: S3 (authenticated)
  • 5.
    AWS Cloud compromised access keyA Attacker 1 Compromised Credentials
  • 6.
    AWS Cloud compromised access keyA Attacker 1 Compromised Credentials
  • 7.
    AWS Cloud compromised access keyA Attacker 1 Compromised Credentials
  • 8.
    AWS Cloud compromised access keyA Attacker 1 generate temp token B temp token B AWS STS 2 Generate Temp Credentials
  • 9.
    AWS Cloud compromised access keyA Attacker 1 generate temp token B temp token B AWS STS 2 Generate Temp Credentials
  • 10.
  • 11.
    Discovery Account of the stolen accesskey User who owns the key Groups of the user other Users aws sts get-access-key-info --access-key-id <any key> (works for perm keys, temp keys, in and outside of your account) https://docs.aws.amazon.com/IAM/latest/UserGuide/document-history.html
  • 12.
    Discovery Attached Policy of theuser can Assume Role JenkoBucketRole
  • 13.
    Discovery and JenkoBucketRole hasa policy that can perform any action on jenko-bucket6
  • 14.
  • 15.
  • 16.
  • 17.
    AWS Cloud access keyA jenko-bucket6 AssumeRole JenkoBucketRole Privilege Escalation Details AWS STS temp token B temp token A’ temp token B’Attacker temp token A’ temp token B’ can AssumeRole belongs to compromised access key A jenko-bucket6 jenko_temp_user JenkoBucketRole can do Action: “s3:*” on
  • 18.
    AWS Cloud access keyA jenko-bucket6 AssumeRole JenkoBucketRole Privilege Escalation Details AWS STS temp token B temp token A’ temp token B’Attacker temp token A’ temp token B’
  • 19.
    AWS Cloud compromised access keyA Attacker 1 generate temp token B temp token B AWS STS 2 escalate privileges with compromised access key A or temp token B 3 Data Exfiltration
  • 20.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Data Exfiltration
  • 21.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Data Exfiltration
  • 22.
  • 23.
    Defender Viewpoint • Assumptions •AWS experience • CloudTrail/CloudWatch • Less knowledge of temp credentials • Starting Point • External party re: leaked data • Events/Alarms 23
  • 24.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Defender Viewpoint: Challenges Detect: 1.CloudTrail/Watch detects Data Exfil (action/destination) 2. Privilege Escalation? 3. Correlation / Anomaly detection?
  • 25.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Defender Viewpoint: Challenges Investigate: 1. Logs: access key A AssumeRole
  • 26.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Defender Viewpoint: Challenges Investigate: 1. Logs: access key A AssumeRole
  • 27.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Defender Viewpoint: Challenges Investigate: 1. Logs: access key A AssumeRole 2. JenkoBucketRole valid, not overprivileged, assigned to correct users 3. user interview => compromised key
  • 28.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Defender Viewpoint: Challenges Mitigate/Remediate: 1. Delete access key A 2. Key rotation 3. Change Console password 4. User training
  • 29.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Defender Viewpoint: Challenges Mitigate/Remediate: 1. Delete access key A 2. Key rotation 3. Change Console password 4. User training
  • 30.
    Defender Viewpoint: Challenges •GetSessionToken and the returned temp token B are troubling • We're seeing STS and temp tokens • A temp token is returned similar to AssumeRole • Reading up...we see we have another set of access keys floating around 30
  • 31.
    STS Temp Tokens •Expiration/Timing: • 15 minutes to 36 hours • +CloudTrail event latency (from API call to logging on S3) of at least 20 minutes • Temporary tokens generated by AWS (e.g. passing roles to services like EC2) usually have shorter time frames (1 hour). But automatically refreshed, so an attacker who’s gained control of an EC2 instance only needs to refresh their tokens every hour. • API Access • Can use any service that the original user has privileges for, except… • Sessions using temporary tokens cannot create more temporary tokens • Within STS, can only invoke AssumeRole • Many techniques for Privilege escalation (AssumeRole), not a barrier (follow rhino) 31
  • 32.
    STS Temp Tokens Unmanaged •Untracked, no way to list current active ones or historically generated • Not in Console, no CLI/API command to ListGeneratedTokens • This does not exist for temporary tokens: 32 Logging • Creation/usage are logged but you would have to parse and persist from CloudTrail
  • 33.
    Defensive Viewpoint: TempTokens 33 Detect Update CloudWatch/SIEM filters to detect • Creation: GetSessionToken AssumeRole actions • Usage: accessKeyId =~ ASIA*[1] [1]https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_access-keys-audit
  • 34.
    AWS Cloud Attacker generate temp tokenB temp token B AWS STS sessions temp token B’ S3 Bucket 1 2 4 Defender Viewpoint: Temp Tokens Mitigate/Remediate: 1. Can’t delete temp token 2. a) Restrict Role[1] b) Delete User[2] 3. Update Remediation Playbook 4. Revoke Active Session for Role[3] AssumeRole JenkoBucketRole temp token B’ 1 belongs to all keys/tokens jenko_temp_user 2 [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_access-keys-audit [2] https://aws.amazon.com/premiumsupport/knowledge-center/potential-account-compromise/ [3] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
  • 35.
    [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_access-keys.html#Using_access-keys-audit [2] https://aws.amazon.com/premiumsupport/knowledge-center/potential-account-compromise/ [3]https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html AWS Cloud Attacker generate temp token B temp token B AWS STS sessions temp token B’ S3 Bucket 1 2 4 Defender Viewpoint: Temp Tokens Mitigate/Remediate: 1. Can’t delete temp token 2. a) Restrict Role b) Delete User 3. Update Remediation Playbook 4. Revoke Active Session for Role AssumeRole JenkoBucketRole temp token B’ 1 belongs to all keys/tokens jenko_temp_user 2
  • 36.
    AWS Cloud Attacker generate temp tokenB temp token B AWS STS sessions temp token B’ S3 Bucket 1 Defender Viewpoint: Temp Tokens Prevention: GetSessionToken 1. Can’t prevent[1] AssumeRole JenkoBucketRole temp token B’ generated from all keys/tokens jenko_temp_user[1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html
  • 37.
    Prevention: GetSessionToken 1. Can’t prevent[1] AWSCloud Attacker generate temp token B temp token B AWS STS sessions temp token B’ S3 Bucket 1 AssumeRole JenkoBucketRole temp token B’ generated from all keys/tokens jenko_temp_user Defender Viewpoint: Temp Tokens [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html
  • 38.
    AWS Cloud Attacker generate temp tokenB temp token B AWS STS sessions temp token B’ S3 Bucket 1 Prevention: GetSessionToken 1. Can’t prevent[1] 2. Can’t MFA-protect 3. Can’t use IAM permissions boundaries AssumeRole JenkoBucketRole temp token B’ 2 3 generated from all keys/tokens jenko_temp_user max perms Defender Viewpoint: Temp Tokens [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html [2] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
  • 39.
    AWS Cloud Attacker generate temp tokenB temp token B AWS STS sessions temp token B’ S3 Bucket 1 4 Prevention: GetSessionToken 1. Can’t prevent[1] 2. Can’t MFA-protect 3. Can’t use IAM permissions boundaries AssumeRole 4. Can restrict 5. Can Revoke active sessions for Role[2] AssumeRole JenkoBucketRole temp token B’ 2 5 3 generated from all keys/tokens jenko_temp_user max perms Defender Viewpoint: Temp Tokens [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_credentials_temp_control-access_enable-create.html [2] https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_use_revoke-sessions.html
  • 40.
    RED - Generate tempcredentials for backdoor access - Combine temp credentials with presigned-urls, lambdas, log attacks - Consider lambdas as a means to persist temp credentials - Assess whether logging/alerting for temp credentials is being done 40
  • 41.
    BLUE • Plan ASAP •manage temp token usage especially remediation/recovery • Prevention • lockdown access keys (aws:sourceIp/aws:sourceVpc[1]/MFA) • isolate temp token usage in separate accounts • service-only IAMUsers in separate accounts • minimal privileges for AssumeRole and PassRole • Detection • alert on GetSessionToken • alert on temp tokens (ASIA*) • harden CloudTrail/CloudWatch/SIEM • AWS Config (IAM,Lambda) 41 [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html
  • 42.
    BLUE • Mitigation/Remediation • review/reviseremediation playbook • do not use GetSessionToken, use AssumeRole • maybe don’t use temp tokens at all…permanent access keys • use revoke active sessions for role(aws:TokenIssueTime[1]) • create/test a recovery plan from compromised temp tokens • AWS Config (IAM,Lambda) • Provisioning/Inventory • track temp tokens that are created in a datastore • use wrapper code for custom apps that need temp tokens • for AWS-generated tokens (IoT, AssumeRole) have to parse logs 42 [1] https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_condition-keys.html
  • 43.
    AWS Cloud compromised access keyA Attacker generate temp token B temp token B AWS STS escalate privileges with compromised access key A or temp token B § AssumeRole § new temp token S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Never…we have #1 and #3 locked down…
  • 44.
  • 45.
    Services that work withTemp Credentials (AssumeRole) 45 https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html
  • 46.
  • 47.
  • 48.
  • 49.
  • 50.
  • 51.
    51 https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_aws-services-that-work-with-iam.html AWS Cloud AssumeRole AWS STS temptoken Attacker X.509 certificate GET curl --cert cert.pem --key private.key -H "x-amzn-iot- thingname: vacuum-iot-thing" -- cacert AmazonRootCA1.pem https://d6juort4q58376.credentia ls.iot.us-east- 2.amazonaws.com/role- aliases/IoTRoleAlias/credentials Services that work with Temp Credentials (AssumeRole)
  • 52.
    AWS Cloud compromised access keyA Attacker AWS STS S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Attack Scenario: EC2 (authenticated) EC2 escalate privileges with compromised access key A § PassRole § RunInstance § metadata svc § temp token
  • 53.
    AWS Cloud compromised access keyA Attacker AWS STS S3 Bucket access S3 Bucket data exfiltration 3 1 2 4 5 Attack Scenario: EC2 (authenticated) EC2 escalate privileges with compromised access key A § PassRole § RunInstance § metadata svc § temp token Metadata Service: curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role> { "Code" : "Success", "LastUpdated" : "2012-04-26T16:39:16Z", … "Expiration" : "2017-05-17T15:09:54Z" }, "AccessKeyId" : "ASIAIOSFODNN7EXAMPLE", "SecretAccessKey" : "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
  • 54.
    AWS Cloud AWS STS S3Bucket access S3 Bucket data exfiltration 1 2 3 4 Attack Scenario: EC2 (network) EC2 Network service exploit EC2 § metadata svc § temp token Attacker Metadata Service: curl http://169.254.169.254/latest/meta-data/iam/security-credentials/<role> { "Code" : "Success", "LastUpdated" : "2012-04-26T16:39:16Z", … "Expiration" : "2017-05-17T15:09:54Z" }, "AccessKeyId" : "ASIAIOSFODNN7EXAMPLE", "SecretAccessKey" : "wJalrXUtnFEMI/K7MDENG/bPxRfiCYEXAMPLEKEY"
  • 55.
    Mitigation Active Defense -Dynamically Locking AWS Credentials to Your Environment 55Netflix: https://medium.com/swlh/active-defense-dynamically-locking-aws-credentials-to-your-environment-47a9c920e704
  • 56.
    What’s the bigdeal? • Doesn’t this boil down to: • “Don’t be stupid about security and don’t allow GetSessionToken.” • Temporary access keys ~ Permanent keys • Except • AssumeRole is ubiquitous and EC2 Privilege attacks leverage this • Any ”user” can create temporary access keys (GetSessionToken) and you can’t stop it • what if sudo returned a temporary username/password? • Surface Area • Blue techniques for prevention, detection, mitigation/remediation, provisioning/inventory of temp keys are different enough that you need to review => complicated, different, distracting, and bad. • Red techniques using temp keys can make prevention, detection, mitigation/remediation, provisioning/inventory more complicated, confusing at the minimum => different, distracting, and an opportunity. 56
  • 57.
    Generalized Approach 57 ATTACKER Tactics [1] Initial Access Execution PersistencePrivilege Escalation Defense Evasion Credential Access Discovery Lateral Movement Collection C2 Exfiltration Impact Techniques Stolen Credentials in Cloud (e.g. github, Pastebin) GetSession Token AssumeRole <elevated role> Use Temp Tokens Copy temporary credentials from Privilege Escalation <many> AssumeRole <any role> Bucket Object Copy / Replication Destroy Buckets or Objects DEFENDER Prevent • IP/VPC whitelist • MFA n/a IP/VPC whitelist role policy conditions • IP/VPC whitelist role policy conditions • metadata proxy with secret header MFA MFA Detect Filter on failed auth Filter on GetSession Token Anomaly Detection / UBA? Filter on “ASIA*” and GetToken • Filter on API calls • Correlate • UBA Anomaly Detection / UBA? Anomaly Detection / UBA? Mitigate / Remediate Delete and recreate user using CFT Delete and recreate user using CFT Revoke Role Sessions Conditions Revoke Role Sessions Conditions [1] Mitre Att&ck: https://attack.mitre.org
  • 58.