<?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 Dawood Arshad on Medium]]></title>
        <description><![CDATA[Stories by Dawood Arshad on Medium]]></description>
        <link>https://medium.com/@daod.arshad?source=rss-33cfb10e6f01------2</link>
        <image>
            <url>https://cdn-images-1.medium.com/fit/c/150/150/1*AIIrK2ss4vsHR-xlMc7kGQ@2x.jpeg</url>
            <title>Stories by Dawood Arshad on Medium</title>
            <link>https://medium.com/@daod.arshad?source=rss-33cfb10e6f01------2</link>
        </image>
        <generator>Medium</generator>
        <lastBuildDate>Sat, 28 Nov 2026 21:02:44 GMT</lastBuildDate>
        <atom:link href="https://medium.com/@daod.arshad/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 Advisory Automation]]></title>
            <link>https://medium.com/@daod.arshad/security-advisory-automation-59a50ad206e9?source=rss-33cfb10e6f01------2</link>
            <guid isPermaLink="false">https://medium.com/p/59a50ad206e9</guid>
            <category><![CDATA[information-security]]></category>
            <category><![CDATA[wazuh]]></category>
            <category><![CDATA[security-engineering]]></category>
            <category><![CDATA[automation]]></category>
            <dc:creator><![CDATA[Dawood Arshad]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 14:08:28 GMT</pubDate>
            <atom:updated>2025-04-12T11:57:57.746Z</atom:updated>
            <content:encoded><![CDATA[<h3>Usecase</h3><p>Anyone working in the security department of medium to large scale organizations would know how much pain is inflicted by vulnerabilities. Therefore, we will be automating the process of releasing security advisories over email by utilizing the <a href="https://documentation.wazuh.com/current/user-manual/capabilities/vulnerability-detection/how-it-works.html">vulnerability detection</a> module of Wazuh.</p><h3>Preamble</h3><p>A number of things to keep in mind before proceeding with this automation:</p><ol><li>The script requires an active account of <a href="https://vuldb.com/">vuldb.com</a></li><li>The free account for vuldb only supports 5 api calls.</li><li>The vulnerability detection module of Wazuh needs to be working properly.</li><li>The script runs periodically after the set amount of time and releases an email for the vulnerabilities detected between the current time and the last time script ran.</li><li>Only one email is released for each vulnerability. All the agents which are affected by the vulnerability are included in the same email.</li></ol><h3>Working</h3><p>Lets assume the script runs every 24 hours. The script will fetch the events of all the critical vulnerabilities appeared on Wazuh within the last 24 hours. After that, the script will create a mapping between CVE and all the agents assosciated with it. Then, it will query the vuldb api for furhter information related to CVE. Finally, releasing the email.</p><h3>Script</h3><ol><li>Install the required python libraries.</li></ol><pre>pip install &#39;keyring[completion]&#39;<br>pip install keyrings.alt</pre><p>2. If an image is required to be sent in the email body, place it in the same location as the script.</p><p>3. Store the wazuh credentials in keyring.</p><pre>python3<br>import keyring<br>keyring.set_password(&quot;service&quot;,&quot;username&quot;,&quot;password&quot;)<br>exit()</pre><p>3. Create a .py file and copy the below script into that file.</p><pre>import os<br>import smtplib<br>import email<br>from email.mime.multipart import MIMEMultipart<br>from email.mime.text import MIMEText<br>from email.mime.image import MIMEImage<br>import json<br>import requests<br>import time<br>import keyring<br><br># Add your personal API key for VaulDB here<br>personalApiKey = &quot;&lt;vauldb-api-key&gt;&quot;<br><br># Set HTTP Header for VaulDB API<br>userAgent = &#39;VulDB API Advanced Python Agent&#39;<br>headers = {&#39;User-Agent&#39;: userAgent, &#39;X-VulDB-ApiKey&#39;: personalApiKey}<br><br># URL VulDB endpoint<br>url = &#39;https://vuldb.com/?api&#39;<br><br># Sender Email<br>sender = &quot;&quot;<br><br># Recipients<br>recipients = [&quot;&quot;]<br>cc = [&quot;&quot;]<br><br>alerts = {}<br><br># Function to inject all the hosts affected by a CVE in the email body<br>def impacted_hosts(hosts):<br>        html = &quot;&quot;&quot; &quot;&quot;&quot;<br>        for host in hosts:<br>                html=html+&quot;&quot;&quot;&lt;h3 style=&#39;margin-left:.5in;text-indent:-.25in;mso-list:l0 level1 lfo1&#39;&gt;&lt;![if !supportLists]&gt;&lt;span style=&#39;font-size:11.0pt;font-family:Symbol;font-weight:normal&#39;&gt;&lt;span style=&#39;mso-list:Ignore&#39;&gt;&amp;middot;&lt;span style=&#39;font:7.0pt &quot;Times New Roman&quot;&#39;&gt;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp;&amp;nbsp; &lt;/span&gt;&lt;/span&gt;&lt;/span&gt;&lt;![endif]&gt;&lt;span style=&#39;font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;font-weight:normal&#39;&gt;{agent}&lt;/span&gt;&lt;span style=&#39;font-size:11.0pt;font-family:&quot;Calibri&quot;,sans-serif;font-weight:normal&#39;&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/h3&gt;&quot;&quot;&quot;<br>                html = html.replace(&quot;{agent}&quot;,host)<br>#               print(html)<br>        return html<br><br># Function to inject the vulnerability references in the email body<br>def vuln_references(links):<br>        links_html = &quot;&quot;&quot; &quot;&quot;&quot;<br>        for link in links:<br>                links_html=links_html + &quot;&quot;&quot;&lt;tr style=&#39;height:22.05pt&#39;&gt;&lt;td width=627 style=&#39;width:466.85pt;padding:.75pt .75pt .75pt .75pt;height:22.05pt&#39;&gt;&lt;p class=MsoNormal style=&#39;line-height:105%&#39;&gt;&lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif;color:black&#39;&gt;&lt;a href=&quot;{url}&quot;&gt;{url}&lt;/a&gt;&lt;o:p&gt;&lt;/o:p&gt;&lt;/span&gt;&lt;/p&gt;&lt;/td&gt;&lt;/tr&gt; &quot;&quot;&quot;<br>                links_html = links_html.replace(&quot;{url}&quot;,link)<br>        return links_html<br><br># Function to send email<br>def send_email(subject, body, sender, recipients, cc, image):<br>#        msg = MIMEText(body, &#39;html&#39;)<br>        msg = MIMEMultipart()<br>        msg.attach(image)<br>        msg.attach(MIMEText(body, &#39;html&#39;))<br>        msg[&#39;Subject&#39;] = subject<br>        msg[&#39;From&#39;] = sender<br>        msg[&#39;To&#39;] = &#39;, &#39;.join(recipients)<br>        msg[&#39;Cc&#39;] = &#39;, &#39;.join(cc)<br>        with smtplib.SMTP(&#39;&lt;email-server-ip&gt;&#39;, 25) as smtp_server:<br>                # In case of TLS, uncomment the below lines.<br>#                server.starttls()  # Secure the connection<br>#                server.login(&quot;email-username&quot;, &quot;email-password&quot;)<br>                smtp_server.sendmail(sender, recipients , msg.as_string())<br>#    print(&quot;Message sent!&quot;)<br><br><br># Getting Alerts From Wazuh Indexer<br>os.system(&quot;curl -k -u &quot; + &quot;username:&quot; + keyring.get_password(&quot;service&quot;, &quot;username&quot;) + &quot; \&quot;https://&lt;ip-of-wazuh&gt;:9200/wazuh-alerts-4.x-*/_search\&quot; -H \&quot;Content-Type: application/json\&quot; -d \&#39;{ \&quot;size\&quot;: 1000, \&quot;query\&quot;: { \&quot;bool\&quot;: { \&quot;must\&quot;: [ { \&quot;term\&quot;: { \&quot;rule.id\&quot;: { \&quot;value\&quot;: \&quot;23506\&quot;, \&quot;boost\&quot;: 1 } } }, { \&quot;term\&quot;: { \&quot;data.vulnerability.severity\&quot;: { \&quot;value\&quot;: \&quot;Critical\&quot;, \&quot;boost\&quot;: 1 } } }, { \&quot;range\&quot;: { \&quot;timestamp\&quot;: { \&quot;from\&quot;: \&quot;now-1d\&quot;, \&quot;to\&quot;: \&quot;now\&quot;, \&quot;include_lower\&quot;: true, \&quot;include_upper\&quot;: true, \&quot;boost\&quot;: 1 } } } ], \&quot;adjust_pure_negative\&quot;: true, \&quot;boost\&quot;: 1 } }, \&quot;sort\&quot;: [ { \&quot;timestamp\&quot;: { \&quot;order\&quot;: \&quot;desc\&quot; } } ] }\&#39; &gt; results.json&quot;)<br><br># In case if you would like to add images<br>f = open(&#39;infoSecBanner.png&#39;, &#39;rb&#39;)<br>infosec_image = MIMEImage(f.read(&quot;image.png&quot;))<br>f.close()<br># Specify the ID according to the img src in the HTML part<br>infosec_image.add_header(&#39;Content-ID&#39;, &#39;&lt;infosec_image&gt;&#39;)<br><br># Opening JSON file<br>f = open(&#39;results.json&#39;)<br><br># returns JSON object as<br># a dictionary<br>data = json.load(f)<br><br>f.close()<br><br># Creating a dictionary to only store valuable information<br># Dictionary Format<br># {&quot;cve-1&quot;:[[&quot;agent-1&quot;,&quot;agent-2&quot;],&quot;severity&quot;,[&quot;reference-1&quot;,&quot;reference-2&quot;]],&quot;cve-2&quot;:[[&quot;agent-1&quot;,&quot;agent-2&quot;],&quot;severity&quot;,[&quot;reference-1&quot;,&quot;reference-2&quot;]]}<br>for i in data[&quot;hits&quot;][&quot;hits&quot;]:<br>        alerts[i[&quot;_source&quot;][&quot;data&quot;][&quot;vulnerability&quot;][&quot;cve&quot;]] = [[],i[&quot;_source&quot;][&quot;data&quot;][&quot;vulnerability&quot;][&quot;severity&quot;],i[&quot;_source&quot;][&quot;data&quot;][&quot;vulnerability&quot;][&quot;references&quot;]]<br><br># Adding agents to each CVE<br>for cve in list(alerts.keys()):<br>        for i in data[&quot;hits&quot;][&quot;hits&quot;]:<br>                if cve == i[&quot;_source&quot;][&quot;data&quot;][&quot;vulnerability&quot;][&quot;cve&quot;] and i[&quot;_source&quot;][&quot;agent&quot;][&quot;name&quot;]+&quot; (&quot;+i[&quot;_source&quot;][&quot;agent&quot;][&quot;ip&quot;]+&quot;)&quot; not in alerts[cve][0]:<br>                        alerts[cve][0].append(i[&quot;_source&quot;][&quot;agent&quot;][&quot;name&quot;]+&quot; (&quot;+i[&quot;_source&quot;][&quot;agent&quot;][&quot;ip&quot;]+&quot;)&quot;)<br><br># Selecting a CVE<br>for alert in list(alerts.keys()):<br>#        print(alerts[alert][1])<br>        postData={}<br>        postData[&#39;details&#39;] =  1<br>        # Defining the CVE to be queried<br>        postData[&#39;search&#39;] = alert<br>        # Get API response<br>        response = requests.post(url,headers=headers,data=postData)<br>        # Display result if evertything went OK<br>        if response.status_code == 200:<br>        # Parse HTTP body as JSON<br>                responseJson = json.loads(response.content)<br>        # Output<br>                for i in responseJson[&#39;result&#39;]:<br>                        cve_data=i[&quot;entry&quot;]<br>                        #print(cve_data)<br><br>                        # Email Body<br>                        body = &quot;&quot;&quot;&lt;html xmlns:v=&quot;urn:schemas-microsoft-com:vml&quot; xmlns:o=&quot;urn:schemas-microsoft-com:office:office&quot; xmlns:w=&quot;urn:schemas-microsoft-com:office:word&quot; xmlns:m=&quot;http://schemas.microsoft.com/office/2004/12/omml&quot; xmlns=&quot;http://www.w3.org/TR/REC-html40&quot;&gt; &lt;head&gt; &lt;meta http-equiv=Content-Type content=&quot;text/html; charset=us-ascii&quot;&gt; &lt;meta name=Generator content=&quot;Microsoft Word 15 (filtered medium)&quot;&gt; &lt;!--[if !mso]&gt; &lt;style&gt;v\:* {behavior:url(#default#VML);} o\:* {behavior:url(#default#VML);} w\:* {behavior:url(#default#VML);} .shape {behavior:url(#default#VML);} &lt;/style&gt; &lt;![endif]--&gt; &lt;style&gt; &lt;!-- /* Font Definitions */ @font-face {font-family:Wingdings; panose-1:5 0 0 0 0 0 0 0 0 0;} @font-face {font-family:&quot;Cambria Math&quot;; panose-1:2 4 5 3 5 4 6 3 2 4;} @font-face {font-family:&quot;Calibri Light&quot;; panose-1:2 15 3 2 2 2 4 3 2 4;} @font-face {font-family:Calibri; panose-1:2 15 5 2 2 2 4 3 2 4;} /* Style Definitions */ p.MsoNormal, li.MsoNormal, div.MsoNormal {margin:0in; margin-bottom:.0001pt; font-size:11.0pt; font-family:&quot;Calibri&quot;,sans-serif;} h1 {mso-style-priority:9; mso-style-link:&quot;Heading 1 Char&quot;; margin-top:12.0pt; margin-right:0in; margin-bottom:0in; margin-left:0in; margin-bottom:.0001pt; page-break-after:avoid; font-size:16.0pt; font-family:&quot;Calibri Light&quot;,sans-serif; color:#2E74B5; font-weight:normal;} h3 {mso-style-priority:9; mso-style-link:&quot;Heading 3 Char&quot;; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; font-size:13.5pt; font-family:&quot;Times New Roman&quot;,serif; font-weight:bold;} a:link, span.MsoHyperlink {mso-style-priority:99; color:#0563C1; text-decoration:underline;} a:visited, span.MsoHyperlinkFollowed {mso-style-priority:99; color:#954F72; text-decoration:underline;} p {mso-style-priority:99; mso-margin-top-alt:auto; margin-right:0in; mso-margin-bottom-alt:auto; margin-left:0in; font-size:12.0pt; font-family:&quot;Times New Roman&quot;,serif;} span.EmailStyle17 {mso-style-type:personal-compose; font-family:&quot;Calibri&quot;,sans-serif; color:windowtext;} span.Heading3Char {mso-style-name:&quot;Heading 3 Char&quot;; mso-style-priority:9; mso-style-link:&quot;Heading 3&quot;; font-family:&quot;Times New Roman&quot;,serif; font-weight:bold;} span.Heading1Char {mso-style-name:&quot;Heading 1 Char&quot;; mso-style-priority:9; mso-style-link:&quot;Heading 1&quot;; font-family:&quot;Calibri Light&quot;,sans-serif; color:#2E74B5;} .MsoChpDefault {mso-style-type:export-only; font-family:&quot;Calibri&quot;,sans-serif;} @page WordSection1 {size:8.5in 11.0in; margin:1.0in 1.0in 1.0in 1.0in;} div.WordSection1 {page:WordSection1;} /* List Definitions */ @list l0 {mso-list-id:1312712335; mso-list-type:hybrid; mso-list-template-ids:1880671168 67698689 67698691 67698693 67698689 67698691 67698693 67698689 67698691 67698693;} @list l0:level1 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:Symbol;} @list l0:level2 {mso-level-number-format:bullet; mso-level-text:o; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:&quot;Courier New&quot;;} @list l0:level3 {mso-level-number-format:bullet; mso-level-text:\F0A7; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:Wingdings;} @list l0:level4 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:Symbol;} @list l0:level5 {mso-level-number-format:bullet; mso-level-text:o; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:&quot;Courier New&quot;;} @list l0:level6 {mso-level-number-format:bullet; mso-level-text:\F0A7; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:Wingdings;} @list l0:level7 {mso-level-number-format:bullet; mso-level-text:\F0B7; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:Symbol;} @list l0:level8 {mso-level-number-format:bullet; mso-level-text:o; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:&quot;Courier New&quot;;} @list l0:level9 {mso-level-number-format:bullet; mso-level-text:\F0A7; mso-level-tab-stop:none; mso-level-number-position:left; text-indent:-.25in; font-family:Wingdings;} ol {margin-bottom:0in;} ul {margin-bottom:0in;} --&gt; &lt;/style&gt; &lt;!--[if gte mso 9]&gt; &lt;xml&gt; &lt;o:shapedefaults v:ext=&quot;edit&quot; spidmax=&quot;1026&quot; /&gt; &lt;/xml&gt; &lt;![endif]--&gt;&lt;!--[if gte mso 9]&gt; &lt;xml&gt; &lt;o:shapelayout v:ext=&quot;edit&quot;&gt; &lt;o:idmap v:ext=&quot;edit&quot; data=&quot;1&quot; /&gt; &lt;/o:shapelayout&gt; &lt;/xml&gt; &lt;![endif]--&gt; &lt;/head&gt; &lt;body lang=EN-US link=&quot;#0563C1&quot; vlink=&quot;#954F72&quot;&gt; &lt;div class=WordSection1&gt; &lt;p class=MsoNormal&gt; &lt;img width=792 height=202 style=&#39;width:8.25in;height:2.1in&#39; id=&quot;Picture_x0020_3&quot; src=&quot;cid:infosec_image&quot;&gt; &lt;o:p&gt;&lt;/o:p&gt; &lt;/p&gt; &lt;table class=MsoNormalTable border=0 cellspacing=0 cellpadding=0 width=0 style=&#39;width:490.2pt;border-collapse:collapse&#39;&gt; &lt;tr&gt; &lt;td width=654 valign=top style=&#39;width:490.2pt;padding:0in 5.4pt 0in 5.4pt&#39;&gt; &lt;h1 style=&#39;margin-top:0in;background:white&#39;&gt; &lt;b&gt;&lt;span style=&#39;font-size:14.0pt;color:#242424&#39;&gt;{title}&lt;/span&gt;&lt;/b&gt; &lt;b&gt;&lt;span style=&#39;font-size:14.0pt;color:windowtext&#39;&gt; |&lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&#39;font-size:14.0pt;color:#1F497D&#39;&gt; &lt;/span&gt;&lt;/b&gt;&lt;b&gt;&lt;span style=&#39;font-size:14.0pt;color:windowtext&#39;&gt;Apply Security Patch&lt;/span&gt;&lt;/b&gt; &lt;b&gt; &lt;span style=&#39;font-size:14.0pt;color:#242424&#39;&gt; &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/b&gt; &lt;/h1&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=654 valign=top style=&#39;width:490.2pt;padding:0in 5.4pt 0in 5.4pt&#39;&gt; &lt;p class=MsoNormal&gt; &lt;b&gt; &lt;span style=&#39;font-size:14.0pt;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; &lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt; &lt;/span&gt; &lt;/b&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=654 valign=top style=&#39;width:490.2pt;padding:0in 5.4pt 0in 5.4pt&#39;&gt; &lt;p class=MsoNormal&gt; &lt;b&gt; &lt;span style=&#39;font-size:14.0pt;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; Description Summary: &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/b&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=654 valign=top style=&#39;width:490.2pt;padding:0in 5.4pt 0in 5.4pt&#39;&gt; &lt;p class=MsoNormal&gt; {details} &lt;span style=&#39;font-size:14.0pt&#39;&gt; &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td valign=top style=&#39;padding:0in 5.4pt 0in 5.4pt&#39;&gt; &lt;table class=MsoNormalTable border=0 cellspacing=3 cellpadding=0 width=0 style=&#39;width:479.4pt&#39;&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;h3 style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; &lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt; &lt;/span&gt; &lt;/h3&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;h3 style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; Threat Level: &lt;span style=&#39;color:red&#39;&gt; {level} &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/span&gt; &lt;/h3&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt;&lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;h3 style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; Impact: &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/h3&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;h3 style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-size:11.0pt;line-height:105%;font-family:&quot;Calibri&quot;,sans-serif;color:#242424;background:white;font-weight:normal&#39;&gt;{impact}&lt;/span&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif;font-weight:normal&#39;&gt; &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/h3&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;h3&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; &lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt; &lt;/span&gt; &lt;/h3&gt; &lt;h3&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt;Impacted Hosts:&lt;/span&gt; &lt;span style=&#39;font-size:12.0pt;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/h3&gt; {agents} &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;h3 style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt; Recommended Mitigation Strategy: &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/h3&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt&#39;&gt; &lt;table class=MsoNormalTable border=1 cellspacing=3 cellpadding=0 width=0 style=&#39;width:468.3pt&#39;&gt; &lt;thead&gt; &lt;tr style=&#39;height:9.1pt&#39;&gt; &lt;td width=624 style=&#39;width:463.9pt;background:#AEAAAA;padding:.75pt .75pt .75pt .75pt;height:9.1pt&#39;&gt; &lt;p class=MsoNormal style=&#39;line-height:105%&#39;&gt; &lt;b&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif;color:black&#39;&gt; Remediation &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/b&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; &lt;/table&gt; &lt;p class=MsoNormal style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif;color:#7F7F7F&#39;&gt; {remediation} &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/p&gt; &lt;p class=MsoNormal style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-size:10.0pt;line-height:105%&#39;&gt; &lt;o:p&gt;&amp;nbsp;&lt;/o:p&gt; &lt;/span&gt; &lt;/p&gt; &lt;table class=MsoNormalTable border=1 cellspacing=3 cellpadding=0 width=0 style=&#39;width:470.45pt&#39;&gt; &lt;thead&gt; &lt;tr style=&#39;height:2.5pt&#39;&gt; &lt;td width=627 style=&#39;width:466.85pt;background:#AEAAAA;padding:.75pt .75pt .75pt .75pt;height:2.5pt&#39;&gt; &lt;p class=MsoNormal style=&#39;line-height:105%&#39;&gt; &lt;b&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif;color:black&#39;&gt; References &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/b&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;/thead&gt; {references} &lt;/table&gt; &lt;p class=MsoNormal style=&#39;line-height:105%&#39;&gt; &lt;span style=&#39;font-size:12.0pt;line-height:105%;font-family:&quot;Times New Roman&quot;,serif&#39;&gt; &lt;o:p&gt;&lt;/o:p&gt; &lt;/span&gt; &lt;/p&gt; &lt;/td&gt; &lt;/tr&gt; &lt;tr style=&#39;height:.5in&#39;&gt; &lt;td width=639 style=&#39;width:475.0pt;padding:.75pt .75pt .75pt .75pt;height:.5in&#39;&gt; &lt;p class=MsoNormal style=&#39;margin-bottom:12.0pt;line-height:105%&#39;&gt; &lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt;&lt;br&gt;&lt;strong&gt;&lt;span style=&#39;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt;Regards,&lt;/span&gt;&lt;/strong&gt;&lt;br&gt;&lt;/span&gt;&lt;span style=&#39;font-size:10.0pt;line-height:105%;font-family:&quot;Calibri Light&quot;,sans-serif&#39;&gt;Security Operations Unit&lt;br&gt;&quot;&quot;&quot;<br>                        # Replacing the placeholder title with the original title of CVE<br>                        body = body.replace(&quot;{title}&quot;,cve_data[&quot;title&quot;])<br>                        # Replacing the placeholder details with CVE Summary<br>                        body = body.replace(&quot;{details}&quot;,cve_data[&quot;summary&quot;])<br>                        # Replacing the level with the severity CVE<br>                        body = body.replace(&quot;{level}&quot;,alerts[alert][1])<br>                        # Replacing the placeholder impact with the impact of CVE<br>                        body = body.replace(&quot;{impact}&quot;,cve_data[&quot;details&quot;][&quot;impact&quot;])<br>                        # Replacing the placeholder remediation with the remediation of CVE<br>                        body = body.replace(&quot;{remediation}&quot;, cve_data[&quot;details&quot;][&quot;countermeasure&quot;])<br>                        # Replacing the placeholder references with the references provided by Wazuh<br>                        body = body.replace(&quot;{references}&quot;, vuln_references(alerts[alert][2]))<br>                        # Replacing the placeholder agents with the agents affected by the CVE<br>                        body = body.replace(&quot;{agents}&quot;,impacted_hosts(alerts[alert][0]))<br>                        # Setting the subject to CVE<br>                        subject = alert+ &quot; | Security Advisory&quot;<br>                        # Sending Email<br>                        send_email(subject, body, sender, recipients, cc, infosec_image)<br>                        # Adding the CVE for which alert is sent to opsgenie data in order to add the note<br>                        data_for_opsgenie[alert] = []<br>                        # Sleeping for 1 Second in order to avoid rate limiting on email server<br>                        time.sleep(1)</pre><p>4. We can now setup a cronjob to run the script every 24 hours.</p><pre>0 0 * * * python3 advisory_automation.py 2&gt;&amp;1 &gt;/dev/null</pre><p>If you want to select a time that fit your needs, please make sure to change the timestamp value in command where alerts are being fetched from Wazuh.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=59a50ad206e9" width="1" height="1" alt="">]]></content:encoded>
        </item>
        <item>
            <title><![CDATA[Fetching Oracle Audit Logs Using Logstash]]></title>
            <link>https://medium.com/@daod.arshad/fetching-oracle-audit-logs-using-logstash-72652e0b8b75?source=rss-33cfb10e6f01------2</link>
            <guid isPermaLink="false">https://medium.com/p/72652e0b8b75</guid>
            <category><![CDATA[logstash]]></category>
            <category><![CDATA[security-engineering]]></category>
            <category><![CDATA[oracle-database]]></category>
            <dc:creator><![CDATA[Dawood Arshad]]></dc:creator>
            <pubDate>Sat, 05 Oct 2024 11:41:19 GMT</pubDate>
            <atom:updated>2024-10-05T11:41:19.516Z</atom:updated>
            <content:encoded><![CDATA[<h3>About the Usecase</h3><p>Recently, I was facing a setback while onboarding audit logs from Oracle database. The version of Oracle was 19c. The database had unified auditing enabled. Unified audit allows one to store audit logs in a system file or oracle database. Upon using the file option as any engineer would do :D, the logs printed in the file did not contain any useful field apart from what action was performed and on which object. But the logs appearing in the table contained extra fields such as username, sql_query, source ip address etc.</p><p>That was one part of the problem. The other part of the issue was that I had the usecase the onboard the audit logs in Wazuh which only supports file based or syslog based event monitoring.</p><p>Therefore, the solution I came up with was to use logstash and its jdbc connector to fetch logs using Logstash and then write them to a file.</p><h3>Some useful information to begin with</h3><ol><li>I used a dedicated redhat machine to fetch the logs.</li><li>Logstash was installed on the dedicated machine using repository manager.</li><li>Wazuh agent was installed on the same machine.</li></ol><h3>Steps</h3><ol><li><a href="https://www.elastic.co/guide/en/logstash/current/installing-logstash.html">Install </a>logstash on the dedicated machine.</li><li><a href="https://edelivery.oracle.com/otn-pub/otn_software/jdbc/1920/ojdbc10.jar">Download</a> the oracle jdbc driver.</li><li>Place the download file i.e. <strong>ojdb10.jar</strong> in the location /usr/share/logstash/logstash-core/lib/jars/ and assign the jar file same permission as other jar files.</li><li>Create a logstash keystore to safely store the database credentials.</li></ol><pre>set +o history<br>export LOGSTASH_KEYSTORE_PASS=mypassword<br>set -o history<br>sudo -E /usr/share/logstash/bin/logstash-keystore --path.settings /etc/logstash create</pre><p>5. Create a logstash service file name <strong>/etc/sysconfig/logstash</strong> if it does not exist already and add the following line:</p><pre>LOGSTASH_KEYSTORE_PASS=mypassword</pre><p>6. Add the database credentials in the keystore.</p><pre>/usr/share/logstash/bin/logstash-keystore --path.settings /etc/logstash/ add &lt;variable&gt;</pre><p>7. In case of username and password, repeat step 6 for storing password.</p><p>8. Validate if entries have been successfully saved in the database.</p><pre>/usr/share/logstash/bin/logstash-keystore list --path.settings /etc/logstash/</pre><p>9. Navigate to /etc/logstash/conf.d/,create a file named oracle_&lt;db_name&gt;.conf and add the following configuration to the file:</p><pre>input {<br>        jdbc {<br>                jdbc_driver_library =&gt; &quot;/usr/share/logstash/logstash-core/lib/jars/ojdbc8.jar&quot;<br>                jdbc_driver_class =&gt; &quot;Java::oracle.jdbc.driver.OracleDriver&quot;<br>                jdbc_connection_string =&gt; &quot;jdbc:oracle:thin:@&lt;db ip address&gt;:&lt;port&gt;/&lt;db_name&gt;&quot;<br>                jdbc_user =&gt; &quot;${ORACLE_DB_USER}&quot;<br>                jdbc_password =&gt; &quot;${ORACLE_DB_PASSWD}&quot;<br>                statement =&gt; &quot;select action_name,additional_info,application_contexts,audit_option,audit_type,authentication_type,client_identifier,client_program_name,current_user,dbid,dblink_info,dbproxy_username,dbusername,direct_path_num_columns_loaded,dp_boolean_parameters1,dp_text_parameters1,entry_id,event_timestamp,event_timestamp_utc,excluded_object,excluded_schema,excluded_user,execution_id,external_userid,global_userid,instance_id,ksacl_service_name,ksacl_source_location,ksacl_user_name,new_name,new_schema,object_edition,object_name,object_privileges,object_schema,os_process,os_username,protocol_action_name,protocol_message,protocol_return_code,protocol_session_id,protocol_userhost,proxy_sessionid,return_code,rls_info,rman_device_type,rman_object_type,rman_operation,rman_session_recid,rman_session_stamp,role,scn,sessionid,sql_binds,sql_text,statement_id,system_privilege,system_privilege_used,target_user,terminal,unified_audit_policies,userhost from unified_audit_trail where event_timestamp &gt; :sql_last_value order by event_timestamp&quot;<br>                use_column_value =&gt; true<br>                tracking_column =&gt; &quot;event_timestamp&quot;<br>                tracking_column_type =&gt; &quot;timestamp&quot;<br>                schedule =&gt; &quot;*/60 * * * * *&quot;<br>                plugin_timezone =&gt; &quot;local&quot;<br>                jdbc_default_timezone =&gt; &quot;Etc/GMT-5&quot;<br>                last_run_metadata_path =&gt; &quot;/tmp/.logstash_last_run_oracle_pri_walletpdb&quot;<br>                record_last_run =&gt; true<br>        }<br>}<br><br><br>output {<br><br>        file {<br>                path =&gt; &quot;path and name of file to store logs&quot;<br>                codec =&gt; json_lines<br>                file_mode =&gt; 0640<br>        }<br><br>}</pre><p>A little information, about the configuration file we just used:</p><ul><li><strong>jdbc_connection_string </strong>defines the ip address, port and pdb for whom logs need to be fetched.</li><li><strong>jdbc_user</strong> and <strong>jdbc_password </strong>require the variable name with which we stored credentials in keystore.</li><li><strong>statement </strong>defines the query to run on the database. I have tailored the query to my needs. One can run * too.</li><li><strong>tracking_* </strong>are the most important one. Since we want logstash to fetch new audit log entries therefore, we need to define a tracking column which if have a new value would prompt logstash to fetch logs.</li><li><strong>schedule </strong>defines the periodic time after which logstash would check for new logs.</li><li><strong>last_run_metadata_path </strong>stores the last value of tracking column when logs were fetched. The next time logstash goes to fetch logs, it will compare the value to tracking column with the value in this file.</li></ul><p>10. Set up appropriate permissions.</p><pre>chmod 640 oracle_&lt;db_name&gt;.conf<br>chown logstash:logstash logstash-config.conf</pre><p>11. If we have multiple databases to fetch audit logs from, we need to repeat steps 9 and 10, accordingly.</p><p>12. Create a separate pipeline for each of these configuration files. Please note that the pipeline id must be unique.</p><pre>- pipeline.id: &lt;pipeline name&gt;<br>  path.config: &quot;/etc/logstash/conf.d/oracle_&lt;db_name&gt;.conf&quot;</pre><p>13. Since, the path I defined for storing the output in configuration resides in /var/log/logstash therefore, I must change permissions of this folder for logstash to be able to access it. You need to setup permissions for your location accordingly.</p><pre>chown logstash: /var/log/logstash/*<br>sudo systemctl restart logstash</pre><p>In case of any errors, please refer to the following file.</p><pre>tail -f /var/log/logstash/logstash-plain.log</pre><p>To onboard logs on wazuh, we can use the <strong>localfile </strong>feature provided in <a href="https://documentation.wazuh.com/current/user-manual/reference/centralized-configuration.html">Centralized Mangement</a>.</p><img src="https://medium.com/_/stat?event=post.clientViewed&referrerSource=full_rss&postId=72652e0b8b75" width="1" height="1" alt="">]]></content:encoded>
        </item>
    </channel>
</rss>