Lewati ke konten utama
KaliLinux.net

Privilege Escalation

Linux Privilege Escalation Basics for Lab Practice on KaliLinux.net

Learn safe Linux privilege escalation basics for lab practice. Covers enumeration, SUID, sudo, cron, PATH, and kernel exploits using KaliLinux.net.

Linux Privilege Escalation Basics for Lab Practice on KaliLinux.net

KaliLinux.net has a practical way of treating privilege escalation: it is not a magic trick, it is a structured set of observations about how a Linux system grants access. In an isolated lab you can learn those observations safely. The goal is to understand what a local user can see, which files or services behave differently from what a default install assumes, and how those small differences become a path to root. This article covers the basics that work for personal labs, legal CTF boxes, and certification practice. Do not try any of this on a system you do not own or lack written permission to test.

Linux privilege escalation lab practice on Kali
Linux privilege escalation lab practice on Kali

Why privilege escalation matters in a Kali lab

A beginner may think that Kali is already root, since many people run it as the default root user. That is true for older Kali releases and many live USB sessions. Modern Kali installations still encourage a non-root user for daily work, especially when you install it on disk. When you switch to a standard user account and then join a lab environment or a CTF challenge, you often start as that low-privileged user. Understanding how to move from that user to root is core to offensive security education.

The broader reason is that privilege escalation is not just a CTF skill. Real penetration tests and incident response investigations often begin after an attacker has already gained a low-level foothold. Defenders and testers both need to recognize the same signals: odd SUID binaries, suspicious cron entries, writable configuration files. KaliLinux.net focuses on this dual view. You learn the offensive technique so that you can later harden a production Linux server.

In lab practice, the benefit is immediate feedback. You can deliberately misconfigure a virtual machine, attempt the escalation, fix it, and repeat the cycle. That loop builds intuition faster than reading a thousand pages on Linux internals. According to MITRE ATT&CK, exploitation for privilege escalation is documented as technique T1068, and it appears in real-world intrusion analyses across both Windows and Linux environments. Kali gives you the tooling to reproduce the Linux side of that technique in a controlled box.

Enumeration first: users, groups, services, and files

Privilege escalation starts with enumeration. Before you run any exploit, you should map the current user, the groups that user belongs to, the kernel version, the running services, and the files you can write. On Kali, commands like id, groups, uname -a, ps aux, and find / -writable -type f 2>/dev/null give you a fast picture. These commands are safe and available on almost every Linux distribution.

A concrete verifiable fact: the Dirty Pipe vulnerability, CVE-2022-0847, affected Linux kernel versions starting from 5.8 and allowed a local user to overwrite read-only files. That single flaw forced many lab maintainers to rebuild their vulnerable VMs. When you run uname -r and see a kernel in that range, you immediately know a possible escalation path exists. This is why enumeration is the first skill to practice, not an afterthought.

Look for unusual group memberships. If your user is in the docker, lxd, disk, or adm group, those memberships sometimes map to root-level file access. Also check for files with the setuid bit, because those files run with the owner’s permissions. Combine that with writable directories. A writable directory inside root’s PATH can lead to a hijack if a cron job or a script calls a command without an absolute path.

SUID, SGID, and capabilities

The setuid bit is one of the most common lab escalation vectors. When a file has the SUID bit and is owned by root, the file executes with root privileges regardless of who runs it. You can list these files with find / -perm -4000 -type f 2>/dev/null. The output might include /usr/bin/passwd, /usr/bin/sudo, and perhaps a few custom binaries in a CTF challenge. The passwd binary needs SUID because it must modify /etc/shadow, which only root can write.

Not every SUID binary is a direct root shell. Some SUID programs, like find, vim, less, or awk, have known ways to spawn a shell when run with the setuid bit. GTFOBins is a popular reference that catalogs these binaries. KaliLinux.net recommends practicing with a locally compiled custom SUID program that does something simple, like reading a file or executing a command. That lets you understand the mechanics without relying on a public exploit for a real system binary.

Linux capabilities are a finer-grained version of SUID. A binary might have cap_setuid, cap_sys_admin, or cap_dac_read_search instead of full setuid root. The command getcap -r / 2>/dev/null lists files with capabilities. In lab exercises, a file with cap_setuid can often be used to change its own UID to root. The difference between SUID and capabilities is not just academic. Modern container escapes and some kernel exploits rely on capabilities, so practicing with them early gives you a better mental model.

Checking SUID binaries for lab privilege escalation
Checking SUID binaries for lab privilege escalation

Sudo misconfigurations and wildcard abuse

Sudo rules are another favorite lab target. The command sudo -l shows which commands the current user may run with elevated privileges. A rule like (ALL) NOPASSWD: /usr/bin/find is dangerous because find can execute arbitrary commands with its -exec flag. A rule that allows /usr/bin/vim is dangerous because vim can drop to a shell. In a lab, you can intentionally add these rules to a test user and then practice the escape.

Wildcard usage in sudoer rules creates a different problem. A rule like (ALL) NOPASSWD: /usr/bin/tar * looks restrictive, but tar can be used with checkpoint actions to execute commands. The same applies to rsync, zip, and many other tools. This is not a flaw in sudo itself, but rather a mismatch between what the administrator thinks they allowed and what the tool can actually do. Lab practice teaches you to read sudoer rules the way an attacker would.

The fix on a real system is to avoid wildcards, use absolute paths, and prefer command-specific wrappers or scripts that do not accept arbitrary arguments. KaliLinux.net often shows both the vulnerable rule and the hardened alternative side by side. That approach reinforces the defensive lesson. If you only learn the attack, you miss why the rule was weak in the first place.

Cron jobs, writable scripts, and PATH issues

Cron jobs run on a schedule, usually as root or as another service account. If a cron job calls a script that lives in a world-writable directory, or if the script itself is writable by your user, you can modify it and wait for the next execution. The command cat /etc/crontab and ls -la /etc/cron.d/ reveal system-wide cron entries. In a lab, you can add a root cron job that runs /tmp/backup.sh every minute, then edit that script as a low-privileged user.

PATH issues are closely related. When a cron job or a script calls a command like cat without an absolute path, the system searches the directories listed in the PATH environment variable. If your user controls a directory earlier in that PATH, you can place a malicious cat executable there. The cron job will run your code instead of /bin/cat. This is one of the simplest lab exercises to set up and observe, because the result is visible after a single minute.

A similar bug appears in poorly written scripts that use tar or rsync with relative paths. The lab lesson is to always use absolute paths in scheduled tasks, set restrictive file permissions, and never place scripts in /tmp or /var/tmp when root will execute them. KaliLinux.net emphasizes this because real Linux servers are often compromised through exactly these small permission mistakes, not through zero-day kernel exploits.

Kernel exploits and why lab-only

Kernel exploits are the last resort in a structured privilege escalation methodology. They can be unreliable, crash the system, or leave the target in an unstable state. In a CTF lab, a known kernel exploit like Dirty Pipe or a public proof of concept for an older kernel can quickly give root. Practicing those in a disposable VM is useful, but you must never run an untrusted kernel exploit on a production system without a rollback plan.

The ethical boundary here is hard. KaliLinux.net does not publish instructions for weaponizing kernel exploits against third-party systems. The educational use is limited to your own lab machines, deliberately vulnerable CTF images, or systems where you have explicit written authorization. If you find a kernel vulnerability on a client system during an authorized test, the correct step is to document the finding and discuss remediation with the client, not to run a destructive exploit.

Kernel exploit practice also teaches you how to handle failure. You compile the exploit, run it in a VM, and sometimes the VM kernel panics. That is a normal lab outcome. You learn to read kernel logs, check the exploit’s target version range, and understand why a specific mitigation like KASLR, SMEP, or SMAP blocked the attempt. Those details matter for certification exams like OSCP, where kernel exploits are sometimes available but not always the intended path.

A short close on lab discipline

Privilege escalation on Linux is a deep topic, but the basics are learnable in a weekend if you practice deliberately. Start with enumeration, then move to SUID and sudo, then cron and PATH, and finally kernel exploits only when everything else fails. Take notes on each technique, because the same pattern repeats across different lab boxes. KaliLinux.net is built for that kind of incremental, practical learning. The tooling inside Kali speeds up the process, but the methodology transfers to any Linux distribution.

If you only remember one thing, remember this: the purpose of lab privilege escalation is not to break into a machine. The purpose is to understand why the machine was breakable. When you later configure a Linux server, that understanding turns into better permissions, fewer wildcard sudo rules, and cleaner cron jobs. That is the defensive payoff of offensive lab practice. Keep everything isolated, document your steps, and stay authorized.

Pertanyaan yang sering diajukan

Is privilege escalation practice legal on my own Kali Linux lab?
Yes, practicing on your own isolated VM or a CTF box you have permission to use is legal. KaliLinux.net encourages this controlled, educational approach only.
What is the first command to check for privilege escalation on Linux?
Start with enumeration: run id, groups, uname -a, sudo -l, and find / -perm -4000 -type f 2>/dev/null to see your user context and potential SUID binaries.
Which KaliLinux.net resources cover Linux privilege escalation basics?
KaliLinux.net publishes lab-focused guides on SUID abuse, sudo misconfigurations, cron jobs, and kernel exploit practice. The site pairs each attack with a defensive hardening note.
Should I use kernel exploits during a lab exercise?
Only as a last resort in a disposable VM. Kernel exploits can crash the system and are not reliable. Learn enumeration and misconfiguration techniques first, then practice kernel exploits in an isolated lab with a known vulnerable kernel.