<?xml version="1.0" encoding="UTF-8"?><rss xmlns:dc="http://purl.org/dc/elements/1.1/" xmlns:content="http://purl.org/rss/1.0/modules/content/" xmlns:atom="http://www.w3.org/2005/Atom" version="2.0" xmlns:cc="http://cyber.law.harvard.edu/rss/creativeCommonsRssModule.html">
    <channel>
        <title><![CDATA[Stories by Paweł Kusiński on Medium]]></title>
        <description><![CDATA[Stories by Paweł Kusiński on Medium]]></description>
        <link>https://medium.com/@pkusik?source=rss-49faa4969b68------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*j7wbkXqBl-EOG3tjjaYZVQ.jpeg</url>
            <title>Stories by Paweł Kusiński on Medium</title>
            <link>https://medium.com/@pkusik?source=rss-49faa4969b68------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 21 Nov 2026 08:16:25 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@pkusik/feed" rel="self" type="application/rss+xml"/>
        <webMaster><![CDATA[yourfriends@medium.com]]></webMaster>
        <atom:link href="http://medium.superfeedr.com/" rel="hub"/>
        <item>
            <title><![CDATA[Setting up your AWS Monitoring — Security tips]]></title>
            <link>https://medium.com/securing/setting-up-your-aws-monitoring-security-tips-c71c8e7fe816?source=rss-49faa4969b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/c71c8e7fe816</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[monitoring]]></category>
            <category><![CDATA[cybersecurity-awareness]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[cloud]]></category>
            <dc:creator><![CDATA[Paweł Kusiński]]></dc:creator>
            <pubDate>Mon, 07 Mar 2022 09:49:00 GMT</pubDate>
            <atom:updated>2022-03-08T08:14:03.675Z</atom:updated>
            <content:encoded><![CDATA[<h3>Setting up your AWS Monitoring — Security tips</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BYqK0_us95IotlzO.jpg" /></figure><p>AWS offers many services for different tasks, sometimes it even looks like multiple solutions try to solve the same problem. Choosing the right one could be challenging — that’s why I thought up about writing this article. It contains a little sum-up of the most important monitoring services offered by AWS, short guides on how to set them up, and as an addition — a few known evasion techniques collected in one place.</p><p>The content of this post may be updated with further services (or our research if new evasion techniques appear).</p><p>List of AWS services and evasion techniques covered in the article:</p><p>1. Monitoring Services</p><ul><li>Budgets — manage your cost limits</li><li>CloudTrail — watch over AWS API calls</li><li>Config — inspect your configuration history</li><li>GuardDuty — detect suspicious activity</li><li>Terraform — create the services with one command</li></ul><p>2. Evasion techniques</p><p>▹Cheating the GuardDuty</p><ul><li>PenTest Finding</li><li>InstanceCredentialExfiltration Finding</li></ul><h3>AWS Monitoring Services</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*sMFGWBXbY0l3kudW.png" /></figure><p>Monitoring for Amazon Web Services is a collection of procedures for ensuring the security and performance of your AWS resources and data. To acquire, analyze, and communicate data insights, AWS relies on a variety of technologies and services.</p><p>I have listed these kinds of services further in this article. Information gathered by them may then be used to spot vulnerabilities and faults, detect indicators of compromise, and improve setups.</p><h3>Budgets — manage your cost limits</h3><p>AWS Budgets in the simplest words allows you to <strong>track your costs</strong> and the most important useful feature is setting a threshold that will <strong>automatically notify</strong> you by email or SMS when this limit will be exceeded.</p><p>Furthermore, creating a budget is free and more specifically, the first two action-enabled budgets are free (regardless of the number of configured actions). That should be enough for most of you, and I believe that 0.10 $ per day (for every next budget) won’t kill any company which needs more of them 😉</p><p>Why do I think it is necessary to configure at least one budget? Notifications about exceeding a limit could simply inform you that you forgot to disable some services, or that <strong>someone is trying to abuse your account</strong>!</p><p>There are a lot of threat actors who want to gain access to your AWS account just to set up as many biggest EC2 instances as possible to mine some cryptocurrencies — and the bill for that could be a real killer!</p><p>If You don’t believe me, look at this (already archived) <a href="https://web.archive.org/web/20190903185201/https:/www.olindata.com/en/blog/2017/04/spending-100k-usd-45-days-amazon-web-services">article</a> from 2017 which describes how little less than 5 days was enough to create a cost of nearly 100k USD.</p><h4>How to configure AWS Budgets?</h4><p>It is important to know that AWS Budgets are <strong>only accessible for root accounts by default</strong>, but it is possible to <strong>manage access</strong> to it <strong>using IAM permissions</strong>. To change it, you have to login as a root, go to the Account settings:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/495/0*6Pwmr1DoOqNKlzFY.png" /></figure><p>Then scroll down to the <em>IAM User and Role Access to Billing Information</em> section:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*KLQlFWf0IIvwqWdP.png" /></figure><p>And change it to allow managing access by IAM:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/524/0*xGcjjq6Kovb6gByg.png" /></figure><p>Description of creating a budget from CLI could be too long for this article, as it requires creating a JSON file with details of the budget, so for now I will send you a link to relevant AWS CLI docs — description of <a href="https://docs.aws.amazon.com/cli/latest/reference/budgets/create-budget.html">create-budget</a> call and <a href="https://docs.aws.amazon.com/cli/latest/reference/budgets/create-notification.html">create-notification</a>.</p><p>Now, I’m going to describe the Console configuration of the Cost Budget.</p><p>Firstly, go to the AWS Budgets service and start the process with <em>Create a Budget</em> button. Choose <em>Cost Budget</em>. First configuration options are presented below:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LxE4_xSKRZLj2218.png" /></figure><p>The next step is configuration of email notifications alerts.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*7sMYbSlAuuLl2YyH.png" /></figure><p>Or SNS alerts (which will allow SMS notifications):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/672/0*Wfu9-EzUVa8o44sv.png" /></figure><p>To use SNS, you have to create Standard queue with the following Access Policy:</p><pre>{<br>    &quot;Version&quot;: &quot;2012-10-17&quot;,<br>    &quot;Statement&quot;: [<br>        {<br>            &quot;Sid&quot;: &quot;AWSBudgetsSNSPublishingPermissions&quot;,<br>            &quot;Effect&quot;: &quot;Allow&quot;,<br>            &quot;Principal&quot;: {<br>              &quot;Service&quot;: &quot;budgets.amazonaws.com&quot;<br>            },<br>            &quot;Action&quot;: &quot;SNS:Publish&quot;,<br>            &quot;Resource&quot;: &quot;&lt;Budget_ARN&gt;&quot;<br>          }<br>    ]<br>}</pre><p>Remember also to set up subscription to the topic, to actually get these alerts:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/516/0*8Ig9ZDur3g94TkNh.png" /></figure><p>That’s all — basic Budget configuration is done.</p><h4>Short sum up</h4><p>Is it needed or recommended? <strong>Needed</strong>. It creates a possibility of early detecting an attack which tries to spawn cryptominers or do other costly operations.</p><p>How hard is it to implement? Subjectively — <strong>easy</strong>.</p><p>Price? <strong>Free </strong>(in most basic use cases).</p><h3>CloudTrail — watch over AWS API calls</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VB-ncRZZh5Rmvbty.png" /></figure><p>Is there any service that should be enabled by default as a first step when creating a new AWS Account? <strong>Yes </strong>— that’s a CloudTrail. It logs AWS API calls — basically that gives us information about <strong>everything </strong>that happens in our account:</p><ul><li><strong>Who </strong>made an API call?</li><li><strong>When </strong>was the API call made?</li><li><strong>What </strong>was the API call?</li><li><strong>Which </strong>resources were involved in the API call?</li><li><strong>Where </strong>did the API call come from and where it goes?</li></ul><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*LrusXvp0VGprQCMe.png" /></figure><p>Without CloudTrail, we won’t know if there is any suspicious activity on our account.</p><p>Furthermore, CloudTrail could be easily integrated with other AWS services. We can for example stream logs to the CloudWatch and create alarms for specific API calls or even define automatic actions, like running Lambda functions which will verify our configuration or try to limit someone’s actions.</p><p>It’s worth mentioning that there are some actions that aren’t <strong>logged by default</strong>, for example, S3 bucket read &amp; write events or Lambda invocations. It’s possible to enable logging of them and that’s called <strong>Data Events</strong>, but it’s paid functionality. A little more about it could be found in AWS documentation <a href="https://docs.aws.amazon.com/awscloudtrail/latest/userguide/logging-data-events-with-cloudtrail.html">here</a>. It’s worth giving a thought on logging for example access to buckets with sensitive data.</p><h4>How to configure CloudTrail?</h4><h4>Single account</h4><p>Configuration on a single account is really quick and simple.</p><p>It could be done using cli with these commands:</p><pre>aws cloudtrail create-trail --name [trail_name] --s3-bucket-name [bucket_name] --include-global-service-events --is-multi-region-trail --enable-log-file-validation --cloud-watch-logs-log-group-arn [cloud_watch_logs_group_arn] --cloud-watch-logs-role-arn [role_arn] --kms-key-id [kms_arn_or_alias]<br>aws cloudtrail start-logging --name [trail_name]</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*kHzniHRc0LOL9UZz.png" /></figure><p>Any cons? You have to prepare S3 Bucket before running the command. Also if you want to encrypt the trail and stream it to the CloudWatch — encryption key, log group and correct role have to be also prepared beforehand.</p><p>For a single account it would be easier to use the console as it creates all the needed resources during the process. In order to do that, navigate to the CloudTrail service and go to <em>Trails</em>, then click <em>Create trail</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*3h0xVYmhM5FMPHmD.png" /></figure><p>Then choose desirable options, for example:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/847/0*Kp2F3b78PAFcX9Sa.png" /></figure><p>It is also possible to configure CloudWatch Logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/846/0*OTem3sI5ADjFV5Qi.png" /></figure><p>Second step would be configuring log events:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/875/0*tqwZr2SB-vpcwAsq.png" /></figure><p>Important! By default, data events (e.g. S3 or DynamoDB read &amp; write events, Lambda executions) aren’t logged. Also, keep in mind that those functionalities are paid. It can be configured during the second step:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/850/0*6EQr5gmxWEwtjtM3.png" /></figure><p>And with that we created a new trail!</p><h4>Short sum up</h4><p>Is it needed or recommended? <strong>Definitely Needed</strong>. Without CloudTrail, we don’t know what’s going on within our account. Moreover, sometimes other services also make use of CloudTrail.</p><p>How hard to implement?</p><ul><li>Single account — <strong>easy</strong></li><li>Organization — <strong>medium </strong>(it is rather easy, but there could be some problems when doing it the first time with separate bucket on another account and with encryption)</li></ul><p>Price? <strong>It depends</strong> — Single account and organizational trail, without data events would be <strong>free</strong>. Data events cost 0,10$ per 100k events. Every new trail would be billed 2$ per 100k management event.</p><h3>Config — inspect your configuration history</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*BBhUKrHjpc7ThX2A.png" /></figure><p>AWS Config is a great service not only from a security point of view but also for debugging/development purposes. The basic functionality of the Config is to <strong>record all of the configuration changes</strong> — it will create a history of every change for every recorded resource, for example, Security Group:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*VeLVRFpyVCF-RdNT.png" /></figure><p>It has some delay before displaying the changes, so don’t worry if your Config won’t work immediately after modifying some resources.</p><p>Furthermore, there are Config Rules — their task is to <strong>monitor our resources for compliance</strong>. In case of detecting non-compliant resources (for example, users without MFA enabled) it would notify admins. It is possible to configure some automated actions in case of occurrence of these alarms — It may be used to change the configuration to the compliant one, or to delete it.</p><p>Worth mentioning is the fact that it is possible to create your own Config Rules using Lambda functions. There is also a whole <a href="https://github.com/awslabs/aws-config-rules">Github Repository</a> with rules created by the AWS community!</p><p>It is a nice option to have in case of forensics analysis — it will allow you to find every modified resource and find for example created backdoors.</p><h4>How to set up AWS Config?</h4><h4>Single Account</h4><p>There is an option in the Console for <em>1-click setup</em> which creates a default AWS Config:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1018/0*WKZJpp7GuJSHHVKT.png" /></figure><p>Alternatively, you can use <em>Get started</em> button with more advanced options:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1020/0*oYAQAeU29TG-lceD.png" /></figure><p>Remember, that AWS Config is a regional service — if you want to use it in a few regions, you have to set it up in every one of them.</p><h4>Short sum up</h4><p>Is it needed or recommended? <strong>Recommended to set up in every enabled region</strong>. Mostly forensic helper, but could also help to find created backdoors and other modified resources during the attack.</p><p>How hard to implement?</p><ul><li>Single account — <strong>easy</strong></li><li>Organization — <strong>medium/hard</strong> (AWS Config has to be configured in every region/account which we want to monitor, and then it’s possible to aggregate all of it in a single view in single account using aggregator)</li></ul><p>Price?<strong> $0.003 per configuration item recorded + Rules per number of evaluations</strong> (<a href="https://aws.amazon.com/config/pricing/">details</a>)</p><p>Because pricing of AWS Config is based on the amount of records, it is recommended to set up in every region! It should be free for unused regions, but in case of the attack, it gives visibility of changes done by an attacker in unused regions.</p><h3>GuardDuty — detect suspicious activity</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*Y1Iy_iKuJxScxvHD.png" /></figure><p>GuardDuty is one of the services which makes use of machine learning. It will <strong>analyze your logs</strong> from different sources (CloudTrail, Flow logs, and DNS logs) for default checks, like signs of compromise or connection to the known bad actor IP.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*SScSY9WMYG2uU3q7.png" /></figure><p>Where is machine learning in all of it? GuardDuty <strong>continuously tries to learn how you use your AWS account</strong>, which user or role does what. After some time of using it, it will start to notify you about <strong>suspicious activity</strong> — for example, if one of the users always uses only S3 API calls, but suddenly EC2 or IAM API calls are made, GuardDuty should notify you about it. It gives a possibility of finding a stealthy attacker in our infrastructure.</p><h4>How to configure GuardDuty?</h4><h4>Single account</h4><p>Probably one of the fastest instruction — using CLI:</p><p><em>aws guardduty create-detector –enable</em></p><p>And when using Console — goto the GuardDuty service, click <em>Get Started!</em> and then <em>Enable GuardDuty</em> — no additional configuration is required in basic situations. You can set additional things like allowlist of IPs which won’t set off GuardDuty alarms, but I’m leaving it to you for exploration!</p><h4>Short sum up</h4><p>Is it needed or recommended? <strong>Recommended to set up in every enabled region</strong>. Detector of suspicious activity or obvious indicators of compromise.</p><p>How hard to implement?</p><ul><li>Single account — <strong>easy</strong></li></ul><p>Price? <strong>Price is based on amount of analyzed logs</strong> (<a href="https://aws.amazon.com/guardduty/pricing/">details</a>)</p><p>In unused regions, there shouldn’t be any logs — because of that, GuardDuty won’t additionally charge you. In case of any unusual actions in unused regions, it could detect it and notify you about possible indicators of compromise.</p><h3>Terraform — create the services with one command</h3><p>I really like to use Terraform when it comes to managing cloud services. Nearly the whole infrastructure and labs for our <a href="https://www.securing.pl/en/training/overview/practical-aws-security-training/">Practical AWS Security Training</a> are coded in it. That’s why I created a terraform script for deploying described services, as it is probably preferred over a CLI or Console configuration.</p><p>For now, it’s mainly for usage on a single account (I want to update it later together with this article). It could be used as a whole package, where setting <em>terraform.tfvars</em> gives you an option for fast configuration. It is also possible for you to copy single modules and modify them to your liking.</p><p><strong>You can find the code 👉 </strong><a href="https://github.com/securing/aws_monitoring_terraform"><strong>here</strong></a><strong>.</strong></p><p>I’m also open to suggestions on how to make these scripts better! I was a self-learner with Terraform, and I used a few hacks to automate it as much as possible — if something could be done better, let me know (or maybe you will learn something from mine hacks ;)).</p><h3>Evasion techniques in AWS</h3><p>Threat actors utilize evasion techniques to escape detection by monitoring services. Attackers have two goals when taking over the cloud infrastructure: to be silent and stay lethal, to obtain as much as possible for as little effort.</p><h3>Cheating the GuardDuty</h3><h4>PenTest Finding:</h4><p>Using common penetration testing distributions, like Kali Linux, Parrot Linux or Pentoo Linux will be detected by GuardDuty and will trigger a <a href="https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_finding-types-iam.html#pentest-iam-kalilinux">PenTest Finding</a>.</p><p>How is it done? If we will look up into the code of the <em>botocore</em> package (used by <em>awscli</em>), and more precisely into <em>session.py code</em>, we can find this fragment of the code:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/595/0*pY-mqlIY04xNYRmA.png" /></figure><p><em>platform.system() </em>and <em>platform.release()</em> are similar to <em>uname -o </em>and <em>uname -r</em>. It’s send along every our command, what we can verify by looking up into CloudTrail logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/674/0*ke0vg1WshfQnvr22.png" /></figure><p>The easiest way to evade this type of finding would be to replace <em>platform</em> calls with, for example, hardcoded “secure” versions of the OS.</p><p>The fastest way to find <em>session.py</em> is to use another Python package — <em>inspect</em>!:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/568/0*7322bqMmAVYYLn1O.png" /></figure><p>I’ve also created a little script which will try to replace both of these platform calls automatically:</p><p><a href="https://gist.github.com/Djkusik/88d06ebaf7fbf9b7db99798a9f07fb6f">https://gist.github.com/Djkusik/88d06ebaf7fbf9b7db99798a9f07fb6f</a></p><p>It will hardcode <em>Linux/4.16.0 </em>string into the library.</p><p><strong>Little disclaimer </strong>— I tested it only on Linux, I don’t know how it would work with Windows. Furthermore, <em>awscli </em>was installed using <em>pip </em>— I couldn’t make it work with installation from a zip downloaded from amazonaws. Also — any update of this package will overwrite the changes.</p><p>The best way to avoid these problems would be to monkey patch this function — for example by creating a wrapper for <em>awscli</em>.</p><p>So let’s try it in action! I’ve created two users — <em>kali_default</em> and <em>kali_modified </em>— the first one will make a few commands with default userAgent from Kali Linux.</p><p>Results?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*suZIdFoipYeV2Kxr.png" /></figure><p>After a few moments, we can see PenTest finding in our GuardDuty dashboard (this doesn’t work instantly after receiving the commands). We can also verify that by searching through CloudTrail logs, that userAgent is saying that we are using Kali Linux:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/702/0*-yid7CRqhUwCE4Gx.png" /></figure><p>So now, let’s run our script and send some commands again:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*qlKnQWUnJlF2jG0B.png" /></figure><p>I’ve waited, but GuardDuty stayed silent — let’s look up into the CloudTrail logs:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/619/0*dtJTabgCV__B_Kfm.png" /></figure><p>Everything worked, GuardDuty didn’t notice anything.</p><p>But to be honest — <strong>I really doubt that this finding would help</strong> — probably it could detect some script kiddies or irritate you during ordered pentests when someone will use Kali without hiding its release.</p><h3>InstanceCredentialExfiltration Finding</h3><p><strong>Update March 2022 — </strong>This issue is now fixed and GuardDuty informs us about usage of EC2 credentials from another AWS Account: <a href="https://gist.githubusercontent.com/0xdabbad00/e19a974c13c1d9249a242a9d3463bfbc/raw/a44e832dbfc91b275005d8774f97051ce0600d4c/InstanceCredentialExfiltration.InsideAWS">source</a>.</p><p><a href="https://docs.aws.amazon.com/guardduty/latest/ug/guardduty_finding-types-iam.html#unauthorizedaccess-iam-instancecredentialexfiltrationoutsideaws">InstanceCredentialExfiltration</a> finding of GuardDuty detects if:</p><blockquote><em>“Credentials that were created exclusively for an EC2 instance through an Instance launch role are being used from an external IP address”.</em></blockquote><p>In other words — it <strong>detects </strong>if <strong>someone is using</strong> our attached <strong>EC2 role</strong> outside of our EC2 instance. What could be ambiguous is “external IP address”, as there is a little problem. It doesn’t mean IP address outside of our infrastructure, it means <strong>IP address outside of AWS infrastructure</strong>. You could probably see the problem here now. Using exfiltrated credentials on your PC or from VPS of another cloud provider would set off an alarm, but using them <strong>on an EC2 instance</strong> (on a different account) wouldn’t!</p><p>Let’s test it.</p><p>I created two instances on one of my accounts and attached an IAM role to it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*llslDnlka1JllZk8.png" /></figure><p>I got <em>aws_access_key_id, aws_secret_access_key </em>and <em>aws_session_token </em>from both of them — by connecting through SSH and curling them from the metadata service for simplicity:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6XPDlRf2k9cTuNq2.png" /></figure><p>Firstly I tried to use the first set of credentials from my local PC (multiple times even outside of the screenshot):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*-nQrBhUK8LRBTVYT.png" /></figure><p>And as we can see, after few moments (to be honest — surprisingly long moments) a new finding shown in my GuardDuty console:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*2VbtbluLCied_LM6.png" /></figure><p>Then I created a new machine on another account:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/763/0*Kg4OgasB8PkvmmE3.png" /></figure><p>I connected to it and used second set of credentials from it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*vLyQUOXsp3HBSs8C.png" /></figure><p>As we can see in CloudTrail history, there are logs of using credentials from my second machine (<em>UndetectedInstanceCredentialExf </em>with ID <em>i-03e5a21f1026445af</em>):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*6wqPMZOHv2DwHzck.png" /></figure><p>GuardDuty stayed silent this time!</p><p>I feel sorry for how this finding works, as it could be a great detector for most ec2 credentials thefts, but in this situation, most of the experienced attackers would be able to easily evade it. From the other side — I also understand that upgrading GuardDuty to verify exact IP addresses at the time of API call is probably near to impossible (<strong>Update March 2022</strong> — I was wrong!).</p><h3>Last words</h3><p>As you can see, there are a lot of AWS monitoring services, it’s easy to get lost or forget about some of them. Each of them is built for a different purpose, which makes it even harder. That’s why I wanted to create this sum up of the most important ones and maintain this article up to date. Maybe even describe all of them.</p><p>During our <a href="https://www.securing.pl/en/training/overview/practical-aws-security-training/">Practical AWS Security training</a> we also present these services (and more) — we talk about e.g their use cases, pros and cons or discuss how to implement them in your company.</p><p>If you want to ask me something or discuss this article, you can catch me by messaging through my <a href="https://linkedin.com/in/pkusik">LinkedIn</a> or <a href="https://twitter.com/_pkusik">Twitter</a> account!</p><p>If you have any questions about this article feel free to <a href="https://www.securing.pl/en/contact">contact us</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c71c8e7fe816" width="1" height="1" alt=""><hr><p><a href="https://medium.com/securing/setting-up-your-aws-monitoring-security-tips-c71c8e7fe816">Setting up your AWS Monitoring — Security tips</a> was originally published in <a href="https://medium.com/securing">SecuRing</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Top 7 AWS security vulnerabilities based on real-world tests]]></title>
            <link>https://medium.com/securing/top-7-aws-security-vulnerabilities-based-on-real-world-tests-2f65ee1f79c5?source=rss-49faa4969b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/2f65ee1f79c5</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[cybersecurity-awareness]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cloud-security]]></category>
            <dc:creator><![CDATA[Paweł Kusiński]]></dc:creator>
            <pubDate>Thu, 19 Aug 2021 12:25:04 GMT</pubDate>
            <atom:updated>2021-08-19T12:25:04.032Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*C0P9UnYiCCB6rIKE0W9epw.jpeg" /></figure><p>Imagine you ordered a security assessment of your AWS infrastructure, hoping that the report would be juicy in wicked hacking techniques. However, the document starts with things like “Lack of MFA for users” or “Lack of Log File Validation”. These security misconfigurations might sound a little disappointing right? Let me show you why these findings could be a real threat or even a business killer in some cases.</p><p>In this article, I’ll focus on the most common vulnerabilities (according to our own tests), that are exploitable and could lead to unpleasant consequences.</p><p>To give you a bit of a heads up — below is a list of vulnerabilities that are discussed later in this article:</p><ol><li>Sensitive data in X in plaintext</li><li>Publicly accessible SQS</li><li>Publicly accessible S3</li><li>Privilege escalation</li><li>Wide cross-account access</li><li>Lack of monitoring</li><li>Lack of Transfer Lock</li></ol><p><strong>Disclaimer </strong>— probably you would be a little surprised that I’m not writing about the most popular AWS vulnerabilities overall, but that’s because they are already well known and described — highlighting the less obvious ones may be more beneficial for the community 😉</p><p>About risk level — it always depends on the case, and it could differ. In this article, I categorized the risks as they appear in our reports.</p><h3>1. Sensitive data in X in plaintext</h3><p>First things first — what could be X? EC2 User Data, EC2 Auto Scaling Launch configuration, Lambda environment variables, Elastic Beanstalk environment variables, CloudFormation Stack parameters — these are places where we are often finding <strong>unencrypted and hardcoded secrets</strong>.</p><p>Secrets could be retrieved by any user with suitable privileges (for example ec2:DescribeInstances or autoscaling:DescribeLaunchConfigurations). The severity of this issue depends on the nature of the secret. Usually, it is rated as medium or high risk, based on the following factors:</p><ol><li>Privileges needed to read secrets are <strong>commonly used</strong> by a client, probably unconsciously as they aren’t required for most of the users/roles to do their work.</li><li>Secrets found may have critical risk impact — Jira recovery admin password, Gitlab runner credentials, Sonar credentials, credentials to monitoring services — to sum up, services with <strong>access to our code repositories, internal discussions, bugs, documentation</strong> — a lot of data which shouldn’t be accessible for an anonymous user.</li><li>As our red team tests show, it is always possible to own an account within the company by targeted phishing. It isn’t the hardest thing to takeover a developer account, read the credentials and get access to a lot of things, or escalate further inside a private network.</li></ol><p>Risk: Medium or high.</p><p><strong>Hint</strong>: Store your secrets in AWS Secret Manager! You could also use the Systems Manager Parameter Store (but remember to use encrypted parameters!).</p><h3>2. Publicly accessible SQS</h3><p>Publicly accessible SQS indicates that it is possible to read messages from it. We found that typically if SQS is opened to read, it is also opened to write or delete. All of this means that <strong>anonymous user</strong> can <strong>read </strong>messages, <strong>write </strong>some malicious data, or <strong>delete </strong>real messages before they are handled by your code.</p><p><strong>Leaking sensitive data, Denial-of-Service</strong> of an application, executing malicious tasks — these are a few of the consequences, as it depends on how you use SQS.</p><p>Risk: High</p><p><strong>Hint</strong>: Modify queue Access policy — disallow public access, configure access only for services that actually need it.</p><h3>3. Publicly accessible S3</h3><p>As my last <a href="https://www.securing.pl/en/what-can-you-find-in-57k-aws-s3-buckets-2021-update/">research</a> shows, public buckets are still a problem. During our assessments, we often find <strong>publicly readable</strong> buckets, sometimes even <strong>writable</strong>. It means that an anonymous user can read stored data and in the worst-case scenario — overwrite it (which is equivalent to deleting it, if Versioning is disabled) or host malicious content using our bucket. If the bucket is hosting static content, then having write privilege gives an option to <strong>change anything</strong> inside and for example inject XSS.</p><p>Risk: From low to high (highly depends on the content and privileges of the bucket)</p><p><strong>Hint</strong>: Disallow public read access (until it’s a static content bucket) and write access using ACLs or Bucket policy. Turn on Block Public Access options if you want to ensure it.</p><h3>4. Privilege escalation</h3><p>Privilege escalation is a classical vulnerability that allows obtaining more privileges than one account originally had. For example, a typical case is to give an employee iam:PassRole and ec2:RunInstances permissions, to give it the ability to create a new EC2 instance and pass an existing role to it. If a role with higher privileges that could be assumed by EC2 exists, then this employee is able to escalate his privileges by creating a new instance with this role.</p><p>It is a common problem for AWS environments that grew quickly, managing a multi-account environment is a different thing and could be challenging. The second problem is trusting AWS Managed policies too much. They can offer way more privileges than is needed, which could create a situation where privilege escalation is possible. Also remember, that AWS updates these policies regularly. They could change them in a way, which could create escalation opportunities in your account.</p><p>Risk: High</p><p><strong>Hint</strong>: A simple recipe doesn’t exist in this case. If we know about privilege escalation, modify IAM policies to mitigate it. The most important thing is to prevent a situation like that — avoid Inline policies, use Least Privilege Principle when creating new policies, use Groups for user management. Remember that privilege escalation could be done using services like EC2 or Lambda, by passing the role.</p><h3>5. Wide cross-account access</h3><p>Using AWS Organizations and different AWS accounts for dividing projects and different stages (test, prod, etc.) is recommended. Employees in order to work, have to move in between different accounts, which could be done for example by obtaining temporary security credentials — in other words, assuming roles. But what could go wrong? What if Trust policies are misconfigured and anyone can assume the Admin role (privilege escalation scenario)? Imagine that everyone can access any account (also production stage). Owning one user account would be equal to obtaining access to every account.</p><p>Risk: Medium or high</p><p><strong>Hint</strong>: Limit the amount of people which can access production and security accounts. Use Least Privilege Principle — give access to the accounts which the employee really needs, not to everyone.</p><h3>6. Lack of monitoring</h3><p>That’s the common mistake — having monitoring services turned off or using them only in one or two regions. Without monitoring, we won’t know if there is any malicious movement. Furthermore, any forensic action would be impossible — we won’t know how an attacker gained access to which AWS account was used, or what was done — and in the case of monitoring only a few regions, the attacker could target unmonitored ones. The <strong>absolute minimum</strong> is to turn on CloudTrail in every enabled region.</p><p>Risk: Medium</p><p><strong>Hint</strong>: Make use of the AWS monitoring services — configure CloudTrail (and run it in every enabled region), turn on GuardDuty. Turning on AWS Config in the used regions could be also beneficial. There are other services which could help, but these are the few most important ones.</p><h3>7. Lack of Transfer Lock</h3><p>This is the vulnerability that is often overlooked — I also wasn’t sure if I should put this one here. The process of transferring the domain to another registrar seems secure enough. However, not so long ago Cyberis <a href="https://www.cyberis.co.uk/blog/domain-hijacking.html">identified</a> a vulnerability which <strong>enabled a possibility of domain hijacking</strong> by using logic error. Domain hijacking could be <strong>devastating</strong> for the company (both financially and PR), as it gives an attacker the ability to host a website under your domain. Turning Transfer Lock is really simple mitigation to a lot of problems from a situation like this.</p><p>Risk: Low</p><p><strong>Hint</strong>: Enable Transfer Lock option on your Route53 Domains.</p><h3>Conclusion</h3><p>I’ve described seven vulnerabilities, but remember — there is a lot more than that! I wanted to highlight the most common ones from our own reports. Maybe it’s not too loud about them, but they could lead to serious consequences. Misconfigurations like “Lack of MFA for users” or “Lack of Log File Validation” which I mentioned at the beginning, are also important — having modified logs probably isn’t the best thing for forensics.</p><p>I’m planning to describe some of these seven problems in the future — exploitations chains, full remediations and more detailed descriptions.</p><p>We recently updated <a href="https://www.securing.pl/en/seven-step-guide-to-securing-your-aws-kingdom/">our AWS guide</a> too. If you deal with these solutions on a daily basis, I am sure it will help you a lot:</p><p>If you want to be up to date with my cloud security work, you can also follow me on <a href="https://twitter.com/_pkusik">Twitter</a> and / or <a href="https://www.linkedin.com/in/pkusik/">Linkedin</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=2f65ee1f79c5" width="1" height="1" alt=""><hr><p><a href="https://medium.com/securing/top-7-aws-security-vulnerabilities-based-on-real-world-tests-2f65ee1f79c5">Top 7 AWS security vulnerabilities based on real-world tests</a> was originally published in <a href="https://medium.com/securing">SecuRing</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Buggy Doggo CTF — Python memory leak FTW!]]></title>
            <link>https://medium.com/@pkusik/buggy-doggo-ctf-python-memory-leak-ftw-3a015973e20e?source=rss-49faa4969b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a015973e20e</guid>
            <category><![CDATA[python]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[writeup]]></category>
            <dc:creator><![CDATA[Paweł Kusiński]]></dc:creator>
            <pubDate>Tue, 04 May 2021 09:03:00 GMT</pubDate>
            <atom:updated>2021-05-04T09:56:51.617Z</atom:updated>
            <content:encoded><![CDATA[<h3>Buggy Doggo CTF — Python memory leak FTW!</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*JRb8CUrzNYw4oMIr9i0sAA.png" /></figure><p>Last Saturday I received a message from my acquaintance — James Santiago — about a CTF hosted by <a href="https://twitter.com/bugpoc_official">BugPoc</a> and <a href="https://twitter.com/NahamSec">NahamSec</a>, sponsored by Amazon. I thought there would be a challenge connected with AWS security, but oh… the task surprised me and really got me hooked!</p><p>So if you want to know how I did my reconnaissance on AWS infrastructure and chained <strong>cryptographic attack</strong> with obfuscated <strong>path traversal</strong> to obtain a <strong>memory leak</strong> from the Python application — then get some snacks or something to drink and check it out!</p><h3>First things first — reconnaissance</h3><p>At the beginning of the challenge we obtained three pieces of information:</p><ol><li>The challenge domain is doggo.buggywebsite.com</li><li>The objective is to access Python variable called <strong>SECRET_API_KEY</strong></li><li>We have to find the memory leak</li></ol><h4>First look at the page</h4><p>Let’s then jump to the domain:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/929/1*gHPDXuCw5xY2AOhaEmNl2Q.png" /><figcaption>Sweet — a lot of dog pictures — it will be useful to soothe the nerves 😄</figcaption></figure><p>By looking at the proxy (Burp) it is possible to see these four requests:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/350/0*JgbgWT8jCLxcsUW5" /></figure><p>We’ve got a second domain — <em>doggo-api</em> — and also a script.js.</p><p>Let’s get a look at this script:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*R5NcJS_CSQyzZK_BW2fRHA.png" /><figcaption>deleted few unnecessary lines here</figcaption></figure><p>Again API domain with two endpoints (<em>/get-dogs</em>, <em>/fingerprint</em>) and a few base64-encoded strings.</p><p>Decoding base64 does nothing, as it is some encrypted data.</p><p>Verify these two endpoints, first <em>/fingerprint</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*JXp94cFcKEQxUihyWgt19A.png" /></figure><p>Returns base64-encoded ciphertext with a very similar-looking beginning — <strong>gAAAAABg</strong> — like hardcoded strings in JS file. Nothing else special here, let’s check <em>/get-dogs</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*4rVinkWWyiVhnQr6" /></figure><p>Returns dog pics from <strong>S3 Bucket</strong> — that’s something. Also two headers here</p><ul><li><em>x-param</em> — one of the hardcoded strings from JS</li><li><em>x-fingerprint</em> — the one returned from <em>/fingerprint</em>!</li></ul><p>Furthermore, by changing <em>x-param</em> to other hardcoded strings, the only different thing is a response path parameter, as it changes from <em>/dogs?page=1</em> to <em>page=2</em>, <em>3</em> and <em>4</em>. When trying to input another value, the server returns “<strong>ERROR: Unable to Decrypt</strong>”. Also if I tried to call <em>/dogs</em> myself, I received “<strong>Error, this endpoint is only internally accessible</strong>”.</p><p>What if we will use our <em>x-fingerprint</em> value as <em>x-param</em>?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/890/0*dX4zEqxigvJn_9cc" /></figure><p>Our <strong>User-Agent header value</strong> inside JSON! Nice — that’s the moment when I had some idea about it, but before going into explanation, let’s verify what we have there.</p><h4>Infrastructure</h4><p>Let’s <em>dig </em>some information about our domains with some further look using <em>nslookup</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/856/0*5FHCNj3KpnrsDL18" /></figure><p>Okay, second <strong>S3 Bucket</strong> and <strong>EC2 instance</strong>. I like buckets, especially the open ones 😉 so why not, let’s try some listing:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/711/0*SPXg8Cdgqdb76dY3" /></figure><p>Oh… Not this time. I also checked if they are writable, but unfortunately no.</p><p>Meanwhile, I started a <a href="https://github.com/OJ/gobuster"><strong>gobuster</strong></a><strong> dir scan</strong> using few lists from <a href="https://github.com/danielmiessler/SecLists/">SecLists</a> (Discovery <em>common.txt</em>, <em>quickhits.txt</em>, <em>py.txt</em>, <em>js.txt</em>) on the buckets (maybe some hidden downloadable file?) and domains. One of them was pretty successful!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/684/0*jC4PIonxiCkPaVNM" /></figure><p>There was an interesting finding, <strong><em>/heapdump</em> endpoint</strong>, which when used, returned:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/410/1*w3fzPoMQNGiEFBqyiXRrAg.png" /></figure><p>The same response when I tried to call <em>/dogs</em>!</p><h3>The theory</h3><p>At this stage, I jumped to two conclusions</p><ol><li>We have to call <em>/heapdump</em> by passing on properly crafted <em>x-param</em> value using /get-dogs API endpoint</li><li>We have to break encryption somehow</li></ol><p>And also, two possibilities how to do it:</p><ol><li>By analyzing the encryption, try to <strong>modify this ciphertext</strong> (Padding Oracle attack or some CBC modification)</li><li>By properly crafted User-Agent value <strong>generate ciphertext</strong> which will modify the JSON or be interpreted as <em>/heapdump</em> path (Signing Oracle attack)</li></ol><h3>Encryption</h3><p>By googling the phrase “gAAAAAB encryption”, I found that this one is <a href="https://cryptography.io/en/latest/fernet/">symmetric Fernet encryption</a>, and by looking at <a href="https://github.com/fernet/spec/blob/master/Spec.md">specification</a> I get to know that generated <em>token</em> is a concatenation of the following fields:</p><pre>Version ‖ Timestamp ‖ IV ‖ Ciphertext ‖ HMAC</pre><p>And verified this with ciphertexts generated by <em>/fingerprint</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/760/0*jBqWZpp0MIr_IspC" /><figcaption>Decryption code from <a href="https://asecuritysite.com/encryption/ferdecode">ASecuritySite</a></figcaption></figure><h4>Wrong idea</h4><p>I thought that maybe somehow HMAC is not verified and I will be able to tamper with the data (simple explanation about HMAC — it verifies data integrity and authenticity, as it hashes the message — first four fields in our case — using some secret key).</p><p>To be honest — I <strong>lost a few hours</strong> here trying to tamper it and it was awful, better don’t ask my friends about my comments. I won’t waste your time, so let’s jump to the right answer.</p><h4>Correct idea</h4><p>I got some sleep and went with my second thought — <strong>Signing Oracle attack</strong> — this one is possible if the same signing method and secret are used in two or more places. And this is our case — we can create proper ciphertexts using <em>/fingerprint</em> endpoint.</p><p>By fuzzing it a little, I discovered that almost all special characters are accessible (only <strong>“</strong> and <strong>\</strong> were escaped). There weren’t any SSTI or any other weird behaviour.</p><p>Let’s analyze it from the beginning as I did it. I started with value “test” as User-Agent and send the returned value as <em>x-param</em> to the <em>/get-dogs</em> endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/755/1*vG63QRd0b1OYuXaAzWOdIw.png" /></figure><p><strong>“/dogs{\”UA\”: \”test\”}”</strong> is our generated path. What is worth to notice, is that <strong>statusCode is 404 Not Found </strong>— that means the backend formats path value properly, as characters <strong>{</strong>, <strong>}</strong> and <strong>“</strong> without encoding would return 400 Bad Request.</p><p>So my thought — why lose time generating these ciphertexts, if I can try to request it directly — if I would achieve a response with an error about the internal endpoint, <strong>I would win</strong>.</p><h3>Path Traversal — obfuscation and security evasion</h3><p>So I encoded this path and tried to request it:</p><pre>/dogs%7b\%22UA\%22:+\%22test\%22%7d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*wZGc7rYzfXKrtNKLiARobQ.png" /></figure><p>Status 404 — the same as before — that’s correct.</p><p>We need to create something like this:</p><pre>/dogs/../heapdump</pre><p>This would result in requesting <em>/heapdump.</em></p><p>The first thing, I added <strong>?test=</strong> at the end of my payload, then the last characters of JSON — <strong>\”}</strong> — would be excluded from path:</p><pre>/dogs%7b\%22UA\%22:+\%22test<strong>?test=</strong>\%22%7d</pre><p>Of course, we need to obtain <em>/heapdump</em>:</p><pre>/dogs%7b\%22UA\%22:+\%22test<strong>/heapdump</strong>?test=\%22%7d</pre><p>Now add some traversing:</p><pre>/dogs%7b\%22UA\%22:+\%22test/<strong>../../</strong>heapdump?test=\%22%7d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*efPAlLK84o1QnNGTZCBOnA.png" /></figure><p>Whoops —a little different than usual 400 Bad Request response here. Why that? Because probably Load Balancer which was used, <strong>tried to block it</strong> — but there is a <a href="https://github.com/swisskyrepo/PayloadsAllTheThings/tree/master/Directory%20Traversal#nginxalb-bypass"><strong>simple trick</strong></a><strong> for evasion</strong> 😉</p><pre>/dogs%7b\%22UA\%22:+\%22test<strong>/////////</strong>../../heapdump?test=\%22%7d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/791/0*a6ZnP-7heO6U5Z2F" /></figure><p>401 Unauthorized — <strong>we’ve got this</strong>! Let’s try encrypting it and using as <em>x-param</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/620/0*g1P0iVfxEDMCu1Ac" /></figure><p>Oh, the ../../ part was deleted… Let’s try to <strong>URL encode it</strong>:</p><pre>/dogs%7b\%22UA\%22:+\%22test/////////<strong>%2e%2e%2f%2e%2e%2f</strong>heapdump?test=\%22%7d</pre><figure><img alt="" src="https://cdn-images-1.medium.com/max/920/0*r2tuOX-XMFuB45Y2" /></figure><p>Here we are, our beautiful <strong>heapdump</strong> response!</p><p>By scrolling down I was able to find the flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/554/0*_mIkApdt6NePPL0B" /></figure><p><strong>I win!</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2Fa0h7sAqON67nO%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fborat-great-success-a0h7sAqON67nO&amp;image=https%3A%2F%2Fmedia4.giphy.com%2Fmedia%2Fa0h7sAqON67nO%2Fgiphy.gif%3Fcid%3D790b76112df3e7d33623f688713de6e6ac03c035b8b9387a%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="244" frameborder="0" scrolling="no"><a href="https://medium.com/media/7f301f67e11c18d81c73319a0285d5a2/href">https://medium.com/media/7f301f67e11c18d81c73319a0285d5a2/href</a></iframe><h3>BugPoc Proof-of-Concept</h3><p>As it was required, I created an <strong>automatic PoC</strong> for this using the <a href="https://bugpoc.com/">BugPoc platform</a>. I decided to go with Python PoC — created a script that requests new ciphertext, uses it on <em>/get-dogs</em> endpoint and by using regex extracts the flag.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/936/0*4t0PJiq0RLas26LN" /></figure><p>Source code here: <a href="https://bugpoc.com/poc#bp-uNE91jDI">https://bugpoc.com/poc#bp-uNE91jDI</a><br>ID: bp-uNE91jDI<br>Password: AfrAIDllaMA91</p><h3>Summary</h3><p>I submitted my report using the <a href="https://hackerone.com/bugpoc">HackerOne platform</a> and got confirmation about the correct solution:</p><blockquote>Great job! Thanks for participating in our CTF Challenge! Your solution is <strong>correct</strong>, however unfortunately the 1st place prize has already been claimed.</blockquote><p>Because I started this challenge too late on Sunday, I wasn’t the first one to solve it.</p><p>Still, I have to say that was some <strong>great task</strong> — nice chaining of not so popular vulnerabilities. Also, I had a chance to train and verify my cryptography skills. And don’t forget about reconnaissance — without a proper one, there would be probably a sad ending.</p><p>I’m just a little sad there weren’t more AWS-specific things, but couldn’t have everything 😄</p><p>I included the part with my wrong idea, to show to everyone, especially beginners, that <strong>we aren’t flawless robots</strong> and not everything goes so smoothly like in writeups. Me, you, we’re all just human, <strong>we make mistakes </strong>— that’s normal. We have to accept it, learn from them and keep going! <strong>Try harder!</strong></p><p><strong>Kudos to everyone </strong>who solved it!</p><p>Remember to follow me on <a href="https://twitter.com/_pkusik">Twitter</a> if You want to be up to date with my work!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a015973e20e" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[What can you find in 57K AWS S3 buckets? 2021 update]]></title>
            <link>https://medium.com/securing/what-can-you-find-in-57k-aws-s3-buckets-2021-update-e8105661e55e?source=rss-49faa4969b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/e8105661e55e</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[cybersecurity]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[cloud-security]]></category>
            <dc:creator><![CDATA[Paweł Kusiński]]></dc:creator>
            <pubDate>Thu, 29 Apr 2021 06:36:01 GMT</pubDate>
            <atom:updated>2021-04-29T06:36:01.842Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Ig9yQ-HxstjjYlRmsYCFQA.jpeg" /></figure><p>Almost 3 years have passed since my friend — <a href="https://www.securing.pl/en/author/pawelrzepa/">Paweł Rzepa</a> — did a <a href="https://www.securing.pl/en/exploring-25k-aws-s3-buckets/">research</a> about open S3 buckets. The situation did not look good then, but maybe the topic of cloud security was not as widely publicized as it is today. However, with each subsequent AWS penetration test and assessment in my work, I get surprised <strong>how often we are finding open buckets with sensitive data</strong>.</p><p>So it turns out that the topic is not as obvious as it seems. Therefore, I decided to revise this research and confront what it looks like in 2021. The results did not disappoint me so here is my attempt.</p><h3>Revision of the basics:</h3><h4>What is an AWS bucket?</h4><p>AWS S3 Bucket is (according to its documentation) “Object storage built to store and retrieve any amount of data from anywhere” — it could be used as cloud storage (like Google Drive), static content storage served by CDN or even as a static website!</p><h4>How to use knowledge about buckets?</h4><p>As you probably know, access to the buckets is possible not only using AWS CLI, SDK or Console, but also using HTTP endpoints — more specifically:</p><pre>http[s]://[bucket_name].s3.amazonaws.com/<br>http[s]://s3.amazonaws.com/[bucket_name]<br>http[s]://s3-[region_name].amazonaws.com/[bucket_name]</pre><p>As mentioned above, S3 Buckets could be also used to host static websites, where I noticed that sometimes the domain name is equal to the bucket name, as presented in Scott Piper <a href="http://flaws.cloud/">flaws.cloud</a> challenge:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/602/1*2ZHkhWXJo_Ko98RGyp5q_A.jpeg" /></figure><p>By using these facts, we could apply various techniques and tools to search for S3 buckets.</p><h3>Method for finding bucket names</h3><p>So what can we do to find as many bucket names as possible (and be able to scan them)? I did a few things listed below:</p><ul><li>Enumerate Wayback Machine using Metasploit enum_wayback module</li><li>Use discovery (OSINT) tools — Sublist3r and Amass</li><li>Watch certificate transparency logs</li><li>Gather data about companies that use AWS — scan, map, and brute force them*</li></ul><p>*Disclaimer — using this method I chose only companies with Bug Bounty programs which allows for actions like that!</p><h4>Wayback Machine</h4><p>Wayback Machine is a commonly known digital archive of the World Wide Web. Everything that has been indexed by it, could be then retrieved using a proper API call. If there was a single file on an S3 bucket that was indexed, we can obtain its URL and extract the bucket name. Even if the indexed file is already inaccessible (deleted or set private), we still have the name of the bucket, which could be scanned.</p><p>Our goal is to search for different S3 endpoints to gather every possible indexed URL — to do this I used <a href="https://www.metasploit.com/">Metasploit</a> module called enum_wayback:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/601/1*5CdUEUzB66rkoWLmMhBQ1A.jpeg" /></figure><p>As previously mentioned, it is possible to refer to the bucket’s content using a URL with region specification. By saving every region name to the file and using this simple bash one-liner, we can make our results even more precise:</p><pre>$ while read -r region; do msfconsole -x &quot;use \<br>auxiliary/scanner/http/enum_wayback; set DOMAIN $region;\<br>set OUTFILE $region.txt; run; exit&quot;; done &lt; regions.txt</pre><p>Using this method, I gathered about <strong>900MB of txt files</strong>, but as you probably suspect, there were a lot of useless paths and duplicates of the same names — <em>awk</em>, <em>cut</em>, <em>uniq</em> and <em>sort</em> in this situation were my best friends.</p><p>To sum up — I extracted <strong>31177 potential bucket names</strong> and <strong>4975</strong> of them were <strong>publicly open</strong>. Furthermore, I was able to <strong>write to 764</strong> of them.</p><h4>OSINT tools</h4><p>Wayback Machine is not the only service that gathers data like that — there are also search engines (Bing, Yahoo, Google), different APIs (CommonCrawl, ZoomEye, URLScan, VirusTotal) and techniques like reverse DNS sweeping. Doing everything manually would take a lot of time, so I decided to use two tools that harvest data for me — <a href="https://github.com/aboul3la/Sublist3r">Sublist3r</a> and <a href="https://github.com/OWASP/Amass">Amass</a>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/708/1*wSZq3yuTrGrlsaMaMRG6lg.jpeg" /></figure><p>Sublist3r:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/732/1*aILrF20L0KyA2jpBtS9dKw.jpeg" /></figure><p>And going to the results — Amass gathered a total of <strong>unique 29562 bucket names</strong>, where I was able to <strong>read 4800</strong> of them and <strong>write to 1148</strong>.</p><p>Sublist3r collected a crazy amount of <strong>125525 bucket names</strong>! But to our misfortune, 122468 of them did not exist, so we are left with <strong>193 publicly open</strong> buckets and <strong>59 writable</strong> ones.</p><h4>Certificate transparency logs</h4><p>One of the mentioned techniques was listening to certificate transparency logs. Quoting Wikipedia — “Certificate Transparency (CT) is an Internet security standard and open source framework for monitoring and auditing digital certificates.”</p><p>As you may know, every issued TLS certificate is logged publicly (to verify if a certificate is properly issued and is not maliciously used). The idea of this is correct, but… it leaks publicly every domain — also the S3 buckets, which is good for us!</p><p>Because I’m not the first who figured it out, there’s already an open-source tool called the <a href="https://github.com/eth0izzle/bucket-stream">bucket-stream</a>.</p><p>After running it for two days, I gathered <strong>310 bucket names</strong>, where only <strong>16 were accessible</strong>, and to <strong>4 I was able to write</strong>.</p><h4>And now the fun part: scanning, mapping and bruteforcing</h4><p>The last method I used and I guess the most interesting one (despite not having the most spectacular results) — <strong>gathering data about companies that use AWS services</strong>.</p><p>By searching through public statistics of AWS usage, as well as HackerOne and BugCrowd scopes — I created a list of companies that allow bug bounty, just to be sure everything I’m doing is legal.</p><p>While browsing their BB programs, I created also domain lists basing on their scopes:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/274/1*28zPZ9qEZWncvYBeH6v-gA.jpeg" /></figure><h4>Discovery time!</h4><p>That was not enough — so the first thing I did was to use Amass again, to gather even more subdomains! To do this, I used the following command:</p><pre>$ amass enum -active \<br>-d $(sed -z &#39;s/\r\n/,/g;s/,$/\r\n/&#39; bounty_domains/redacted.txt) \<br>-brute -w dns_brute_merged.txt -o redacted_amass.txt -p 80,443</pre><p><strong>59358 </strong>— this is the number of addresses I gathered from <strong>19 targets</strong>.</p><p>You are probably thinking now:</p><blockquote><em>“So what? They aren’t S3 buckets or even any AWS service”</em></blockquote><p>And you’re right! And I’m going to describe what I did to search for S3 buckets from this dump, right below 😉</p><h4>Inspecting found domains</h4><p>In the next step, I used a tool called <a href="https://github.com/michenriksen/aquatone">Aquatone</a>, which did a lot of work for me — by screenshotting every page and harvesting headers from all of the accessed addresses:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/582/1*YQZbg6g-4nTM4My6OPhjKg.jpeg" /></figure><p>It took some time, but in the end I was left with <strong>2,7GB of output data</strong> (mainly screenshots and txt). By searching for a header “<em>server: AmazonS3</em>” I was able to extract <strong>178 addresses</strong>.</p><p>It turned out that most of them were behind a CDN, probably with access restricted only for CloudFront! <strong>19</strong> of them were correct bucket names, where <strong>only 1</strong> was publicly accessible.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FENagATV1Gr9eg%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fslow-clap-good-job-whisky-ENagATV1Gr9eg&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FENagATV1Gr9eg%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/accea69325d5a46fae71f208053f8f35/href">https://medium.com/media/accea69325d5a46fae71f208053f8f35/href</a></iframe><h4>Brute-force</h4><p>The last thing in my prepared arsenal is Brute-forcing bucket names! I used a popular tool named <a href="https://github.com/nahamsec/lazys3">LazyS3</a> for guessing on the basis of a company name set as an argument:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/390/1*qhbX2TIt9AmTZMs60T64qg.jpeg" /></figure><p>Results? 965 bucket names, where 64 of them were open publicly, and to 25 I uploaded a test file.</p><h3>An overview of our findings — what are those buckets?</h3><p>Paweł created a tool named <a href="https://github.com/securing/BucketScanner">BucketScanner</a>, but I found it lacks a few functionalities and is a little bit outdated, so… I’ve updated it!</p><p>First thing — I’ve changed the code to use Python 3.6+ and the newest versions of libraries (boto3, requests).</p><p>Furthermore, I wanted to add a passive scanning mode, which Paweł described in his article, as one of the available methods. I’ve added more detailed logging, some colours — and voilà:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/733/1*7FexvPgeeucBToYocsyxBQ.jpeg" /></figure><h3>Why deal with AWS buckets in the first place?</h3><p>As I mentioned — it was an interesting thing for me to do. I also had a chance to experiment a bit more with AWS and test my skills.</p><p>Furthermore, it is worth mentioning that a lot of people search for “How to make AWS bucket public” — I think Amazon did a good job securing this service, by making it private by default, implementing features <a href="https://docs.aws.amazon.com/AmazonS3/latest/userguide/access-control-block-public-access.html">blocking public access</a> (which even prevent from making bucket public accidentally) and forcing the user to tick a million checkboxes and to write “confirm” at every step of making a bucket public.</p><p>The only thing which could be quite confusing, especially for new users, is mixing IAM Policies with Bucket Policies, Bucket Access Control Lists, and Object Access Control Lists.</p><p>But the most important thing is… S3 Buckets are used for various purposes — they can host a website, store logs, databases, backups, datasets… To sum up — a lot of awfully fascinating data!</p><h3>So what exactly have I found?</h3><p>I was surprised by what I saw at the beginning (I even jumped up in my chair) and then I even got a little scared. I’ve found a handful of buckets with database dumps (or backups) — this could be a <strong>huge client’s data leak</strong>! For now, everything is reported and we are waiting for feedback. I have been wondering for a long time whether to share at least a little bit of the secret, but until we get an answer from that company, we remain these good guys as usual; )</p><p>Searching through other findings was also fun at times!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/369/1*rijqgGGtPuAgrIaGm-MqDg.jpeg" /></figure><h3>Ok, but what could be the consequences?</h3><p>You are reading about one of them right now, as said above — database leak (or any other sensitive data like backups, logs, reports, private code etc.).</p><p>Furthermore, the possibility of writing to the bucket enables multiple malicious options:</p><ul><li>Creating a new webpage/overwriting the existing one with added malicious code, as it happened to <a href="https://medium.com/@jonathanbouman/how-i-hacked-apple-com-unrestricted-file-upload-bcda047e27e3">Apple once</a></li><li>Deleting stored data (and probably you forgot to enable MFA Delete to countermeasure this ;)) — and even without DELETE permission, overwriting a file is equivalent to deleting it, if Versioning is disabled.</li><li>Storing malware in your bucket with some tempting name “Annual Finance Summary 2021.pdf” — your business department uses a sandboxed environment when downloading data from your infrastructure?</li></ul><p>And remember — that is your bucket — this account is pinned to you or your company, so it is your problem, if there is any unwanted content.</p><h3>Summary</h3><p>For a total of <strong>185381 unique bucket names</strong>, <strong>57221</strong> were still existing ones — I was able to access <strong>9860 (17,2%)</strong> of them, and <strong>upload a file to 1965 (3,4%)</strong> buckets.</p><p>Compared to results obtained 3 years ago (24652 scanned buckets, 5241–21% — publicly open and 1365 writable — 6%) we can see some improvement! But the problem still exists and there is still a possibility of hearing about giant leaks like <a href="https://cloudsek.com/threatintelligence/7-2-million-records-were-exposed-but-not-from-the-bhim-app/">CSC-BHIM</a> or <a href="https://www.theregister.com/2020/07/21/twilio_javascript_sdk_code_injection/">code modification of open-source tools</a>.</p><h3>How to secure your buckets?</h3><p>My fairly obvious suggestion is that early prevention is the best option. That’s why at the beginning you should focus on setting efficient bucket permissions for your case. It’s always a good time to look into your setup, especially when it comes to security!</p><p>The second piece of advice is to look at your infrastructure from a fresh and broader perspective, for example with the help of professional security audits.</p><p>Certainly, with time, I will discuss more topics related to security of the broadly understood cloud. If you want to stay up-to-date with my discoveries you can find me on <a href="https://www.linkedin.com/in/pkusik/">Linkedin</a> or just give a quick follow on <a href="https://twitter.com/_pkusik">Twitter</a>!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=e8105661e55e" width="1" height="1" alt=""><hr><p><a href="https://medium.com/securing/what-can-you-find-in-57k-aws-s3-buckets-2021-update-e8105661e55e">What can you find in 57K AWS S3 buckets? 2021 update</a> was originally published in <a href="https://medium.com/securing">SecuRing</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Hacking AWS: HackerOne & AWS CTF 2021 writeup]]></title>
            <link>https://medium.com/@pkusik/hacking-aws-hackerone-aws-ctf-2021-writeup-7772effd1512?source=rss-49faa4969b68------2</link>
            <guid isPermaLink="false">https://medium.com/p/7772effd1512</guid>
            <category><![CDATA[cloud]]></category>
            <category><![CDATA[ctf]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Paweł Kusiński]]></dc:creator>
            <pubDate>Sun, 18 Apr 2021 08:03:17 GMT</pubDate>
            <atom:updated>2021-04-21T13:19:53.044Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*6yw-fKyvB2WfnO5E8MWMkQ.png" /></figure><p>People interested in AWS Security probably know projects like <a href="https://github.com/RhinoSecurityLabs/cloudgoat">CloudGoat</a>, <a href="http://flaws.cloud/">flaws</a> and <a href="http://flaws2.cloud/">flaws2.cloud </a>— but I was lacking something new — and here came HackerOne CTF! Last week between 5 and 12 April they organised a CTF together with AWS — and it was a brilliant experience!</p><p>If you are interested in Cloud Security or just why I thought it was so brilliant — let’s jump into the reading!</p><h3>How it started</h3><p>It’s a Sunday evening — I’m chilling before the workweek and reading some news on the internet.</p><p>I found an <a href="https://www.reddit.com/r/aws/comments/mlfbcw/i_built_a_tool_which_automatically_suggests/">interesting article</a> about the new AWS tool for creating least-privilege IAM policies… And that caused something to click — I forgot about the AWS CTF! And I was hyped to verify my skills by doing it, so — it’s 7 PM — let’s begin!</p><h3>First challenge — obtaining access to the AWS account</h3><h4>Solving Server-Side Request Forgery</h4><p>The first thing we see going into the challenge is this landing page:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*nJFLpm-pMoLZiDSgkkYR3Q.png" /></figure><p>Input box for URL — classic 😄<br>So, why not use it?</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*2WTzUfTuY14sgjctKvh5IQ.png" /></figure><p>HTTP response of our request has a <em>page </em>parameter which is…</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/747/1*AD-jSflBSH53saAuqNrPtQ.png" /></figure><p>Base64 encoded response from the requested URL!</p><p>So now I had two thoughts:</p><ul><li><strong>Command injection </strong>— to retrieve environments by for example something like that: “<em>https://example.com;env</em>&quot; or inject some other command</li><li><strong>Server-Side Request Forgery (SSRF) </strong>— to try communicating with hidden services inside a subnet or with a meta-data server.</li></ul><p>Why did I think that? First — a hunch. Furthermore few things I had in head:</p><p>In the situation of serverless service (hosted using Lambda), <em>env </em>command would retrieve stored variables (where the <strong>access keys obtained from the function’s execution role are stored!</strong>)</p><p>Second thought — if the input is not validated, then we could try to communicate with internal addresses, perform port scanning or try to harvest data from meta-data server (which is specific for cloud deployments).</p><p>After trying the most basic payloads of command injection which did not work, I decided to try communicating with <strong>169.254.196.254</strong> and… bingo!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/941/1*qcod3N0pdQbhyBT-4f8X5Q.png" /></figure><p>Status 200! So now, there are two things we can pull out from it — <strong>User Data</strong> and used <strong>role temporary access keys</strong>!</p><h4>User data extraction</h4><p>User Data often stores some sensitive data, like passwords, keys, etc. (what is worth mentioning, that is an incorrect configuration).</p><p>Let’s try to read it from <em>/latest/user-data</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1010/1*dgZN9LwNB7drco9zGU_pfA.png" /></figure><p>And we can see something interesting in the response!</p><p>S3 bucket — first thought — “<em>Check if this bucket is publicly available</em>” — and as I thought, I did by using my AWS account (with S3FullAccess policy):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/750/1*UWCI-DOghtKkcaY_GWCmXQ.png" /></figure><p>And as you can see — it was only a red herring 🙁</p><h4>Meta-data server &amp; temporary access keys</h4><p>As you may or may not know, meta-data server of EC2 instance under path: <em>/latest/meta-data/iam/security-credentials/&lt;role_name&gt;</em> stores <strong>access keys</strong> to the used role!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/253/1*Dl3LrrNi6A2OyFkhSIYCeQ.png" /><figcaption>EC2 Instance used Role name</figcaption></figure><p>By requesting <em>/latest/meta-data/iam/security-credentials</em> I’ve obtained role name.</p><p>And then extracted access keys:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*u7bjPGK88PBti9WRRdZH8g.png" /></figure><p>Let’s check what we got using AWS CLI — <em>sts get-caller-identity</em> could be called by <strong>every entity</strong>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/786/1*1fBRZazjquJ5cZb4_T5g-A.png" /></figure><p>We are in!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FiKBAAfYNDu1dowhnEj%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fthelonelyisland-snl-saturday-macgruber-iKBAAfYNDu1dowhnEj&amp;image=https%3A%2F%2Fmedia0.giphy.com%2Fmedia%2FiKBAAfYNDu1dowhnEj%2Fgiphy.gif%3Fcid%3D790b761124037783ecf67dc65178199c49174af8e74da6b4%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="326" frameborder="0" scrolling="no"><a href="https://medium.com/media/69a2e0bdcb35c4ed4333e861876167b5/href">https://medium.com/media/69a2e0bdcb35c4ed4333e861876167b5/href</a></iframe><h3>Second challenge — going deeper</h3><h4>Enumeration &amp; data extraction</h4><p>Okay, so we are in — what now?</p><p>We should get to know what we can do — and because that’s a CTF I’m not scared about brute-forcing IAM permissions (normally it would be very loud and someone should notice a scan like that).</p><p>I’ve used <a href="https://github.com/andresriancho/enumerate-iam">enumerate-iam</a> to do the job for me:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/951/1*GFlE3jIRRq0KiGrTwzqOeA.png" /></figure><p>And I’ve found something —<em> list-secrets</em> from Secrets Manager and EC2 <em>describe-instances</em>.</p><p>Let’s check it out!</p><p>I could use normal AWS CLI, but I want to show a little bit more and present a useful tool called <a href="https://github.com/RhinoSecurityLabs/pacu"><strong>Pacu </strong></a>— and more specifically <em>enum__secrets </em>script. It enumerates the Secrets Manager and Parameter Store in every region (or just the one specified).</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*npoc3zwNbTuR23CxybGnRw.png" /></figure><p>And there they are! Let’s see them:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/482/1*JtAEMnHI_XhlIm-O5aIVqA.png" /></figure><p>Okay — so we’ve got not 10, but 1 secret. probably because of redundancy between regions.</p><p>At the moment of finding it, I tried adding it as HTTP header and URL parameter (hoping for some different response from the service) — but nothing new came. I assumed that it probably would be useful later.</p><p>So I jumped to the second privilege I had — describe-instances.</p><p>With having SSRF vulnerability in mind, I decided to check <strong>private IP addresses</strong> of existing machines (the region was guessed by trial and error method):</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/740/1*ViEqGZJK2d5CiCFJuF1nRA.png" /></figure><h4>SSRF again</h4><p>I tried all four IP addresses, and one of them returned a different response than the others:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/912/1*J3KweSES4_65HZJrHp2wZg.png" /></figure><p>So now it is known where the API key from Secrets Manager should be used 😉</p><p>By using it, I obtained access to the internal application:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/972/1*Y5YNPw3p_MNo5wrHepiqOQ.png" /></figure><p>As I marked on the screenshot, the <strong>JavaScript file was included</strong>, by requesting and decrypting it I obtained a nice description of what paths are available:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/778/1*0cQQM78ufEsa5waYCT6dcw.png" /></figure><p>Spoiler — <em>/api/get_machines</em> was not working, so <em>/api/get_status</em> is the one we should be interested in. And there’s something we saw already — <em>addr </em>parameter — I assumed that there would be SSRF again, and I was correct, but I doubted for the moment…</p><p>You would probably laugh — because of a typo I made in the URL I was obtaining the wrong response for something like 10–20 minutes 😔</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2F27EhcDHnlkw1O%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Ffacepalm-mega-27EhcDHnlkw1O&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2F27EhcDHnlkw1O%2Fgiphy.gif%3Fcid%3D790b7611b773259fe97c5c2ad0d3f93a0925d7820ec153f6%26rid%3Dgiphy.gif%26ct%3Dg&amp;key=d04bfffea46d4aeda930ec88cc64b87c&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="344" frameborder="0" scrolling="no"><a href="https://medium.com/media/96846d6719b4877f52ee26be3c56f7e0/href">https://medium.com/media/96846d6719b4877f52ee26be3c56f7e0/href</a></iframe><p>I again tried to call the meta-data server, and I was successful — screenshot with correctly written URL — it is important to remember about <strong>correct encoding!</strong></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*MNmmFCFhiyV18HdNjAr9lQ.png" /></figure><p>You know the drill — I accessed user-data (nothing new here), requested role name and obtained temporary access keys of it:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/836/1*0pF61Ywts_oVBnHsGAKFPA.png" /></figure><p>We are “deeper” in 😉</p><h3>Third challenge — recovering the flag</h3><h4>Disastrous secret</h4><p>This is the moment that took me a while, because of my mistake.</p><p>I started from… <em>enum__secrets</em>:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/641/1*msXTjWvDu9pUGVa4GsrUsg.png" /></figure><p>And obtained <em>h101_flag_secret_secondary</em> which at first was fantastic, but it turned out to be disastrous! I didn’t have a clue what to do — tried using it as HTTP Header, URL parameter, POST parameter, looked up online hash databases (to try dehashing).</p><p>The welcome screen from the challenge did not help:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*y6pwATsKuJW8n6_mvDNXcA.png" /></figure><blockquote>Submit the flag along with your username</blockquote><p>I started trying to submit it like <em>&lt;username&gt;&lt;value&gt;</em>, <br><em>&lt;username&gt;:&lt;value&gt;</em>, hashing the whole string — nothing worked. <br>Looking upon the HackerOne Twitter comments and Discord channel didn’t help too.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FL95W4wv8nnb9K%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2FL95W4wv8nnb9K&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2Fv1.Y2lkPTc5MGI3NjExc2J6bjN2Y3RhYTZueXNtbXllZ3dkcGxkenZxdm5mNjZxNXNqZjN1eCZlcD12MV9pbnRlcm5hbF9naWZfYnlfaWQmY3Q9Zw%2FL95W4wv8nnb9K%2Fgiphy_s.gif&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="248" frameborder="0" scrolling="no"><a href="https://medium.com/media/3ff5d413a14c2695f448b24bf024d94e/href">https://medium.com/media/3ff5d413a14c2695f448b24bf024d94e/href</a></iframe><p>Before this part, everything went so smoothly, that I was really surprised with this turn of events.</p><p>So I thought, what is the best thing to do if nothing works?</p><blockquote>Return to the last successful point and start everything over.</blockquote><h4>One step backward, two steps forward</h4><p>I’ve got a new role, what can I do? Maybe start with smaller steps and… Check our privileges!</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/945/1*0KAvf7gf_OK6VnVLVM52hQ.png" /></figure><p>Oh my… there it is — S3 list-buckets — the thing that I omitted at first.<br>So let’s list the buckets:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/693/1*SYkP2B57k3Ee_zzv36hfkQ.png" /></figure><p>I had the listing privilege of only one of them. There was a single README file that I downloaded and read:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1013/1*Fmg9I0DGzk5iuiyQVbIm1g.png" /></figure><p>Instruction on <strong>how to generate the flag</strong> — nice! From this point, everything went smoothly again.</p><p>I requested the internal endpoint:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VVtFkTZlzVeBvNB8WttiCQ.png" /></figure><p>Obtained SQS queue URL using AWS CLI:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*eQYaLl3boceb2yGLvulUUg.png" /></figure><p>Sent SQS message:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*3HVt4ba9G3f_LNOWAlE-Vw.png" /></figure><p>Retrieved generated secret:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/958/1*Zz438RND2tWGV5cpMzTkYg.png" /></figure><p>And traded it for the flag:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/955/1*w_jmX5fYOn9cUPRi604jGA.png" /></figure><p><strong>Success!</strong></p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fgiphy.com%2Fembed%2FxT0GqssRweIhlz209i%2Ftwitter%2Fiframe&amp;display_name=Giphy&amp;url=https%3A%2F%2Fgiphy.com%2Fgifs%2Fbreaking-bad-bryan-cranston-i-won-xT0GqssRweIhlz209i&amp;image=https%3A%2F%2Fmedia3.giphy.com%2Fmedia%2FxT0GqssRweIhlz209i%2Fgiphy.gif&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=giphy" width="435" height="290" frameborder="0" scrolling="no"><a href="https://medium.com/media/821d28970160d75c02c944c26138e606/href">https://medium.com/media/821d28970160d75c02c944c26138e606/href</a></iframe><h3>Ending thoughts</h3><p>What can I say — that was a refreshing and interesting challenge! I liked the idea of this kill-chain and how <strong>realistic</strong> it was — bugs I found were similar to the ones I’m finding during AWS infrastructure penetration tests and configuration assessments (part of my job).</p><p>It took me something like 3 hours to obtain the flag and additional 3 hours after as I tried to solve <em>secret_secondary_flag. </em>If this was a red herring — I have to say it wasn’t the nice one. I still think that it had to be something, so send me a message if you know more about this 😉</p><p>As a reward for solving the challenge, I obtained an <strong>invitation to a private bug bounty program</strong> 😄</p><p>Congrats if you also solved the challenge! If not — remember to “<strong>Try harder</strong>” next time 😉</p><p>I suggest also following me on <a href="https://twitter.com/_pkusik">Twitter</a> to be up to date with my publications!</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=7772effd1512" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>