subprocess.call(..., user=xx, group=xxx) is not able to gain privileges
Đang mở
Chưa có ai nhận issue này.
stdlib
topic-subprocess
type-bug
- Ngôn ngữ chính
- Python
- Star
- 77.2k
- Fork
- 36k
- Chỉ số merge pull request
- Chỉ số pull request đang chờ
Mô tả
#!/usr/bin/python3
from os import getresuid, initgroups, setresgid, setresuid
from pwd import getpwnam
from subprocess import check_call
def drop_permissions():
user = 'nobody'
info = getpwnam(user)
uid = info.pw_uid
gid = info.pw_gid
assert uid
assert gid
initgroups(user, gid)
setresgid(gid, gid, gid)
setresuid(uid, uid, 0)
def run_privileged_proc():
def restore():
setresuid(0, 0, 0)
setresgid(0, 0, 0)
initgroups('root', 0)
check_call(['id'], preexec_fn=restore)
def main():
assert getresuid() == (0, 0, 0)
# This on works (dropping permissions in child process)
check_call(['id'], user=65534, group=65534)
drop_permissions()
# This one works:
run_privileged_proc()
# This does not:
check_call(['id'], user=0, group=0)
main()
for the last subprocess, strace of child process:
set_robust_list(0x7eff7bfaea20, 24) = 0
close(7) = 0
close(9) = 0
close(11) = 0
dup2(6, 0) = 0
dup2(8, 1) = 1
dup2(10, 2) = 2
rt_sigaction(SIGPIPE, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7eff7b83ea30}, {sa
rt_sigaction(SIGXFSZ, {sa_handler=SIG_DFL, sa_mask=[], sa_flags=SA_RESTORER|SA_ONSTACK, sa_restorer=0x7eff7b83ea30}, {sa
setgroups(0, []) = -1 EPERM (Операция не позволена)
write(12, "OSError:", 8) = 8
write(12, "1", 1) = 1
write(12, ":", 1) = 1
write(12, "noexec", 6) = 6
exit_group(255) = ?
+++ exited with 255 +++
Python 3.10.7
Linked PRs
- gh-134400
Hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Hướng nghiên cứu
Bắt đầu với các lệnh gọi subprocess.check_call sử dụng user, group và preexec_fn, sau đó so sánh hành vi của các lệnh gọi này đối với tiến trình con với đầu ra strace được cung cấp. Được xem là hoàn tất khi subprocess có đặc quyền cuối cùng có thể chạy thành công sau khi các quyền đã bị hạ xuống; issue cũng liệt kê PR được liên kết gh-134400.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Đánh giá
- Công nghệ
- python
- Lĩnh vực
- operating-systems
- Loại issue
- Lỗi
- Độ khó
- 4/5
- Thời gian dự kiến
- 3-5 ngày
- Mức độ hoạt động
- Đình trệ
- Độ rõ ràng
- Cần làm rõ
- Mức phù hợp với người mới
- 25/100