Created
November 13, 2011 09:37
-
-
Save zed/1361886 to your computer and use it in GitHub Desktop.
getuid() vs. geteuid() in Python
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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