<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>Forem: Nathan Getty</title>
    <description>The latest articles on Forem by Nathan Getty (@getsec).</description>
    <link>https://forem.com/getsec</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F216832%2Ffe2e3a81-75f5-48dd-8a21-97b70ac940a6.png</url>
      <title>Forem: Nathan Getty</title>
      <link>https://forem.com/getsec</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://forem.com/feed/getsec"/>
    <language>en</language>
    <item>
      <title>aws security automation concepts for beginners (s3).</title>
      <dc:creator>Nathan Getty</dc:creator>
      <pubDate>Wed, 20 Nov 2019 01:33:33 +0000</pubDate>
      <link>https://forem.com/getsec/aws-security-automation-concepts-for-beginners-s3-ijk</link>
      <guid>https://forem.com/getsec/aws-security-automation-concepts-for-beginners-s3-ijk</guid>
      <description>&lt;blockquote&gt;
&lt;p&gt;I plan to make multiple posts with implementation later, lets get through some concepts first!&lt;/p&gt;
&lt;/blockquote&gt;

&lt;h1&gt;
  
  
  whoami
&lt;/h1&gt;

&lt;p&gt;Hey, I'm Nathan. I work in Canada and have a bunch of experience in security and AWS. I just wanna share some beginner tips and techniques/tools I use to help secure my organizations cloud environment.&lt;/p&gt;

&lt;h2&gt;
  
  
  Automation Concepts
&lt;/h2&gt;

&lt;p&gt;Let's be honest, responding to threats after they happen is much worse than being able to detect and respond as soon as they happen (or within a reasonable time). What can we do in AWS to make this a little bit more efficient? Well, lucky for us AWS CloudWatch offers a capability called events! This allows us to listen for events and launch responses as we wish. (You can also do this with systems manager but that isn't included). When using cloudwatch events, we want to listen for high security API calls. Stuff like:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;s3:CreateBucket&lt;/li&gt;
&lt;li&gt;s3:PutBucketPolicy&lt;/li&gt;
&lt;li&gt;ec2:RunInstance&lt;/li&gt;
&lt;li&gt;ec2:AuthorizeSecurityGroupIngress&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;For each one of these events we'd like to ensure they are called with the correct parameters. We wouldn't want someone to update the bucket policy and make the bucket public, or if someone launches an EC2 instance we want to make sure that ec2 instance isn't allowing ssh or rdp open to the world.&lt;/p&gt;

&lt;p&gt;Lets take a look at s3! What are some possible security concerns around s3?&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;Public buckets&lt;br&gt;
Most of the time, when we see public buckets, it's normally a dev trying to do some testing, which isn't necessarily malicious, but having an open bucket can lead to unauthorized access or data leakage, depending whats in the bucket. We can use CloudWatch events to trigger a lambda when a bucket is created and when a bucket policy is updated. This lambda should have your code (leveraging boto3) and should grab the bucket name and look at the policy, if the policy exceeds what you want, use boto3 to set a new policy to remove public access.&lt;br&gt;
&lt;a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_policy"&gt;Updating Bucket Policy&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;Non-Encrypted buckets&lt;br&gt;
Again, depending on your organizations requirements and risk apetite. You should always consider using encrypted buckets. Encrypting the data ensures that if assets get stolen from the AWS data center, they are encrypted. &lt;em&gt;This does not encrypt each object independently&lt;/em&gt;. Like above, Use CloudWatch events and lambda to update the encryption status of the bucket.&lt;br&gt;
&lt;a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_encryption"&gt;Updating Bucket Encryption&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;No S3 access logging enabled&lt;br&gt;
S3 Access logging is a pretty nice feature. It gives us apache like logs when people access s3 objects. This is pretty nice in incident response scenarios when you need to identify how many times an object was accessed, or which IP accessed an object, although this should not be used to identify a malicious actor. You will need more data to attribute someone to the activity. Just like with the above two, We can use CloudWatch events when a bucket is created to ensure S3 Access logging is enabled. Take a look at the docs below for lambda creation help.&lt;br&gt;
&lt;a href="https://boto3.amazonaws.com/v1/documentation/api/latest/reference/services/s3.html#S3.Client.put_bucket_logging"&gt;Put Bucket Logging&lt;/a&gt;&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;h2&gt;
  
  
  Thats it for now.
&lt;/h2&gt;

&lt;p&gt;Stay tuned, I will be making more posts to detail the exact implementation of the above concepts. There will be more posts that talk about other services too!&lt;/p&gt;

</description>
      <category>security</category>
      <category>aws</category>
      <category>devops</category>
    </item>
    <item>
      <title>Integrate static security checking for python!</title>
      <dc:creator>Nathan Getty</dc:creator>
      <pubDate>Mon, 18 Nov 2019 19:33:15 +0000</pubDate>
      <link>https://forem.com/getsec/integrate-static-security-checking-for-python-4i59</link>
      <guid>https://forem.com/getsec/integrate-static-security-checking-for-python-4i59</guid>
      <description>&lt;h2&gt;
  
  
  The basics
&lt;/h2&gt;

&lt;p&gt;Today we will be talking about bandit, a python static analysis tool that reviews your code for possible security flaws. We will be using bandit, lets create a virtual environment and use pip to install bandit.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;python &lt;span class="nt"&gt;-m&lt;/span&gt; venv venv
&lt;span class="nb"&gt;source &lt;/span&gt;venv/bin/activate
pip &lt;span class="nb"&gt;install &lt;/span&gt;bandit
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Lets use the following application below as an example.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="kn"&gt;from&lt;/span&gt; &lt;span class="nn"&gt;os&lt;/span&gt; &lt;span class="kn"&gt;import&lt;/span&gt; &lt;span class="n"&gt;system&lt;/span&gt;

&lt;span class="n"&gt;system&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="s"&gt;'sudo su'&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Obviously using sudo su in a shell process isn't good practice, but we're just showing off the capabilities of bandit. So, lets run bandit against our file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight shell"&gt;&lt;code&gt;bandit app_name.py
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;blockquote&gt;
&lt;p&gt;Below is an example of the response&lt;br&gt;
&lt;/p&gt;
&lt;/blockquote&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight plaintext"&gt;&lt;code&gt;Test results:
&amp;gt;&amp;gt; Issue: [B605:start_process_with_a_shell] Starting a process with a shell: Seems safe, but may be changed in the future, consider rewriting without shell
   Severity: Low   Confidence: High
   Location: bad.py:3
   More Info: https://bandit.readthedocs.io/en/latest/plugins/b605_start_process_with_a_shell.html
2
3       system('sudo su')

--------------------------------------------------
&amp;gt;&amp;gt; Issue: [B607:start_process_with_partial_path] Starting a process with a partial executable path
   Severity: Low   Confidence: High
   Location: bad.py:3
   More Info: https://bandit.readthedocs.io/en/latest/plugins/b607_start_process_with_partial_path.html
2
3       system('sudo su')

--------------------------------------------------

Code scanned:
        Total lines of code: 2
        Total lines skipped (#nosec): 0

Run metrics:
        Total issues (by severity):
                Undefined: 0.0
                Low: 2.0
                Medium: 0.0
                High: 0.0
        Total issues (by confidence):
                Undefined: 0.0
                Low: 0.0
                Medium: 0.0
                High: 2.0
Files skipped (0):
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;This is pretty nice it gives us all the results we need. We can use these results in a bunch of different ways, but in what I do is grep the report and look to see if there are any "High or Medium" severity items, and then kill the CI/CD pipeline.&lt;/p&gt;

&lt;h2&gt;
  
  
  VSCode Implementation
&lt;/h2&gt;

&lt;p&gt;In VSCode, what you can do is use CMD+Shift+P while in your python application and select linter, and choose bandit, you may be asked to install it, choose yes, ensure you tell VSCode to use bandit once more, and now, if you hover over the marked text, you will see the error/warnings.&lt;/p&gt;

</description>
      <category>security</category>
      <category>python</category>
      <category>vscode</category>
    </item>
    <item>
      <title>Reverse Shell Generation.</title>
      <dc:creator>Nathan Getty</dc:creator>
      <pubDate>Mon, 18 Nov 2019 19:20:47 +0000</pubDate>
      <link>https://forem.com/getsec/reverse-shell-generation-47im</link>
      <guid>https://forem.com/getsec/reverse-shell-generation-47im</guid>
      <description>&lt;p&gt;The below tool is a good resource for generating reverse shells for a whole bunch of different systems and programming languages.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://github.com/mzfr/rsh"&gt;https://github.com/mzfr/rsh&lt;/a&gt;&lt;/p&gt;

</description>
      <category>security</category>
      <category>reverse</category>
      <category>shells</category>
    </item>
  </channel>
</rss>
