<?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 Abhay Bhargav on Medium]]></title>
        <description><![CDATA[Stories by Abhay Bhargav on Medium]]></description>
        <link>https://medium.com/@abhaybhargav?source=rss-b5a962f46c8f------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*tC5bUKsRk69zR-U0Dh1x0g.jpeg</url>
            <title>Stories by Abhay Bhargav on Medium</title>
            <link>https://medium.com/@abhaybhargav?source=rss-b5a962f46c8f------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Wed, 18 Nov 2026 05:13:35 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@abhaybhargav/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[Security Engineer Interview Questions: What is XXE?]]></title>
            <link>https://abhaybhargav.medium.com/security-engineer-interview-questions-what-is-xxe-3a649461f7ca?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/3a649461f7ca</guid>
            <category><![CDATA[web-security]]></category>
            <category><![CDATA[owasp]]></category>
            <category><![CDATA[bug-bounty]]></category>
            <category><![CDATA[vulnerability]]></category>
            <category><![CDATA[application-security]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Fri, 29 Jan 2021 17:51:13 GMT</pubDate>
            <atom:updated>2021-01-29T17:51:13.062Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*1hi6W0hVN9oDQwhiU6N3iw.png" /></figure><p>We’re creating a super-useful series called Security Engineer interview questions, where we dive into real-world interview questions on AppSec from <a href="https://www.linkedin.com/company/glassdoor/">Glassdoor</a>, <a href="https://www.linkedin.com/company/indeed-com/">Indeed.com</a> and other sources. This week, I dive into the question “What is XXE” with the aid of an amazing lab from our Learning Path on Application Security. Enjoy!</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FvmQsCVg9AzQ%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DvmQsCVg9AzQ&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FvmQsCVg9AzQ%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/a81129e48a4453a03f859fd1922eeb76/href">https://medium.com/media/a81129e48a4453a03f859fd1922eeb76/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3a649461f7ca" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[TL;DR on the AWS Lambda Security Overview]]></title>
            <link>https://abhaybhargav.medium.com/tl-dr-on-the-aws-lambda-security-overview-fa6362d898c8?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/fa6362d898c8</guid>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[lambda]]></category>
            <category><![CDATA[aws-security]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Tue, 26 Jan 2021 07:08:21 GMT</pubDate>
            <atom:updated>2021-01-26T07:08:21.228Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*a-P3zmoCIshJqSyuAQQGeA.jpeg" /></figure><p>AWS recently released a whitepaper on the Security Overview of Lambda. This <a href="https://d1.awsstatic.com/whitepapers/Overview-AWS-Lambda-Security.pdf">document</a> is meant to be an in-depth look at Lambda Security. Its definitely a worthwhile read. However, I have tried to simplify and distill some of the most important security points for general consumption</p><p>A little bit of background on my work in Lambda. I work with AWS Lambda every day. I continue to build and release production-grade applications on Lambda and have deployed complex stacks in EdTech, Security Automation and Payment Processing, built entirely as an event-driven system on AWS Lambda. I really love AWS Lambda and the general “serverless” paradigm. It has been a game-changer for the way we build applications within we45. We’ve been able to be much more productive and faster to market because we’ve built our stack on AWS Lambda. Some of the obvious benefits of Lambda include:</p><ul><li>No managing servers</li><li>Massive, Elastic Scalability as a Service</li><li>Pay for what you use, down to the last millisecond</li></ul><p>I will divide this blogpost into specific segments based on topics related to AWS Lambda security. Let’s dive in!</p><h3>Shared Responsibility and Lambda Layers</h3><ul><li>Unlike IaaS services (EC2) and PaaS Services (Elastic Beanstalk) on AWS, the Shared Responsibility Model (your problem) for Lambda largely extends to your Code, third party libraries, configurations and IAM configs applied on Lambda. You don’t need to manage the servers, consequently, the hardening, the hypervisor, the Runtime, the Sandbox, the hardware, etc.</li><li>You use Layers to load custom third party libraries for your Lambda stack. The libraries and code within these layers are your problem. So is the IAM for the layers. However, access to layers is encrypted with TLS 1.2 (transit) and at-rest with AWS Key Management Service. Check out our interactive KMS Tour on <a href="https://github.com/we45/AWS-KMS-Tour">Github</a></li></ul><h3>AWS Lambda Invoke Modes</h3><ul><li>Two types of Invoke Modes: Event and Request-Response Invoke Modes</li><li>Request-Response is a synchronous invoke with payload and returns response immediately. For example Lambda triggered from an API Gateway is Request-Response</li></ul><pre>Request =&gt; API Gateway =&gt; Invoke Service =&gt; Worker (VM) =&gt; MicroVM (for exec)</pre><ul><li>Event Invoke Modes are queued with SQS. Retrieved in batches by poller fleet. Passes to the invoke service</li><li>Control Plane == Management APIs ⇒ CreateFunction, UpdateFunctionCode and PublishLayerVersion</li><li>Communications to Control plane are encrypted</li><li>Data Plane ⇒ Runs the Lambda Function (Invoke) API</li><li>Allocates a worker (EC2)</li></ul><h3>Lambda Execution Environment and Execution Role</h3><ul><li>Customers cannot directly communicate with execution environment</li><li>Execution Environments are bound to specific function versions ⇒ Cant be shared across versions, accounts, etc.</li><li>Execution Environment ⇒ One concurrent invocation at a time. Multiple invokes of the same function version for performance</li><li>No isolation of state between invokes ⇒ i.e. invoke state from a previous invoke is likely available to the next invoke. This has been the cause of some <a href="https://www.abhaybhargav.com/security-impacts-of-stale-state-serverless-bugs/">security gotchas</a></li><li>Exec Role == IAM role that is assumed by the Lambda Function</li><li>Credentials are mounted and cached in the ENV-Vars of the function</li></ul><h3></h3><p>Protip: When bughunting a #AWS #Lambda function, remember that the metadata objects are env-vars. Escalate privs after RCE with envvars. In this screenshot have a function that&#39;s vulnerable to a deserialization vuln (RCE) through which I have dumped the envvars with secrets pic.twitter.com/mVDjMV7HVX</p><ul><li>Exec Role is assumed to perform Control-Plane Ops like configuring ENIs, Logs for Cloudwatch, AWS X-Ray</li></ul><h3>Micro-VMs, Workers and Lambda Isolation</h3><ul><li>Fleet of EC2 Servers == Lambda Workers</li><li>Runs on EC2 Nitro ⇒ Nitro Hypervisor, Nitro Security Chip, Nitro Cards and Enclaves</li><li>Lambda team uses Inspector to stay on top of security issues with Ntro instances</li><li>Workers have a max lease time of 8 hours</li><li>Function code is zipped and encrypted with AES-GCM</li><li>Functions created as containers is chunked and encrypted with a combination of AES-CTR, AES-GCM and SHA-256 MAC</li><li>Exec Environment has a copy of: Your code + Layers + Runtime + writeable tmp directory + minimal user-space with Amazon Linux-2</li><li>Isolation done with: cgroups, dedicated namespaces, seccomp-bpf, iptables, chroot</li><li>/tmp is not accessible across exec environments. You&#39;ll need to persist with Elastic File System or S3, etc.</li></ul><h3>Monitoring</h3><ul><li>Cloudwatch ⇒ Logs</li><li>X-Ray ⇒ Traces</li><li>AWS Config ⇒ Managing Config and compliance and security</li></ul><blockquote>Abhay is the Chief Research Officer of AppSecEngineer. One of the courses within AppSecEngineer is “<a href="https://appsecengineer.com/product/aws-serverless-applications/">Attacking AWS Serverless Applications</a>”. With our library and hands-on cloud labs and cyber-ranges consisting of amazing courses on DevSecOps, AppSec, Cloud Security and Threat Modeling, AppSecEngineer helps you become a better AppSec Professional. <a href="https://appsecengineer.com/ase-pricing">Subscribe today!</a></blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=fa6362d898c8" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[These are the things I want to learn in the year 2021]]></title>
            <link>https://abhaybhargav.medium.com/these-are-the-things-i-want-to-learn-in-the-year-2021-1f520c776bbd?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1f520c776bbd</guid>
            <category><![CDATA[new-year]]></category>
            <category><![CDATA[cloud-security]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[learning]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Sun, 17 Jan 2021 15:28:23 GMT</pubDate>
            <atom:updated>2021-01-18T05:48:25.212Z</atom:updated>
            <content:encoded><![CDATA[<iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2F8lenumhjsco%3Ffeature%3Doembed&amp;display_name=YouTube&amp;url=https%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3D8lenumhjsco&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2F8lenumhjsco%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="854" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/391fadda3d8d8e80a158b2743b85d9c0/href">https://medium.com/media/391fadda3d8d8e80a158b2743b85d9c0/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1f520c776bbd" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seven Deadly Sins of Container Security — Part 2]]></title>
            <link>https://abhaybhargav.medium.com/seven-deadly-sins-of-container-security-part-2-80ea975889ea?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/80ea975889ea</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[container-security]]></category>
            <category><![CDATA[containers]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Wed, 29 May 2019 16:27:39 GMT</pubDate>
            <atom:updated>2019-05-29T16:27:39.007Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*Bx7cxU4n4AtaNe20Sr2J4w.jpeg" /></figure><h3>Seven Deadly Sins of Container Security — Part 2</h3><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FFOSLxa6-fuY%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DFOSLxa6-fuY&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FFOSLxa6-fuY%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/542d70cc201bd6b0e7fee6317af9d7db/href">https://medium.com/media/542d70cc201bd6b0e7fee6317af9d7db/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=80ea975889ea" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Seven Deadly Sins of Container Security — Part 1]]></title>
            <link>https://abhaybhargav.medium.com/seven-deadly-sins-of-container-security-part-1-99a08de0e337?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/99a08de0e337</guid>
            <category><![CDATA[kubernetes]]></category>
            <category><![CDATA[containers]]></category>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[docker]]></category>
            <category><![CDATA[linux]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Wed, 22 May 2019 15:49:17 GMT</pubDate>
            <atom:updated>2019-05-22T15:49:17.356Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/854/1*Bx7cxU4n4AtaNe20Sr2J4w.jpeg" /></figure><h3>Seven Deadly Sins of Container Security — Part 1</h3><p>This video is AppSecEngineer’s Part 1 of Seven Deadly Sins of Container Security. These specifically refer to 7 different mistakes that people and orgs make when running containerized deployments in their environment.</p><iframe src="https://cdn.embedly.com/widgets/media.html?src=https%3A%2F%2Fwww.youtube.com%2Fembed%2FJmsjpgfheas%3Ffeature%3Doembed&amp;url=http%3A%2F%2Fwww.youtube.com%2Fwatch%3Fv%3DJmsjpgfheas&amp;image=https%3A%2F%2Fi.ytimg.com%2Fvi%2FJmsjpgfheas%2Fhqdefault.jpg&amp;key=a19fcc184b9711e1b4764040d3dc5c07&amp;type=text%2Fhtml&amp;schema=youtube" width="640" height="480" frameborder="0" scrolling="no"><a href="https://medium.com/media/f9ffbaef8b9a6d55150ea56a24265c02/href">https://medium.com/media/f9ffbaef8b9a6d55150ea56a24265c02/href</a></iframe><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=99a08de0e337" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[InfoSec is a lot like Stand-up Comedy]]></title>
            <link>https://abhaybhargav.medium.com/infosec-is-a-lot-like-stand-up-comedy-28e7ba0aa882?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/28e7ba0aa882</guid>
            <category><![CDATA[careers]]></category>
            <category><![CDATA[personal-development]]></category>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[comedy]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Thu, 15 Nov 2018 05:21:36 GMT</pubDate>
            <atom:updated>2018-11-15T05:21:36.921Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/0*HVqjl21T2tIu-cm7.jpg" /></figure><p>I have been in InfoSec since 2008. I started extensively presenting at conferences and events from 2014 or so <em>(when I felt I had something to say)</em>. It wasn’t that I had nothing much to say before then, but I constantly felt weird about “not researching enough”, or “Who’s going to want to listen to me?” and so on. Somehow, in 2014, I decided to abandon a lot of doubts that I had and started to put more of my work “out there”.</p><blockquote>That’s been the best decision I have made so far</blockquote><p>Since 2014, I have spoken at several international events. Trained at several conferences and private events, architected a product with my team at we45 and developed an open-source tool, ThreatPlaybook that I am proud of. And I owe all of that to my experiences with speaking or more generally “putting my work out there”.</p><p>I love stand-up comedy, and I read a lot about them. Comedians like George Carlin, Jerry Seinfeld and Dave Chappelle are comedians that I greatly admire. I am in awe of the fact that they have to go out on stage and elicit laughs from the minute they are on. They need their material to work, their comic timing to be on point, relate to the audience, stay current and stay away from/walk that razor’s edge, where they have edgy material. They truly are a window to the human condition. Although it seems far-fetched, I see them as researchers. Researchers, who constantly address the subjects they research day-in-and-day-out. Stand up comedians also embrace the “iterative lifestyle” where they present sets at smaller comedy clubs all over, constantly perfecting their set, till they present at massive venues with thousands of people in the audience. We usually get to see that massive show on Netflix, etc but we don’t get to see the innumerable number of good and bad shows that they have at smaller comedy clubs and open mic nights.</p><p>I see similar trends playing out in information security. In a field like information security, you invariably have to be a “researcher”. Overall, the field is so new and so dynamically evolving, that you need to constantly read, practice and deliver Proof of concepts of your work, either inside your organisation or publicly. Several Infosec folks are in a position, where they need to get endorsements and sponsorships from management for their security initiatives, which requires not only a good grasp of the (technical) security concept, but an equal grasp of business priorities, RoI and related concepts. So regardless of your role, your job, your position or overall path, you are a security researcher. If you are a good security professional, you probably already see it that way. If you want to be a good InfoSec professional, you should consider seeing your profession this way.</p><blockquote>So if you are already a researcher, don’t you think you should do it right?</blockquote><p>Let’s look at some ways you should approach this, for your own career and for the benefit of the organization you represent.</p><p><strong>Embrace the “Open mic night”</strong></p><p>I have found tremendous value in “putting work out there”. This could be in the form of speaking, writing, whatever. This not only forces me to do my homework, but also constantly gives me ideas. Especially when I meet new people at events or hear from readers of my blogs and tools. But you might think…</p><blockquote>I am really terrible at public speaking. How do I manage? And I am not some established author. Why would anyone care to read my work?</blockquote><p>Well, you don’t need to have a Churchillian gift-of-gab or have Hemingway’s writing flair. You need to just put your work out there.</p><p>It probably will be mediocre at first. But with persistence, you will get better. Without exception.</p><p>Thankfully information security is a relatively casual and chilled out community that doesn’t require you to have amazing oratory skills or even great language skills. Your content matters. That’s it.</p><p>Start writing on Medium or speaking at local meet-ups, which are always starved for speakers. All this while, you can apply to present at your Dream Conference, and you’ll possibly get selected, based on your content and an existing track record. Lot of conferences have great spots for first-time speakers (BSides) and you will be more than welcome even at ones which don’t explicitly have such policies. InfoSec is a small and welcoming community. You should leverage that to the hilt.</p><p>This is very similar to stand-up comedy where comedians perfect their set (research) over time at smaller venues before going big. You’ll have to do this throughout your career, which gives you a great opportunity to meet and learn from interesting people.</p><p><strong>Feedback Loop</strong></p><p>One of the great things about putting your work out there is that you get feedback. For a stand-up comedian, that feedback mostly comes in the form of laughs.</p><blockquote>For you, it should come in the form of discussions at events, GitHub pull requests. Blog comments, or even something like size of an audience to hear you speak. It can come quite extensively in the form of rejected submissions to be a speaker at conferences.</blockquote><p>I get rejected for talks constantly. I also get selected constantly. I learn from the rejection, and tune my message or research.</p><p>With feedback, you also get a sense of where the industry is going and where you stand in relation to that.</p><p>This is invaluable. I am fortunate that I work at a security services and product company where I get to meet different clients and solve different problems. However, you might be working at an organization where you are executing a standard set of tasks for that organization. This limits your view of the overall industry. Feedback from outside is not only refreshing, but is invaluable to your career in the long run.</p><p><strong>Real Researchers don’t (write articles/speak at events)</strong></p><p>I have heard several folks in this industry repeat this phrase or something close to it.</p><blockquote>Real researchers just do the work. They don’t showboat by speaking at conferences and writing blogs.</blockquote><p>I personally don’t agree with this philosophy. Not one bit. While that’s a personal opinion. I don’t see how someone can do their best work, without having that work being showcased/used outside. While it may not be a talk/blogpost(s), it could be tools, methodologies, etc.</p><p><strong>Conclusion</strong></p><p>InfoSec, like any other industry, is about doing good work and showcasing that work. If you don’t put your work out there, you are unlikely to make any impact. All of us can learn a thing or two from stand-up comics by embracing some of their best qualities.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=28e7ba0aa882" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[A Guided Tour of the AWS Key Management Service (KMS)-as-Code]]></title>
            <link>https://medium.com/appsecengineer/a-guided-tour-of-the-aws-key-management-service-kms-as-code-4da580710e5b?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/4da580710e5b</guid>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[crypto]]></category>
            <category><![CDATA[cloud-computing]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Mon, 12 Nov 2018 09:57:00 GMT</pubDate>
            <atom:updated>2018-11-12T09:57:00.131Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*oRRk4J39KrOc48JBBh0dCQ.jpeg" /></figure><p>I started doing PCI-DSS Audit work in 2008 (yes I know). Since then, PCI-DSS has always had “Requirement 3”, a PCI-DSS set of security requirements that were typically seen as infamous because of the number of organizations, who would just not be able to fulfill them. What was Requirement 3? It pertained “Protecting Cardholder Data”, more specifically “at rest”. And when someone says “Protecting Data at rest”, you naturally gravitate towards that one dreaded word, “Crypto”. No, I don’t mean the other dreaded avatar of “Crypto” (as in CryptoCurrency), but “Crypto” as in Cryptography.</p><p>The problem was never encrypting and decrypting data, but the greatest challenge: “How do we manage and protect keys?” Key Management is no easy task, and was even less so back then. I have seen implementations involving “home-grown” key management servers, PGP/GPG Implementations of Key Management with Symmetric Keys, Windows Executables shared between the CEO and COO that would be used to perform “Dual Custodianship of encryption keys” to something more simplistic like “Hey, we can’t encrypt and manage keys, lets look at compensating controls”. But some of you might wonder “What about Banks? Didn’t they have those fancy HSMs that could manage encryption and key management?”</p><blockquote>Yes, Banks did have HSMs, but they used to be notoriously difficult to work with and way, way beyond the financial reach of other organizations</blockquote><p>Which is why I smiled when I saw Amazon Key Management System (KMS). Amazon’s KMS is one among several other solutions including Hashicorp Vault, Google Key Management Service, etc that have aimed at comprehensively addressing the problem of managing keys and secrets. According to me, good Key Management systems must facilitate:</p><ul><li>Key Generation</li><li>Key Rotation and Key Versioning</li><li>Managing Secrets like API Tokens, Passwords, etc</li><li>Comprehensive Access Control</li><li>Logging and Audit Trail</li><li>Dynamic Secrets and leases =&gt; Hashicorp Vault rocks this by the way!</li></ul><p>With Amazon KMS and Amazon Secrets Manager, you can nearly do all of those things, and quite comprehensively. KMS is also backed by HSMs, which provides the necessary assurance of quality of encryption and so on.</p><p>In this article, I’ll be exploring some of the key features of Amazon KMS with Terraformand the AWS SDK for Python, boto3. This is by no means, a comprehensive tutorial, but I’ll be taking you through some of the commonly used features of KMS and Amazon Secrets Manager.</p><p><strong>Generate and Rotate Keys</strong></p><p>Amazon KMS utilizes the concept of Customer Master Keys (CMKs). Customer Master Keys are the primary resources of Amazon’s KMS. CMKs are symmetric keys that never leave the KMS (i.e. you never have access to the CMK itself). You can use and generate any number of CMKs for different requirements that you may have. You can use CMKs, either to directly encrypt and decrypt data. Or you could use CMKs to generate a data key that is used to encrypt and decrypt data. The latter seems to be more in vogue. In fact, the latter is what is used by Amazon S3 when you need to perform Server-Side Encryption with Amazon KMS. Either way, the CMK never leaves the confines of KMS. If the rotation for the CMK is enabled, AWS also version manages the encryption for you. For example, if you have encrypted some data with the CMK, and subsequently rotate it. Once you need to decrypt the data again, AWS recognizes that the ciphertext has been generated with the old version of the key and handles the decryption process accordingly. Thus making key rotation a simple process.</p><p>Let’s look at two examples. One with terraform, where we will use a generated CMK and directly encrypt and decrypt data with that CMK and the other, where we will generate a CMK, subsequently generate a Data Key and use the Data Key to encrypt and decrypt data.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/63d4044d5a6524e409271354cd0c9d1f/href">https://medium.com/media/63d4044d5a6524e409271354cd0c9d1f/href</a></iframe><p>In the above example (Terraform) I am generating a CMK and subsequently using that CMK to encrypt some plaintext. The CMK has been set to auto-rotate (after 365 days). I have also added some context to the key with the `Tags` attribute. Now, the key will be logged in Cloudtrail with this name that it’s been “tagged” with. Once you run this example you should get the payload ciphertext and subsequently the plaintext.</p><p>Now, let’s look at the next example</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/0b23c40445b4b51b73a8ca147d6ba330/href">https://medium.com/media/0b23c40445b4b51b73a8ca147d6ba330/href</a></iframe><p>The above code is in Python. I am using the boto3 and pycrypto library to:</p><ol><li>Generate a CMK</li><li>Generate a data key (plaintext and encrypted) with the CMK</li><li>Encrypt some plaintext with the plaintext key, generating a data ciphertext</li><li>Subsequently, decrypt the ciphertext with the data key</li></ol><p>In the next example, we will be using Terraform to generate a new CMK and use Server-Side encryption with Amazon S3. In this approach, the CMK generates a data key, that is used to encrypt an object in Amazon S3</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ad2c94255b80c52a4b0abb33b96b0d7b/href">https://medium.com/media/ad2c94255b80c52a4b0abb33b96b0d7b/href</a></iframe><p><strong>Key Policies and Grants</strong></p><p>One of the other key aspects of Key Management, is controlling access to the Keys itself. This can be a pretty serious problem, if its not centralized or managed under a single access umbrella.</p><p>This is where its beneficial to have the Amazon IAM (Identity and Access Management) framework at our disposal. I will not go too much into the IAM framework of Amazon, but it gives you a comprehensive set of tools to provision access to resources, based on users, groups, roles and so on.</p><p>The first type of access control is the KeyPolicy. With the Key Policy, you can define who can do what with the keys in KMS. For instance, you have a serverless function that encrypts and decrypts user data. This function is managed by an IAM role, let’s call it… functionUserRole. This role should allow the serverless function to:</p><ul><li>Read/Write access to a specific DynamoDB Table</li><li>Encrypt/Decrypt Data stored in the DynamoDB Table with Amazon KMS’s CMK</li><li>Generate Data Keys that are stored with each record of the DynamoDB Table, with encrypted entries</li></ul><p>For this, you can create an IAM Policy that allows that role to only perform the following actions.</p><p>This is an example of a Key Policy</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/f8e235db6dd5d59cfc4bce4a8cf073e9/href">https://medium.com/media/f8e235db6dd5d59cfc4bce4a8cf073e9/href</a></iframe><p>The other way to restrict access privileges for Amazon KMS, is with the use of Grant. The concept of a Grant doesn’t require a user to generate a complex IAM configuration, but localizes the access configurations to keys within Amazon KMS.</p><p>This is an example of a Grant with Amazon KMS</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/ce3d1aff14cdc1825cc7767e22b3540c/href">https://medium.com/media/ce3d1aff14cdc1825cc7767e22b3540c/href</a></iframe><p>In the above example, I am creating a CMK, a user (with a random user name) and a grant, called “hugh-grant” (’cause I was tired of naming resources at this point 😛). This grant allows this user to use a specific CMK for Encrypt, Decrypt and GenerateDataKey functions. The user also needs to add an encryption context (additional attributes) while performing these operations, with a key of Department with a value of finance implying that the Key and user is for the use of the Finance department of the organization.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=4da580710e5b" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appsecengineer/a-guided-tour-of-the-aws-key-management-service-kms-as-code-4da580710e5b">A Guided Tour of the AWS Key Management Service (KMS)-as-Code</a> was originally published in <a href="https://medium.com/appsecengineer">AppSecEngineer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[DynamoDB Injection]]></title>
            <link>https://medium.com/appsecengineer/dynamodb-injection-1db99c2454ac?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1db99c2454ac</guid>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[hacking]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[nosql]]></category>
            <category><![CDATA[serverless]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Thu, 28 Jun 2018 13:16:25 GMT</pubDate>
            <atom:updated>2018-06-28T13:18:14.767Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/245/0*rUUTwVthZFvPlo_J.png" /></figure><p>I have been developing a bunch of serverless apps and experimenting with serverless security for our (we45’s) work in Pentesting and for our training on Serverless Security in <a href="https://appsecus2018.sched.com/event/F00X/2-day-training-container-security-serverless-and-orchestration-training?iframe=no&amp;w=100%&amp;sidebar=yes&amp;bg=no">OWASP AppSecUSA 2018</a> and I came across this interesting scenario during my research.</p><p>If you are working with AWS Lambda (Serverless), chances are that you would be working with AWS’s NoSQL Database, DynamoDB. DynamoDB is AWS’s cloud NoSQL solution that supports both Document models (like MongoDB) and Key-Value models (like Redis). DynamoDB and Lambda are a popular combination that several developers use to develop and run serverless applications on AWS infrastructure.</p><h4><strong>A Quick note on DynamoDB</strong></h4><p>As DynamoDB is a cloud based NoSQL solution, it comes with a plethora of features from in-memory caching (DAX) to Seamless Scaling, to Encryption at rest and many more (full list <a href="https://aws.amazon.com/dynamodb/details/">here</a>). As a Database, it supports a bunch of CRUD operations on Data, including INSERTS, UPDATES, DELETE, QUERY &amp; SCAN operations. DynamoDB has TABLES (named similarly to SQL Tables). Tables can have Items (collection of attributes of a document).</p><p>DynamoDB has two types of primary keys. One is a Partition Key (primary key), which computes the value internally to a hash function. In tables where there’s only the Partition Key, the Partition key has to be unique. For example, in a User table with a partition key of UserID, the UserID has to be unique and you can GET the user’s attributes by referencing the UserID</p><p>DynamoDB also supports tables with Partition Keys and Sort Key. The first attribute is the Partition Key and the second attribute is the Sort Key (forming a composite primary key). In tables with both Partition and Sort Key, one can have a non-unique partition key, but would need to have different sort key values. This is also called a Range Key.</p><p>The two major ways to perform SELECT-like functions on DynamoDB tables is the use of Queries and Scans. A queryrequires users to use the primary key attributes as well as additional filters to return the data queried. However, the scan function scans the entire table and returns results based on the ScanFilters. It goes without saying that the query feature is more efficient, but the scan feature is equally useful for fuzzy searches or search by attributes, without having to deal with the partition key.</p><h4>Injecting DynamoDB</h4><p>This attack scenario is very similar to NoSQL Injection attacks against MongoDB (<a href="https://blog.sqreen.io/mongodb-will-not-prevent-nosql-injections-in-your-node-js-app/">link</a>). And I have been able to validate this against the scan() function of the DynamoDB database.</p><blockquote>Full disclosure: I have reported this issue to AWS. However, they (rightly) mentioned that this is the intended behavior of the DB and its up to the developers to ensure the security of their applications when they use DynamoDB. Therefore, its something that developers need to be watchful</blockquote><p>Let’s examine a simple scan operation against my DynamoDB table. I have a User table with some attributes. I am using python boto3 client for this example.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/b78b40bf5557ad2e61f96ddef78225bc/href">https://medium.com/media/b78b40bf5557ad2e61f96ddef78225bc/href</a></iframe><p>In the above code snippet, I am using a scan operation to filter based on the first_name and last_name attributes. I am using a String filter, denoted by S (in AttributeValueList) with a string filter condition. I am using the ComparisonOperator == EQ (code for equals). You have a bunch of Comparison operators including</p><pre>EQ|NE|IN|LE|LT|GE|GT|BETWEEN|NOT_NULL|NULL|CONTAINS|NOT_CONTAINS|BEGINS_WITH</pre><p>With String attributes, comparison gets tricky, as comparison depends on the ASCII lexical ordering of strings, therefore, if you compare string values against another string with lower lexical ordering like * or an string with whitespace its likely to be always greater than or less than the queried string. Here’s another code snippet demonstrating this…</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/bd1074676d7d3c1d21f3f134ce14ecc0/href">https://medium.com/media/bd1074676d7d3c1d21f3f134ce14ecc0/href</a></iframe><p>In the above example, I am using the “Greater than” ComparisonOperator to check if the first_name and last_name attributes are greater than * or &quot; &quot;. In most cases, this would match all records in my Database, as these string attributes as WhateverString &lt; * in all cases. In this case, if the attacker is able to manipulate (through the app/interface), the search section of the AttributeValueList or can manipulate/utilize a ComparisonOperator like GT, LT, NE, NOT_CONTAINS, etc then the attacker may be able to query more than the datasets that the developer intends to expose to the user.</p><p>As I mentioned before, this is very similar to the <a href="https://blog.sqreen.io/mongodb-will-not-prevent-nosql-injections-in-your-node-js-app/">MongoDB NoSQL Injection</a> attack possibilities, where MongoDB expressions like $gte, $lte, $ne can be used to manipulate the returned resultset.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1db99c2454ac" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appsecengineer/dynamodb-injection-1db99c2454ac">DynamoDB Injection</a> was originally published in <a href="https://medium.com/appsecengineer">AppSecEngineer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[HOWTO: Amazon Inspector with Terraform]]></title>
            <link>https://medium.com/appsecengineer/howto-amazon-inspector-with-terraform-1c061a66f40c?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/1c061a66f40c</guid>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[aws]]></category>
            <category><![CDATA[devsecops]]></category>
            <category><![CDATA[security]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Fri, 15 Jun 2018 07:56:22 GMT</pubDate>
            <atom:updated>2018-06-15T07:56:58.638Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/200/0*gR2Vng7FwAtpkRXI" /></figure><p>I have been playing around with Terraform for the last 2 months or so, and I really enjoy working on it. The entire approach to Infrastructure as Code, especially the modular parts, are not only powerful, but also extremely intuitive and easy-to-use, once you get used to the HCL (Hashicorp Configuration Language).</p><p>Today, I’d like to detail a simple use-case where Terraform is used as a way to provision and configure an Amazon EC2 Server (I’ll be using Ubuntu in this example) and configure Amazon Inspector to scan said server for security vulnerabilities once provisioned.</p><p>While this appears to be a seemingly simple use-case, I didn’t find too many good examples detailing this implementation. Before, I dive in, some intro:</p><h4>What is Amazon Inspector?</h4><p>Amazon (AWS) Inspector is a service that Amazon provides for its customers on AWS. This service allows you to configure a vulnerability scanner to identify and flag vulnerabilities in your server environment.</p><p>In short, Amazon Inspector is a Vulnerability Scanner (similar to Nessus/Qualys/etc) that scans the target server for security vulnerabilities to captures these vulnerabilities in a set of reports that can be used by the DevOps team to patch and remediate as required.</p><p>Amazon inspector is an agent-based service, which needs to be deployed on the servers that needs to assess for vulnerabilities. Unlike several vulnerability scanners, Amazon Inspector cannot be run remotely against a target to identify flaws.</p><p>Amazon inspector uses “Rules Packages” to identify vulnerabilities against the target packages. These Packages contain different signatures, rules and payloads that would be used to identify security vulnerabilities on the target system. They are, namely:</p><ul><li>Common Vulnerabilities and Exposures (CVE Database) =&gt; <em>Popular database of existing vulnerabilities against commonly used software components.</em></li><li>CIS Benchmarks =&gt; <em>Center for Internet Security Hardening Benchmarks for commonly used software components</em></li><li>Security Best Practices =&gt; <em>Specific list of good security practices that one should follow while running servers.</em></li><li>Runtime Behavior Analysis =&gt; <em>Security analysis based on the services deployed on the target EC2 instance. Typically includes Insecure ports and services, Unused TCP ports, Insecure Client protocols, among others.</em></li></ul><p>Details of these Rules Packages can be found <a href="https://docs.aws.amazon.com/inspector/latest/userguide/inspector_rule-packages.html">here</a>.</p><p>Amazon Inspector can be run against specific Linux and Windows Operating System versions and distros. You can find that list <a href="https://docs.aws.amazon.com/inspector/latest/userguide/inspector_supported_os_regions.html">here</a>. In addition, Amazon Inspector works only for deployments in specific AWS regions.</p><h4>A Minimal Example: Terraform and Amazon Inspector</h4><p>As Amazon Inspector is an agent-based service. You would need to download the agent to the EC2 server(s) that you want to run security assessments against, to identify vulnerabilities. Obviously, when you have a small set of servers, manually installing the agent is not very complex, but when you are running deployments at (massive) scale, you would need automated orchestration to handle this for you, and that’s where Terraform comes in.</p><p>In this example, I will use Terraform to provision an Ubuntu 16.X server on Amazon EC2. To use Amazon Inspector, this server needs to be part of a “Resource Group”, that is used by Terraform to identify the specific targets that it would need to be run against. Subsequently, I will generate Amazon Inspector-specific configurations to specify an “Assessment Template” which is Amazonspeak for “configure a set of rules to be run against the target(s)”. Finally, after this has been provisioned, you can actually “run” the assessment, which in this case is 1 hour.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/d4ed383f685b5edd72542358857bfff7/href">https://medium.com/media/d4ed383f685b5edd72542358857bfff7/href</a></iframe><p><strong>Explanation (for the above):</strong></p><ul><li>In the above code snippet, I am provisioning an AWS EC2 ubuntu instance, using a generated keypair to inject ssh keys into the newly provisioned instance.</li><li>In line 12: I am adding this EC2 server to a tag called “InspectInstances” which I will be using subsequently to run Inspector assessments against (Resource Group)</li><li>Line 15–26: I am downloading and installing the Amazon Inspector agent from an approved source. Consider hash-matching for higher security.</li></ul><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/895286221733dd25c5225fcdc60248c7/href">https://medium.com/media/895286221733dd25c5225fcdc60248c7/href</a></iframe><p><strong>Explanation (for the above):</strong></p><ul><li>In this segment of the <em>instance.tf</em> file, I am initializing a Resource Group that will be used by Amazon Inspector to perform its security scan. (Line 1–5)</li><li>Subsequently, I am adding all the servers in that Resource Group to be targets of my security assessment. <em>Please note that this will only work against servers that have the agents installed.</em></li><li>Lines 12–23, I am defining an Assessment Template. In this case, my server is hosted in the <em>us-east-1</em> region. So the rules for CVE, CIS, etc are specific to the region. You can find this list of Amazon Resource Names (arns) <a href="https://docs.aws.amazon.com/inspector/latest/userguide/inspector_rule-packages_across_os.html">here</a> and <a href="https://docs.aws.amazon.com/inspector/latest/userguide/inspector_rules-arns.html">here</a></li></ul><p><strong><em>Please note that this code is only for demonstration purposes. I have not added several other security features to the EC2 deployment like VPCs, and more restrictive security groups. That’s beyond the scope of this article</em></strong></p><p>Now, once I run “terraform apply”, I would find that the EC2 server (ubuntu 16) gets provisioned and the inspector agent gets installed in the server.</p><p>Subsequently, an Amazon Inspector Assessment also gets provisioned, based on the Resource Group, Assessment Rules and Targets.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*kEWXhLPIe8Z9HHki6MNP7Q.png" /><figcaption>Amazon Inspector Assessment Target for the “InspectInstances” Tag</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*jS_qPc3qAeCuJjNXhl-fPQ.png" /><figcaption>Assessment Template provisioned by Terraform</figcaption></figure><p>All that remains now is to actually “run” the assessment. Unfortunately, I didnt find any terraform modules that run the assessment for you (I may be wrong). However, since AWS can be completely controlled with its SDK, you can use boto (or equivalent) to invoke the “run_assessment()” function.</p><p>For this example, I manually invoked the “Run Assessment” and these are the example of some of the results</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*Q3P69hCvnkuukVxQn-QC7w.png" /><figcaption>Assessment Run Screen</figcaption></figure><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*5H3RyIt397aRwV7xeD_H_A.png" /><figcaption>Findings from the Assessment Run</figcaption></figure><p>As you can see, Amazon Inspector has identified a number of security issues that I would need to investigate and remediate as required.</p><p><strong>Conclusions:</strong></p><ul><li>Amazon Inspector is Vulnerability Scanning Service from Amazon that works in an “agent-based” mode against specific Operating Systems on EC2</li><li>Terraform has comprehensive modules that allow you to not only provision and setup infrastructure on cloud environments, but also invoke APIs related to ancillary services like Amazon Inspector</li></ul><p><em>This content has been made possible by the team at </em><a href="https://www.we45.com/"><em>we45</em></a><em>. we45 is a focused Application Security and Security Automation Company. Apart from Technical Security Services, we45 offers in-depth training programs on Application Security, Cloud Security, Containers, DevSecOps among others. Contact us at </em><a href="https://www.we45.com/"><em>we45.com</em></a><em> if you want to know more.</em></p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=1c061a66f40c" width="1" height="1" alt=""><hr><p><a href="https://medium.com/appsecengineer/howto-amazon-inspector-with-terraform-1c061a66f40c">HOWTO: Amazon Inspector with Terraform</a> was originally published in <a href="https://medium.com/appsecengineer">AppSecEngineer</a> on Medium, where people are continuing the conversation by highlighting and responding to this story.</p>]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Integrating E2E and Application Security Testing: HOWTo with NightwatchJS and OWASP ZAP]]></title>
            <link>https://abhaybhargav.medium.com/integrating-e2e-and-application-security-testing-howto-with-nightwatchjs-and-owasp-zap-8240c540c524?source=rss-b5a962f46c8f------2</link>
            <guid isPermaLink="false">https://medium.com/p/8240c540c524</guid>
            <category><![CDATA[application-security]]></category>
            <category><![CDATA[devops]]></category>
            <category><![CDATA[nodejs]]></category>
            <category><![CDATA[security]]></category>
            <category><![CDATA[javascript]]></category>
            <dc:creator><![CDATA[Abhay Bhargav]]></dc:creator>
            <pubDate>Mon, 16 Apr 2018 13:40:02 GMT</pubDate>
            <atom:updated>2018-04-24T06:53:10.409Z</atom:updated>
            <content:encoded><![CDATA[<figure><img alt="" src="https://cdn-images-1.medium.com/max/960/1*_k-DN8Rf49UX2vSJ31FWJA.png" /></figure><p><strong>The Problem</strong></p><p>Ever since I started my journey in DevSecOps and Application Security Automation, one of the key areas of my work has been “Parameterized Scanning”. “Parameterized Scanning” started off when we were attempting to automate an application security test for one of our largest clients, a World’s Top 10 Travel Portal. Before Parameterized Scanning, the pen tester had to rely either on manually crawling through the application to identify parameters, consequently testing them to identify security vulnerabilities, or use the “spider” feature of the Web Application Scanner. The spider feature of most Web Application Vulnerability Scanners has become a relic that we should be associating with the dark ages. Why? Simply because traditional spidering simply does not work. Traditional spidering works on the principle of crawling a particular HTML page, discovering new links, forms, etc on the HTML page and attempting to identify more such pages with the same technique, recursively. This largely has been rendered obsolete today.</p><ul><li>Powerful front-end JavaScript frameworks like Angular/React/Vue/Mojo2, etc that are often Single Page Apps, and generate links and other content on the fly, based on events and user actions. These frameworks have made it very easy for a user to interact with a web application, making them highly responsive and user-friendly, but have made it notoriously difficult for spiders to identify content, forms and parameters, thereby reducing the spider’s result to a “nothingburger”.</li><li>A lot of the apps we test are web services or micro-services today. With the rise of mobile apps and multiple client requirements, developers seldom create “monolithic” web applications any more, but rather prefer a modular approach to creating a web service that has the ability to work with multiple clients, and other applications as API. Clearly, spiders are completely useless here as there’s no content to discover in the first place.</li></ul><p>This creates a significant problem for DAST Scanners. Some of them provide “Recorded Authentication” settings. They figure that since “Authenticated Scans” (scans where you need to be authenticated as the user) are the only thing that’s important, they allow a user to record an authentication sequence in their scan tool and replay this scan sequence to recreate the authentication and subsequently, the scanner still resorts to spidering the application. This still doesn’t solve the problem, because spiders dont find anything anymore.</p><p>Which is why =&gt; Parameterized Scanning</p><p><strong>The Solution — Parameterized Scanning</strong></p><p>Parameterized Scanning is the practice of creating/leveraging software test automation to use as an input for Application Security Testing. Let’s assume that your organization has a QA department. Let’s assume that this QA department creates test automation (End to End Tests, e2e test) in Selenium or similar framework. The idea is to leverage that existing test automation to serve as an input for the DAST Scanner. Essentially:</p><ol><li>The Test runs against the application, with the DAST scanner as the proxy.</li><li>Once the test completes the scan process, the DAST Scan starts scanning for security vulnerabilities</li><li>Once the scan is done, the DAST scanner generates/publishes reports/artifacts that can be used by engineering teams to triage and fix the identified vulnerabilities.</li></ol><p>As you can see, this model has some non-trivial benefits (only a few are captured here):</p><ul><li>The entire test has valid parameters, urls and modules that are being used by the e2e test. Therefore, this can be used against even complex front-end heavy apps, web services, etc. This makes the “coverage” aspect of a security test more specific, with all the right parameters and inputs. This makes the test more effective, and the possibility of finding more security vulnerabilities, more probable.</li><li>The entire test can be run in an Automated manner, thereby making it a great candidate for DevOps integration. Once this E2E test is available, and ready to use, it becomes a matter of running and re-running the security test against the application</li><li>Security Testing becomes more modular — You can choose to test only specific modules of the app that are captured by the E2E test. Let’s say you want to test the Patient Management Functionality of the application, you can do so, without having to configure the scanner’s crawler from identifying all kinds of URLs that may even be out of scope.</li></ul><p>We at we45, have created a host of solutions/tools that facilitate Parameterized Scanning, right from our product Orchestron Client to <a href="https://github.com/we45/RoboZap">RoboZap</a>, (Github link) etc that can be used by our customers and the community at large to perform Parameterized, Automated Scanning, leveraging existing or new e2e tests. However, thus far, my examples and work had largely been with Python based libraries like Python-Selenium, Python-requests among others.</p><p>I have written this blogpost to showcase an experiment in a JavaScript End-to-End Testing Framework. I have been working extensively with NodeJS recently, so I thought that I would give this a shot and write about some of my experiences for everyone’s benefit.</p><p>For this example, I have used the following:</p><ul><li>NightwatchJS (an E2E Testing Framework for NodeJS that is meant to facilitate “Browser Automation Testing”. It uses Selenium under the hood =&gt; <a href="http://nightwatchjs.org/">http://nightwatchjs.org/</a></li><li>Selenium Server</li><li>ChromeDriver =&gt; I felt that Chrome was far faster and more reliable than Firefox for Selenium Tests recently.</li><li>Export Report =&gt; Its a ZAP Add-on that I use to generate my JSON report</li><li>An intentionally vulnerable web application called “we care” that was developed by us at we45. Its available as a Docker container =&gt; <a href="https://hub.docker.com/r/nithinwe45/wecare/">https://hub.docker.com/r/nithinwe45/wecare/</a></li><li>ZAP JSON-RPC Service. A Small JSON-RPC service that I created that you can use to interact with ZAP’s API. =&gt; <a href="https://github.com/we45/OWASP-ZAP-JSON-RPC-Service">https://github.com/we45/OWASP-ZAP-JSON-RPC-Service</a></li></ul><p><strong>The Good</strong></p><ul><li>OWASP ZAP is probably one of the best tools that you can use for integration into an automated pipeline. Its API is extremely powerful and allows the user to control even the smallest operational aspect of ZAP. Highly recommended for this reason. ZAP also has a host of other benefits including some really powerful Add-ons etc</li><li>Writing the End-to-End test in NightwatchJS was a breeze. But there were several issues with the other things (see “The Bad”). Nightwatch also provides Test Hooks. These are events that can be fired before the test, after the test and before and after each test. I have used test hooks (before and after) extensively in this example</li><li>(Shameless Plug) I am glad I wrote my minimalistic ZAP JSON RPC service. While ZAP does have a REST API, its painful to use REST endpoints over more intuitive “functions” that a JSON-RPC service allows you to use.</li></ul><p><strong>The Bad:</strong></p><ul><li>Nightwatch is NodeJS, which is JavaScript, which is Asynchronous. There were several times that this led me to nearly tear my hair out in frustration. Async events tend to be a little alien to Python devs like myself. Also, with Testing, you like things to run in sequence. Node and JS make you work for it. You’d see evidence of my frustration in the before and after hooks, where I have used “hacky” solutions to stitch things together.</li><li>OWASP ZAP Javascript API is not very usable. I had to make up for it with the JSON-RPC service. It all worked out in the end 🙂</li><li>Firefox and Geckodriver. I had initially envisioned using Firefox and Geckodriver for the test. But the proxy experience was so terrible and Geckodriver was so slow, I decided to switch the Chrome. It was far far more consistent, and wayyy faster.</li></ul><p><strong>Steps in the Example</strong></p><p>The first thing we want to do is set up Nightwatch to proxy the browser’s traffic through our ZAP’s proxy port. In my example, this port is <em>8090</em> (ZAP). Here’s a gist of the Proxy Settings in <em>nightwatch.conf.js</em>. I have also setup a bunch of other settings in this file, including the ZAP executable path, the report path, etc.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/17e13dd6851471ad6e99d90fe4676333/href">https://medium.com/media/17e13dd6851471ad6e99d90fe4676333/href</a></iframe><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/eba21b2cf6098eef6dc76d87456810b6/href">https://medium.com/media/eba21b2cf6098eef6dc76d87456810b6/href</a></iframe><p>The next thing I did, was setup a “before” test hook. True to the name, this is a test hook that is fired, BEFORE the test commences. What I like to do is to start the ZAP executable in this hook and get it ready to receive requests from the E2E test. I have executed ZAP in the GUI mode, but adding a headless flag when you are invoking the executable runs it without the GUI (needed in CI-style environments)</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/771988a53a1de323a563f50f7b59f3e0/href">https://medium.com/media/771988a53a1de323a563f50f7b59f3e0/href</a></iframe><p>Next, the E2E test executes and runs all the tests. Here, I have two very simple tests setup. This is your actual test.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/2a9787ec3758161a15c8ab639013b78c/href">https://medium.com/media/2a9787ec3758161a15c8ab639013b78c/href</a></iframe><p>Once the test executes, we want the browser to close. Subsequently, I signal to ZAP (through the ZAP JSON RPC service) to commence an “Active Scan” against the application. Once the Active Scan is triggered, its status (in percentage) is queried every 10 seconds. Be advised that with large apps, scans can take the proverbial “several hours”. Once the scan completes (100%), the result is written to the the report path (from nightwatch.conf.js) as a JSON document. Once all this is done, ZAP shuts down and all is well with the world 🙂 All of this magic happens in the “after” test hook.</p><iframe src="" width="0" height="0" frameborder="0" scrolling="no"><a href="https://medium.com/media/114d28ae7fbea252f3ecd3a657281071/href">https://medium.com/media/114d28ae7fbea252f3ecd3a657281071/href</a></iframe><p><strong>Tips and Tricks</strong></p><ul><li>I make this recommendation to all my clients. And I maintain it. Never write massive tests. They result in scans running for hours. Smaller tests have smaller scan runtimes, hence more focused results.</li><li>Optimize ZAP’s Scan Policy to suit your application. I highly recommend that you don’t run the default, especially with plugins like Active Scan ++, etc enabled. I have used a scan policy called “Light” (in this example) which runs a low intensity set of checks for only a few vulnerabilities. You should tailor your scan policy to your application. For instance an Active Scan check for “Trace axd Information Disclosure” would probably be useless against a NodeJS app as its only meant to capture flaws with a <a href="http://asp.net/">ASP.NET</a> application. Or similarly, checking for SQL Injection with SQLite doesnt make any sense when your DB is MySQL.</li><li>If you are testing HTTPS sites, you should consider installing ZAP’s certificate into the browser that you are planning on using.</li></ul><p><a href="https://asciinema.org/a/qTF3MXXNHuLrUNxaPZxcQ8IQi">NightWatchJS with OWASP ZAP</a></p><p>This entire example can be downloaded from this repo: <a href="https://github.com/we45/Nightwatch-ZAP">https://github.com/we45/Nightwatch-ZAP</a></p><blockquote>Follow Abhay on Twitter: <a href="http://twitter.com/abhaybhargav">@abhaybhargav</a></blockquote><blockquote>Abhay Bhargav is the CTO of we45, a focused Application Security company. Abhay is the author of two international publications. “Secure Java for Web Application Development” and “PCI Compliance: A Definitive Guide”. Abhay is a builder and breaker of applications, and has authored multiple applications in Django and NodeJS. He is the Chief Architect of “Orchestron”, a leading Application Vulnerability Correlation and Orchestration Framework. He is a passionate Pythonista and loves the idea of automation in security. This passion prompted him to author the world’s first hands-on Security in DevOps training that has been delivered in multiple locations, and recently as a highly successful training programs at the OWASP AppSecUSA 2016, OWASP AppSec EU and USA 2017. Abhay recently delivered a workshop on SecDevOps at DEFCON 25.</blockquote><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=8240c540c524" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>