Created
December 19, 2018 14:29
-
-
Save brianv0/5eb12c3a2271e5a183f79591f56e0e6d to your computer and use it in GitHub Desktop.
FS setuid python
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
| from cffi import FFI | |
| import os | |
| ffi = FFI() | |
| ffi.cdef(""" | |
| int setfsuid(int fsuid); | |
| int getgroups(int fsuid, int[]); | |
| int setgroups(int size, const int *list); | |
| """) | |
| sys = ffi.dlopen(None) | |
| def setfsuid(uid): | |
| return sys.setfsuid(ffi.cast("int", uid)) | |
| def getgroups(): | |
| ptr = ffi.new("int[]", []) | |
| size = sys.getgroups(ffi.cast("int", 0), ptr) | |
| ret_val = ffi.new("int[]", size) | |
| sys.getgroups(size, ret_val) | |
| return ret_val | |
| def setgroups(groups): | |
| new_groups = ffi.new("const int[]", groups) | |
| size = sys.setgroups(len(new_groups), new_groups) | |
| return size | |
| setfsuid(1000) | |
| setfsuid(1000) | |
| print(os.getuid()) | |
| print(os.getgroups()) | |
| print(getgroups()) | |
| setgroups([1000, 1001]) | |
| print(os.getgroups()) | |
| print(getgroups()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment