Skip to main content

4000

SUID (Set User ID)

SUID grants a file the ability to execute with file owner's privileges, not the user running it. In WordPress VPS context, it is **rarely required and usually a **security risk if misused.

Objective

Understand SUID (4000), how it works, when to use/avoid it, and security considerations for WordPress VPS.

Core Concept

  • Regular permission code: **rwx defines what a user can do.
  • **SUID adds execution privilege escalation to the owner level during runtime.

Meaning of 4 in first digit:

DigitMeaning
4Enable SUID bit

Pattern

4xyz

Where xyz = standard file permission digits.

Example:

4755

= SUID + 755

Syntax Formula

Set SUID

chmod 4xxx filename

Remove SUID

chmod u-s filename

Check SUID files

find / -perm -4000 2>/dev/null

Indicator in File Listing

Command

ls -l file

Output Pattern

-rwsr-xr-x

Key indicator: **s replacing **x in owner field.

Real Examples with Output

Example 1: Apply SUID

chmod 4755 /usr/local/bin/custom-script
ls -l /usr/local/bin/custom-script

Expected Output

-rwsr-xr-x 1 root root ... custom-script

Example 2: Check common SUID binaries

ls -l /usr/bin/passwd

Expected Output

-rwsr-xr-x 1 root root ... passwd

Use Case Patterns

Use CaseValid?Notes
Privilege escalation for trusted binariespasswd, sudo, ping etc.
WordPress/PHP scriptsSecurity risk
WP plugin filesNever
User-uploaded filesCritical risk
Maintenance scripts (rare, controlled)Only internal admin scripts

WordPress VPS Scenarios

ScenarioRecommendation
Custom backup script needs root files accessAvoid — use sudoers instead
WP site management scriptsNever use SUID
Server admin automationUse root cron / sudo, not SUID
Temporary escalate permission for service scriptDo only with audit & policy

Security Considerations

Risks

ThreatDescription
Privilege EscalationUntrusted script becomes root
BackdoorsMalware sets SUID on shells
Privilege abuseUser can modify and escalate

Detection & Response

Check risky SUID executables

find / -perm -4000 2>/dev/null

Remove SUID

chmod u-s file

Monitor for new SUID files

(best practice: cron with diff+alert)

Best Practices

  • Do **not use SUID for web-facing scripts
  • Restrict SUID to known system binaries
  • Audit SUID weekly on production server
  • Prefer **sudo rules instead:
  • safer
  • controlled
  • logs access

Example sudoers rule:

visudo

Add:

wpadmin ALL=(root) NOPASSWD: /usr/local/bin/wp-maintenance.sh

WordPress-Focused Quick Audit

Scan WP home directory for SUID (should be zero)

find /home -perm -4000

Correct if found

chmod u-s /path/file

Go-Live Checklist

ItemStatus
Verify no SUID on wp-content
Verify only system binaries use SUID
Sudoers rules audited
Root scripts owned by root
Cron task monitors SUID changes

Troubleshooting Matrix

IssueCauseFix
Unexpected root accessSUID applied wronglychmod u-s file
"Permission denied" after removalScript relied on SUIDUse sudoer policy
Malware alert on SUID binaryBackdoor attemptRemove + scan system

Quick Lab

Exercise

  1. Create dummy script
echo '#!/bin/bash
id' > test.sh
chmod +x test.sh

  1. Run normally
./test.sh

Expected:

uid=1001(...)

  1. Enable SUID
chmod 4755 test.sh
./test.sh

Expected:

uid=0(root)

  1. Remove SUID
chmod u-s test.sh

Cheat Sheet

CommandPurpose
chmod 4xxx fileApply SUID
chmod u-s fileRemove SUID
find / -perm -4000Scan SUID files
ls -l fileVerify s bit

Mini-Quiz

QuestionAnswer
What does 4 mean in 4755?SUID enabled
Where does SUID apply? File or directory?File
Safe for WordPress PHP files?No
Indicator in ls output?s in owner execute flag