Alert icon Keyboard navigation enabled.
Alert icon TAB or Shift+TAB to navigate across. Down ↓ to open menu. ESC to close menu.
Alert icon Down ↓ to select section. Right → to activate. Up ↑ / Down ↓ / Tab to traverse all. ESC to exit.
BeyondTrust
Skip to content Use space or enter to skip.

What can we help you find today?

Instant Results
  • Website Results
  • Technical Documentation

Filter Options

Focus your search

Filtering by

Your recent searches:

Contact Us Chat with Sales Get Support
  • English
  • Deutsch
  • français
  • español
  • 한국어
  • português
  • Home
  • Resources
  • Blog
  • Linux Privilege Escalation: How an Attacker can Escalate from Low-Level Privileges to Root current page
Link copied

Linux Privilege Escalation: How an Attacker can Escalate from Low-Level Privileges to Root

Jan 13, 2020
Author:
Jay Beale 2021 Headshot
Jay Beale
CEO, CTO at InGuardians, Inc.
Blog banner default
Linux Privilege Escalation: How an Attacker can Escalate from Low-Level Privileges to Root
Jay Beale 2021 Headshot
Jay Beale
CEO, CTO at InGuardians, Inc.

In this demo-filled webinar on privilege escalation, I demonstrate how to hack five different Capture the Flag (CTF) Linux virtual machines. On each CTF virtual machine, I demonstrate a distinct method of escalating privilege in Linux. What makes these demonstrations particularly useful is that they don’t target a vulnerability that’s here today, patched tomorrow. An attacker can exploit these machines because of a configuration vulnerability, the likes of which will show up on systems for decades.

To keep this blog post interesting, even after you’ve watched the webinar, let’s explore a type of privilege escalation attack that isn’t demonstrated in the webcast.

Think of yourself here as an attacker who has just gained a low-privilege shell on a system. More specifically, you’ve compromised a web application with a remote code execution vulnerability and now you have a reverse shell running as the web server’s www-data user.

Suppose you run echo $PATH and notice your $PATH variable starts a single period “.” entry? That means that your bash shell will check the current directory for commands. Like, when you type “passwd” to change your password, the shell will run ./passwd (if it exists) instead of the system’s /usr/bin/passwd binary. However, this configuration isn’t useful to you unless other users share it too. So, you check out the files that define PATH variables for everyone on the system, files like: /etc/profile and /etc/bash.bashrc. You notice that one of these sets the PATH variable to include the current directory, with a “.” entry. As an “attacker”, that’s a great sign!

Next, you need to find a directory to which you can write. If a user or script ever had that directory as its current working directory, you’ll be able to gain the same privilege that user or script has. Suppose you take a look at /usr/local/sbin, where many sites put their custom scripts, and find scripts that are world-readable. You find one called “mirror-web-server.sh.” Here are the contents, which we’ll explain next:

#!/bin/bash

cd /var/www/html/

rsync -auv ./ www@disaster-recovery-web-server:/var/www/html/ --delete

This script switches into the /var/www/html directory, where the web server you just compromised gets its files to serve. It then runs a synchronization command that sends any new or updated files from the source machine to the destination machine, a web server in the company’s disaster recovery data center. Things like this are reasonably common, if kludgy, ways of maintaining a disaster recovery environment, or a simple backup.

Let’s imagine that you found this script mentioned in the /etc/cron.hourly crontab file. That means that this script is going to change directory into /var/www/html, to which you have write access, and run an rsync command. This normally causes the shell to execute “/usr/bin/rsync.” You create an rsync command in /var/www/html/ with these contents:

#!/bin/bash

echo “www-data ALL=(ALL) NOPASSWD:ALL“ >>/etc/sudoers

/usr/bin/rsync $*

This script will add the www-data user to the /etc/sudoers file, allowing that user to run any command as root, without having to enter any kind of password.

Set the script’s permissions to world-readable and executable:

chmod ugo+rx /var/www/html/rsync

Now, you’ve trojan-horsed the mirror-web-server.sh’s use of the rsync command. Wait an hour and you’ll find your www-data user can “sudo su” its way to root without a password!

If you enjoyed what you just learned in this blog, please check out my webinar Attacking and Defending Linux Systems – Privilege Escalation.

Other Linux Attack & Defense Webinars

Linux Attack and Defense: The Matrix

Linux Attack and Defense - Office Space Style!

Unix & Linux Server Security: 10 Best Practices

Blog

Unix & Linux Server Security: 10 Best Practices

Why is Log Integrity so Important for Unix & Linux Security?

Blog

Why is Log Integrity so Important for Unix & Linux Security?

Latest Posts
  • The Most Common & Most Dangerous Types of Shadow IT
    Jun 5, 2026 The Most Common & Most Dangerous Types of Shadow IT
    Blog
    19m
  • 14 Password Management Best Practices
    May 28, 2026 14 Password Management Best Practices
    Blog
    12m
  • A Security Researcher’s Guide to Understanding Copilot Studio AI Agents
    May 26, 2026 A Security Researcher’s Guide to Understanding Copilot Studio AI Agents
    Blog
    3m
  • How to Secure Cloud-Native Infrastructure at Scale and Speed: A Conversation with Madhu Adireddi
    May 21, 2026 How to Secure Cloud-Native Infrastructure at Scale and Speed: A Conversation with Madhu Adireddi
    Blog
    5m
  • Cybersecurity as a Boardroom Priority for Major African TelCos
    May 12, 2026 Cybersecurity as a Boardroom Priority for Major African TelCos
    Blog
    8m
Related
  • Recalibrating Your Data Security Model to Achieve Zero Trust for Government Agencies
    Mar 7, 2022 Recalibrating Your Data Security Model to Achieve Zero Trust for Government Agencies
    Blog
    1m
  • Why Identity Security Should Be the Basis of Modern Cybersecurity
    Apr 8, 2024 Why Identity Security Should Be the Basis of Modern Cybersecurity
    Blog
    1m
Share this Article
  • Link
Stay up to Date
Get the latest news, ideas, and tactics from BeyondTrust. You may unsubscribe at any time.

Keep up with BeyondTrust

Customer Support Get Started
  • LinkedIn
  • X
  • Facebook
  • Instagram
  • Add BeyondTrust as a preferred source on Google
  • Privacy
  • Security
  • Manage Cookies
  • Do Not Sell My Data
  • WEEE Compliance

Copyright © 2003 — 2026 BeyondTrust Corporation. All rights reserved. Other trademarks identified on this page are owned by their respective owners. BeyondTrust Corporation is not a chartered bank or trust company, or depository institution. It is not authorized to accept deposits or trust accounts and is not licensed or regulated by any state or federal banking authority.

Prefers reduced motion setting detected. Animations will now be reduced as a result.