<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Mehmet Ayberk</title>
    <description>The latest articles on Forem by Mehmet Ayberk (@mhmtayberk).</description>
    <link>https://forem.com/mhmtayberk</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F827955%2F955d077c-b288-4041-84db-fa0a8d00cb85.jpg</url>
      <title>Forem: Mehmet Ayberk</title>
      <link>https://forem.com/mhmtayberk</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/mhmtayberk"/>
    <language>en</language>
    <item>
      <title>Managing Security Alarms with Automation in AWS</title>
      <dc:creator>Mehmet Ayberk</dc:creator>
      <pubDate>Tue, 28 Jan 2025 11:32:50 +0000</pubDate>
      <link>https://forem.com/mhmtayberk/managing-security-alarms-with-automation-in-aws-3dfi</link>
      <guid>https://forem.com/mhmtayberk/managing-security-alarms-with-automation-in-aws-3dfi</guid>
      <description>&lt;h2&gt;
  
  
  TLDR;
&lt;/h2&gt;

&lt;p&gt;Automated detection of security threats and taking necessary actions are among the most important aspects. As the attack surface expands daily, the number of topics requiring regular monitoring also increases. At this point, it is critical to build, design, and maintain automated systems as well as manual controls and human power. AWS has various security services that allow us to perform some security checks on a regular basis. Using these services more efficiently depends on the architecture we will design depending on the structure of our organization. In this blog post, I will take some security alarms that we think may be harmful in AWS by using AWS's security services and take automatic actions thanks to Lambda.&lt;/p&gt;

&lt;h2&gt;
  
  
  What Will We Automate?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Detection and Automated Action of AWS CloudTrail Deactivation&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  What Else Can You Automate?
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;Abnormal Pod Incidents to the EKS&lt;/li&gt;
&lt;li&gt;Unexpected Traffic Increase on EC2&lt;/li&gt;
&lt;li&gt;Detection of Abnormal Activity of an IAM User&lt;/li&gt;
&lt;li&gt;Disabling Encryption Settings on RDS&lt;/li&gt;
&lt;li&gt;Automatic Check and Correction of S3 Bucket Encryption Status&lt;/li&gt;
&lt;li&gt;Detect IAM Root User Usage and Send Alarm&lt;/li&gt;
&lt;li&gt;Controlling EC2 Instance Security Groups&lt;/li&gt;
&lt;li&gt;IAM High Authority Role Monitoring&lt;/li&gt;
&lt;li&gt;And much more&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Detecting and Automating Responses to AWS CloudTrail Deactivation
&lt;/h3&gt;

&lt;p&gt;When attackers gain unauthorized access through the interface or CLI, there are some steps they will take. One of them will be to erase the traces they have left behind. The first method they will try for this will be to deactivate CloudTrail if it is active. In this example, we will check whether CloudTrail is active or not in an automated way and reactivate it if it is deactivated. Of course, the task of activating CloudTrail also falls to our automation.&lt;/p&gt;

&lt;p&gt;My goal here is to give you an overview of how you can build mini security automations in AWS, rather than having you do these examples in person.&lt;/p&gt;

&lt;p&gt;At the end of the day, our architecture will look like this:&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdeeihflf12wk91y9mvi5.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fdeeihflf12wk91y9mvi5.png" alt="Image description" width="800" height="245"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Enable cloudtrail-enabled Rule in AWS Config
&lt;/h4&gt;

&lt;p&gt;First of all, we need to activate the &lt;strong&gt;AWS Config&lt;/strong&gt; service. I skip the part on how to activate AWS Config and continue my article in the scenario where it is already active. We need to check whether CloudTrail is active on AWS Config. For that from the left menu we have to go to &lt;strong&gt;Rules&lt;/strong&gt; and &lt;strong&gt;Add Rule&lt;/strong&gt;. By selecting &lt;strong&gt;AWS Managed Rule&lt;/strong&gt;, we select &lt;strong&gt;cloudtrail-enabled&lt;/strong&gt; or &lt;strong&gt;multi-region-cloudtrail-enabled&lt;/strong&gt; and create our rule.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;We could have created the automation for this scenario by listening to CloudTrail calls directly on EventBridge without using AWS Config. I added this step so that you can see different scenarios.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fba02duqvae41ak0sec2h.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fba02duqvae41ak0sec2h.png" alt="Image description" width="800" height="214"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Automatic Response with Lambda Function
&lt;/h4&gt;

&lt;p&gt;We need the Lambda function to take the automatic action if CloudTrail is deactivated. The code we will write here will be quite simple. Of course, you may need to improve your code depending on the needs of the organization. For this, we will of course create an IAM role, create our Lambda function, and add the IAM code to this Lambda function. (Spoiler: Yes! We will then use EventBridge to trigger the Lambda function).&lt;/p&gt;

&lt;p&gt;Before we start creating the Lambda function, we will need to create an IAM role to give the Lambda function the authorizations it needs to make the necessary changes to CloudTrail. You can also use &lt;a href="https://awspolicygen.s3.amazonaws.com/policygen.html" rel="noopener noreferrer"&gt;AWS's IAM Role Generator&lt;/a&gt; to create an IAM role.&lt;/p&gt;

&lt;p&gt;For this, you must follow these steps on the IAM screen:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Go to IAM &amp;gt; Policies &amp;gt; Create Policy&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;Make sure to comply with the least privilege policy when creating a new IAM role. This could prevent further security problems. Here, we will create our authorization instead of authorizing our role such as AdministratorAccess.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Here is what our policy looks like:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Version"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"2012-10-17"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"Statement"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Effect"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"Allow"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Action"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"cloudtrail:UpdateTrail"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"cloudtrail:StartLogging"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"cloudtrail:DescribeTrails"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"lambda:InvokeFunction"&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;&lt;span class="w"&gt;
                &lt;/span&gt;&lt;span class="s2"&gt;"cloudtrail:GetTrailStatus"&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
            &lt;/span&gt;&lt;span class="nl"&gt;"Resource"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="s2"&gt;"*"&lt;/span&gt;&lt;span class="w"&gt;
        &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;You can customize the Policy according to your needs.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create the policy.&lt;/li&gt;
&lt;li&gt;Go to IAM &amp;gt; Roles.&lt;/li&gt;
&lt;li&gt;Select AWS Service as Trusted entity type and proceed by selecting Lambda in the Use case field just below.&lt;/li&gt;
&lt;li&gt;In the Permission policy tab, let's assign the role by selecting the Policy we just created and complete the new role creation step.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Finally we can create our Lambda function. I will create the Lambda function in Python 3.x. You can of course use any other programming language that suits you or that you are comfortable with. Anyway, it is up to you to improve and extend the code here according to your needs. Here is my PoC code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="c1"&gt;# Import the required libs
&lt;/span&gt;&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;json&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;
&lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;
&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="n"&gt;botocore.exceptions&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;ClientError&lt;/span&gt;

&lt;span class="c1"&gt;# Making logging settings
&lt;/span&gt;&lt;span class="n"&gt;logger&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;getLogger&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;
&lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;setLevel&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;logging&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="n"&gt;INFO&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

&lt;span class="k"&gt;def&lt;/span&gt; &lt;span class="nf"&gt;lambda_handler&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="n"&gt;context&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="c1"&gt;# Create a client to access the AWS CloudTrail service
&lt;/span&gt;    &lt;span class="n"&gt;cloudtrail&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;boto3&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;client&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;cloudtrail&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

    &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="c1"&gt;# Log the incoming event
&lt;/span&gt;        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Received event: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;json&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;dumps&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;event&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="c1"&gt;# List all CloudTrails in the account
&lt;/span&gt;        &lt;span class="n"&gt;response&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cloudtrail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;describe_trails&lt;/span&gt;&lt;span class="p"&gt;()&lt;/span&gt;

        &lt;span class="c1"&gt;# If there is no trail, return an error
&lt;/span&gt;        &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;trailList&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
            &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;warning&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;No CloudTrail trails found in the account&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
            &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
                &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;statusCode&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;404&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
                &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;No CloudTrail trails found&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
            &lt;span class="p"&gt;}&lt;/span&gt;

        &lt;span class="c1"&gt;# Perform operations for each trail
&lt;/span&gt;        &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;trail&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="n"&gt;response&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;trailList&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
            &lt;span class="n"&gt;trail_name&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;trail&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Name&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;

            &lt;span class="k"&gt;try&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="c1"&gt;# Checking the current status of the trail
&lt;/span&gt;                &lt;span class="n"&gt;status&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;cloudtrail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;get_trail_status&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;trail_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

                &lt;span class="c1"&gt;# If logging is closed then do them
&lt;/span&gt;                &lt;span class="k"&gt;if&lt;/span&gt; &lt;span class="ow"&gt;not&lt;/span&gt; &lt;span class="n"&gt;status&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;IsLogging&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;]:&lt;/span&gt;
                    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Trail &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;trail_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is disabled. Enabling it...&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

                    &lt;span class="c1"&gt;# Activate the Trail
&lt;/span&gt;                    &lt;span class="n"&gt;cloudtrail&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;start_logging&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Name&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;&lt;span class="n"&gt;trail_name&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

                    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Successfully enabled trail: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;trail_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;else&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                    &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;info&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Trail &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;trail_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt; is already enabled&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;

            &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;ClientError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
                &lt;span class="c1"&gt;# If an error occurs while activating a trail, we continue with other trails
&lt;/span&gt;                &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error processing trail &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="n"&gt;trail_name&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="s"&gt;: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
                &lt;span class="k"&gt;continue&lt;/span&gt;

        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;statusCode&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;200&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;Successfully processed all trails&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;

    &lt;span class="k"&gt;except&lt;/span&gt; &lt;span class="n"&gt;ClientError&lt;/span&gt; &lt;span class="k"&gt;as&lt;/span&gt; &lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;
        &lt;span class="n"&gt;logger&lt;/span&gt;&lt;span class="p"&gt;.&lt;/span&gt;&lt;span class="nf"&gt;error&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
        &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
            &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;statusCode&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="mi"&gt;500&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt;
            &lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="s"&gt;body&lt;/span&gt;&lt;span class="sh"&gt;'&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt; &lt;span class="sa"&gt;f&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;&lt;span class="s"&gt;Error: &lt;/span&gt;&lt;span class="si"&gt;{&lt;/span&gt;&lt;span class="nf"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;e&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;&lt;span class="si"&gt;}&lt;/span&gt;&lt;span class="sh"&gt;"&lt;/span&gt;
        &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Event Triggering with EventBridge
&lt;/h4&gt;

&lt;p&gt;We need to connect the Lambda function to an Event via EventBridge to automatically take action when the case we expect occurs. For this let's create a new event. While creating our rule, we select the &lt;strong&gt;Config Rules Compliance Change&lt;/strong&gt; option in the Sample event section. As the creation method, we will write our own rule by selecting Custom pattern again. Our rule will be as follows:&lt;/p&gt;

&lt;p&gt;For this scenario, we want to trigger the Lambda function we wrote to recognize when a Trail is stopped. We need to create our EventBridge rule as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can fill in the Event name field as you wish.&lt;/li&gt;
&lt;li&gt;In our scenario here, the Rule Type field should be &lt;strong&gt;Rule with an event pattern.&lt;/strong&gt;
&lt;/li&gt;
&lt;li&gt;On the next page we must select &lt;strong&gt;Other&lt;/strong&gt; in the &lt;strong&gt;Event Source&lt;/strong&gt; field.&lt;/li&gt;
&lt;li&gt;On the Build event pattern page, we can go down to the bottom and write our rule in the Event pattern field just below by making the &lt;strong&gt;Creation method&lt;/strong&gt; &lt;strong&gt;Custom pattern&lt;/strong&gt; without changing any other settings.&lt;/li&gt;
&lt;li&gt;You can write the following code in the event pattern field:
&lt;/li&gt;
&lt;/ul&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight json"&gt;&lt;code&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"source"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"aws.config"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"detail-type"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"Config Rules Compliance Change"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="nl"&gt;"detail"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"configRuleName"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"cloudtrail-enabled"&lt;/span&gt;&lt;span class="p"&gt;],&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="nl"&gt;"newEvaluationResult"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;{&lt;/span&gt;&lt;span class="w"&gt;
      &lt;/span&gt;&lt;span class="nl"&gt;"complianceType"&lt;/span&gt;&lt;span class="p"&gt;:&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="s2"&gt;"NON_COMPLIANT"&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;&lt;span class="w"&gt;
    &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
  &lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;span class="p"&gt;}&lt;/span&gt;&lt;span class="w"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;I can say that the writing format of Event Patterns is very clear and simple. If you have more questions about writing Custom Event Patterns, you can check AWS's official documentation..&lt;/p&gt;
&lt;/blockquote&gt;

&lt;ul&gt;
&lt;li&gt;Select the &lt;strong&gt;AWS service&lt;/strong&gt; radio button as the target and then select the &lt;strong&gt;Lambda function&lt;/strong&gt; in the Select a target section and the Lambda function we have prepared in the Function section.&lt;/li&gt;
&lt;li&gt;Create the rule.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The EventBridge Rule summary we created should look like this:&lt;br&gt;
&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil1t3oxmyo01v7b2qmsg.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fil1t3oxmyo01v7b2qmsg.png" alt="Image description" width="800" height="833"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;That's all. Now we have a mini automation that will reactivate any of the CloudTrail Trails in case any of them is deactivated. Of course, you can also develop different solutions specific to your organization. For example:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;If you have Trails that should not be included in this automation, you can create an Exception list and develop your code accordingly.&lt;/li&gt;
&lt;li&gt;When the automation runs, you can send an e-mail containing information such as the Trail name, the user who deactivated the Trail, the time when the Lambda function was triggered.&lt;/li&gt;
&lt;li&gt;You can visualize the logs of all these operations by sending them to ELK.&lt;/li&gt;
&lt;/ul&gt;

&lt;h4&gt;
  
  
  Test
&lt;/h4&gt;

&lt;p&gt;Just deactivate an existing Trail. After a short time, you will see that the Trail has been reactivated. You can also observe your test by following these metrics after deactivating your Trail:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;You can observe whether your Lambda code is triggered or not from CloudWatch Log groups.&lt;/li&gt;
&lt;li&gt;You can observe your EventBridge metrics.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Also after a while you have to see Noncompliant Warning on the AWS Config.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fayddzu4ouw4h79hfi373.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fayddzu4ouw4h79hfi373.png" alt="Image description" width="718" height="458"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;In fact, we could have triggered our Lambda function by selecting the Create custom Lambda rule option while creating our Config Rule without using EventBridge. I would like to state again that my goal here is to provide you with different perspectives. There are many different ways to create such mini security automations on AWS. Of course, you can create the most suitable architecture according to your needs and by getting to know AWS services.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Last Word
&lt;/h2&gt;

&lt;p&gt;In this blog post, my goal was to give you a perspective on how you can set up mini automations to make your AWS environment more secure. I strongly encourage you to try building the other automations in the "What Else Can You Automate?" section or develop the automations mentioned in this blog post.&lt;/p&gt;

&lt;p&gt;Depending on your business needs, the automations you can build will vary and change. The code you write may change and the AWS services you use may change.&lt;/p&gt;

&lt;p&gt;If you have any suggestions for the article, please feel free to contact me through any communication channel (Linkedin, Twitter, Threema, etc.). I am constantly updating the articles in line with your feedback.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>automation</category>
    </item>
    <item>
      <title>Incident Response On AWS</title>
      <dc:creator>Mehmet Ayberk</dc:creator>
      <pubDate>Tue, 20 Sep 2022 09:05:34 +0000</pubDate>
      <link>https://forem.com/mhmtayberk/incident-response-on-aws-122h</link>
      <guid>https://forem.com/mhmtayberk/incident-response-on-aws-122h</guid>
      <description>&lt;h2&gt;
  
  
  TLDR;
&lt;/h2&gt;

&lt;p&gt;As in on-prem environments, security in cloud environments should be considered as a whole. As it can happen in any environment, hacking cases can occur in AWS environments. We see examples of this situation from time to time. In this article, I will not go into the details of Incident Response processes. I will mostly explain how you can run Incident Response processes on AWS.&lt;/p&gt;

&lt;h2&gt;
  
  
  Is It So Different from Incident Response?
&lt;/h2&gt;

&lt;p&gt;In essence, no. Of course there are some differences. But it is important to remember that cloud systems are not much different from normal computer systems. Without going deeper, I should mention that I will not talk about Incident Response processes in this article. I will talk about how Incident Response processes are implemented in AWS. If you do not have basic knowledge about Incident Response, I recommend you take a break here and read a short articles about Incident Response processes.&lt;/p&gt;

&lt;h2&gt;
  
  
  AWS Incident Manager
&lt;/h2&gt;

&lt;p&gt;There is a service offered by AWS that allows you to easily manage Incident Response processes. &lt;a href="https://console.aws.amazon.com/systems-manager/incidents/home" rel="noopener noreferrer"&gt;Incident Manager&lt;/a&gt;. With the Incident Manager service, you can plan your Incident Response processes, define Runbooks, send notifications to relevant teams and review incident details for up-to-date information during an incident. Incident Manager does all this by leveraging other AWS services.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Faws-incident-manager.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Faws-incident-manager.png" alt="AWS Incident Manager" width="800" height="253"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's examine how Incident Manager is configured and how to use it.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Replication
&lt;/h3&gt;

&lt;p&gt;After entering Incident Manager's panel, we can start configuring it by clicking the &lt;strong&gt;Set up&lt;/strong&gt; button under General Settings. Then let's continue by confirming the Terms and conditions.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-replication.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-replication.png" alt="AWS Incident Manager Replication" width="800" height="489"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;At this point, we make general adjustments to Incident Manager. In the Regions field, we determine in which Regions we will use Incident Manager. We need to select at least one Region. But there is no upper limit to the number of Regions we will select.&lt;/p&gt;

&lt;p&gt;You can use the KMS Encryption field to guarantee that the data stored in Incident Manager is protected and cannot be changed without deletion. Once you have done this, it can take up to 5 minutes to set up Replication (but it usually takes a few seconds). You can get yourself a cup of coffee.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Contact Details
&lt;/h3&gt;

&lt;p&gt;This stage is optional. You do not have to set it. But I recommend you &lt;br&gt;
to follow every step in Incident Manager to run a good Incident Response process. This is the area where we set the people and communication channels to respond to the Incident.&lt;/p&gt;

&lt;p&gt;In the Contact details field, the name of the person who will deal with IR processes and an alias are specified.&lt;/p&gt;

&lt;p&gt;In the Contact channel field, we specify how to contact the person we specified in the Contact details field in case of a case. In this field, we can specify a communication channel via E-mail, SMS, or Voice. We can also specify more than one communication channel. My recommendation is to specify at least two communication channels. Thus, if the relevant person cannot be reached through one channel, they can be reached through the other channel.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-contact-detail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-contact-detail.png" alt="AWS Incident Manager Contact Detail" width="800" height="215"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In the Engagement area, you can specify when to contact the relevant contact(s) in case of an incident. Note that after you have set up the contact channels, a validation will be sent for each contact channel you have set up.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-contact-verification.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-contact-verification.png" alt="AWS Incident Manager Contact Verification" width="800" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;If you want to set more than one contact you have to repeat the same procedure.&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Escalation Plans
&lt;/h3&gt;

&lt;p&gt;Creating an escalation plan is optional, just like creating a contact. But this time, if you want to create an escalation plan, you need to have already created a contact. You can use it in situations where you want more than one person to deal with a case at the same time. You can designate more than one person and forward the case to the other person(s) in case the first person does not respond to the case. &lt;/p&gt;

&lt;p&gt;In the Escalation plan details field you must assign a name and alias to the related plan. In the Stages field, you can specify which people will deal with the case, and with the Duration parameter, you can specify how long in minutes it will be escalated to the next Responder. Duration must be 30 or less than 30.&lt;/p&gt;

&lt;p&gt;If you want to create more than one Escalation plan you should repeat the same steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-esc-stages.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-esc-stages.png" alt="AWS Incident Manager Escalation Stages" width="800" height="584"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Setting Up Response Plan
&lt;/h3&gt;

&lt;p&gt;I think the most crucial part is the Response Plan. You can use this area to plan how to respond to incidents, determine the severity of incidents, determine which contacts to contact, select metrics to track, and determine the automated runbooks to start.&lt;/p&gt;

&lt;p&gt;As always, we start by specifying a name and alias for the Response plan in the Response plan details field. The values in the Incident Defaults field and their descriptions are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Title:&lt;/strong&gt; The incident title helps to identify an incident on the incidents home page.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Impact:&lt;/strong&gt; It allows you to identify an impact to determine the potential risk of the case.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Summary:&lt;/strong&gt; It allows you to write a summary of the case. It is an optional field.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Dedupe String:&lt;/strong&gt; Incident Manager uses the dedupe string to prevent the same root cause from creating multiple incidents in the same account. Incident Manager deduplicates Incidents created from the same CloudWatch alarm or EventBridge event into the same incident. (Source: AWS Docs.)&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Tags:&lt;/strong&gt; If you are familiar with AWS, you should be familiar with the tagging structure. Every event that starts using this response plan will have these tags. This will make it easier for you to do things like reporting.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-incident-defaults.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-incident-defaults.png" alt="AWS Incident Manager Incident Defaults" width="800" height="745"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The chat channel field is optional but very useful. Select a chat channel for responders to interact during the case. Currently, only Slack and Chime are supported. In order to use this area, you must first configure a Chatbot Client. For more detailed information, you can review the &lt;a href="https://docs.aws.amazon.com/chatbot/latest/adminguide/getting-started.html" rel="noopener noreferrer"&gt;AWS document.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;I explained the Engagements section in the previous chapter, so I will continue by skipping this section.&lt;/p&gt;

&lt;p&gt;Runbooks allow you to automate some processes. You can create and use a Runbook, use one of the Runbooks created by AWS, or use another Runbook that has been shared with you. I should mention that for Runbooks to work, you must assign an IAM role with &lt;strong&gt;ssm:StartAutomationExecution&lt;/strong&gt; authorization. Also, if you are going to use Runbook in Cross-Accounts, you must have &lt;strong&gt;sts:AssumeRole&lt;/strong&gt; role.&lt;/p&gt;

&lt;h4&gt;
  
  
  Creating A New Runbook
&lt;/h4&gt;

&lt;p&gt;Creating a new Runbook is quite easy. You need to enter a description in Markdown format and set up the Runbook steps.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fcreating-a-runbook.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fcreating-a-runbook.png" alt="AWS Creating Runbook" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Again, it contains a lot of detail. For detailed information on how to create a Runbook in AWS, you can check the &lt;a href="https://docs.aws.amazon.com/systems-manager/latest/userguide/automation-documents.html" rel="noopener noreferrer"&gt;AWS documentation.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Finally, you can tag the Response plan you created if you want. After all these steps, you can create the Response plan with the "Create response plan" button. You can also edit and delete the Response Plan, Escalation Plan and Contacts you created later.&lt;/p&gt;

&lt;h3&gt;
  
  
  Starting A Incident
&lt;/h3&gt;

&lt;p&gt;Now that we have done our preliminary preparation, we can return to the Incident Manager dashboard and start a new Incident. There are three ways we can start an Incident. These are:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Automatically create incidents with CloudWatch alarms&lt;/li&gt;
&lt;li&gt;Automatically create incidents with EventBridge events&lt;/li&gt;
&lt;li&gt;Manually create incidents&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;In this article, I will talk about how to start an Incident manually and automaticly via CloudWatch.&lt;/p&gt;

&lt;h4&gt;
  
  
  Manually Create Incidents
&lt;/h4&gt;

&lt;p&gt;Starting an Incident manually is quite easy and does not require much information. Click the "Start Incident" button on the Incident Manager dashboard. Select the Response Plan we prepared before and optionally give a title to the Incident and determine its Impact. Immediately afterward, the Incident is started by clicking the "Start" button.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fmanually-incident-starting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fmanually-incident-starting.png" alt="AWS Incident Manager - Manually Incident Starting" width="800" height="595"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h4&gt;
  
  
  Automatically Start Incidents With CloudWatch Alarms
&lt;/h4&gt;

&lt;p&gt;With CloudWatch, we can track metrics and ensure that cases are automatically created in line with the conditions we want. For this, you must first create an Alarm from the CloudWatch panel. When creating an alarm, select Create Incident under &lt;strong&gt;Systems Manager Action&lt;/strong&gt; menu and then select Response Plan to create an alarm.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fcloudwatch-incident-starting.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fcloudwatch-incident-starting.png" alt="AWS CloudWatch Incident Starting" width="800" height="335"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;From this moment on, an Incident will automatically occur in every situation that matches the condition you set when creating the Alarm.&lt;/p&gt;

&lt;h3&gt;
  
  
  Tracking And Resolving Incidents
&lt;/h3&gt;

&lt;p&gt;You can follow the created cases from the Incident Manager dashboard. Here you can see general data about the cases, metrics, timeline, runbooks, engagements and you can edit some of them.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-incident-dashboard.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-incident-dashboard.png" alt="AWS Incident Manager - Incident Dashboad" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In order to Resolve the Incident, all you need to do is to click on the "Resolve incident" button on the top left.&lt;/p&gt;

&lt;h3&gt;
  
  
  Post-Incident Analysis
&lt;/h3&gt;

&lt;p&gt;After the relevant case is resolved, you can start an analysis of this case and review the issues related to improving your processes. This analysis process is done with Templates. You can create your Template or use the Template created by AWS. Analysis details include metrics, timeline, question set, actions and a checklist. Once an analysis has been created, some areas, such as the question set, can be edited later.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-incident-analysis.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fincident-manager-incident-analysis.png" alt="AWS Incident Manager - Incident Analysis" width="800" height="543"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Isolating EC2 Instances
&lt;/h2&gt;

&lt;p&gt;In the event of an incident on an EC2 Instance, it is critical to isolate that Instance from the network. The steps to be followed at this point are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Detach the related Instance if it belongs to an Autoscaling group.&lt;/li&gt;
&lt;li&gt;Create a new Security Group that denies all Inbound and Outbound traffic so that in case of an Incident the related Instance will not communicate with any address.&lt;/li&gt;
&lt;li&gt;Detach the existing Security Group of the related Instance and attach the Security Group you created in the previous step.&lt;/li&gt;
&lt;li&gt;Detach if an IAM role is defined on the related Instance. This will allow you to minimize the damage. Make sure that no IAM role is defined on the related Instance.&lt;/li&gt;
&lt;li&gt;Take a Snapshot of the root volume of the respective Instance. You will need this Snapshot during the analysis. It will help you understand the root cause of the incident.&lt;/li&gt;
&lt;li&gt;Finally, again create the AMI of the relevant Instance for analysis.&lt;/li&gt;
&lt;li&gt;Remember that using tags at these stages will be very useful for you in stages such as analysis and report generation.&lt;/li&gt;
&lt;/ul&gt;

&lt;blockquote&gt;
&lt;p&gt;I mentioned that I will not go into the details of Incident Response processes or AWS in this document, but the steps described (such as creating a new Security Group) are quite simple. If there are any missing points here, you can use AWS's documents.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h2&gt;
  
  
  Open Source Incident Response Toolkit
&lt;/h2&gt;

&lt;p&gt;There are some open open-source toolkits created by Andrew Krug, Alex McCormack, Joel Ferrier, and Jeff Parr that streamline our Incident Response processes in cloud environments.&lt;/p&gt;

&lt;h3&gt;
  
  
  Margarita Shotgun
&lt;/h3&gt;

&lt;p&gt;Margarita Shotgun is a very simple to use memory dump tool written in Python programming language. It is designed to work in AWS environments. Detailed information is available in its own &lt;a href="https://margaritashotgun.readthedocs.io/en/latest/" rel="noopener noreferrer"&gt; documentation.&lt;/a&gt;&lt;/p&gt;

&lt;h3&gt;
  
  
  Incident Pony
&lt;/h3&gt;

&lt;p&gt;Incident Pony is a first of its kind case management and Incident Response orchestration tool specifically designed for AWS (Source: ThreatResponse).&lt;/p&gt;

&lt;h3&gt;
  
  
  AWS_IR CLI
&lt;/h3&gt;

&lt;p&gt;AWS_IR CLI is the third and final Incident Response tool written by the ThreatResponse team. The purpose of the tool is to automate Incident Response processes. You can review the &lt;a href="https://www.blackhat.com/docs/us-16/materials/us-16-Krug-Hardening-AWS-Environments-And-Automating-Incident-Response-For-AWS-Compromises-wp.pdf" rel="noopener noreferrer"&gt; Black Hat document&lt;/a&gt; about the AWS_IR tool and other tools.&lt;/p&gt;

&lt;h2&gt;
  
  
  Yet Another Automation
&lt;/h2&gt;

&lt;p&gt;There are many ways to automate Incident Response processes in an AWS environment. These processes can be automated with third-party tools and/or AWS's own services. At this point, it is important to choose the most suitable solution for your needs. In this blogpost, I will show you an automation that AWS describes in their Security Blog and I will also link to some other automations.&lt;/p&gt;

&lt;p&gt;The automatization we will use takes the necessary actions by following AWS GuardDuty and AWS Config controls. The architecture is as in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fautomated-incident-response-arc.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fautomated-incident-response-arc.png" alt="AWS Automated Incident Response Flowchart" width="800" height="625"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The installation steps are quite easy. Because we don't do the installation manually. We can quickly install it with CloudFormation Stack.&lt;br&gt;
&lt;strong&gt;&lt;a href="https://console.aws.amazon.com/cloudformation/home?#/stacks/new?stackName=Automated-Incident-Response&amp;amp;templateURL=https://awsiammedia.s3.amazonaws.com/public/sample/AutomatedIncidentResponse319/master-account-main.yaml" rel="noopener noreferrer"&gt; CloudFormation Stack&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;

&lt;p&gt;In the Stack Parameters section, it asks us for some information. These are as follows:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;S3 Bucket with sources:&lt;/strong&gt; S3 Bucket name summarizing all AWS resources used. If you cannot provide this information, you can leave it as default.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Prefix for S3 bucket with sources:&lt;/strong&gt; This is the setting where you can specify the Prefix for your S3 bucket objects.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security IR Role Name:&lt;/strong&gt; The name of the IAM role to be given to Lambda functions for actions to be taken automatically.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Security Exception Tag:&lt;/strong&gt; This is the setting where you specify the name of the Tag you should use when you want to define an exception.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Organization Id:&lt;/strong&gt; As a Best Practice, your security account should be a different account. This setting is your AWS organization ID, which is used to authorize CloudWatch data to be forwarded to the security account.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Allowed Network Range IPv4/IPv6:&lt;/strong&gt; This is the setting used to limit all security groups that are not defined as exceptions.&lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Isolate EC2 Findings:&lt;/strong&gt; This is a list of all GuardDuty findings that should lead to an EC2 instance being isolated. &lt;/li&gt;
&lt;li&gt;
&lt;strong&gt;Block Printcipal Finding:&lt;/strong&gt; This is a list of all GuardDuty findings that should lead to blocking this role or user by attaching a deny all policy.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fautomated-ir-stack-options.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fincident-response-on-aws%2Fautomated-ir-stack-options.png" alt="AWS Automated Incident Response Stack Options" width="800" height="624"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;After all these settings, you can start Stack. Once Stack is complete, you will now have an automated IR process. For more details, you can read the &lt;a href="https://aws.amazon.com/blogs/security/how-to-perform-automated-incident-response-multi-account-environment/" rel="noopener noreferrer"&gt; AWS Security Blog&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Other Automations
&lt;/h2&gt;

&lt;p&gt;I mentioned that there are many different ways to automate Incident Response processes in AWS. At this point, you should determine the most suitable solution for you. I have linked some other automatizations in the list below.&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://docs.aws.amazon.com/prescriptive-guidance/latest/patterns/automate-incident-response-and-forensics.html" rel="noopener noreferrer"&gt; Automate incident response and forensics (AWS Doc.)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/security/how-to-automate-incident-response-in-aws-cloud-for-ec2-instances/" rel="noopener noreferrer"&gt; How to automate incident response in the AWS Cloud for EC2 instances (AWS Security Blog)&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://aws.amazon.com/blogs/security/how-to-automate-incident-response-to-security-events-with-aws-systems-manager-incident-manager/" rel="noopener noreferrer"&gt; How to automate incident response to security events with AWS Systems Manager Incident Manager (AWS Security Blog)&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Last Word
&lt;/h2&gt;

&lt;p&gt;In this blogpost, I aimed to give you basic information about Indicent Response processes in AWS. I hope it has contributed. Please note that Incident Response processes are not limited to what is described in this document. Incident Response and DFIR processes require expertise on their own. Also make sure to do the following in Incident Response processes in AWS:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Create CloudWatch alarms to suit your needs and connect them with Incident Manager.&lt;/li&gt;
&lt;li&gt;Follow &lt;a href="https://aws.amazon.com/blogs/security/how-to-automate-incident-response-to-security-events-with-aws-systems-manager-incident-manager/" rel="noopener noreferrer"&gt; AWS’s Security Incident Response Guide.&lt;/a&gt;
&lt;/li&gt;
&lt;li&gt;Don't forget to use AWS's other security services.&lt;/li&gt;
&lt;li&gt;Set up different security accounts for use in AWS. Make sure everything is isolated and apply the Least Privilege method.&lt;/li&gt;
&lt;li&gt;Establish a process that complies with NIST's Incident Response Guidelines.&lt;/li&gt;
&lt;li&gt;Improve your team and yourself Incident Response processes by solving &lt;a href="https://www.wellarchitectedlabs.com/security/quests/quest_200_incident_response_day/" rel="noopener noreferrer"&gt; AWS's Well-Architected Labs&lt;/a&gt;
&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;If you have any suggestions for the article, please feel free to contact me through any communication channel (Linkedin, Twitter, Threema, etc.). I am constantly updating the articles in line with your feedback.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>cloud</category>
    </item>
    <item>
      <title>Detection of Malicious Content in Files Uploaded to S3 Bucket</title>
      <dc:creator>Mehmet Ayberk</dc:creator>
      <pubDate>Thu, 07 Apr 2022 18:37:02 +0000</pubDate>
      <link>https://forem.com/mhmtayberk/detection-of-malicious-content-in-files-uploaded-to-s3-bucket-42og</link>
      <guid>https://forem.com/mhmtayberk/detection-of-malicious-content-in-files-uploaded-to-s3-bucket-42og</guid>
      <description>&lt;h2&gt;
  
  
  TLDR;
&lt;/h2&gt;

&lt;p&gt;No service scans for malicious content on files uploaded to S3 Buckets on AWS. There are some free and paid 3rd solutions to this problem. This article focuses on installing and using one of these open source solutions, along with a brief introduction to paid and other free solutions. We will briefly talk about S3 Antiviruses.&lt;/p&gt;

&lt;h2&gt;
  
  
  The Problem
&lt;/h2&gt;

&lt;p&gt;Undoubtedly, S3 is one of the most frequently used services of AWS. You can keep the files uploaded to your applications on S3, use it to store log files, and use S3 for almost any build that requires storage. This will be completely tailored to your needs. Of course, in some scenarios, you may want the files uploaded to S3 to be viewed and/or downloaded by the end-users of your application. At this point, you can use Macie, a service of AWS, to detect sensitive data in the files uploaded to your S3 Bucket and take necessary actions regarding this data. So, isn't it important to check whether the files uploaded to your S3 Bucket contain harmful content? At this point, there is no service available from AWS. But of course, there is a solution to this too. It even has multiple solutions. In this blogpost, I will tell you how we can detect harmful content uploaded to S3 Buckets.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with BucketAV (ClamAV)
&lt;/h2&gt;

&lt;p&gt;BucketAV offers both free and paid solutions. In this blog post, I will focus on the free and open-source version. You can find detailed information about the paid version &lt;a href="https://bucketav.com/" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Let's take a closer look at this solution and experience it by installing it in our AWS environment. It is really simple to set up and use. CloudFormation Templates perform most of the configurations we need to do.&lt;/p&gt;

&lt;h3&gt;
  
  
  Some Feature The Project
&lt;/h3&gt;

&lt;ul&gt;
&lt;li&gt;It uses ClamAV to detect harmful content and its signature database is constantly updated.&lt;/li&gt;
&lt;li&gt;It automatically deletes harmful content from S3 Bucket. (Optionally)&lt;/li&gt;
&lt;li&gt;When a malicious file is uploaded to Bucket, it can send a Mail notification via SNS.&lt;/li&gt;
&lt;li&gt;Logs to CloudWatch.&lt;/li&gt;
&lt;li&gt;An EC2 wakes up the machine and the system runs there. At this point, it automatically scales the machines. (The reason it needs an EC2 machine is that it uses the clamscan command for malicious content detection.)&lt;/li&gt;
&lt;/ul&gt;

&lt;h3&gt;
  
  
  Installation
&lt;/h3&gt;

&lt;p&gt;As I said before, the installation is quite simple. We'll be installing using CloudFormation Templates soon, but let's talk about what these Templates do in the background.&lt;/p&gt;

&lt;p&gt;The first template we will use creates public and private subnets in two different AZs using VPC. Of course, it also makes Route Tables for these subnets, Internet Gateway, and Network ACL settings for the Public subnet. You can analyze it yourself by downloading the Template we use from &lt;a href="https://s3-eu-west-1.amazonaws.com/widdix-aws-cf-templates-releases-eu-west-1/stable/vpc/vpc-2azs.yaml" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;The other template we will use is to set up the EC2 instance, configure the Auto Scaling Group, and make all other settings such as SQS, SNS, and CloudWatch. In other words, the main template that helps us to solve the problem we focus on is this second template.  You can analyze it yourself by downloading the Template we use from &lt;a href="https://s3-eu-west-1.amazonaws.com/widdix-aws-s3-virusscan/template.yaml" rel="noopener noreferrer"&gt;here.&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;For installation, let's set up our first template on AWS from &lt;a href="https://console.aws.amazon.com/cloudformation/home#/stacks/create/review?templateURL=https://s3-eu-west-1.amazonaws.com/widdix-aws-cf-templates-releases-eu-west-1/stable/vpc/vpc-2azs.yaml&amp;amp;stackName=vpc" rel="noopener noreferrer"&gt;here.&lt;/a&gt; We don't need to make any changes to the settings for this first stack. If the installation of this stack is completed without encountering any errors, it means that we can proceed to the installation of the other template.&lt;/p&gt;

&lt;p&gt;You can install the second template directly from &lt;a href="https://console.aws.amazon.com/cloudformation/home#/stacks/create/review?templateURL=https://s3-eu-west-1.amazonaws.com/widdix-aws-s3-virusscan/template.yaml&amp;amp;stackName=s3-virusscan&amp;amp;param_ParentVPCStack=vpc" rel="noopener noreferrer"&gt;here.&lt;/a&gt; I performed these installations in the us-east-1 (N. Virginia) Region.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fstack-2-installation.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fstack-2-installation.png" alt="Stack Installation" width="800" height="590"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;There is no need to explain each setting in this area one by one. Clear explanations have already been made. I just continued by changing the &lt;strong&gt;InstanceType&lt;/strong&gt; value under EC2 Parameters from t2.small to t2.micro. You can also change other settings according to your preference. If this resulted in CREATE_COMPLETE on the stack, great! We can continue on our way.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-stack-complete.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-stack-complete.png" alt="Stack Installation Complete" width="580" height="708"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Now we need to make some settings from the S3 Bucket that we want to be scanned. I created a test Bucket named s3-virus-scan-bucket in the same Region. In case a new object is uploaded to this Bucket, we need to create a new Event so that it can be scanned and the relevant actions can be taken. For this, we click the "Create event notification" button from the &lt;strong&gt;Event Notification&lt;/strong&gt; field under the &lt;strong&gt;Properties&lt;/strong&gt; tab. In the &lt;strong&gt;Event Type&lt;/strong&gt; field, you need to select the "All object create event" option. In the &lt;strong&gt;Destination&lt;/strong&gt; field, you have to choose SQS Queue and choose the &lt;strong&gt;non-DLQ&lt;/strong&gt; option at the end. You can see this area in the picture below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-s3-event-sqs.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-s3-event-sqs.png" alt="S3 Bucket SQS Event" width="800" height="552"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can record the Event without making any other settings. From this point on, every object uploaded to the relevant S3 Bucket will be first scanned by ClamAV, if there is no harmful content, the relevant file will be stored in the Bucket, if there is any harmful content, the relevant file will be deleted.&lt;/p&gt;

&lt;p&gt;Finally, let's make the relevant settings to receive e-mail notification via SNS in case of a malicious file upload and test the system we have created. You will see that a new Topic is automatically created under the &lt;strong&gt;SNS&lt;/strong&gt; service. All we have to do is create a new Subscription for this Topic. Just click the "Create subscription" button and then choose E-Mail as Protocol to continue. There will be no other adjustments you need to make. Finally, confirm the Subscription Confirmation e-mail sent to the e-mail address you provided.&lt;/p&gt;

&lt;h3&gt;
  
  
  Test
&lt;/h3&gt;

&lt;p&gt;Everything is ready now. We can test the system. For this, I upload a harmless txt file called justAtxt and two file called malware.ex_ and AzorultPasswordStealer.bin which is known to be harmful. The malware.ex_ file is a file belonging to the Stuxnet malware and the AzorultPasswordStealer.bin file is a file belonging to the Azorult Stealer. So they are quite popular.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-files-upload.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-files-upload.png" alt="S3 File Upload" width="800" height="274"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Just a few seconds after uploading the relevant files, I see that I receive mail via SNS.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-sns-mail.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fs3-av-sns-mail.png" alt="Malicious File Mail Notification" width="800" height="315"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, when we look at the S3 Bucket, where we upload the files, we see that the related files have been deleted, but our harmless file is still with us. While installing the CloudFormation Template, you can specify settings such as not deleting the uploaded files even though they are harmful, scanning only, notifying them by mail, and tagging harmful files.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with ClamAV (Another Way)
&lt;/h2&gt;

&lt;p&gt;While researching on this subject, I came across a very nice open-source project (&lt;a href="https://github.com/bluesentry/bucket-antivirus-function" rel="noopener noreferrer"&gt;bucket-antivirus-function&lt;/a&gt;). This project allows scanning of new objects uploaded to S3 Buckets with the help of AWS Lambda. This tool scans files uploaded to S3 with ClamAV and deletes them if they contain harmful content. With the CloudFormation Template can be installed quite easily with a few manual steps. You can check the GitHub Repo for detailed information and installation stages.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with Trend Micro Cloud One
&lt;/h2&gt;

&lt;p&gt;Trend Micro Cloud One is a paid solution. You can use Trend Micro Cloud One Yu not only to scan files uploaded to S3 Buckets but also as a security solution at many points related to your cloud environments. I cannot give a positive or negative comment as I have not used this product except for a few PoCs and demos. I wanted to include it in the scope of Blogpost as it provides a solution to our problem. Briefly, the working structure of Cloud One is explained in the image below. (Screenshot taken from Trend Micro documentation.)&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Ftrend-micro-cloud-one-s3-av.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Ftrend-micro-cloud-one-s3-av.png" alt="Trend Micro Cloud One S3 Antivirus" width="800" height="409"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;In addition, the Cloud One platform has a wider variety of capabilities. You can find detailed information &lt;a href="https://aws.amazon.com/blogs/apn/amazon-s3-malware-scanning-using-trend-micro-cloud-one-and-aws-security-hub/" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with Kaspersky Scan Engine
&lt;/h2&gt;

&lt;p&gt;Kaspersky Scan Engine is a paid solution just like Trend Micro Cloud One. This platform can scan objects uploaded to S3, as well as to detect insecure configurations in Kubernetes and Docker configurations, and scan a wider variety of cloud platforms. You can find detailed information &lt;a href="https://www.kaspersky.com/scan-engine" rel="noopener noreferrer"&gt;here&lt;/a&gt;.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with Cloud Storage Security
&lt;/h2&gt;

&lt;p&gt;Products are available on the AWS Marketplace of &lt;a href="https://aws.amazon.com/marketplace/seller-profile?id=6ca3cdf7-b551-4872-b1cf-2f818b397df3&amp;amp;ref=dtl_B089QBV2GC" rel="noopener noreferrer"&gt;Cloud Storage Security&lt;/a&gt;. This product can tag, delete or quarantine scanned malicious items just like any other product. In addition, findings from API-driven, real-time, and scheduled scans are published on the AWS Security Hub. These AV products of Cloud Storage Security are also paid. But there are also free trial versions.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with Scanii
&lt;/h2&gt;

&lt;p&gt;Another paid solution is &lt;a href="https://scanii.com/" rel="noopener noreferrer"&gt;Scanii&lt;/a&gt;. Scanii can scan for vulnerabilities on S3 Bucket with the help of AWS Lambda. It is very simple to set up and use.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets with BinaryAlert
&lt;/h2&gt;

&lt;p&gt;According to its own explanations, &lt;a href="https://www.binaryalert.io/" rel="noopener noreferrer"&gt;BinaryAlert&lt;/a&gt;;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;BinaryAlert is a serverless, real-time framework for detecting malicious files. Organizations can deploy BinaryAlert to their AWS account in a matter of minutes, allowing them to analyze internal files and documents within the confines of their own environment.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Since it has very detailed documentation, it can be easily installed and used.&lt;/p&gt;

&lt;h2&gt;
  
  
  Detection of Malicious File Uploaded to S3 Buckets ClamAV and CDK
&lt;/h2&gt;

&lt;p&gt;While doing my research, I came across a &lt;a href="https://aws.amazon.com/blogs/developer/virus-scan-s3-buckets-with-a-serverless-clamav-based-cdk-construct/" rel="noopener noreferrer"&gt;blogpost&lt;/a&gt; from AWS. By using aws-cdk it satisfies the need we mentioned. You can find detailed information in the related blog post. The working logic is illustrated in the image below.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fserverless-clamscan.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media2.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fayberk.ninja%2Fassets%2Fblog-photos%2Fs3-antivirus%2Fserverless-clamscan.png" alt="Serverless ClamScan" width="800" height="450"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;h2&gt;
  
  
  Feedback
&lt;/h2&gt;

&lt;p&gt;In addition to all these, I recommend you to follow the steps in the &lt;a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/security-best-practices.html" rel="noopener noreferrer"&gt;Security Best Practices for Amazon S3&lt;/a&gt; document published by Amazon. This was the first article I wrote in English. So, if there are points that I have mistranslated, please do not be offended. You can contact me through any channel on any technical and/or non-technical issue.&lt;/p&gt;

</description>
      <category>aws</category>
      <category>security</category>
      <category>s3</category>
      <category>cloud</category>
    </item>
  </channel>
</rss>
