Created
March 1, 2011 02:41
-
-
Save sorin-ionescu/848498 to your computer and use it in GitHub Desktop.
Ruby privilege de-escalation.
This file contains hidden or 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
| if ENV['USER'] == 'root' | |
| puts "uid: #{Process::UID.rid} euid: #{Process::UID.eid} gid: #{Process::GID.rid} egid: #{Process::GID.eid}" | |
| fork do | |
| begin | |
| uid, gid = Process.euid, Process.egid | |
| target_uid, target_gid = ENV['SUDO_UID'].to_i, ENV['SUDO_GID'].to_i | |
| if uid != target_uid or gid != target_gid | |
| Process.initgroups(ENV['SUDO_USER'], target_gid) | |
| Process::GID.change_privilege(target_gid) | |
| Process::UID.change_privilege(target_uid) | |
| end | |
| rescue Errno::EPERM => e | |
| exit 1 | |
| end | |
| puts "uid: #{Process::UID.rid} euid: #{Process::UID.eid} gid: #{Process::GID.rid} egid: #{Process::GID.eid}" | |
| # DO STUFF HERE | |
| end | |
| puts "uid: #{Process::UID.rid} euid: #{Process::UID.eid} gid: #{Process::GID.rid} egid: #{Process::GID.eid}" | |
| end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment