<?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: Linux Pedia</title>
    <description>The latest articles on DEV Community by Linux Pedia (@pedialinux).</description>
    <link>https://dev.to/pedialinux</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.us-east-2.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F4239006%2Fb5d3b817-ef52-4b03-9d74-60364b03e33c.jpg</url>
      <title>DEV Community: Linux Pedia</title>
      <link>https://dev.to/pedialinux</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/pedialinux"/>
    <language>en</language>
    <item>
      <title>Linux Privilege Escalation: Why One SUID Binary Gives Attackers Root (And How to Fix It)</title>
      <dc:creator>Linux Pedia</dc:creator>
      <pubDate>Wed, 11 Nov 2026 12:16:11 +0000</pubDate>
      <link>https://dev.to/pedialinux/linux-privilege-escalation-why-one-suid-binary-gives-attackers-root-and-how-to-fix-it-316a</link>
      <guid>https://dev.to/pedialinux/linux-privilege-escalation-why-one-suid-binary-gives-attackers-root-and-how-to-fix-it-316a</guid>
      <description>&lt;p&gt;⚠️ &lt;strong&gt;Disclaimer: For Educational Purposes Only&lt;/strong&gt;  &lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;All commands and demonstrations in this article are provided strictly for educational purposes, authorized security testing, and sysadmin defense. Never attempt unauthorized privilege escalation against systems you do not own.&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Getting initial access to a Linux machine is often only half the story. &lt;/p&gt;

&lt;p&gt;When a vulnerability gives an attacker or penetration tester an initial foothold, it usually lands as a restricted, low-privilege account (like &lt;code&gt;www-data&lt;/code&gt;, &lt;code&gt;nobody&lt;/code&gt;, or a sandboxed application user). In this state, they cannot inspect password hashes, load kernel modules, or view sensitive directories.&lt;/p&gt;

&lt;p&gt;To gain full control, they need to elevate their permissions to UID 0 (root). This is &lt;strong&gt;privilege escalation&lt;/strong&gt;.&lt;/p&gt;

&lt;p&gt;In this guide, adapted from our &lt;a href="https://pedialinux.github.io/linuxpedia/linux-privilege-escalation-suid.html" rel="noopener noreferrer"&gt;complete Linux Privilege Escalation breakdown on LinuxPedia&lt;/a&gt;, we explore one of the most common and dangerous vectors: &lt;strong&gt;misconfigured SUID binaries&lt;/strong&gt;.&lt;/p&gt;




&lt;h3&gt;
  
  
  1. What is the SUID Bit?
&lt;/h3&gt;

&lt;p&gt;Standard Linux file permissions define read (&lt;code&gt;r&lt;/code&gt;), write (&lt;code&gt;w&lt;/code&gt;), and execute (&lt;code&gt;x&lt;/code&gt;) permissions for the file owner, the group, and everyone else. (If you need a refresher on permission octals, check out our guide on &lt;a href="https://pedialinux.github.io/linuxpedia/linux-file-permissions.html" rel="noopener noreferrer"&gt;Linux File Permissions &amp;amp; Octal Math&lt;/a&gt;).&lt;/p&gt;

&lt;p&gt;There is also a special fourth octal bit: the &lt;strong&gt;SUID (Set User ID)&lt;/strong&gt; bit, represented by numeric value &lt;code&gt;4000&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;When SUID is enabled on an executable file, any user who runs that binary executes it with the privileges of the &lt;strong&gt;file owner&lt;/strong&gt; rather than their own user account.&lt;/p&gt;

&lt;p&gt;You can spot an SUID binary immediately by running &lt;code&gt;ls -l&lt;/code&gt;. Instead of standard &lt;code&gt;-rwxr-xr-x&lt;/code&gt; permissions, the user execute position displays an &lt;code&gt;s&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;$ ls -l /usr/bin/passwd
-rwsr-xr-x 1 root root 68208 Apr 10 2024 /usr/bin/passwd
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Notice the &lt;code&gt;s&lt;/code&gt; in &lt;code&gt;-rwsr-xr-x&lt;/code&gt;. The &lt;code&gt;passwd&lt;/code&gt; binary is owned by root. When a standard user runs &lt;code&gt;passwd&lt;/code&gt; to change their own password, the binary needs temporary root access to update the hash in &lt;code&gt;/etc/shadow&lt;/code&gt;. Because &lt;code&gt;passwd&lt;/code&gt; is strictly coded not to allow command execution, this SUID assignment is safe and legitimate.&lt;/p&gt;




&lt;h3&gt;
  
  
  2. The Administrator Mistake
&lt;/h3&gt;

&lt;p&gt;Problems start when an administrator applies the SUID bit to standard utilities to solve quick permission friction.&lt;/p&gt;

&lt;p&gt;For example, suppose a junior sysadmin wants developers or support staff to search through restricted system logs without handing over the root password. They might run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ sudo chmod u+s /usr/bin/find
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The administrator intended only to let users search files across restricted directories. But they inadvertently handed every single account on the server an instant, zero-password path to root.&lt;/p&gt;




&lt;h3&gt;
  
  
  3. How Attackers Discover SUID Binaries
&lt;/h3&gt;

&lt;p&gt;Whenever an attacker lands on a Linux shell, one of the first reconnaissance commands they run is a search for SUID files across the entire filesystem:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ find / -perm -4000 -type f 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Here is how that command works:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;find /&lt;/code&gt; : Searches starting from the root directory.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-perm -4000&lt;/code&gt; : Matches files with the SUID bit active.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;-type f&lt;/code&gt; : Restricts results to regular executable files.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;2&amp;gt;/dev/null&lt;/code&gt; : Discards permission denied errors from directories the low-privilege account cannot access.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;The output returns a list of all SUID binaries on the machine:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;/usr/bin/mount
/usr/bin/umount
/usr/bin/su
/usr/bin/passwd
/usr/bin/sudo
/usr/bin/find     &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;-- CRITICAL MISCONFIGURATION DETECTED
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Seeing &lt;code&gt;/usr/bin/find&lt;/code&gt; on this list is an immediate red flag.&lt;/p&gt;




&lt;h3&gt;
  
  
  4. Spawning Root with GTFOBins
&lt;/h3&gt;

&lt;p&gt;In cybersecurity, &lt;strong&gt;GTFOBins&lt;/strong&gt; is a curated catalog showing how standard Unix binaries can be bypassed to escape restricted shells or escalate privileges.&lt;/p&gt;

&lt;p&gt;Many standard utilities have built-in execution flags. When the binary runs with the SUID bit as root, whatever process it spawns runs with root authority.&lt;/p&gt;

&lt;p&gt;Because &lt;code&gt;find&lt;/code&gt; has an &lt;code&gt;-exec&lt;/code&gt; parameter, an attacker can spawn an unrestricted shell in one command:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ whoami
student

$ /usr/bin/find . -exec /bin/sh -p \&lt;span class="o"&gt;;&lt;/span&gt; -quit

&lt;span class="c"&gt;# whoami&lt;/span&gt;
root

&lt;span class="c"&gt;# id&lt;/span&gt;
&lt;span class="nv"&gt;uid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;student&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;gid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;student&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;euid&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;0&lt;span class="o"&gt;(&lt;/span&gt;root&lt;span class="o"&gt;)&lt;/span&gt; &lt;span class="nv"&gt;groups&lt;/span&gt;&lt;span class="o"&gt;=&lt;/span&gt;1001&lt;span class="o"&gt;(&lt;/span&gt;student&lt;span class="o"&gt;)&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;The &lt;code&gt;-p&lt;/code&gt; flag tells &lt;code&gt;/bin/sh&lt;/code&gt; to preserve effective user privileges (&lt;code&gt;euid=0&lt;/code&gt;). The user is now root. They can alter system files, create new administrative accounts, or dump credentials.&lt;/p&gt;




&lt;h3&gt;
  
  
  5. How Sysadmins Audit and Fix SUID Flaws
&lt;/h3&gt;

&lt;p&gt;Securing your systems against SUID escalation requires three basic defensive practices:&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 1: Run Weekly Audits
&lt;/h4&gt;

&lt;p&gt;Run this audit command to inventory all SUID files:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ sudo find / -perm -4000 -type f -exec ls -la &lt;span class="o"&gt;{&lt;/span&gt;&lt;span class="o"&gt;}&lt;/span&gt; + 2&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;/dev/null
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;If you see text editors (&lt;code&gt;vim&lt;/code&gt;, &lt;code&gt;nano&lt;/code&gt;), scripting interpreters (&lt;code&gt;python&lt;/code&gt;, &lt;code&gt;bash&lt;/code&gt;, &lt;code&gt;perl&lt;/code&gt;, &lt;code&gt;awk&lt;/code&gt;), or utilities (&lt;code&gt;find&lt;/code&gt;, &lt;code&gt;cp&lt;/code&gt;, &lt;code&gt;tar&lt;/code&gt;, &lt;code&gt;nmap&lt;/code&gt;), investigate immediately.&lt;/p&gt;

&lt;h4&gt;
  
  
  Step 2: Strip the SUID Bit
&lt;/h4&gt;

&lt;p&gt;To remove the SUID bit from a misconfigured binary, run:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;$ sudo chmod u-s /usr/bin/find
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Verify that the permissions return to standard &lt;code&gt;-rwxr-xr-x&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;$ ls -l /usr/bin/find
-rwxr-xr-x 1 root root 320160 /usr/bin/find
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;h4&gt;
  
  
  Step 3: Mount Temporary Partitions with nosuid
&lt;/h4&gt;

&lt;p&gt;Attackers frequently drop and compile custom SUID binaries inside world-writable directories like &lt;code&gt;/tmp&lt;/code&gt;.&lt;/p&gt;

&lt;p&gt;Add the &lt;code&gt;nosuid&lt;/code&gt; option to &lt;code&gt;/etc/fstab&lt;/code&gt; for temporary filesystems:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;tmpfs   /tmp        tmpfs   defaults,noexec,nosuid,nodev   0  0
tmpfs   /var/tmp    tmpfs   defaults,noexec,nosuid,nodev   0  0
tmpfs   /dev/shm    tmpfs   defaults,noexec,nosuid,nodev   0  0
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;When a partition is mounted with &lt;code&gt;nosuid&lt;/code&gt;, the Linux kernel ignores the SUID bit entirely, blocking this attack vector at the kernel level.&lt;/p&gt;




&lt;h3&gt;
  
  
  Source &amp;amp; Further Reading
&lt;/h3&gt;

&lt;blockquote&gt;
&lt;p&gt;🔗 &lt;strong&gt;Original Article &amp;amp; Interactive Cheatsheet:&lt;/strong&gt;&lt;br&gt;&lt;br&gt;
This tutorial is part of the Linux Hardening series on &lt;strong&gt;LinuxPedia&lt;/strong&gt;.&lt;br&gt;&lt;br&gt;
You can read the full interactive post with copyable shell snippets here:&lt;br&gt;&lt;br&gt;
&lt;strong&gt;&lt;a href="https://pedialinux.github.io/linuxpedia/linux-privilege-escalation-suid.html" rel="noopener noreferrer"&gt;Linux Privilege Escalation: SUID Binaries Explained (LinuxPedia)&lt;/a&gt;&lt;/strong&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;Related Guides on LinuxPedia:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;&lt;a href="https://pedialinux.github.io/linuxpedia/linux-server-hardening.html" rel="noopener noreferrer"&gt;5 Essential Steps to Harden a Linux Server in Production&lt;/a&gt;&lt;/li&gt;
&lt;li&gt;&lt;a href="https://pedialinux.github.io/linuxpedia/linux-ssh-bruteforce-fail2ban.html" rel="noopener noreferrer"&gt;SSH Brute-Force Attacks Explained: How Fail2ban Jails Hackers&lt;/a&gt;&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;&lt;strong&gt;Community Question:&lt;/strong&gt; Have you ever caught an unexpected SUID binary during an internal server audit? What tool was it? Let's discuss in the comments!&lt;/p&gt;

</description>
      <category>linux</category>
      <category>sysadmin</category>
      <category>security</category>
      <category>devops</category>
    </item>
  </channel>
</rss>
