Skip to content

Instantly share code, notes, and snippets.

@zed
Created November 13, 2011 09:37
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zed/1361886 to your computer and use it in GitHub Desktop.
Save zed/1361886 to your computer and use it in GitHub Desktop.
getuid() vs. geteuid() in Python
# checkout pyintaller
##svn co http://svn.pyinstaller.org/trunk pyinstaller && cd pyinstaller
# make Python script that prints uid, euid
printf '#!/usr/bin/env python\nimport os\nprint(os.getuid(),os.geteuid())\n' >print-uid.py
# create stand-alone executable
python pyinstaller.py -F print-uid.py
# change ownership to root
cd print-uid/dist
sudo chown root:root ./print-uid
# run as an ordinary user
./print-uid
# -> (1000, 1000) uid, euid are the same and non-root
# setuid
sudo chmod u+s ./print-uid
# run again
./print-uid
# -> (1000, 0) uid says it is an ordinary user, but euid points to root
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment