<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: sachinravindran</title>
    <description>The latest articles on DEV Community by sachinravindran (@sachinravindran).</description>
    <link>https://dev.to/sachinravindran</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F605334%2F53e46926-d53a-4a73-9a99-87c0e6dc47ab.png</url>
      <title>DEV Community: sachinravindran</title>
      <link>https://dev.to/sachinravindran</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/sachinravindran"/>
    <language>en</language>
    <item>
      <title>How We Removed a Crypto Miner Malware That Exploited Linux File Attributes</title>
      <dc:creator>sachinravindran</dc:creator>
      <pubDate>Mon, 03 Feb 2025 08:36:52 +0000</pubDate>
      <link>https://dev.to/sachinravindran/how-we-removed-a-crypto-miner-malware-that-exploited-linux-file-attributes-4i96</link>
      <guid>https://dev.to/sachinravindran/how-we-removed-a-crypto-miner-malware-that-exploited-linux-file-attributes-4i96</guid>
      <description>&lt;h3&gt;
  
  
  Introduction
&lt;/h3&gt;

&lt;p&gt;Imagine walking into a Monday morning only to find your company’s server grinding to a halt. CPU and memory usage are maxed out, services are timing out, and your team is panicking. This was my reality when I discovered a crypto miner malware (&lt;em&gt;perfectl&lt;/em&gt;) had hijacked our server. What followed was a battle against resource-hogging processes, undeletable files, and a crash course in Linux file attributes. Here’s how I fought back—and what I learned along the way.&lt;/p&gt;




&lt;h3&gt;
  
  
  The Discovery: htop Reveals the Culprit
&lt;/h3&gt;

&lt;p&gt;The first clue was the server’s sluggish performance. Running &lt;code&gt;htop&lt;/code&gt;, I spotted a suspicious process named &lt;strong&gt;perfectl&lt;/strong&gt; guzzling 90%+ of the CPU. Crypto miners are notorious for this—they silently hijack resources to mine cryptocurrency for attackers.&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Key Takeaway:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;strong&gt;Monitor resource usage:&lt;/strong&gt; Tools like &lt;code&gt;htop&lt;/code&gt;, &lt;code&gt;top&lt;/code&gt;, or &lt;code&gt;glances&lt;/code&gt; are critical for spotting abnormal processes.&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  The Roadblock: "Operation Not Permitted" Errors
&lt;/h3&gt;

&lt;p&gt;After killing the malicious process, I traced its files to delete them. But even as root, deletion failed with cryptic errors:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;rm&lt;/span&gt;: cannot remove &lt;span class="s1"&gt;'malicious-file'&lt;/span&gt;: Operation not permitted
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;A quick &lt;code&gt;lsattr&lt;/code&gt; check revealed the malware’s sneaky trick: &lt;strong&gt;immutable files&lt;/strong&gt;. The &lt;code&gt;i&lt;/code&gt; attribute was set, preventing deletion or modification:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;lsattr malicious-file  
&lt;span class="nt"&gt;----i---------e----&lt;/span&gt; malicious-file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Why This Matters:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
The &lt;code&gt;i&lt;/code&gt; (immutable) flag locks files, even for root. Attackers use this to protect their malware from being removed.&lt;/p&gt;


&lt;h3&gt;
  
  
  The Fix: chattr to the Rescue
&lt;/h3&gt;

&lt;p&gt;To remove the files, I first had to strip the &lt;code&gt;i&lt;/code&gt; attribute using &lt;code&gt;chattr&lt;/code&gt;:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo &lt;/span&gt;chattr &lt;span class="nt"&gt;-i&lt;/span&gt; malicious-file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;em&gt;Then&lt;/em&gt; deletion worked:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;sudo rm&lt;/span&gt; &lt;span class="nt"&gt;-rf&lt;/span&gt; malicious-file
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;&lt;strong&gt;Important Notes:&lt;/strong&gt;&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Be thorough&lt;/strong&gt;: Malware often spreads across multiple files/directories. Use &lt;code&gt;lsattr -R /path/to/suspicious/dir&lt;/code&gt; to check recursively.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Audit cron jobs/services&lt;/strong&gt;: The malware likely had a persistence mechanism (e.g., a cron job respawning it).&lt;/p&gt;&lt;/li&gt;
&lt;/ul&gt;




&lt;h3&gt;
  
  
  Lessons Learned: Protect Your Server
&lt;/h3&gt;

&lt;ol&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Monitor Actively&lt;/strong&gt;: Use tools like &lt;code&gt;htop&lt;/code&gt;, &lt;code&gt;netstat&lt;/code&gt;, and audit logs.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Lock Down Permissions&lt;/strong&gt;: Restrict write access to critical directories.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Know Linux Attributes&lt;/strong&gt;: The &lt;code&gt;i&lt;/code&gt; (immutable), &lt;code&gt;a&lt;/code&gt; (append-only), and &lt;code&gt;e&lt;/code&gt; (extent format) flags can be abused by attackers.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Automate Scans&lt;/strong&gt;: Tools like &lt;code&gt;chkrootkit&lt;/code&gt;, &lt;code&gt;rkhunter&lt;/code&gt;, or modern EDR solutions can flag hidden threats.&lt;/p&gt;&lt;/li&gt;
&lt;li&gt;&lt;p&gt;&lt;strong&gt;Backup &amp;amp; Test&lt;/strong&gt;: Ensure immutable backups exist to recover from attacks.&lt;/p&gt;&lt;/li&gt;
&lt;/ol&gt;




&lt;h3&gt;
  
  
  Final Thoughts
&lt;/h3&gt;

&lt;p&gt;This incident was a wake-up call. Attackers are getting craftier—using legitimate Linux features (like &lt;code&gt;chattr&lt;/code&gt;) against us. Vigilance, layered security, and understanding system fundamentals are your best defense.``&lt;/p&gt;

</description>
      <category>hacking</category>
      <category>security</category>
      <category>linux</category>
    </item>
  </channel>
</rss>
