SlideShare a Scribd company logo
1 of 31
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS re:INVENT
Using AWS CloudTrail Logs for Scalable,
Automated Anomaly Detection
J e f f P u c h a l s k i , A W S S e c u r i t y
N o v e m b e r 2 9 , 2 0 1 7
S I D 3 4 1
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
What we will cover
Logging with AWS CloudTrail
• Hands-on exercise: examining CloudTrail logs
Using AWS Lambda for CloudTrail log analysis
• Hands-on exercise: automating detection
Simplifying detection with AWS security services
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS CloudTrail
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Intro to AWS CloudTrail
AWS CloudTrail logs activity for supported services to an AWS account
Example API events that are logged:
• iam:CreateUser
• s3:ListBucket
CloudTrail is enabled by default on all AWS accounts (as of August 2017)
• Event history of create, modify, and delete operations for last seven days
• Viewable, searchable, and downloadable
To access CloudTrail log files directly or for a longer time period, create a trail
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Trails in AWS CloudTrail
Log activity for a single AWS account for a single region or all regions
Logs are generally delivered to files in a user-defined Amazon S3 bucket
• Can also be delivered to CloudWatch Logs or CloudWatch Events
Log files are published approximately every 5 minutes
Log files can stay in the S3 bucket for as long as you like
• Indefinitely by default
• Can use S3 bucket lifecycle policies to configure retention
Optional logging of data-level events for Amazon S3 objects
• Events such as s3:GetObject or s3:PutObject
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS CloudTrail log files
Gzipped JSON files created in the Amazon S3 bucket containing records for one or more API events
Each CloudTrail log file covers an approximately five-minute time window
Log files are encrypted by default
• Default is server-side encryption with Amazon S3-managed encryption keys (SSE-S3)
• Can configure encryption using AWS Key Management Service (AWS KMS)-managed keys (SSE-KMS)
Optional log file integrity validation using signed digest file containing log-file hashes
• Digest file contains hashes for previous one hour’s worth of log files
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS CloudTrail events
Each record in a CloudTrail log file represents a single event
All records contain some common fields:
• Time stamp
• Region
• Event name (i.e., the API call)
• Event source (i.e., the service)
• Source IP address
• User identity
Event-specific request and response parameters may also be included for some events
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": "192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": "192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": ”192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": "192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": "192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": "192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
{"Records": [{
"eventVersion": "1.0",
"userIdentity": {
"type": "IAMUser",
"principalId": "EX_PRINCIPAL_ID",
"arn": "arn:aws:iam::123456789012:user/Alice",
"accountId": "123456789012",
"accessKeyId": "EXAMPLE_KEY_ID",
"userName": "Alice”
},
"eventTime": "2017-11-29T11:29:42Z",
"eventSource": "iam.amazonaws.com",
"eventName": "CreateUser",
"awsRegion": "us-east-1",
"sourceIPAddress": ”192.168.0.1",
"userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7",
"requestParameters": {"userName": "Bob”},
"responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob",
"arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"}
}
}]}
What do CloudTrail logs look like?
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Examining CloudTrail logs
H a n d s - o n e x e r c i s e
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on: Examining CloudTrail logs
In this exercise, you will be using the CloudTrail Event history viewer in the AWS console to view
CloudTrail logs for your account
The goal of this exercise is to gain familiarity with, and understanding of, how to examine CloudTrail log
event records
The README file in the code repository contains detailed information on this exercise, including
guidance on things to pay attention to and look for in the records
Code repository URL: amzn.to/sid341repo
Please ask questions! We are here to help 
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Examining CloudTrail logs
E x e r c i s e d e b r i e f
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda for detection
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using AWS Lambda for detection
AWS Lambda enables serverless compute
• Run code in Lambda functions without needing to provision an instance
AWS Lambda scales automatically because it is event-driven
• Invocations run in response to event triggers
• Example:
For our use case, the Lambda function can receive notifications directly from the S3 bucket when new
CloudTrail log files are created!
 Enables automated stream-based processing and analysis
SNS notification
SNS AWS Lambda
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
# Assumes event uses the following JSON format:
# {
# “first_name”: “Inigo”,
# “last_name”: ”Montoya”
# }
def handler(event, context):
message = ’Hello from re:Invent 2017, {} {}!'.format(event['first_name'], event['last_name'])
return { 'message' : message }
Hello world handler in Python
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
import boto3
import gzip
import io
import json
def handler(event, context):
s3 = boto3.client(’s3’)
for event_record in event['Records']: # this event is an s3:ObjectCreated:Put notification
bucket = event_record['s3']['bucket']['name'] # extract the bucket name...
key = event_record['s3']['object']['key’] # ...and key name
response = s3.get_object(Bucket=bucket, Key=key) # fetch the log file from S3
with io.BytesIO(response[‘Body’].read()) as obj: # bytes of gzipped file
with gzip.GzipFile(fileobj=obj) as logfile : # unzip the file
cloudtrail_log = json.load(logfile) # load the CloudTrail log JSON
for record in cloudtrail_log[‘Records’]: # iterate over the CloudTrail records
print(record) # do stuff with each record :)
CloudTrail ingest handler in Python
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Automated detection
H a n d s - o n e x e r c i s e
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on exercise preparations
In this workshop we will be doing some hands-on exercises that use AWS CloudTrail logs
A provided AWS CloudFormation template will create 2 stacks of resources for the following purposes:
• Analysis of CloudTrail logs using an AWS Lambda function
• Activity generation to produce CloudTrail logs for analysis
The events take a bit of time to be created and show up in CloudTrail (~5 mins)
Therefore, we will run the CloudFormation template now so the logs will be ready later 
Please browse to the following URI for CloudFormation stack creation:
amzn.to/sid341cfn
Code repository URL: amzn.to/sid341repo
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on: Automated detection
You have been asked by your security operations team to create an automated solution to analyze
CloudTrail logs in an AWS account where some evil shenanigans may be occurring
Your mission, should you choose to accept it, is to build a simple detection engine to automatically
ingest and analyze CloudTrail logs for indicators of suspicious activity
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Hands-on: Automated detection
We will use an AWS Lambda function and a CloudWatch alarm to accomplish this. You will add code
to the Lambda function to check for, and alarm on, a few specific types of potentially suspicious activity.
The Lambda function already fetches and loads the CloudTrail log files, and passes each record
to analysis functions that you will be filling in
The README file in the code repository contains detailed information on this exercise:
amzn.to/sid341repo
We are here to help, so please ask questions. Good luck!
High-level architecture:
Lambda
Function
CloudWatch
Alarm
CloudTrail
Trail
S3
Bucket
CloudTrail
log file
(gzipped JSON)
S3 “Put” event
notification
(bucket and key)
Metric data to
trigger an alarm
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Automated detection
E x e r c i s e d e b r i e f
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
AWS Security Services:
Amazon Macie and GuardDuty
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Amazon Macie is a security service that uses machine learning (ML)
Automatically discovers, classifies, and protects sensitive data in AWS
• Amazon S3 today
• More AWS data stores soon!
Continuously monitors data-access activity for anomalies
Generates alerts when risk is detected
• Alerts can be sent to Amazon CloudWatch Events
Using Amazon Macie for detection
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Using Amazon GuardDuty for detection
Amazon GuardDuty is a continuous security monitoring service
Analyzes and processes the following data sources:
• AWS CloudTrail logs
• Amazon Virtual Private Cloud (Amazon VPC) flow logs
Identifies unexpected and suspicious activity
• Escalations of privileges
• Uses of exposed credentials
• Communication with malicious IPs
Produces findings that can be viewed in the GuardDuty console
• Alerts can be sent to Amazon CloudWatch Events
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Recap
Logging with AWS CloudTrail
• Hands-on exercise: examining CloudTrail logs
Using AWS Lambda for CloudTrail log analysis
• Hands-on exercise: automating detection
Simplifying detection with AWS security services
© 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved.
Thank you!
Y o u r f e e d b a c k o n t h i s w o r k s h o p
i s v e r y m u c h a p p r e c i a t e d !
S I D 3 4 1

More Related Content

What's hot

What's hot (20)

Introduction to Threat Detection and Remediation on AWS
Introduction to Threat Detection and Remediation on AWSIntroduction to Threat Detection and Remediation on AWS
Introduction to Threat Detection and Remediation on AWS
 
WIN403_AWS Directory Service for Microsoft Active Directory Deep Dive
WIN403_AWS Directory Service for Microsoft Active Directory Deep DiveWIN403_AWS Directory Service for Microsoft Active Directory Deep Dive
WIN403_AWS Directory Service for Microsoft Active Directory Deep Dive
 
AWS CloudWatch
AWS CloudWatchAWS CloudWatch
AWS CloudWatch
 
Introducing AWS DataSync - Simplify, automate, and accelerate online data tra...
Introducing AWS DataSync - Simplify, automate, and accelerate online data tra...Introducing AWS DataSync - Simplify, automate, and accelerate online data tra...
Introducing AWS DataSync - Simplify, automate, and accelerate online data tra...
 
Deep dive into AWS IAM
Deep dive into AWS IAMDeep dive into AWS IAM
Deep dive into AWS IAM
 
AWS Cloud Watch
AWS Cloud WatchAWS Cloud Watch
AWS Cloud Watch
 
AWS Route53 Fundamentals
AWS Route53 FundamentalsAWS Route53 Fundamentals
AWS Route53 Fundamentals
 
Introduction to AWS Organizations
Introduction to AWS OrganizationsIntroduction to AWS Organizations
Introduction to AWS Organizations
 
AWS Security Best Practices
AWS Security Best PracticesAWS Security Best Practices
AWS Security Best Practices
 
AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018
AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018
AWS Landing Zone Deep Dive (ENT350-R2) - AWS re:Invent 2018
 
AWS Security Hub
AWS Security HubAWS Security Hub
AWS Security Hub
 
AWS Security Week: Security, Identity, & Compliance
AWS Security Week: Security, Identity, & ComplianceAWS Security Week: Security, Identity, & Compliance
AWS Security Week: Security, Identity, & Compliance
 
AWS AutoScaling
AWS AutoScalingAWS AutoScaling
AWS AutoScaling
 
Getting Started with Amazon Inspector
Getting Started with Amazon InspectorGetting Started with Amazon Inspector
Getting Started with Amazon Inspector
 
Deep dive ECS & Fargate Deep Dive
Deep dive ECS & Fargate Deep DiveDeep dive ECS & Fargate Deep Dive
Deep dive ECS & Fargate Deep Dive
 
AWS Storage - S3 Fundamentals
AWS Storage - S3 FundamentalsAWS Storage - S3 Fundamentals
AWS Storage - S3 Fundamentals
 
AWS Elastic Load Balancing for AWS Architect & SysOps Certification
AWS Elastic Load Balancing for AWS Architect & SysOps CertificationAWS Elastic Load Balancing for AWS Architect & SysOps Certification
AWS Elastic Load Balancing for AWS Architect & SysOps Certification
 
Security Architectures on AWS
Security Architectures on AWSSecurity Architectures on AWS
Security Architectures on AWS
 
AWS Route53
AWS Route53AWS Route53
AWS Route53
 
AWS Security Hub
AWS Security HubAWS Security Hub
AWS Security Hub
 

Similar to Using AWS CloudTrail Logs for Scalable, Automated Anomaly Detection - SID341 - re:Invent 2017

Serverless architecture-patterns-and-best-practices
Serverless architecture-patterns-and-best-practicesServerless architecture-patterns-and-best-practices
Serverless architecture-patterns-and-best-practices
saifam
 

Similar to Using AWS CloudTrail Logs for Scalable, Automated Anomaly Detection - SID341 - re:Invent 2017 (20)

Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
Using ML with Amazon SageMaker & GuardDuty to identify anomalous traffic - SE...
 
Cloud Adoption Framework: Security Persepctive - Incident Response: Preparing...
Cloud Adoption Framework: Security Persepctive - Incident Response: Preparing...Cloud Adoption Framework: Security Persepctive - Incident Response: Preparing...
Cloud Adoption Framework: Security Persepctive - Incident Response: Preparing...
 
test-sgsgsgs.pptx
test-sgsgsgs.pptxtest-sgsgsgs.pptx
test-sgsgsgs.pptx
 
Incident Response: Preparing and Simulating Threat Response
Incident Response: Preparing and Simulating Threat ResponseIncident Response: Preparing and Simulating Threat Response
Incident Response: Preparing and Simulating Threat Response
 
Deep Dive on Amazon S3 & Amazon Glacier Storage Management - STG311 - re:Inve...
Deep Dive on Amazon S3 & Amazon Glacier Storage Management - STG311 - re:Inve...Deep Dive on Amazon S3 & Amazon Glacier Storage Management - STG311 - re:Inve...
Deep Dive on Amazon S3 & Amazon Glacier Storage Management - STG311 - re:Inve...
 
STG311_Deep Dive on Amazon S3 & Amazon Glacier Storage Management
STG311_Deep Dive on Amazon S3 & Amazon Glacier Storage ManagementSTG311_Deep Dive on Amazon S3 & Amazon Glacier Storage Management
STG311_Deep Dive on Amazon S3 & Amazon Glacier Storage Management
 
Detective Controls: Gain Visibility and Record Change
Detective Controls: Gain Visibility and Record ChangeDetective Controls: Gain Visibility and Record Change
Detective Controls: Gain Visibility and Record Change
 
Using AWS CloudTrail to Enhance Governance and Compliance of Amazon S3 - DEV3...
Using AWS CloudTrail to Enhance Governance and Compliance of Amazon S3 - DEV3...Using AWS CloudTrail to Enhance Governance and Compliance of Amazon S3 - DEV3...
Using AWS CloudTrail to Enhance Governance and Compliance of Amazon S3 - DEV3...
 
Serverless use cases with AWS Lambda
Serverless use cases with AWS Lambda Serverless use cases with AWS Lambda
Serverless use cases with AWS Lambda
 
Storage Data Management
Storage Data ManagementStorage Data Management
Storage Data Management
 
SEC301 Security @ (Cloud) Scale
SEC301 Security @ (Cloud) ScaleSEC301 Security @ (Cloud) Scale
SEC301 Security @ (Cloud) Scale
 
Scalable, Automated Anomaly Detection with GuardDuty, CloudTrail, & Amazon Sa...
Scalable, Automated Anomaly Detection with GuardDuty, CloudTrail, & Amazon Sa...Scalable, Automated Anomaly Detection with GuardDuty, CloudTrail, & Amazon Sa...
Scalable, Automated Anomaly Detection with GuardDuty, CloudTrail, & Amazon Sa...
 
AWS Security for Technical Decision Makers
AWS Security for Technical Decision MakersAWS Security for Technical Decision Makers
AWS Security for Technical Decision Makers
 
Getting started with Serverless on AWS
Getting started with Serverless on AWSGetting started with Serverless on AWS
Getting started with Serverless on AWS
 
Deep Dive on New Features in Amazon S3 & Glacier - AWS Online Tech Talks
Deep Dive on New Features in Amazon S3 & Glacier - AWS Online Tech TalksDeep Dive on New Features in Amazon S3 & Glacier - AWS Online Tech Talks
Deep Dive on New Features in Amazon S3 & Glacier - AWS Online Tech Talks
 
I Want to Analyze and Visualize Website Access Logs, but Why Do I Need Server...
I Want to Analyze and Visualize Website Access Logs, but Why Do I Need Server...I Want to Analyze and Visualize Website Access Logs, but Why Do I Need Server...
I Want to Analyze and Visualize Website Access Logs, but Why Do I Need Server...
 
Augmenting Security Posture and Improving Operational Health with AWS CloudTr...
Augmenting Security Posture and Improving Operational Health with AWS CloudTr...Augmenting Security Posture and Improving Operational Health with AWS CloudTr...
Augmenting Security Posture and Improving Operational Health with AWS CloudTr...
 
Serverless architecture-patterns-and-best-practices
Serverless architecture-patterns-and-best-practicesServerless architecture-patterns-and-best-practices
Serverless architecture-patterns-and-best-practices
 
Best Practices for Building a Data Lake in Amazon S3 and Amazon Glacier, with...
Best Practices for Building a Data Lake in Amazon S3 and Amazon Glacier, with...Best Practices for Building a Data Lake in Amazon S3 and Amazon Glacier, with...
Best Practices for Building a Data Lake in Amazon S3 and Amazon Glacier, with...
 
Security @ (Cloud) Scale Deep Dive
Security @ (Cloud) Scale Deep DiveSecurity @ (Cloud) Scale Deep Dive
Security @ (Cloud) Scale Deep Dive
 

More from Amazon Web Services

Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
Amazon Web Services
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
Amazon Web Services
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
Amazon Web Services
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
Amazon Web Services
 

More from Amazon Web Services (20)

Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
Come costruire servizi di Forecasting sfruttando algoritmi di ML e deep learn...
 
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
Big Data per le Startup: come creare applicazioni Big Data in modalità Server...
 
Esegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS FargateEsegui pod serverless con Amazon EKS e AWS Fargate
Esegui pod serverless con Amazon EKS e AWS Fargate
 
Costruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWSCostruire Applicazioni Moderne con AWS
Costruire Applicazioni Moderne con AWS
 
Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot Come spendere fino al 90% in meno con i container e le istanze spot
Come spendere fino al 90% in meno con i container e le istanze spot
 
Open banking as a service
Open banking as a serviceOpen banking as a service
Open banking as a service
 
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
Rendi unica l’offerta della tua startup sul mercato con i servizi Machine Lea...
 
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...OpsWorks Configuration Management: automatizza la gestione e i deployment del...
OpsWorks Configuration Management: automatizza la gestione e i deployment del...
 
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows WorkloadsMicrosoft Active Directory su AWS per supportare i tuoi Windows Workloads
Microsoft Active Directory su AWS per supportare i tuoi Windows Workloads
 
Computer Vision con AWS
Computer Vision con AWSComputer Vision con AWS
Computer Vision con AWS
 
Database Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatareDatabase Oracle e VMware Cloud on AWS i miti da sfatare
Database Oracle e VMware Cloud on AWS i miti da sfatare
 
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJSCrea la tua prima serverless ledger-based app con QLDB e NodeJS
Crea la tua prima serverless ledger-based app con QLDB e NodeJS
 
API moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e webAPI moderne real-time per applicazioni mobili e web
API moderne real-time per applicazioni mobili e web
 
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatareDatabase Oracle e VMware Cloud™ on AWS: i miti da sfatare
Database Oracle e VMware Cloud™ on AWS: i miti da sfatare
 
Tools for building your MVP on AWS
Tools for building your MVP on AWSTools for building your MVP on AWS
Tools for building your MVP on AWS
 
How to Build a Winning Pitch Deck
How to Build a Winning Pitch DeckHow to Build a Winning Pitch Deck
How to Build a Winning Pitch Deck
 
Building a web application without servers
Building a web application without serversBuilding a web application without servers
Building a web application without servers
 
Fundraising Essentials
Fundraising EssentialsFundraising Essentials
Fundraising Essentials
 
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
AWS_HK_StartupDay_Building Interactive websites while automating for efficien...
 
Introduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container ServiceIntroduzione a Amazon Elastic Container Service
Introduzione a Amazon Elastic Container Service
 

Using AWS CloudTrail Logs for Scalable, Automated Anomaly Detection - SID341 - re:Invent 2017

  • 1. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS re:INVENT Using AWS CloudTrail Logs for Scalable, Automated Anomaly Detection J e f f P u c h a l s k i , A W S S e c u r i t y N o v e m b e r 2 9 , 2 0 1 7 S I D 3 4 1
  • 2. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. What we will cover Logging with AWS CloudTrail • Hands-on exercise: examining CloudTrail logs Using AWS Lambda for CloudTrail log analysis • Hands-on exercise: automating detection Simplifying detection with AWS security services
  • 3. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS CloudTrail
  • 4. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Intro to AWS CloudTrail AWS CloudTrail logs activity for supported services to an AWS account Example API events that are logged: • iam:CreateUser • s3:ListBucket CloudTrail is enabled by default on all AWS accounts (as of August 2017) • Event history of create, modify, and delete operations for last seven days • Viewable, searchable, and downloadable To access CloudTrail log files directly or for a longer time period, create a trail
  • 5. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Trails in AWS CloudTrail Log activity for a single AWS account for a single region or all regions Logs are generally delivered to files in a user-defined Amazon S3 bucket • Can also be delivered to CloudWatch Logs or CloudWatch Events Log files are published approximately every 5 minutes Log files can stay in the S3 bucket for as long as you like • Indefinitely by default • Can use S3 bucket lifecycle policies to configure retention Optional logging of data-level events for Amazon S3 objects • Events such as s3:GetObject or s3:PutObject
  • 6. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS CloudTrail log files Gzipped JSON files created in the Amazon S3 bucket containing records for one or more API events Each CloudTrail log file covers an approximately five-minute time window Log files are encrypted by default • Default is server-side encryption with Amazon S3-managed encryption keys (SSE-S3) • Can configure encryption using AWS Key Management Service (AWS KMS)-managed keys (SSE-KMS) Optional log file integrity validation using signed digest file containing log-file hashes • Digest file contains hashes for previous one hour’s worth of log files
  • 7. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS CloudTrail events Each record in a CloudTrail log file represents a single event All records contain some common fields: • Time stamp • Region • Event name (i.e., the API call) • Event source (i.e., the service) • Source IP address • User identity Event-specific request and response parameters may also be included for some events
  • 8. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": "192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 9. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": "192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 10. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": ”192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 11. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": "192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 12. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": "192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 13. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": "192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 14. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. {"Records": [{ "eventVersion": "1.0", "userIdentity": { "type": "IAMUser", "principalId": "EX_PRINCIPAL_ID", "arn": "arn:aws:iam::123456789012:user/Alice", "accountId": "123456789012", "accessKeyId": "EXAMPLE_KEY_ID", "userName": "Alice” }, "eventTime": "2017-11-29T11:29:42Z", "eventSource": "iam.amazonaws.com", "eventName": "CreateUser", "awsRegion": "us-east-1", "sourceIPAddress": ”192.168.0.1", "userAgent": "aws-cli/1.3.2 Python/2.7.5 Windows/7", "requestParameters": {"userName": "Bob”}, "responseElements": {"user": {"createDate": ”Nov 29, 2017 11:29:42 AM", "userName": "Bob", "arn": "arn:aws:iam::123456789012:user/Bob", "path": "/", "userId": "EXAMPLEUSERID"} } }]} What do CloudTrail logs look like?
  • 15. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Examining CloudTrail logs H a n d s - o n e x e r c i s e
  • 16. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on: Examining CloudTrail logs In this exercise, you will be using the CloudTrail Event history viewer in the AWS console to view CloudTrail logs for your account The goal of this exercise is to gain familiarity with, and understanding of, how to examine CloudTrail log event records The README file in the code repository contains detailed information on this exercise, including guidance on things to pay attention to and look for in the records Code repository URL: amzn.to/sid341repo Please ask questions! We are here to help 
  • 17. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Examining CloudTrail logs E x e r c i s e d e b r i e f
  • 18. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda for detection
  • 19. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using AWS Lambda for detection AWS Lambda enables serverless compute • Run code in Lambda functions without needing to provision an instance AWS Lambda scales automatically because it is event-driven • Invocations run in response to event triggers • Example: For our use case, the Lambda function can receive notifications directly from the S3 bucket when new CloudTrail log files are created!  Enables automated stream-based processing and analysis SNS notification SNS AWS Lambda
  • 20. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. # Assumes event uses the following JSON format: # { # “first_name”: “Inigo”, # “last_name”: ”Montoya” # } def handler(event, context): message = ’Hello from re:Invent 2017, {} {}!'.format(event['first_name'], event['last_name']) return { 'message' : message } Hello world handler in Python
  • 21. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. import boto3 import gzip import io import json def handler(event, context): s3 = boto3.client(’s3’) for event_record in event['Records']: # this event is an s3:ObjectCreated:Put notification bucket = event_record['s3']['bucket']['name'] # extract the bucket name... key = event_record['s3']['object']['key’] # ...and key name response = s3.get_object(Bucket=bucket, Key=key) # fetch the log file from S3 with io.BytesIO(response[‘Body’].read()) as obj: # bytes of gzipped file with gzip.GzipFile(fileobj=obj) as logfile : # unzip the file cloudtrail_log = json.load(logfile) # load the CloudTrail log JSON for record in cloudtrail_log[‘Records’]: # iterate over the CloudTrail records print(record) # do stuff with each record :) CloudTrail ingest handler in Python
  • 22. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Automated detection H a n d s - o n e x e r c i s e
  • 23. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on exercise preparations In this workshop we will be doing some hands-on exercises that use AWS CloudTrail logs A provided AWS CloudFormation template will create 2 stacks of resources for the following purposes: • Analysis of CloudTrail logs using an AWS Lambda function • Activity generation to produce CloudTrail logs for analysis The events take a bit of time to be created and show up in CloudTrail (~5 mins) Therefore, we will run the CloudFormation template now so the logs will be ready later  Please browse to the following URI for CloudFormation stack creation: amzn.to/sid341cfn Code repository URL: amzn.to/sid341repo
  • 24. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on: Automated detection You have been asked by your security operations team to create an automated solution to analyze CloudTrail logs in an AWS account where some evil shenanigans may be occurring Your mission, should you choose to accept it, is to build a simple detection engine to automatically ingest and analyze CloudTrail logs for indicators of suspicious activity
  • 25. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Hands-on: Automated detection We will use an AWS Lambda function and a CloudWatch alarm to accomplish this. You will add code to the Lambda function to check for, and alarm on, a few specific types of potentially suspicious activity. The Lambda function already fetches and loads the CloudTrail log files, and passes each record to analysis functions that you will be filling in The README file in the code repository contains detailed information on this exercise: amzn.to/sid341repo We are here to help, so please ask questions. Good luck! High-level architecture: Lambda Function CloudWatch Alarm CloudTrail Trail S3 Bucket CloudTrail log file (gzipped JSON) S3 “Put” event notification (bucket and key) Metric data to trigger an alarm
  • 26. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Automated detection E x e r c i s e d e b r i e f
  • 27. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. AWS Security Services: Amazon Macie and GuardDuty
  • 28. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Amazon Macie is a security service that uses machine learning (ML) Automatically discovers, classifies, and protects sensitive data in AWS • Amazon S3 today • More AWS data stores soon! Continuously monitors data-access activity for anomalies Generates alerts when risk is detected • Alerts can be sent to Amazon CloudWatch Events Using Amazon Macie for detection
  • 29. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Using Amazon GuardDuty for detection Amazon GuardDuty is a continuous security monitoring service Analyzes and processes the following data sources: • AWS CloudTrail logs • Amazon Virtual Private Cloud (Amazon VPC) flow logs Identifies unexpected and suspicious activity • Escalations of privileges • Uses of exposed credentials • Communication with malicious IPs Produces findings that can be viewed in the GuardDuty console • Alerts can be sent to Amazon CloudWatch Events
  • 30. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Recap Logging with AWS CloudTrail • Hands-on exercise: examining CloudTrail logs Using AWS Lambda for CloudTrail log analysis • Hands-on exercise: automating detection Simplifying detection with AWS security services
  • 31. © 2017, Amazon Web Services, Inc. or its Affiliates. All rights reserved. Thank you! Y o u r f e e d b a c k o n t h i s w o r k s h o p i s v e r y m u c h a p p r e c i a t e d ! S I D 3 4 1