<?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 elkhvn on Medium]]></title>
        <description><![CDATA[Stories by elkhvn on Medium]]></description>
        <link>https://medium.com/@elkhvn?source=rss-70e889678104------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*FIXLMIOtWQFTjQVo94hq0A.png</url>
            <title>Stories by elkhvn on Medium</title>
            <link>https://medium.com/@elkhvn?source=rss-70e889678104------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sun, 29 Nov 2026 01:12:45 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@elkhvn/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[Export AWS Prowler output to .docx report]]></title>
            <link>https://elkhvn.medium.com/export-aws-prowler-output-to-docx-report-3aa0a844b518?source=rss-70e889678104------2</link>
            <guid isPermaLink="false">https://medium.com/p/3aa0a844b518</guid>
            <dc:creator><![CDATA[elkhvn]]></dc:creator>
            <pubDate>Wed, 01 May 2024 11:40:48 GMT</pubDate>
            <atom:updated>2024-05-01T11:40:48.345Z</atom:updated>
            <content:encoded><![CDATA[<h3>Export AWS Prowler output to .docx report</h3><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*tbDwTbopkBCmoiNBYmceQA.png" /></figure><p>The prowler HTML output is something that requires additional package of patience to scroll and filter to find out the weaknesses in the target AWS environment. The process explained here and the resulted code will be helpful to parse the resulted json (have more details than HTML report) to easily readable .docx format. It also can be considered as a final aws security audit report for customer.</p><p>Lets start by analyzing the HTML report generated by the Prowler. I will skip the part of configuring the aws credentials and Prowler execution because it is not the topic.</p><p>As we see from the screenshot it renders first 100 entries and have a small “Filter” button. It works very slow because the amount of the data held in one single HTML file is very excessive. I tried to give more power to my VM and even tried to open it up on my host machine but the speed of the filter execution changed slightly.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*S0lQwwNt7JvfoRNdEG5SKg.png" /><figcaption>Prowler HTML report</figcaption></figure><p>Yeah maybe someone can state that the interface is pretty good because of built-in filtration and sorting mechanism. However it is not the only drawback of an HTML format. It gives less details that json format.</p><p>The screenshot below shows the minimum amount of the details.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*76o7nsqTY2SKdCPx054Eww.png" /><figcaption>finding details in HTML</figcaption></figure><p>Lets compare the exactly same vulnerability in the json file.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*_p0FkUS0d3jcAj4qsMBuHQ.png" /><figcaption>json output</figcaption></figure><p>It gives some details like:</p><ul><li>Description</li><li>Risk</li><li>Remediation (Code, Text, URL)</li><li>Resource ARN</li></ul><p>All of this information is required to fix the issue and adding this to the report will give direction to engineering team.</p><blockquote><strong><em>I have used several tools like DefectDojo and etc. to parse this data but none of them give me the ability to parse it as a one big document file.</em></strong></blockquote><p>Now lets move with the code which will parse this given json and create a .docx report.</p><p>The first stage of developments was understanding how to group vulnerabilities because each of them is self sufficient. I used <a href="https://app.gigasheet.com/">gigasheet</a> to visualize it in table format and group according to some parameters.</p><p>Service Name → Status (PASS/FAIL) → CheckID</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*v0GTjR40KCbeXlyjvjWQKQ.png" /><figcaption>gigasheet (sheet on steroids)</figcaption></figure><p>Lets translate it into code</p><pre>import json<br>import collections<br><br><br>def load_json(filename):<br>    &quot;&quot;&quot; Load and return the JSON data from a file &quot;&quot;&quot;<br>    try:<br>        with open(filename, &#39;r&#39;) as file:<br>            return json.load(file)<br>    except FileNotFoundError:<br>        print(f&quot;Error: The file &#39;{filename}&#39; does not exist.&quot;)<br>        exit(1)<br>    except json.JSONDecodeError:<br>        print(&quot;Error: Failed to decode JSON from the file.&quot;)<br>        exit(1)<br><br><br>def nested_dict(n, type):<br>    if n == 1:<br>        return collections.defaultdict(type)<br>    else:<br>        return collections.defaultdict(lambda: nested_dict(n-1, type))<br><br><br><br><br>def main():<br><br><br>    # load JSON data from the file<br>    json_data = load_json(args.filename) <br><br><br><br>    grouped_data = nested_dict(2, list)  # 2 levels deep: ServiceName, CheckID<br><br><br>    for item in json_data:<br>        service_name = item[&#39;ServiceName&#39;]<br>        status = item[&#39;Status&#39;]<br>        check_id = item[&#39;CheckID&#39;]<br><br><br><br>        findings = {<br>            &#39;description&#39;: item[&#39;Description&#39;],<br>            &#39;remediation_text&#39;: item[&#39;Remediation&#39;][&#39;Recommendation&#39;][&#39;Text&#39;],<br>            &#39;remediation_code&#39;: item[&#39;Remediation&#39;][&#39;Code&#39;][&#39;CLI&#39;],<br>            &#39;remediation_url&#39;:  item[&#39;Remediation&#39;][&#39;Recommendation&#39;][&#39;Url&#39;],<br>            &#39;risk&#39;: item[&#39;Risk&#39;],<br>            &#39;severity&#39;: item[&#39;Severity&#39;],<br>            &#39;status_ext&#39;: item[&#39;StatusExtended&#39;],<br>            &#39;arn&#39;: item[&#39;ResourceArn&#39;]<br>        }<br><br><br>        <br>        if status == &#39;FAIL&#39;:<br>            if findings not in grouped_data[service_name][check_id]:<br>                grouped_data[service_name][check_id].append(findings)</pre><p>I used collections.defaultdict instead of regular python dictionary because of <strong>“automatic key initialization”</strong>. Its ability to automatically initialize entries. When you try to access or modify an entry in a defaultdict for which the key does not yet exist, it automatically creates that key with a default value, and eliminates the need for checks or manual initialization of keys:</p><p><strong>With </strong><strong>defaultdict</strong>:</p><pre>dd[&#39;new_key&#39;].append(1)</pre><p><strong>With regular </strong><strong>dict</strong>:</p><pre>if &#39;new_key&#39; not in d:<br>    d[&#39;new_key&#39;] = []<br>d[&#39;new_key&#39;].append(1)</pre><p>The function <strong>nested_dict() </strong>used to create nested dictionaries with the list as the last (leaf) type. Why nested dictionary → because grouping will be nested. This function written in recursive mode and lambda nested_dict(n-1,type) which is called <strong>“lazy initialization”</strong>. Lazy initialization is a programming strategy that delays the creation of an object, the calculation of a value, or some other expensive process until the first time it is needed.</p><p>By outputting the nested dict we can see that we got the pretty good result</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*VkO39w-ydQNZwJuetQZSmQ.png" /><figcaption>output of the first iteration of grouping</figcaption></figure><p>Now we have another problem. If you notice each finding that I have append to the list are under the same CheckID which means they are same (description, risk, remediation, severity). Therefore we need to group the list stored in the nested dict.</p><pre>def output_data():<br>    for service_name, check_ids in grouped.items():<br>        service_name = &#39; &#39;.join(service_name.split(&#39;-&#39;)).upper()<br>        n = 0<br>        print(&quot; &quot;*4*n, service_name)<br><br>        for check_id, findings in check_ids.items():<br>            check_id = &#39; &#39;.join(check_id.split(&#39;_&#39;)).upper()<br>            print(&quot; &quot;*4*(n+1), check_id)<br><br>            status_group = collections.defaultdict(list)    <br>            for finding in findings:<br>                status_ext = finding[&#39;status_ext&#39;]<br>                arn = finding[&#39;arn&#39;]<br><br>                status_group[status_ext].append(arn)<br>            <br>            print(&#39; &#39;*4*(n+2),finding[&#39;description&#39;])<br>            print(&#39; &#39;*4*(n+2),finding[&#39;remediation_text&#39;])<br>            print(&#39; &#39;*4*(n+2),finding[&#39;remediation_code&#39;])<br>            print(&#39; &#39;*4*(n+2),finding[&#39;remediation_url&#39;])<br>            print(&#39; &#39;*4*(n+2),finding[&#39;risk&#39;])<br>            print(&#39; &#39;*4*(n+2),finding[&#39;severity&#39;])<br><br><br>            for status_extended, arns in status_group.items():<br>                print(&#39; &#39;*4*(n+2), status_extended)<br><br>                for arn in arns:<br>                    print(&#39; &#39;*4*(n+3), arn)<br>          <br></pre><p>I just grouped it again using the same technique. I printed out common info once and then iterate through entire list of ARNs to print them one-by-one.</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*BtPWsYWc8B86k219ExVUBw.png" /><figcaption>the output of our grouping</figcaption></figure><p>Then I used a python-docx library and write all of this with little formatting in docx document.</p><p>The final result looks like:</p><figure><img alt="" src="https://cdn-images-1.medium.com/max/1024/1*4BnwN_1Dy0dca81ErRejsQ.png" /><figcaption>the final AWS audit document</figcaption></figure><p>I have added argparse for command line usability and push it to the <a href="https://github.com/elkhvn/prowler-to-docx">github</a>. I am glad to hear your feedback or advice regarding other possible approaches or things that I missed.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=3aa0a844b518" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>